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)
292 for (i = 0; i < 256; i++)
318 opcode = bytestream2_get_byte(&ctx->
gb);
319 run_len = (opcode >> 1) + 1;
324 color = bytestream2_get_byte(&ctx->
gb);
325 memset(dst, color, run_len);
343 int i, j,
len, flag, code, val, pos,
end;
345 for (i = 0; i <
height; i++) {
351 len = bytestream2_get_le16u(&ctx->
gb);
358 code = bytestream2_get_byteu(&ctx->
gb);
360 code = (code >> 1) + 1;
361 if (pos + code > width)
364 val = bytestream2_get_byteu(&ctx->
gb);
366 memset(dst + pos, val, code);
371 for (j = 0; j < code; j++) {
372 val = bytestream2_get_byteu(&ctx->
gb);
392 for (j = 0; j < 4; j++) {
393 for (i = 0; i < 4; i++) {
394 if ((pos + i) < 0 || (pos + i) >= height * stride)
411 int compr, mvoff, seq,
flags;
412 uint32_t decoded_size;
415 compr = bytestream2_get_byte(&ctx->
gb);
416 mvoff = bytestream2_get_byte(&ctx->
gb);
417 seq = bytestream2_get_le16(&ctx->
gb);
418 decoded_size = bytestream2_get_le32(&ctx->
gb);
420 flags = bytestream2_get_byte(&ctx->
gb);
423 if (decoded_size > ctx->
height * stride - left - top * stride) {
424 decoded_size = ctx->
height * stride - left - top *
stride;
430 if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
443 for (i = 0; i <
height; i++) {
459 for (j = 0; j <
height; j += 4) {
460 for (i = 0; i <
width; i += 4) {
469 code = bytestream2_get_byteu(&ctx->
gb);
474 for (k = 0; k < 4; k++)
480 for (k = 0; k < 4; k++)
481 memset(dst + i + k * stride, bytestream2_get_byteu(&ctx->
gb), 4);
486 t = bytestream2_get_byteu(&ctx->
gb);
487 for (k = 0; k < 4; k++)
488 memset(dst + i + k * stride, t, 4);
491 if (compr == 4 && !code) {
494 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
499 mx =
c37_mv[(mvoff * 255 + code) * 2 ];
500 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
501 codec37_mv(dst + i, prev + i + mx + my * stride,
502 ctx->
height, stride, i + mx, j + my);
510 for (j = 0; j <
height; j += 4) {
511 for (i = 0; i <
width; i += 4) {
518 code = bytestream2_get_byte(&ctx->
gb);
522 for (k = 0; k < 4; k++)
524 }
else if (compr == 4 && !code) {
527 skip_run = bytestream2_get_byteu(&ctx->
gb) + 1;
532 mx =
c37_mv[(mvoff * 255 + code) * 2];
533 my =
c37_mv[(mvoff * 255 + code) * 2 + 1];
534 codec37_mv(dst + i, prev + i + mx + my * stride,
535 ctx->
height, stride, i + mx, j + my);
545 "subcodec 37 compression %d not implemented\n", compr);
562 code = bytestream2_get_byteu(&ctx->
gb);
569 dst[0] = bytestream2_get_byteu(&ctx->
gb);
570 dst[1] = bytestream2_get_byteu(&ctx->
gb);
571 dst[0+
stride] = bytestream2_get_byteu(&ctx->
gb);
572 dst[1+
stride] = bytestream2_get_byteu(&ctx->
gb);
575 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
577 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
583 if (
process_block(ctx, dst, prev1, prev2, stride, tbl, size))
585 if (
process_block(ctx, dst + size, prev1 + size, prev2 + size,
594 t = bytestream2_get_byteu(&ctx->
gb);
595 for (k = 0; k <
size; k++)
596 memset(dst + k * stride, t, size);
602 code = bytestream2_get_byteu(&ctx->
gb);
606 for (k = 0; k <
size; k++)
607 for (t = 0; t <
size; t++)
608 dst[t + k * stride] = colors[!*pglyph++];
611 for (k = 0; k <
size; k++)
612 memcpy(dst + k * stride, prev1 + k * stride, size);
617 t = bytestream2_get_byte(&ctx->
gb);
619 for (k = 0; k <
size; k++)
620 memset(dst + k * stride, t, size);
629 if (index < - mx - my*stride ||
630 (ctx->
buf_size>>1) - index < mx + size + (my + size - 1)*stride) {
635 for (k = 0; k <
size; k++)
636 memcpy(dst + k * stride, prev2 + mx + (my + k) * stride, size);
645 int i, j, seq, compr, new_rot, tbl_pos, skip;
650 uint32_t decoded_size;
653 seq = bytestream2_get_le16(&ctx->
gb);
654 compr = bytestream2_get_byte(&ctx->
gb);
655 new_rot = bytestream2_get_byte(&ctx->
gb);
656 skip = bytestream2_get_byte(&ctx->
gb);
658 decoded_size = bytestream2_get_le32(&ctx->
gb);
661 if (decoded_size > ctx->
height * stride - left - top * stride) {
662 decoded_size = ctx->
height * stride - left - top *
stride;
670 memset(prev1, 0, ctx->
height * stride);
671 memset(prev2, 0, ctx->
height * stride);
678 for (j = 0; j <
height; j++) {
686 for (j = 0; j <
height; j += 2) {
687 for (i = 0; i <
width; i += 2) {
688 dst[i] = dst[i + 1] =
689 dst[stride + i] = dst[stride + i + 1] = bytestream2_get_byteu(&ctx->
gb);
696 for (j = 0; j <
height; j += 8) {
697 for (i = 0; i <
width; i += 8) {
698 if (
process_block(ctx, dst + i, prev1 + i, prev2 + i, stride,
720 "subcodec 47 compression %d not implemented\n", compr);
734 uint16_t codec, top, left, w, h;
736 codec = bytestream2_get_le16u(&ctx->
gb);
737 left = bytestream2_get_le16u(&ctx->
gb);
738 top = bytestream2_get_le16u(&ctx->
gb);
739 w = bytestream2_get_le16u(&ctx->
gb);
740 h = bytestream2_get_le16u(&ctx->
gb);
747 if (ctx->
width < left + w || ctx->
height < top + h) {
782 uint16_t *frm = ctx->
frm0;
789 for (y = 0; y < ctx->
height; y++) {
790 for (x = 0; x < ctx->
width; x++)
791 frm[x] = bytestream2_get_le16u(&ctx->
gb);
803 static void copy_block(uint16_t *pdest, uint16_t *psrc,
int block_size,
int pitch)
809 switch (block_size) {
827 for (y = 0; y < block_size; y++, pdest += pitch)
828 for (x = 0; x < block_size; x++)
833 uint16_t bg_color,
int block_size,
int pitch)
836 uint16_t colors[2] = { fg_color, bg_color };
847 for (y = 0; y < block_size; y++, dst += pitch)
848 for (x = 0; x < block_size; x++)
849 *dst++ = colors[*pglyph++];
857 if (block_size == 2) {
863 indices = bytestream2_get_le32u(&ctx->
gb);
864 dst[0] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
865 dst[1] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
866 dst[pitch] = ctx->
codebook[indices & 0xFF]; indices >>= 8;
867 dst[pitch + 1] = ctx->
codebook[indices & 0xFF];
869 uint16_t fgcolor, bgcolor;
875 glyph = bytestream2_get_byteu(&ctx->
gb);
876 bgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
877 fgcolor = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
879 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
888 if (block_size == 2) {
892 dst[0] = bytestream2_get_le16u(&ctx->
gb);
893 dst[1] = bytestream2_get_le16u(&ctx->
gb);
894 dst[pitch] = bytestream2_get_le16u(&ctx->
gb);
895 dst[pitch + 1] = bytestream2_get_le16u(&ctx->
gb);
897 uint16_t fgcolor, bgcolor;
903 glyph = bytestream2_get_byteu(&ctx->
gb);
904 bgcolor = bytestream2_get_le16u(&ctx->
gb);
905 fgcolor = bytestream2_get_le16u(&ctx->
gb);
907 draw_glyph(ctx, dst, glyph, fgcolor, bgcolor, block_size, pitch);
915 int start_pos = cx + mx + (cy + my) * ctx->
pitch;
916 int end_pos = start_pos + (block_size - 1) * (ctx->
pitch + 1);
918 int good = start_pos >= 0 && end_pos < (ctx->
buf_size >> 1);
922 cx + mx, cy + my, cx, cy, block_size);
930 int16_t mx, my,
index;
936 opcode = bytestream2_get_byteu(&ctx->
gb);
938 av_dlog(ctx->
avctx,
"opcode 0x%0X cx %d cy %d blk %d\n", opcode, cx, cy, blk_size);
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 index = bytestream2_get_le16u(&ctx->
gb);
955 mx = index % ctx->
width;
956 my = index / ctx->
width;
958 if (
good_mvec(ctx, cx, cy, mx, my, blk_size)) {
960 ctx->
frm2 + cx + mx + ctx->
pitch * (cy + my),
961 blk_size, ctx->
pitch);
967 blk_size, ctx->
pitch);
993 bytestream2_get_le16u(&ctx->
gb), blk_size, ctx->
pitch);
1064 uint16_t *frm = ctx->
frm0;
1071 *frm++ = ctx->
codebook[bytestream2_get_byteu(&ctx->
gb)];
1078 uint16_t *pdest = ctx->
frm0;
1116 hdr->
width = bytestream2_get_le32u(&ctx->
gb);
1117 hdr->
height = bytestream2_get_le32u(&ctx->
gb);
1124 hdr->
seq_num = bytestream2_get_le16u(&ctx->
gb);
1125 hdr->
codec = bytestream2_get_byteu(&ctx->
gb);
1130 for (i = 0; i < 4; i++)
1132 hdr->
bg_color = bytestream2_get_le16u(&ctx->
gb);
1137 for (i = 0; i < 256; i++)
1138 ctx->
codebook[i] = bytestream2_get_le16u(&ctx->
gb);
1157 int srcpitch = ctx->
pitch * (hdr ?
sizeof(ctx->
frm0[0]) : 1);
1168 memcpy(dst, src, srcpitch);
1193 sig = bytestream2_get_be32u(&ctx->
gb);
1194 size = bytestream2_get_be32u(&ctx->
gb);
1202 case MKBETAG(
'N',
'P',
'A',
'L'):
1203 if (size != 256 * 3) {
1208 for (i = 0; i < 256; i++)
1209 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1211 case MKBETAG(
'F',
'O',
'B',
'J'):
1217 case MKBETAG(
'X',
'P',
'A',
'L'):
1218 if (size == 6 || size == 4) {
1222 for (i = 0; i < 256; i++) {
1223 for (j = 0; j < 3; j++) {
1224 int t = (ctx->
pal[i] >> (16 - j * 8)) & 0xFF;
1225 tmp[j] = av_clip_uint8((t * 129 + ctx->
delta_pal[i * 3 + j]) >> 7);
1230 if (size < 768 * 2 + 4) {
1236 for (i = 0; i < 768; i++)
1237 ctx->
delta_pal[i] = bytestream2_get_le16u(&ctx->
gb);
1238 if (size >= 768 * 5 + 4) {
1239 for (i = 0; i < 256; i++)
1240 ctx->
pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->
gb);
1242 memset(ctx->
pal, 0,
sizeof(ctx->
pal));
1246 case MKBETAG(
'S',
'T',
'O',
'R'):
1249 case MKBETAG(
'F',
'T',
'C',
'H'):
1285 "subcodec %d: error decoding frame\n", header.
codec);