32 #define HNM4_CHUNK_ID_PL 19536
33 #define HNM4_CHUNK_ID_IZ 23113
34 #define HNM4_CHUNK_ID_IU 21833
35 #define HNM4_CHUNK_ID_SD 17491
54 *bitbuf = bytestream2_get_le32(gb);
70 uint32_t bitbuf = 0, writeoffset = 0, count = 0;
78 if (
getbit(&gb, &bitbuf, &bits)) {
81 "Attempting to write out of bounds");
84 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
86 if (
getbit(&gb, &bitbuf, &bits)) {
87 word = bytestream2_get_le16(&gb);
89 offset = (word >> 3) - 0x2000;
91 count = bytestream2_get_byte(&gb);
95 count =
getbit(&gb, &bitbuf, &bits) * 2;
96 count +=
getbit(&gb, &bitbuf, &bits);
97 offset = bytestream2_get_byte(&gb) - 0x0100;
100 offset += writeoffset;
101 if (offset < 0 || offset + count >= hnm->
width * hnm->
height) {
104 }
else if (writeoffset + count >= hnm->
width * hnm->
height) {
106 "Attempting to write out of bounds");
119 uint32_t x, y, src_x, src_y;
121 for (y = 0; y < hnm->
height; y++) {
123 src_x = src_y * hnm->
width + (y % 2);
124 for (x = 0; x < hnm->
width; x++) {
138 for (y = 0; y < hnm->
height; y++) {
139 memcpy(dst, src, hnm->
width);
149 uint32_t writeoffset = 0, count, left, offset;
150 uint8_t tag, previous, backline, backward, swap;
155 count = bytestream2_peek_byte(&gb) & 0x1F;
157 tag = bytestream2_get_byte(&gb) & 0xE0;
160 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
161 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
162 }
else if (tag == 1) {
163 writeoffset += bytestream2_get_byte(&gb) * 2;
164 }
else if (tag == 2) {
165 count = bytestream2_get_le16(&gb);
167 writeoffset += count;
168 }
else if (tag == 3) {
169 count = bytestream2_get_byte(&gb) * 2;
171 hnm->
current[writeoffset++] = bytestream2_peek_byte(&gb);
179 previous = bytestream2_peek_byte(&gb) & 0x20;
180 backline = bytestream2_peek_byte(&gb) & 0x40;
181 backward = bytestream2_peek_byte(&gb) & 0x80;
183 swap = bytestream2_peek_byte(&gb) & 0x01;
184 offset = bytestream2_get_le16(&gb);
185 offset = (offset >> 1) & 0x7FFF;
186 offset = writeoffset + (offset * 2) - 0x8000;
190 if (!backward && offset + count >= hnm->
width * hnm->
height) {
193 }
else if (backward && offset >= hnm->
width * hnm->
height) {
196 }
else if (writeoffset + count >= hnm->
width * hnm->
height) {
198 "Attempting to write out of bounds");
234 writeoffset -= count * 2;
236 swap = hnm->
current[writeoffset];
238 hnm->
current[writeoffset + 1] = swap;
252 uint32_t writeoffset = 0, offset;
258 count = bytestream2_peek_byte(&gb) & 0x3F;
260 tag = bytestream2_get_byte(&gb) & 0xC0;
263 writeoffset += bytestream2_get_byte(&gb);
264 }
else if (tag == 1) {
265 hnm->
current[writeoffset] = bytestream2_get_byte(&gb);
266 hnm->
current[writeoffset + hnm->
width] = bytestream2_get_byte(&gb);
268 }
else if (tag == 2) {
269 writeoffset += hnm->
width;
270 }
else if (tag == 3) {
274 delta = bytestream2_peek_byte(&gb) & 0x80;
275 previous = bytestream2_peek_byte(&gb) & 0x40;
278 offset = writeoffset;
279 offset += bytestream2_get_le16(&gb);
320 int eight_bit_colors;
322 eight_bit_colors = src[7] & 0x80 && hnm->
version == 0x4a;
328 start = bytestream2_get_byte(&gb);
329 count = bytestream2_get_byte(&gb);
330 if (start == 255 && count == 255)
336 hnm->
palette[writeoffset] = bytestream2_get_be24(&gb);
337 if (!eight_bit_colors)
338 hnm->
palette[writeoffset] <<= 2;
412 "Extradata missing, decoder requires version number\n");