33 #define HNM4_CHUNK_ID_PL 19536
34 #define HNM4_CHUNK_ID_IZ 23113
35 #define HNM4_CHUNK_ID_IU 21833
36 #define HNM4_CHUNK_ID_SD 17491
55 *bitbuf = bytestream2_get_le32(gb);
71 uint32_t bitbuf = 0, writeoffset = 0,
count = 0;
79 if (
getbit(&gb, &bitbuf, &bits)) {
82 "Attempting to write out of bounds\n");
85 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
87 if (
getbit(&gb, &bitbuf, &bits)) {
88 word = bytestream2_get_le16(&gb);
90 offset = (word >> 3) - 0x2000;
92 count = bytestream2_get_byte(&gb);
98 offset = bytestream2_get_byte(&gb) - 0x0100;
101 offset += writeoffset;
102 if (offset < 0 || offset + count >= hnm->
width * hnm->
height) {
107 "Attempting to write out of bounds\n");
120 uint32_t x,
y, src_x, src_y;
122 for (y = 0; y < hnm->
height; y++) {
124 src_x = src_y * hnm->
width + (y % 2);
125 for (x = 0; x < hnm->
width; x++) {
139 for (y = 0; y < hnm->
height; y++) {
140 memcpy(dst, src, hnm->
width);
150 uint32_t writeoffset = 0;
152 uint8_t tag, previous, backline, backward, swap;
157 count = bytestream2_peek_byte(&gb) & 0x1F;
159 tag = bytestream2_get_byte(&gb) & 0xE0;
167 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
168 hnm->
current[writeoffset++] = bytestream2_get_byte(&gb);
169 }
else if (tag == 1) {
170 writeoffset += bytestream2_get_byte(&gb) * 2;
171 }
else if (tag == 2) {
172 count = bytestream2_get_le16(&gb);
174 writeoffset +=
count;
175 }
else if (tag == 3) {
176 count = bytestream2_get_byte(&gb) * 2;
177 if (writeoffset + count > hnm->
width * hnm->
height) {
182 hnm->
current[writeoffset++] = bytestream2_peek_byte(&gb);
194 previous = bytestream2_peek_byte(&gb) & 0x20;
195 backline = bytestream2_peek_byte(&gb) & 0x40;
196 backward = bytestream2_peek_byte(&gb) & 0x80;
198 swap = bytestream2_peek_byte(&gb) & 0x01;
199 offset = bytestream2_get_le16(&gb);
200 offset = (offset >> 1) & 0x7FFF;
201 offset = writeoffset + (offset * 2) - 0x8000;
205 if (!backward && offset + 2*count > hnm->
width * hnm->
height) {
208 }
else if (backward && offset + 1 >= hnm->
width * hnm->
height) {
211 }
else if (writeoffset + 2*count > hnm->
width * hnm->
height) {
213 "Attempting to write out of bounds\n");
217 if (offset < (!!backline)*(2 * hnm->
width - 1) + 2*(left-1)) {
222 if (offset < (!!backline)*(2 * hnm->
width - 1)) {
260 writeoffset -= count * 2;
262 swap = hnm->
current[writeoffset];
264 hnm->
current[writeoffset + 1] = swap;
278 uint32_t writeoffset = 0,
offset;
284 count = bytestream2_peek_byte(&gb) & 0x3F;
286 tag = bytestream2_get_byte(&gb) & 0xC0;
289 writeoffset += bytestream2_get_byte(&gb);
290 }
else if (tag == 1) {
295 hnm->
current[writeoffset] = bytestream2_get_byte(&gb);
296 hnm->
current[writeoffset + hnm->
width] = bytestream2_get_byte(&gb);
298 }
else if (tag == 2) {
299 writeoffset += hnm->
width;
300 }
else if (tag == 3) {
308 delta = bytestream2_peek_byte(&gb) & 0x80;
309 previous = bytestream2_peek_byte(&gb) & 0x40;
313 offset += bytestream2_get_le16(&gb);
359 int eight_bit_colors;
361 eight_bit_colors = src[7] & 0x80 && hnm->
version == 0x4a;
367 start = bytestream2_get_byte(&gb);
368 count = bytestream2_get_byte(&gb);
369 if (start == 255 && count == 255)
375 hnm->
palette[writeoffset] = bytestream2_get_be24(&gb);
376 if (!eight_bit_colors)
377 hnm->
palette[writeoffset] <<= 2;
401 if (avpkt->
size < 8) {
411 if (avpkt->
size < 12) {
461 "Extradata missing, decoder requires version number\n");