42 int16_t delta_pal[768];
50 uint16_t *frm0, *frm1, *
frm2;
62 uint16_t codebook[256];
63 uint16_t small_codebook[4];
70 int seq_num, codec, rotate_code, rle_output_size;
101 const int edge_max = edge_size - 1;
105 }
else if (y == edge_max) {
109 }
else if (x == edge_max) {
142 static void interp_point(int8_t *points,
int x0,
int y0,
int x1,
int y1,
143 int pos,
int npoints)
146 points[0] = (x0 * pos + x1 * (npoints - pos) + (npoints >> 1)) / npoints;
147 points[1] = (y0 * pos + y1 * (npoints - pos) + (npoints >> 1)) / npoints;
162 static void make_glyphs(int8_t *pglyphs,
const int8_t *xvec,
const int8_t *yvec,
163 const int side_length)
165 const int glyph_size = side_length * side_length;
166 int8_t *pglyph = pglyphs;
182 for (ipoint = 0; ipoint <= npoints; ipoint++) {
190 for (irow = point[1]; irow >= 0; irow--)
191 pglyph[point[0] + irow * side_length] = 1;
195 for (irow = point[1]; irow < side_length; irow++)
196 pglyph[point[0] + irow * side_length] = 1;
200 for (icol = point[0]; icol >= 0; icol--)
201 pglyph[icol + point[1] * side_length] = 1;
205 for (icol = point[0]; icol < side_length; icol++)
206 pglyph[icol + point[1] * side_length] = 1;
258 if (rotate_code == 2)
290 for (i = 0; i < 256; i++)
311 opcode = bytestream2_get_byte(&ctx->
gb);
312 run_len = (opcode >> 1) + 1;
317 color = bytestream2_get_byte(&ctx->
gb);
318 memset(dst, color, run_len);
336 int i, j,
len, flag, code,
val, pos,
end;
338 for (i = 0; i <
height; i++) {
344 len = bytestream2_get_le16u(&ctx->
gb);
351 code = bytestream2_get_byteu(&ctx->
gb);
353 code = (code >> 1) + 1;
354 if (pos + code > width)
357 val = bytestream2_get_byteu(&ctx->
gb);
359 memset(dst + pos, val, code);
364 for (j = 0; j < code; j++) {
365 val = bytestream2_get_byteu(&ctx->
gb);
384 pos = x + y * stride;
385 for (j = 0; j < 4; j++) {
386 for (i = 0; i < 4; i++) {
387 if ((pos + i) < 0 || (pos + i) >= height * stride)
404 int compr, mvoff, seq,
flags;
405 uint32_t decoded_size;
408 compr = bytestream2_get_byte(&ctx->
gb);
409 mvoff = bytestream2_get_byte(&ctx->
gb);
410 seq = bytestream2_get_le16(&ctx->
gb);
411 decoded_size = bytestream2_get_le32(&ctx->
gb);
413 flags = bytestream2_get_byte(&ctx->
gb);
416 if (decoded_size > ctx->
height * stride - left - top * stride) {
417 decoded_size = ctx->
height * stride - left - top * stride;
423 if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
427 prev = ((
uint8_t*)ctx->
frm2) + left + top * stride;
436 for (i = 0; i <
height; i++) {
452 for (j = 0; j <
height; j += 4) {
453 for (i = 0; i <
width; i += 4) {
462 code = bytestream2_get_byteu(&ctx->
gb);
467 for (k = 0; k < 4; k++)
473 for (k = 0; k < 4; k++)
474 memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->
gb), 4);
479 t = bytestream2_get_byteu(&ctx->
gb);
480 for (k = 0; k < 4; k++)
481 memset(dst + i + k * stride, t, 4);
484 if (compr == 4 && !code) {
487 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
492 mx =
c37_mv[(mvoff * 255 + code) * 2 ];
493 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
494 codec37_mv(dst + i, prev + i + mx + my * stride,
495 ctx->
height, stride, i + mx, j + my);
503 for (j = 0; j <
height; j += 4) {
504 for (i = 0; i <
width; i += 4) {
511 code = bytestream2_get_byte(&ctx->
gb);
515 for (k = 0; k < 4; k++)
517 }
else if (compr == 4 && !code) {
520 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
525 mx =
c37_mv[(mvoff * 255 + code) * 2];
526 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
527 codec37_mv(dst + i, prev + i + mx + my * stride,
528 ctx->
height, stride, i + mx, j + my);
538 "subcodec 37 compression %d not implemented\n", compr);
555 code = bytestream2_get_byteu(&ctx->
gb);
562 dst[0] = bytestream2_get_byteu(&ctx->
gb);
563 dst[1] = bytestream2_get_byteu(&ctx->
gb);
564 dst[0+stride] = bytestream2_get_byteu(&ctx->
gb);
565 dst[1+stride] = bytestream2_get_byteu(&ctx->
gb);
568 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
570 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
573 dst += size * stride;
574 prev1 += size * stride;
575 prev2 += size * stride;
576 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
578 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
587 t = bytestream2_get_byteu(&ctx->
gb);
588 for (k = 0; k <
size; k++)
589 memset(dst + k * stride, t, size);
595 code = bytestream2_get_byteu(&ctx->
gb);
599 for (k = 0; k <
size; k++)
600 for (t = 0; t <
size; t++)
601 dst[t + k * stride] = colors[!*pglyph++];
604 for (k = 0; k <
size; k++)
605 memcpy(dst + k * stride, prev1 + k * stride, size);
610 t = bytestream2_get_byte(&ctx->
gb);
612 for (k = 0; k <
size; k++)
613 memset(dst + k * stride, t, size);
622 if (index < - mx - my*stride ||
623 (ctx->
buf_size>>1) - index < mx + size + (my + size - 1)*stride) {
628 for (k = 0; k <
size; k++)
629 memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
638 int i, j, seq, compr, new_rot, tbl_pos, skip;
643 uint32_t decoded_size;
646 seq = bytestream2_get_le16(&ctx->
gb);
647 compr = bytestream2_get_byte(&ctx->
gb);
648 new_rot = bytestream2_get_byte(&ctx->
gb);
649 skip = bytestream2_get_byte(&ctx->
gb);
651 decoded_size = bytestream2_get_le32(&ctx->
gb);
654 if (decoded_size > ctx->
height * stride - left - top * stride) {
655 decoded_size = ctx->
height * stride - left - top * stride;
663 memset(prev1, 0, ctx->
height * stride);
664 memset(prev2, 0, ctx->
height * stride);
671 for (j = 0; j <
height; j++) {
679 for (j = 0; j <
height; j += 2) {
680 for (i = 0; i <
width; i += 2) {
681 dst[i] = dst[i + 1] =
682 dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->
gb);
689 for (j = 0; j <
height; j += 8) {
690 for (i = 0; i <
width; i += 8) {
691 if (
process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
713 "subcodec 47 compression %d not implemented\n", compr);
727 uint16_t codec, top, left, w, h;
729 codec = bytestream2_get_le16u(&ctx->
gb);
730 left = bytestream2_get_le16u(&ctx->
gb);
731 top = bytestream2_get_le16u(&ctx->
gb);
732 w = bytestream2_get_le16u(&ctx->
gb);
733 h = bytestream2_get_le16u(&ctx->
gb);
740 if (ctx->
width < left + w || ctx->
height < top + h) {
774 uint16_t *frm = ctx->
frm0;
781 for (y = 0; y < ctx->
height; y++) {
782 for (x = 0; x < ctx->
width; x++)
783 frm[x] = bytestream2_get_le16u(&ctx->
gb);
795 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size,
int pitch)
801 switch (block_size) {
819 for (y = 0; y < block_size; y++, pdest += pitch)
820 for (x = 0; x < block_size; x++)
825 uint16_t bg_color,
int block_size,
int pitch)
828 uint16_t colors[2] = { fg_color, bg_color };
839 for (y = 0; y < block_size; y++, dst += pitch)
840 for (x = 0; x < block_size; x++)
841 *dst++ = colors[*pglyph++];
847 uint16_t *dst = ctx->
frm0 + cx + cy * ctx->
pitch;
849 if (block_size == 2) {
855 indices = bytestream2_get_le32u(&ctx->
gb);
856 dst[0] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
857 dst[1] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
858 dst[pitch] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
859 dst[pitch + 1] = ctx->
codebook[indices & 0xFF];
861 uint16_t fgcolor, bgcolor;
867 glyph = bytestream2_get_byteu(&ctx->
gb);
868 bgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
869 fgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
871 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
878 uint16_t *dst = ctx->
frm0 + cx + cy * ctx->
pitch;
880 if (block_size == 2) {
884 dst[0] = bytestream2_get_le16u(&ctx->
gb);
885 dst[1] = bytestream2_get_le16u(&ctx->
gb);
886 dst[pitch] = bytestream2_get_le16u(&ctx->
gb);
887 dst[pitch + 1] = bytestream2_get_le16u(&ctx->
gb);
889 uint16_t fgcolor, bgcolor;
895 glyph = bytestream2_get_byteu(&ctx->
gb);
896 bgcolor = bytestream2_get_le16u(&ctx->
gb);
897 fgcolor = bytestream2_get_le16u(&ctx->
gb);
899 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
907 int start_pos = cx + mx + (cy + my) * ctx->
pitch;
908 int end_pos = start_pos + (block_size - 1) * (ctx->
pitch + 1);
910 int good = start_pos >= 0 && end_pos < (ctx->
buf_size >> 1);
914 cx + mx, cy + my, cx, cy, block_size);
922 int16_t mx, my,
index;
928 opcode = bytestream2_get_byteu(&ctx->
gb);
930 av_dlog(ctx->
avctx,
"opcode 0x%0X cx %d cy %d blk %d\n", opcode, cx, cy, blk_size);
936 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
938 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
939 blk_size, ctx->
pitch);
945 index = bytestream2_get_le16u(&ctx->
gb);
947 mx = index % ctx->
width;
948 my = index / ctx->
width;
950 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
952 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
953 blk_size, ctx->
pitch);
959 blk_size, ctx->
pitch);
985 bytestream2_get_le16u(&ctx->
gb), blk_size, ctx->
pitch);
1058 uint16_t *frm = ctx->
frm0;
1065 *frm++ = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1072 uint16_t *pdest = ctx->
frm0;
1110 hdr->
width = bytestream2_get_le32u(&ctx->
gb);
1111 hdr->
height = bytestream2_get_le32u(&ctx->
gb);
1118 hdr->
seq_num = bytestream2_get_le16u(&ctx->
gb);
1119 hdr->
codec = bytestream2_get_byteu(&ctx->
gb);
1124 for (i = 0; i < 4; i++)
1126 hdr->
bg_color = bytestream2_get_le16u(&ctx->
gb);
1131 for (i = 0; i < 256; i++)
1132 ctx->
codebook[i] = bytestream2_get_le16u(&ctx->
gb);
1151 int srcpitch = ctx->
pitch * (hdr ?
sizeof(ctx->
frm0[0]) : 1);
1160 memcpy(dst, src, srcpitch);
1184 sig = bytestream2_get_be32u(&ctx->
gb);
1185 size = bytestream2_get_be32u(&ctx->
gb);
1193 case MKBETAG(
'N',
'P',
'A',
'L'):
1194 if (size != 256 * 3) {
1199 for (i = 0; i < 256; i++)
1200 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1202 case MKBETAG(
'F',
'O',
'B',
'J'):
1208 case MKBETAG(
'X',
'P',
'A',
'L'):
1209 if (size == 6 || size == 4) {
1213 for (i = 0; i < 256; i++) {
1214 for (j = 0; j < 3; j++) {
1215 int t = (ctx->
pal[i] >> (16 - j * 8)) & 0xFF;
1216 tmp[j] = av_clip_uint8((t * 129 + ctx->
delta_pal[i * 3 + j]) >> 7);
1221 if (size < 768 * 2 + 4) {
1227 for (i = 0; i < 768; i++)
1228 ctx->
delta_pal[i] = bytestream2_get_le16u(&ctx->
gb);
1229 if (size >= 768 * 5 + 4) {
1230 for (i = 0; i < 256; i++)
1231 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1233 memset(ctx->
pal, 0,
sizeof(ctx->
pal));
1237 case MKBETAG(
'S',
'T',
'O',
'R'):
1240 case MKBETAG(
'F',
'T',
'C',
'H'):
1276 "subcodec %d: error decoding frame\n", header.
codec);