RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
BitStreamerJPEGTest.cpp
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2018 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
22#include "adt/Array1DRef.h"
23#include "adt/Casts.h"
25#include "io/Buffer.h"
26#include "io/ByteStream.h"
27#include "io/Endianness.h"
28#include <array>
29#include <cstdint>
30#include <gtest/gtest.h>
31
37
38namespace rawspeed_test {
39
40namespace {
41
42struct InvOnesTag;
43struct OnesTag;
44struct SaturatedTag;
45
46template <>
47const std::array<uint8_t, 8> Pattern<BitStreamerJPEG, OnesTag>::Data = {
48 {/* [Byte0 Byte1 Byte2 Byte3] */
49 /* Byte: [Bit0 .. Bit7] */
50 0b10100100, 0b01000010, 0b00001000, 0b00011111}};
51template <> uint32_t Pattern<BitStreamerJPEG, OnesTag>::data(int index) {
52 const auto set = GenOnesBE(1, 0);
53 return set[index];
54}
55
56template <>
57const std::array<uint8_t, 8> Pattern<BitStreamerJPEG, InvOnesTag>::Data = {
58 {0b11010010, 0b00100001, 0b00000100, 0b00001111}};
59template <> uint32_t Pattern<BitStreamerJPEG, InvOnesTag>::data(int index) {
60 const auto set = GenOnesBE(0, -1);
61 return set[index];
62}
63
64// If 0xFF0x00 byte sequence is found, it is just 0xFF, i.e. 0x00 is ignored.
65// So if we want 0xFF, we need to append 0x00 byte
66template <>
67const std::array<uint8_t, 8> Pattern<BitStreamerJPEG, SaturatedTag>::Data{
68 {uint8_t(~0U), 0, uint8_t(~0U), 0, uint8_t(~0U), 0, uint8_t(~0U), 0}};
69
70INSTANTIATE_TYPED_TEST_SUITE_P(JPEG, BitStreamerTest,
71 Patterns<BitStreamerJPEG>);
72
73TEST(BitStreamerJPEGTest, 0xFF0x00Is0xFFTest) {
74 // If 0xFF0x00 byte sequence is found, it is just 0xFF, i.e. 0x00 is ignored.
75 static const std::array<uint8_t, 2 + 8> data{
76 {0xFF, 0x00, 0b10100100, 0b01000010, 0b00001000, 0b00011111}};
77
79 data.data(), rawspeed::implicit_cast<int>(data.size()));
80
81 BitStreamerJPEG p(input);
82
83 ASSERT_EQ(p.getBits(8), 0xFF);
84
85 for (int len = 1; len <= 7; len++)
86 ASSERT_EQ(p.getBits(len), 1) << " Where len: " << len;
87}
88
89TEST(BitStreamerJPEGTest, 0xFF0xXXIsTheEndTest) {
90 // If 0xFF0xXX byte sequence is found, where XX != 0, then it is the end.
91 for (uint8_t end = 0x01; end < 0xFF; end++) {
92 static const std::array<uint8_t, 2 + 8> data{
93 {0xFF, end, 0xFF, 0xFF, 0xFF, 0xFF}};
94
96 data.data(), rawspeed::implicit_cast<int>(data.size()));
97
98 BitStreamerJPEG p(input);
99
100 for (int cnt = 0; cnt <= 64 + 32 - 1; cnt++)
101 ASSERT_EQ(p.getBits(1), 0);
102 }
103}
104
105} // namespace
106
107} // namespace rawspeed_test
INSTANTIATE_TYPED_TEST_SUITE_P(JPEG, BitStreamerTest, Patterns< BitStreamerJPEG >)
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32