42 #define BITSTREAM_READER_LE
50 #define PALETTE_COUNT 256
81 int current_offset =
s->pixel_ptr - dst->
data[0];
82 int x = (current_offset % dst->
linesize[0]) / (1 +
s->is_16bpp);
83 int y = current_offset / dst->
linesize[0];
84 int dx = delta_x + x - ((delta_x + x >=
width) - (delta_x + x < 0)) *
width;
85 int dy = delta_y + y + (delta_x + x >=
width) - (delta_x + x < 0);
86 int motion_offset = dy *
src->linesize[0] + dx * (1 +
s->is_16bpp);
88 if (motion_offset < 0) {
91 }
else if (motion_offset >
s->upper_motion_limit_offset) {
93 motion_offset,
s->upper_motion_limit_offset);
100 s->hdsp.put_pixels_tab[!
s->is_16bpp][0](
s->pixel_ptr,
src->data[0] + motion_offset,
122 B = bytestream2_get_byte(&
s->stream_ptr);
124 B = bytestream2_get_byte(&
s->mv_ptr);
131 x = -14 + ((
B - 56) % 29);
132 y = 8 + ((
B - 56) / 29);
135 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
148 B = bytestream2_get_byte(&
s->stream_ptr);
150 B = bytestream2_get_byte(&
s->mv_ptr);
157 x = -(-14 + ((
B - 56) % 29));
158 y = -( 8 + ((
B - 56) / 29));
161 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
168 unsigned char B,
BL, BH;
172 B = bytestream2_get_byte(&
s->stream_ptr);
174 B = bytestream2_get_byte(&
s->mv_ptr);
178 BH = (
B >> 4) & 0x0F;
182 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
192 x = bytestream2_get_byte(&
s->stream_ptr);
193 y = bytestream2_get_byte(&
s->stream_ptr);
195 ff_tlog(
s->avctx,
"motion bytes = %d, %d\n", x, y);
220 P[0] = bytestream2_get_byte(&
s->stream_ptr);
221 P[1] = bytestream2_get_byte(&
s->stream_ptr);
226 for (y = 0; y < 8; y++) {
227 flags = bytestream2_get_byte(&
s->stream_ptr) | 0x100;
229 *
s->pixel_ptr++ =
P[
flags & 1];
230 s->pixel_ptr +=
s->line_inc;
236 flags = bytestream2_get_le16(&
s->stream_ptr);
237 for (y = 0; y < 8; y += 2) {
238 for (x = 0; x < 8; x += 2, flags >>= 1) {
240 s->pixel_ptr[x + 1 ] =
241 s->pixel_ptr[x +
s->stride] =
242 s->pixel_ptr[x + 1 +
s->stride] =
P[
flags & 1];
244 s->pixel_ptr +=
s->stride * 2;
256 unsigned int flags = 0;
265 P[0] = bytestream2_get_byte(&
s->stream_ptr);
266 P[1] = bytestream2_get_byte(&
s->stream_ptr);
269 for (y = 0; y < 16; y++) {
273 P[0] = bytestream2_get_byte(&
s->stream_ptr);
274 P[1] = bytestream2_get_byte(&
s->stream_ptr);
276 flags = bytestream2_get_le16(&
s->stream_ptr);
279 for (x = 0; x < 4; x++, flags >>= 1)
280 *
s->pixel_ptr++ =
P[
flags & 1];
281 s->pixel_ptr +=
s->stride - 4;
283 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
287 flags = bytestream2_get_le32(&
s->stream_ptr);
288 P[2] = bytestream2_get_byte(&
s->stream_ptr);
289 P[3] = bytestream2_get_byte(&
s->stream_ptr);
295 for (y = 0; y < 16; y++) {
296 for (x = 0; x < 4; x++, flags >>= 1)
297 *
s->pixel_ptr++ =
P[
flags & 1];
298 s->pixel_ptr +=
s->stride - 4;
301 s->pixel_ptr -= 8 *
s->stride - 4;
304 flags = bytestream2_get_le32(&
s->stream_ptr);
312 for (y = 0; y < 8; y++) {
316 flags = bytestream2_get_le32(&
s->stream_ptr);
319 for (x = 0; x < 8; x++, flags >>= 1)
320 *
s->pixel_ptr++ =
P[
flags & 1];
321 s->pixel_ptr +=
s->line_inc;
347 for (y = 0; y < 8; y++) {
349 int flags = bytestream2_get_le16(&
s->stream_ptr);
350 for (x = 0; x < 8; x++, flags >>= 2)
351 *
s->pixel_ptr++ =
P[
flags & 0x03];
352 s->pixel_ptr +=
s->line_inc;
359 flags = bytestream2_get_le32(&
s->stream_ptr);
361 for (y = 0; y < 8; y += 2) {
362 for (x = 0; x < 8; x += 2, flags >>= 2) {
364 s->pixel_ptr[x + 1 ] =
365 s->pixel_ptr[x +
s->stride] =
366 s->pixel_ptr[x + 1 +
s->stride] =
P[
flags & 0x03];
368 s->pixel_ptr +=
s->stride * 2;
376 flags = bytestream2_get_le64(&
s->stream_ptr);
378 for (y = 0; y < 8; y++) {
379 for (x = 0; x < 8; x += 2, flags >>= 2) {
381 s->pixel_ptr[x + 1] =
P[
flags & 0x03];
383 s->pixel_ptr +=
s->stride;
386 for (y = 0; y < 8; y += 2) {
387 for (x = 0; x < 8; x++, flags >>= 2) {
389 s->pixel_ptr[x +
s->stride] =
P[
flags & 0x03];
391 s->pixel_ptr +=
s->stride * 2;
418 for (y = 0; y < 16; y++) {
422 flags = bytestream2_get_le32(&
s->stream_ptr);
425 for (x = 0; x < 4; x++, flags >>= 2)
426 *
s->pixel_ptr++ =
P[
flags & 0x03];
428 s->pixel_ptr +=
s->stride - 4;
430 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
436 uint64_t
flags = bytestream2_get_le64(&
s->stream_ptr);
444 for (y = 0; y < 16; y++) {
445 for (x = 0; x < 4; x++, flags >>= 2)
446 *
s->pixel_ptr++ =
P[
flags & 0x03];
449 s->pixel_ptr +=
s->stride - 4;
451 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
452 }
else if (y & 1)
s->pixel_ptr +=
s->line_inc;
457 flags = bytestream2_get_le64(&
s->stream_ptr);
471 for (y = 0; y < 8; y++) {
473 s->pixel_ptr +=
s->stride;
485 for (y = 0; y < 8; y += 2) {
486 for (x = 0; x < 8; x += 2) {
488 s->pixel_ptr[x + 1 ] =
489 s->pixel_ptr[x +
s->stride] =
490 s->pixel_ptr[x + 1 +
s->stride] = bytestream2_get_byte(&
s->stream_ptr);
492 s->pixel_ptr +=
s->stride * 2;
510 for (y = 0; y < 8; y++) {
512 P[0] = bytestream2_get_byte(&
s->stream_ptr);
513 P[1] = bytestream2_get_byte(&
s->stream_ptr);
515 memset(
s->pixel_ptr,
P[0], 4);
516 memset(
s->pixel_ptr + 4,
P[1], 4);
517 s->pixel_ptr +=
s->stride;
530 pix = bytestream2_get_byte(&
s->stream_ptr);
532 for (y = 0; y < 8; y++) {
533 memset(
s->pixel_ptr, pix, 8);
534 s->pixel_ptr +=
s->stride;
547 sample[0] = bytestream2_get_byte(&
s->stream_ptr);
548 sample[1] = bytestream2_get_byte(&
s->stream_ptr);
550 for (y = 0; y < 8; y++) {
551 for (x = 0; x < 8; x += 2) {
552 *
s->pixel_ptr++ =
sample[ y & 1 ];
553 *
s->pixel_ptr++ =
sample[!(y & 1)];
555 s->pixel_ptr +=
s->line_inc;
567 x = bytestream2_get_byte(&
s->stream_ptr);
568 y = bytestream2_get_byte(&
s->stream_ptr);
570 ff_tlog(
s->avctx,
"motion bytes = %d, %d\n", x, y);
579 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
582 P[0] = bytestream2_get_le16(&
s->stream_ptr);
583 P[1] = bytestream2_get_le16(&
s->stream_ptr);
585 if (!(
P[0] & 0x8000)) {
587 for (y = 0; y < 8; y++) {
588 flags = bytestream2_get_byte(&
s->stream_ptr) | 0x100;
590 *pixel_ptr++ =
P[
flags & 1];
591 pixel_ptr +=
s->line_inc;
596 flags = bytestream2_get_le16(&
s->stream_ptr);
597 for (y = 0; y < 8; y += 2) {
598 for (x = 0; x < 8; x += 2, flags >>= 1) {
601 pixel_ptr[x +
s->stride] =
602 pixel_ptr[x + 1 +
s->stride] =
P[
flags & 1];
604 pixel_ptr +=
s->stride * 2;
615 unsigned int flags = 0;
616 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
620 P[0] = bytestream2_get_le16(&
s->stream_ptr);
621 P[1] = bytestream2_get_le16(&
s->stream_ptr);
623 if (!(
P[0] & 0x8000)) {
625 for (y = 0; y < 16; y++) {
629 P[0] = bytestream2_get_le16(&
s->stream_ptr);
630 P[1] = bytestream2_get_le16(&
s->stream_ptr);
632 flags = bytestream2_get_le16(&
s->stream_ptr);
635 for (x = 0; x < 4; x++, flags >>= 1)
636 *pixel_ptr++ =
P[
flags & 1];
637 pixel_ptr +=
s->stride - 4;
639 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
644 flags = bytestream2_get_le32(&
s->stream_ptr);
645 P[2] = bytestream2_get_le16(&
s->stream_ptr);
646 P[3] = bytestream2_get_le16(&
s->stream_ptr);
648 if (!(
P[2] & 0x8000)) {
652 for (y = 0; y < 16; y++) {
653 for (x = 0; x < 4; x++, flags >>= 1)
654 *pixel_ptr++ =
P[
flags & 1];
655 pixel_ptr +=
s->stride - 4;
658 pixel_ptr -= 8 *
s->stride - 4;
661 flags = bytestream2_get_le32(&
s->stream_ptr);
669 for (y = 0; y < 8; y++) {
673 flags = bytestream2_get_le32(&
s->stream_ptr);
676 for (x = 0; x < 8; x++, flags >>= 1)
677 *pixel_ptr++ =
P[
flags & 1];
678 pixel_ptr +=
s->line_inc;
691 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
694 for (x = 0; x < 4; x++)
695 P[x] = bytestream2_get_le16(&
s->stream_ptr);
697 if (!(
P[0] & 0x8000)) {
698 if (!(
P[2] & 0x8000)) {
701 for (y = 0; y < 8; y++) {
703 int flags = bytestream2_get_le16(&
s->stream_ptr);
704 for (x = 0; x < 8; x++, flags >>= 2)
705 *pixel_ptr++ =
P[
flags & 0x03];
706 pixel_ptr +=
s->line_inc;
713 flags = bytestream2_get_le32(&
s->stream_ptr);
715 for (y = 0; y < 8; y += 2) {
716 for (x = 0; x < 8; x += 2, flags >>= 2) {
719 pixel_ptr[x +
s->stride] =
720 pixel_ptr[x + 1 +
s->stride] =
P[
flags & 0x03];
722 pixel_ptr +=
s->stride * 2;
730 flags = bytestream2_get_le64(&
s->stream_ptr);
731 if (!(
P[2] & 0x8000)) {
732 for (y = 0; y < 8; y++) {
733 for (x = 0; x < 8; x += 2, flags >>= 2) {
735 pixel_ptr[x + 1] =
P[
flags & 0x03];
737 pixel_ptr +=
s->stride;
740 for (y = 0; y < 8; y += 2) {
741 for (x = 0; x < 8; x++, flags >>= 2) {
743 pixel_ptr[x +
s->stride] =
P[
flags & 0x03];
745 pixel_ptr +=
s->stride * 2;
759 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
761 for (x = 0; x < 4; x++)
762 P[x] = bytestream2_get_le16(&
s->stream_ptr);
766 if (!(
P[0] & 0x8000)) {
769 for (y = 0; y < 16; y++) {
773 for (x = 0; x < 4; x++)
774 P[x] = bytestream2_get_le16(&
s->stream_ptr);
775 flags = bytestream2_get_le32(&
s->stream_ptr);
778 for (x = 0; x < 4; x++, flags >>= 2)
779 *pixel_ptr++ =
P[
flags & 0x03];
781 pixel_ptr +=
s->stride - 4;
783 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
789 uint64_t
flags = bytestream2_get_le64(&
s->stream_ptr);
791 for (x = 4; x < 8; x++)
792 P[x] = bytestream2_get_le16(&
s->stream_ptr);
793 vert = !(
P[4] & 0x8000);
798 for (y = 0; y < 16; y++) {
799 for (x = 0; x < 4; x++, flags >>= 2)
800 *pixel_ptr++ =
P[
flags & 0x03];
803 pixel_ptr +=
s->stride - 4;
805 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
806 }
else if (y & 1) pixel_ptr +=
s->line_inc;
811 flags = bytestream2_get_le64(&
s->stream_ptr);
823 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
826 for (y = 0; y < 8; y++) {
827 for (x = 0; x < 8; x++)
828 pixel_ptr[x] = bytestream2_get_le16(&
s->stream_ptr);
829 pixel_ptr +=
s->stride;
839 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
842 for (y = 0; y < 8; y += 2) {
843 for (x = 0; x < 8; x += 2) {
846 pixel_ptr[x +
s->stride] =
847 pixel_ptr[x + 1 +
s->stride] = bytestream2_get_le16(&
s->stream_ptr);
849 pixel_ptr +=
s->stride * 2;
860 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
863 for (y = 0; y < 8; y++) {
865 P[0] = bytestream2_get_le16(&
s->stream_ptr);
866 P[1] = bytestream2_get_le16(&
s->stream_ptr);
868 for (x = 0; x < 8; x++)
869 pixel_ptr[x] =
P[x >> 2];
870 pixel_ptr +=
s->stride;
881 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
884 pix = bytestream2_get_le16(&
s->stream_ptr);
886 for (y = 0; y < 8; y++) {
887 for (x = 0; x < 8; x++)
889 pixel_ptr +=
s->stride;
925 s->pixel_ptr +=
s->stride;
929 if (
s->avctx->frame_num > 2)
939 off_x = ((uint16_t)opcode - 0xC000) %
frame->
width;
940 off_y = ((uint16_t)opcode - 0xC000) /
frame->
width;
942 }
else if (opcode > 0) {
943 off_x = ((uint16_t)opcode - 0x4000) %
frame->
width;
944 off_y = ((uint16_t)opcode - 0x4000) /
frame->
width;
963 s->line_inc =
s->stride - 8;
964 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->
linesize[0]
965 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
969 for (pass = 0; pass < 2; ++pass) {
971 for (y = 0; y <
s->avctx->height; y += 8) {
972 for (x = 0; x <
s->avctx->width; x += 8) {
973 opcode = bytestream2_get_le16(&decoding_map_ptr);
976 " block @ (%3d, %3d): opcode 0x%X, data ptr offset %d\n",
987 "decode finished with %d bytes left over\n",
999 s->pixel_ptr +=
s->stride;
1009 off_x = ((uint16_t)opcode - 0xC000) %
s->cur_decode_frame->width;
1010 off_y = ((uint16_t)opcode - 0xC000) /
s->cur_decode_frame->width;
1011 copy_from(
s,
s->prev_decode_frame,
s->cur_decode_frame, off_x, off_y);
1012 }
else if (opcode > 0) {
1013 off_x = ((uint16_t)opcode - 0x4000) %
s->cur_decode_frame->width;
1014 off_y = ((uint16_t)opcode - 0x4000) /
s->cur_decode_frame->width;
1015 copy_from(
s,
s->cur_decode_frame,
s->cur_decode_frame, off_x, off_y);
1025 int pass, x, y, changed_block;
1026 int16_t opcode,
skip;
1036 s->line_inc =
s->stride - 8;
1037 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->
linesize[0]
1038 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
1043 for (pass = 0; pass < 2; ++pass) {
1046 skip = bytestream2_get_le16(&skip_map_ptr);
1048 for (y = 0; y <
s->avctx->height; y += 8) {
1049 for (x = 0; x <
s->avctx->width; x += 8) {
1050 s->pixel_ptr =
s->cur_decode_frame->data[0] + x + y *
s->cur_decode_frame->linesize[0];
1054 opcode = bytestream2_get_le16(&decoding_map_ptr);
1060 skip = bytestream2_get_le16(&skip_map_ptr);
1068 skip = bytestream2_get_le16(&skip_map_ptr);
1069 for (y = 0; y <
s->avctx->height; y += 8) {
1070 for (x = 0; x <
s->avctx->width; x += 8) {
1081 skip = bytestream2_get_le16(&skip_map_ptr);
1084 if (changed_block) {
1088 if (
s->avctx->frame_num)
1099 "decode finished with %d bytes left over\n",
1107 unsigned char opcode;
1119 s->mv_ptr =
s->stream_ptr;
1122 s->line_inc =
s->stride - 8;
1123 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->
linesize[0]
1124 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
1127 for (y = 0; y <
s->avctx->height; y += 8) {
1128 for (x = 0; x <
s->avctx->width; x += 8) {
1134 " block @ (%3d, %3d): encoding 0x%X, data ptr offset %d\n",
1148 s->avctx->frame_num, x, y);
1155 "decode finished with %d bytes left over\n",
1175 if (!
s->last_frame || !
s->second_last_frame ||
1176 !
s->cur_decode_frame || !
s->prev_decode_frame) {
1180 s->cur_decode_frame->width = avctx->
width;
1181 s->prev_decode_frame->width = avctx->
width;
1182 s->cur_decode_frame->height = avctx->
height;
1183 s->prev_decode_frame->height = avctx->
height;
1184 s->cur_decode_frame->format = avctx->
pix_fmt;
1185 s->prev_decode_frame->format = avctx->
pix_fmt;
1193 const uint8_t *buf = avpkt->
data;
1194 int buf_size = avpkt->
size;
1199 int video_data_size;
1208 if (!
s->cur_decode_frame->data[0]) {
1223 frame_format =
AV_RL8(buf);
1224 send_buffer =
AV_RL8(buf + 1);
1225 video_data_size =
AV_RL16(buf + 2);
1226 s->decoding_map_size =
AV_RL16(buf + 4);
1227 s->skip_map_size =
AV_RL16(buf + 6);
1229 switch (frame_format) {
1231 if (
s->decoding_map_size) {
1236 if (
s->skip_map_size) {
1247 s->decoding_map_size = ((
s->avctx->width / 8) * (
s->avctx->height / 8)) * 2;
1248 s->decoding_map = buf + 8 + 14;
1249 video_data_size -=
s->decoding_map_size + 14;
1250 if (video_data_size <= 0 || s->decoding_map_size == 0)
1253 if (buf_size < 8 + s->decoding_map_size + 14 + video_data_size)
1256 bytestream2_init(&
s->stream_ptr, buf + 8 +
s->decoding_map_size + 14, video_data_size);
1261 if (!
s->decoding_map_size) {
1266 if (!
s->skip_map_size) {
1276 if (buf_size < 8 + video_data_size + s->decoding_map_size +
s->skip_map_size)
1280 s->decoding_map = buf + 8 + video_data_size;
1281 s->skip_map = buf + 8 + video_data_size +
s->decoding_map_size;
1286 if (!
s->decoding_map_size) {
1291 if (
s->skip_map_size) {
1296 if (buf_size < 8 + video_data_size + s->decoding_map_size)
1300 s->decoding_map = buf + 8 + video_data_size;
1309 if (buf_size < 8 + s->decoding_map_size + video_data_size +
s->skip_map_size) {
1318 #if FF_API_PALETTE_HAS_CHANGED
1323 #if FF_API_PALETTE_HAS_CHANGED
1328 switch (frame_format) {
1340 *got_frame = send_buffer;
1364 .
p.
name =
"interplayvideo",