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
21
#include "
bitstreams/BitStreamerJPEG.h
"
22
#include "
adt/Array1DRef.h
"
23
#include "
adt/Casts.h
"
24
#include "
bitstreams/BitStreamerTest.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
32
using
rawspeed::BitStreamerJPEG
;
33
using
rawspeed::Buffer
;
34
using
rawspeed::ByteStream
;
35
using
rawspeed::DataBuffer
;
36
using
rawspeed::Endianness
;
37
38
namespace
rawspeed_test
{
39
40
namespace
{
41
42
struct
InvOnesTag;
43
struct
OnesTag;
44
struct
SaturatedTag;
45
46
template
<>
47
const
std::array<uint8_t, 8> Pattern<BitStreamerJPEG, OnesTag>::Data = {
48
{
/* [Byte0 Byte1 Byte2 Byte3] */
49
/* Byte: [Bit0 .. Bit7] */
50
0b10100100, 0b01000010, 0b00001000, 0b00011111}};
51
template
<>
uint32_t
Pattern<BitStreamerJPEG, OnesTag>::data(
int
index) {
52
const
auto
set = GenOnesBE(1, 0);
53
return
set[index];
54
}
55
56
template
<>
57
const
std::array<uint8_t, 8> Pattern<BitStreamerJPEG, InvOnesTag>::Data = {
58
{0b11010010, 0b00100001, 0b00000100, 0b00001111}};
59
template
<>
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
66
template
<>
67
const
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
70
INSTANTIATE_TYPED_TEST_SUITE_P
(JPEG, BitStreamerTest,
71
Patterns<BitStreamerJPEG>);
72
73
TEST
(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
78
const
rawspeed::Array1DRef<const uint8_t>
input(
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
89
TEST
(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
95
const
rawspeed::Array1DRef<const uint8_t>
input(
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
Array1DRef.h
BitStreamerJPEG.h
BitStreamerTest.h
Buffer.h
ByteStream.h
Casts.h
Endianness.h
rawspeed::Array1DRef
Definition
Array1DRef.h:32
rawspeed::BitStreamerJPEG
Definition
BitStreamerJPEG.h:84
rawspeed::Buffer
Definition
Buffer.h:47
rawspeed::ByteStream
Definition
ByteStream.h:43
rawspeed::DataBuffer
Definition
Buffer.h:133
uint32_t
rawspeed_test::anonymous_namespace{BitStreamerJPEGTest.cpp}::INSTANTIATE_TYPED_TEST_SUITE_P
INSTANTIATE_TYPED_TEST_SUITE_P(JPEG, BitStreamerTest, Patterns< BitStreamerJPEG >)
rawspeed_test::anonymous_namespace{BitStreamerJPEGTest.cpp}::TEST
TEST(BitStreamerJPEGTest, 0xFF0x00Is0xFFTest)
Definition
BitStreamerJPEGTest.cpp:73
rawspeed_test
Definition
BitTest.cpp:38
rawspeed::implicit_cast
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition
Casts.h:32
rawspeed::Endianness
Endianness
Definition
Endianness.h:31
test
librawspeed
bitstreams
BitStreamerJPEGTest.cpp
Generated by
1.15.0