Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
decoderstests.cpp
Go to the documentation of this file.
1 
5 #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
6 #include <dcc.h>
7 #include <doctest.h>
8 using WorldStone::DCC;
11 
16 TEST_CASE("DCC decoding BaalSpirit.dcc")
17 {
18  DCC dcc;
19  REQUIRE(dcc.initDecoder(std::make_unique<FileStream>("BaalSpirit.dcc")));
20  // clang-format off
21  const DCC::Header& header = dcc.getHeader();
22 
23  CHECK(header.signature == 116);
24  CHECK(header.version == 6);
25  CHECK(header.directions == 1);
26  CHECK(header.framesPerDir == 200);
27  CHECK(header.tag == 1);
28  CHECK(header.finalDc6Size == 547757);
29 
30  DCC::Direction dir0;
31  SimpleImageProvider<uint8_t> imgProvider;
32  REQUIRE(dcc.readDirection(dir0, 0, imgProvider));
33 
34  CHECK(dir0.header.outsizeCoded == 546933);
35  CHECK(dir0.header.hasRawPixelEncoding == false);
36  CHECK(dir0.header.compressEqualCells == true);
37  CHECK(dir0.header.variable0Bits == 0);
38  CHECK(dir0.header.widthBits == 5);
39  CHECK(dir0.header.heightBits == 5);
40  CHECK(dir0.header.xOffsetBits == 5);
41  CHECK(dir0.header.yOffsetBits == 5);
42  CHECK(dir0.header.optionalBytesBits == 0);
43  CHECK(dir0.header.codedBytesBits == 9);
44 
45  CHECK(dir0.extents.xLower == -51);
46  CHECK(dir0.extents.yLower == -178);
47  CHECK(dir0.extents.xUpper == (143+1));
48  CHECK(dir0.extents.yUpper == (45+1));
49  CHECK(dir0.extents.width() == 195);
50  CHECK(dir0.extents.height() == 224);
51  // clang-format on
52 }
53 
57 TEST_CASE("DCC decoding CRHDBRVDTHTH.dcc")
58 {
59  DCC dcc;
60  REQUIRE(dcc.initDecoder(std::make_unique<FileStream>("CRHDBRVDTHTH.dcc")));
61  // clang-format off
62  const DCC::Header& header = dcc.getHeader();
63 
64  CHECK(header.signature == 116);
65  CHECK(header.version == 6);
66  CHECK(header.directions == 8);
67  CHECK(header.framesPerDir == 24);
68  CHECK(header.tag == 1);
69  CHECK(header.finalDc6Size == 59600);
70 
71  DCC::Direction dir0;
72  SimpleImageProvider<uint8_t> imgProvider;
73  REQUIRE(dcc.readDirection(dir0, 0, imgProvider));
74 
75  CHECK(dir0.header.outsizeCoded == 7225);
76  CHECK(dir0.header.hasRawPixelEncoding == true);
77  CHECK(dir0.header.compressEqualCells == true);
78  CHECK(dir0.header.variable0Bits == 0);
79  CHECK(dir0.header.widthBits == 4);
80  CHECK(dir0.header.heightBits == 4);
81  CHECK(dir0.header.xOffsetBits == 4);
82  CHECK(dir0.header.yOffsetBits == 5);
83  CHECK(dir0.header.optionalBytesBits == 0);
84  CHECK(dir0.header.codedBytesBits == 6);
85 
86  CHECK(dir0.extents.xLower == -12);
87  CHECK(dir0.extents.yLower == -75);
88  CHECK(dir0.extents.xUpper == (46+1));
89  CHECK(dir0.extents.yUpper == (-15+1));
90  CHECK(dir0.extents.width() == 59);
91  CHECK(dir0.extents.height() == 61);
92  // clang-format on
93 }
94 
99 TEST_CASE("DCC decoding BloodSmall01.dcc")
100 {
101  DCC dcc;
102  REQUIRE(dcc.initDecoder(std::make_unique<FileStream>("BloodSmall01.dcc")));
103  // clang-format off
104  const DCC::Header& header = dcc.getHeader();
105 
106  CHECK(header.signature == 116);
107  CHECK(header.version == 6);
108  CHECK(header.directions == 8);
109  CHECK(header.framesPerDir == 9);
110  CHECK(header.tag == 1);
111  CHECK(header.finalDc6Size == 14200);
112 
113  DCC::Direction dir0;
114  SimpleImageProvider<uint8_t> imgProvider;
115  REQUIRE(dcc.readDirection(dir0, 0, imgProvider));
116 
117  CHECK(dir0.header.outsizeCoded == 1776);
118  CHECK(dir0.header.hasRawPixelEncoding == false);
119  CHECK(dir0.header.compressEqualCells == false);
120  CHECK(dir0.header.variable0Bits == 0);
121  CHECK(dir0.header.widthBits == 4);
122  CHECK(dir0.header.heightBits == 4);
123  CHECK(dir0.header.xOffsetBits == 4);
124  CHECK(dir0.header.yOffsetBits == 5);
125  CHECK(dir0.header.optionalBytesBits == 0);
126  CHECK(dir0.header.codedBytesBits == 6);
127 
128  CHECK(dir0.extents.xLower == -18);
129  CHECK(dir0.extents.yLower == -44);
130  CHECK(dir0.extents.xUpper == (13+1));
131  CHECK(dir0.extents.yUpper == (9+1));
132  CHECK(dir0.extents.width() == 32);
133  CHECK(dir0.extents.height() == 54);
134  // clang-format on
135 }
136 
140 TEST_CASE("DCC decoding HZTRLITA1HTH.dcc")
141 {
142  DCC dcc;
143  REQUIRE(dcc.initDecoder(std::make_unique<FileStream>("HZTRLITA1HTH.dcc")));
144  // clang-format off
145  const DCC::Header& header = dcc.getHeader();
146 
147  CHECK(header.signature == 116);
148  CHECK(header.version == 6);
149  CHECK(header.directions == 8);
150  CHECK(header.framesPerDir == 12);
151  CHECK(header.tag == 1);
152  CHECK(header.finalDc6Size == 92732);
153 
154  DCC::Direction dir;
155  SimpleImageProvider<uint8_t> imgProvider;
156  REQUIRE(dcc.readDirection(dir, 0, imgProvider));
157 
158  CHECK(dir.header.outsizeCoded == 10923);
159  CHECK(dir.header.hasRawPixelEncoding == false);
160  CHECK(dir.header.compressEqualCells == true);
161  CHECK(dir.header.variable0Bits == 0);
162  CHECK(dir.header.widthBits == 4);
163  CHECK(dir.header.heightBits == 4);
164  CHECK(dir.header.xOffsetBits == 4);
165  CHECK(dir.header.yOffsetBits == 1);
166  CHECK(dir.header.optionalBytesBits == 0);
167  CHECK(dir.header.codedBytesBits == 6);
168 
169  CHECK(dir.extents.xLower == -22);
170  CHECK(dir.extents.yLower == -62);
171  CHECK(dir.extents.xUpper == (33+1));
172  CHECK(dir.extents.yUpper == (-1+1));
173  CHECK(dir.extents.width() == 56);
174  CHECK(dir.extents.height() == 62);
175 
176  REQUIRE(dcc.readDirection(dir, 4, imgProvider));
177 
178  CHECK(dir.header.outsizeCoded == 9774);
179  CHECK(dir.header.hasRawPixelEncoding == false);
180  CHECK(dir.header.compressEqualCells == true);
181  CHECK(dir.header.variable0Bits == 0);
182  CHECK(dir.header.widthBits == 4);
183  CHECK(dir.header.heightBits == 4);
184  CHECK(dir.header.xOffsetBits == 1);
185  CHECK(dir.header.yOffsetBits == 1);
186  CHECK(dir.header.optionalBytesBits == 0);
187  CHECK(dir.header.codedBytesBits == 6);
188 
189  CHECK(dir.extents.xLower == -1);
190  CHECK(dir.extents.yLower == -62);
191  CHECK(dir.extents.xUpper == (22+1));
192  CHECK(dir.extents.yUpper == (-1+1));
193  CHECK(dir.extents.width() == 24);
194  CHECK(dir.extents.height() == 62);
195  // clang-format on
196 }
bool readDirection(Direction &outDir, uint32_t dirIndex, IImageProvider< uint8_t > &imgProvider)
Decodes a direction of the file into memory.
Definition: dcc.cpp:618
Decoder for the DCC image format.
Definition: dcc.h:46
const Header & getHeader() const
Returns the header of the file read by extractHeaderAndOffsets.
Definition: dcc.h:203
A simple image provider that allocates a new buffer for each call to getNewImage() ...
Definition: ImageView.h:140
TEST_CASE("DCC decoding BaalSpirit.dcc")
Try to decode BaalSpirit.dcc.
Wrapper around POSIX file io, same as ifstream but without iostream formatting.
Definition: FileStream.h:16
Implementation of a DCC file decoder.
bool initDecoder(StreamPtr &&streamPtr)
Start decoding the stream and preparing data.
Definition: dcc.cpp:44