41 int16_t delta_pal[768];
49 uint16_t *frm0, *frm1, *
frm2;
61 uint16_t codebook[256];
62 uint16_t small_codebook[4];
69 int seq_num, codec, rotate_code, rle_output_size;
100 const int edge_max = edge_size - 1;
104 }
else if (y == edge_max) {
108 }
else if (x == edge_max) {
141 static void interp_point(int8_t *points,
int x0,
int y0,
int x1,
int y1,
142 int pos,
int npoints)
145 points[0] = (x0 * pos + x1 * (npoints - pos) + (npoints >> 1)) / npoints;
146 points[1] = (y0 * pos + y1 * (npoints - pos) + (npoints >> 1)) / npoints;
161 static void make_glyphs(int8_t *pglyphs,
const int8_t *xvec,
const int8_t *yvec,
162 const int side_length)
164 const int glyph_size = side_length * side_length;
165 int8_t *pglyph = pglyphs;
181 for (ipoint = 0; ipoint <= npoints; ipoint++) {
189 for (irow = point[1]; irow >= 0; irow--)
190 pglyph[point[0] + irow * side_length] = 1;
194 for (irow = point[1]; irow < side_length; irow++)
195 pglyph[point[0] + irow * side_length] = 1;
199 for (icol = point[0]; icol >= 0; icol--)
200 pglyph[icol + point[1] * side_length] = 1;
204 for (icol = point[0]; icol < side_length; icol++)
205 pglyph[icol + point[1] * side_length] = 1;
254 if (rotate_code == 2)
288 for (i = 0; i < 256; i++)
314 opcode = bytestream2_get_byte(&ctx->
gb);
315 run_len = (opcode >> 1) + 1;
320 color = bytestream2_get_byte(&ctx->
gb);
321 memset(dst, color, run_len);
339 int i, j,
len, flag, code, val, pos,
end;
341 for (i = 0; i <
height; i++) {
347 len = bytestream2_get_le16u(&ctx->
gb);
354 code = bytestream2_get_byteu(&ctx->
gb);
356 code = (code >> 1) + 1;
357 if (pos + code > width)
360 val = bytestream2_get_byteu(&ctx->
gb);
362 memset(dst + pos, val, code);
367 for (j = 0; j < code; j++) {
368 val = bytestream2_get_byteu(&ctx->
gb);
388 for (j = 0; j < 4; j++) {
389 for (i = 0; i < 4; i++) {
390 if ((pos + i) < 0 || (pos + i) >= height * stride)
407 int compr, mvoff, seq,
flags;
408 uint32_t decoded_size;
411 compr = bytestream2_get_byte(&ctx->
gb);
412 mvoff = bytestream2_get_byte(&ctx->
gb);
413 seq = bytestream2_get_le16(&ctx->
gb);
414 decoded_size = bytestream2_get_le32(&ctx->
gb);
416 flags = bytestream2_get_byte(&ctx->
gb);
419 if (decoded_size > ctx->
height * stride - left - top * stride) {
420 decoded_size = ctx->
height * stride - left - top *
stride;
426 if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
439 for (i = 0; i <
height; i++) {
455 for (j = 0; j <
height; j += 4) {
456 for (i = 0; i <
width; i += 4) {
465 code = bytestream2_get_byteu(&ctx->
gb);
470 for (k = 0; k < 4; k++)
476 for (k = 0; k < 4; k++)
477 memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->
gb), 4);
482 t = bytestream2_get_byteu(&ctx->
gb);
483 for (k = 0; k < 4; k++)
484 memset(dst + i + k * stride, t, 4);
487 if (compr == 4 && !code) {
490 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
495 mx =
c37_mv[(mvoff * 255 + code) * 2 ];
496 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
497 codec37_mv(dst + i, prev + i + mx + my * stride,
498 ctx->
height, stride, i + mx, j + my);
506 for (j = 0; j <
height; j += 4) {
507 for (i = 0; i <
width; i += 4) {
514 code = bytestream2_get_byte(&ctx->
gb);
518 for (k = 0; k < 4; k++)
520 }
else if (compr == 4 && !code) {
523 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
528 mx =
c37_mv[(mvoff * 255 + code) * 2];
529 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
530 codec37_mv(dst + i, prev + i + mx + my * stride,
531 ctx->
height, stride, i + mx, j + my);
541 "subcodec 37 compression %d not implemented\n", compr);
558 code = bytestream2_get_byteu(&ctx->
gb);
565 dst[0] = bytestream2_get_byteu(&ctx->
gb);
566 dst[1] = bytestream2_get_byteu(&ctx->
gb);
567 dst[0+
stride] = bytestream2_get_byteu(&ctx->
gb);
568 dst[1+
stride] = bytestream2_get_byteu(&ctx->
gb);
571 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
573 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
579 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
581 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
590 t = bytestream2_get_byteu(&ctx->
gb);
591 for (k = 0; k <
size; k++)
592 memset(dst + k * stride, t, size);
598 code = bytestream2_get_byteu(&ctx->
gb);
602 for (k = 0; k <
size; k++)
603 for (t = 0; t <
size; t++)
604 dst[t + k * stride] = colors[!*pglyph++];
607 for (k = 0; k <
size; k++)
608 memcpy(dst + k * stride, prev1 + k * stride, size);
613 t = bytestream2_get_byte(&ctx->
gb);
615 for (k = 0; k <
size; k++)
616 memset(dst + k * stride, t, size);
621 for (k = 0; k <
size; k++)
622 memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
631 int i, j, seq, compr, new_rot, tbl_pos, skip;
636 uint32_t decoded_size;
639 seq = bytestream2_get_le16(&ctx->
gb);
640 compr = bytestream2_get_byte(&ctx->
gb);
641 new_rot = bytestream2_get_byte(&ctx->
gb);
642 skip = bytestream2_get_byte(&ctx->
gb);
644 decoded_size = bytestream2_get_le32(&ctx->
gb);
647 if (decoded_size > ctx->
height * stride - left - top * stride) {
648 decoded_size = ctx->
height * stride - left - top *
stride;
656 memset(prev1, 0, ctx->
height * stride);
664 for (j = 0; j <
height; j++) {
665 for (i = 0; i <
width; i++)
673 for (j = 0; j <
height; j += 2) {
674 for (i = 0; i <
width; i += 2) {
675 dst[i] = dst[i + 1] =
676 dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->
gb);
683 for (j = 0; j <
height; j += 8) {
684 for (i = 0; i <
width; i += 8) {
707 "subcodec 47 compression %d not implemented\n", compr);
721 uint16_t codec, top, left, w, h;
723 codec = bytestream2_get_le16u(&ctx->
gb);
724 left = bytestream2_get_le16u(&ctx->
gb);
725 top = bytestream2_get_le16u(&ctx->
gb);
726 w = bytestream2_get_le16u(&ctx->
gb);
727 h = bytestream2_get_le16u(&ctx->
gb);
734 if (ctx->
width < left + w || ctx->
height < top + h) {
768 uint16_t *frm = ctx->
frm0;
775 for (y = 0; y < ctx->
height; y++) {
776 for (x = 0; x < ctx->
width; x++)
777 frm[x] = bytestream2_get_le16u(&ctx->
gb);
789 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size,
int pitch)
795 switch (block_size) {
813 for (y = 0; y < block_size; y++, pdest += pitch)
814 for (x = 0; x < block_size; x++)
819 uint16_t bg_color,
int block_size,
int pitch)
822 uint16_t colors[2] = { fg_color, bg_color };
833 for (y = 0; y < block_size; y++, dst += pitch)
834 for (x = 0; x < block_size; x++)
835 *dst++ = colors[*pglyph++];
843 if (block_size == 2) {
849 indices = bytestream2_get_le32u(&ctx->
gb);
850 dst[0] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
851 dst[1] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
852 dst[pitch] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
853 dst[pitch + 1] = ctx->
codebook[indices & 0xFF];
855 uint16_t fgcolor, bgcolor;
861 glyph = bytestream2_get_byteu(&ctx->
gb);
862 bgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
863 fgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
865 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
874 if (block_size == 2) {
878 dst[0] = bytestream2_get_le16u(&ctx->
gb);
879 dst[1] = bytestream2_get_le16u(&ctx->
gb);
880 dst[pitch] = bytestream2_get_le16u(&ctx->
gb);
881 dst[pitch + 1] = bytestream2_get_le16u(&ctx->
gb);
883 uint16_t fgcolor, bgcolor;
889 glyph = bytestream2_get_byteu(&ctx->
gb);
890 bgcolor = bytestream2_get_le16u(&ctx->
gb);
891 fgcolor = bytestream2_get_le16u(&ctx->
gb);
893 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
901 int start_pos = cx + mx + (cy + my) * ctx->
pitch;
902 int end_pos = start_pos + (block_size - 1) * (ctx->
pitch + 1);
904 int good = start_pos >= 0 && end_pos < (ctx->
buf_size >> 1);
908 cx + mx, cy + my, cx, cy, block_size);
916 int16_t mx, my,
index;
922 opcode = bytestream2_get_byteu(&ctx->
gb);
924 av_dlog(ctx->
avctx,
"opcode 0x%0X cx %d cy %d blk %d\n", opcode, cx, cy, blk_size);
930 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
932 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
933 blk_size, ctx->
pitch);
939 index = bytestream2_get_le16u(&ctx->
gb);
941 mx = index % ctx->
width;
942 my = index / ctx->
width;
944 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
946 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
947 blk_size, ctx->
pitch);
953 blk_size, ctx->
pitch);
979 bytestream2_get_le16u(&ctx->
gb), blk_size, ctx->
pitch);
1050 uint16_t *frm = ctx->
frm0;
1057 *frm++ = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1064 uint16_t *pdest = ctx->
frm0;
1102 hdr->
width = bytestream2_get_le32u(&ctx->
gb);
1103 hdr->
height = bytestream2_get_le32u(&ctx->
gb);
1110 hdr->
seq_num = bytestream2_get_le16u(&ctx->
gb);
1111 hdr->
codec = bytestream2_get_byteu(&ctx->
gb);
1116 for (i = 0; i < 4; i++)
1118 hdr->
bg_color = bytestream2_get_le16u(&ctx->
gb);
1123 for (i = 0; i < 256; i++)
1124 ctx->
codebook[i] = bytestream2_get_le16u(&ctx->
gb);
1143 int srcpitch = ctx->
pitch * (hdr ?
sizeof(ctx->
frm0[0]) : 1);
1154 memcpy(dst, src, srcpitch);
1179 sig = bytestream2_get_be32u(&ctx->
gb);
1180 size = bytestream2_get_be32u(&ctx->
gb);
1188 case MKBETAG(
'N',
'P',
'A',
'L'):
1189 if (size != 256 * 3) {
1194 for (i = 0; i < 256; i++)
1195 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1197 case MKBETAG(
'F',
'O',
'B',
'J'):
1203 case MKBETAG(
'X',
'P',
'A',
'L'):
1204 if (size == 6 || size == 4) {
1208 for (i = 0; i < 256; i++) {
1209 for (j = 0; j < 3; j++) {
1210 int t = (ctx->
pal[i] >> (16 - j * 8)) & 0xFF;
1211 tmp[j] = av_clip_uint8((t * 129 + ctx->
delta_pal[i * 3 + j]) >> 7);
1216 if (size < 768 * 2 + 4) {
1222 for (i = 0; i < 768; i++)
1223 ctx->
delta_pal[i] = bytestream2_get_le16u(&ctx->
gb);
1224 if (size >= 768 * 5 + 4) {
1225 for (i = 0; i < 256; i++)
1226 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1228 memset(ctx->
pal, 0,
sizeof(ctx->
pal));
1232 case MKBETAG(
'S',
'T',
'O',
'R'):
1235 case MKBETAG(
'F',
'T',
'C',
'H'):
1271 "subcodec %d: error decoding frame\n", header.
codec);