43 #define BITSTREAM_READER_LE
52 #define PALETTE_COUNT 256
83 int current_offset =
s->pixel_ptr - dst->
data[0];
84 int x = (current_offset % dst->
linesize[0]) / (1 +
s->is_16bpp);
85 int y = current_offset / dst->
linesize[0];
86 int dx = delta_x + x - ((delta_x + x >=
width) - (delta_x + x < 0)) *
width;
87 int dy = delta_y + y + (delta_x + x >=
width) - (delta_x + x < 0);
88 int motion_offset = dy *
src->linesize[0] + dx * (1 +
s->is_16bpp);
90 if (motion_offset < 0) {
93 }
else if (motion_offset >
s->upper_motion_limit_offset) {
95 motion_offset,
s->upper_motion_limit_offset);
102 s->hdsp.put_pixels_tab[!
s->is_16bpp][0](
s->pixel_ptr,
src->data[0] + motion_offset,
124 B = bytestream2_get_byte(&
s->stream_ptr);
126 B = bytestream2_get_byte(&
s->mv_ptr);
133 x = -14 + ((
B - 56) % 29);
134 y = 8 + ((
B - 56) / 29);
137 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
150 B = bytestream2_get_byte(&
s->stream_ptr);
152 B = bytestream2_get_byte(&
s->mv_ptr);
159 x = -(-14 + ((
B - 56) % 29));
160 y = -( 8 + ((
B - 56) / 29));
163 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
170 unsigned char B,
BL, BH;
174 B = bytestream2_get_byte(&
s->stream_ptr);
176 B = bytestream2_get_byte(&
s->mv_ptr);
180 BH = (
B >> 4) & 0x0F;
184 ff_tlog(
s->avctx,
"motion byte = %d, (x, y) = (%d, %d)\n",
B, x, y);
194 x = bytestream2_get_byte(&
s->stream_ptr);
195 y = bytestream2_get_byte(&
s->stream_ptr);
197 ff_tlog(
s->avctx,
"motion bytes = %d, %d\n", x, y);
222 P[0] = bytestream2_get_byte(&
s->stream_ptr);
223 P[1] = bytestream2_get_byte(&
s->stream_ptr);
228 for (y = 0; y < 8; y++) {
229 flags = bytestream2_get_byte(&
s->stream_ptr) | 0x100;
231 *
s->pixel_ptr++ =
P[
flags & 1];
232 s->pixel_ptr +=
s->line_inc;
238 flags = bytestream2_get_le16(&
s->stream_ptr);
239 for (y = 0; y < 8; y += 2) {
240 for (x = 0; x < 8; x += 2, flags >>= 1) {
242 s->pixel_ptr[x + 1 ] =
243 s->pixel_ptr[x +
s->stride] =
244 s->pixel_ptr[x + 1 +
s->stride] =
P[
flags & 1];
246 s->pixel_ptr +=
s->stride * 2;
258 unsigned int flags = 0;
267 P[0] = bytestream2_get_byte(&
s->stream_ptr);
268 P[1] = bytestream2_get_byte(&
s->stream_ptr);
271 for (y = 0; y < 16; y++) {
275 P[0] = bytestream2_get_byte(&
s->stream_ptr);
276 P[1] = bytestream2_get_byte(&
s->stream_ptr);
278 flags = bytestream2_get_le16(&
s->stream_ptr);
281 for (x = 0; x < 4; x++, flags >>= 1)
282 *
s->pixel_ptr++ =
P[
flags & 1];
283 s->pixel_ptr +=
s->stride - 4;
285 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
289 flags = bytestream2_get_le32(&
s->stream_ptr);
290 P[2] = bytestream2_get_byte(&
s->stream_ptr);
291 P[3] = bytestream2_get_byte(&
s->stream_ptr);
297 for (y = 0; y < 16; y++) {
298 for (x = 0; x < 4; x++, flags >>= 1)
299 *
s->pixel_ptr++ =
P[
flags & 1];
300 s->pixel_ptr +=
s->stride - 4;
303 s->pixel_ptr -= 8 *
s->stride - 4;
306 flags = bytestream2_get_le32(&
s->stream_ptr);
314 for (y = 0; y < 8; y++) {
318 flags = bytestream2_get_le32(&
s->stream_ptr);
321 for (x = 0; x < 8; x++, flags >>= 1)
322 *
s->pixel_ptr++ =
P[
flags & 1];
323 s->pixel_ptr +=
s->line_inc;
349 for (y = 0; y < 8; y++) {
351 int flags = bytestream2_get_le16(&
s->stream_ptr);
352 for (x = 0; x < 8; x++, flags >>= 2)
353 *
s->pixel_ptr++ =
P[
flags & 0x03];
354 s->pixel_ptr +=
s->line_inc;
361 flags = bytestream2_get_le32(&
s->stream_ptr);
363 for (y = 0; y < 8; y += 2) {
364 for (x = 0; x < 8; x += 2, flags >>= 2) {
366 s->pixel_ptr[x + 1 ] =
367 s->pixel_ptr[x +
s->stride] =
368 s->pixel_ptr[x + 1 +
s->stride] =
P[
flags & 0x03];
370 s->pixel_ptr +=
s->stride * 2;
378 flags = bytestream2_get_le64(&
s->stream_ptr);
380 for (y = 0; y < 8; y++) {
381 for (x = 0; x < 8; x += 2, flags >>= 2) {
383 s->pixel_ptr[x + 1] =
P[
flags & 0x03];
385 s->pixel_ptr +=
s->stride;
388 for (y = 0; y < 8; y += 2) {
389 for (x = 0; x < 8; x++, flags >>= 2) {
391 s->pixel_ptr[x +
s->stride] =
P[
flags & 0x03];
393 s->pixel_ptr +=
s->stride * 2;
420 for (y = 0; y < 16; y++) {
424 flags = bytestream2_get_le32(&
s->stream_ptr);
427 for (x = 0; x < 4; x++, flags >>= 2)
428 *
s->pixel_ptr++ =
P[
flags & 0x03];
430 s->pixel_ptr +=
s->stride - 4;
432 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
438 uint64_t
flags = bytestream2_get_le64(&
s->stream_ptr);
446 for (y = 0; y < 16; y++) {
447 for (x = 0; x < 4; x++, flags >>= 2)
448 *
s->pixel_ptr++ =
P[
flags & 0x03];
451 s->pixel_ptr +=
s->stride - 4;
453 if (y == 7)
s->pixel_ptr -= 8 *
s->stride - 4;
454 }
else if (y & 1)
s->pixel_ptr +=
s->line_inc;
459 flags = bytestream2_get_le64(&
s->stream_ptr);
473 for (y = 0; y < 8; y++) {
475 s->pixel_ptr +=
s->stride;
487 for (y = 0; y < 8; y += 2) {
488 for (x = 0; x < 8; x += 2) {
490 s->pixel_ptr[x + 1 ] =
491 s->pixel_ptr[x +
s->stride] =
492 s->pixel_ptr[x + 1 +
s->stride] = bytestream2_get_byte(&
s->stream_ptr);
494 s->pixel_ptr +=
s->stride * 2;
512 for (y = 0; y < 8; y++) {
514 P[0] = bytestream2_get_byte(&
s->stream_ptr);
515 P[1] = bytestream2_get_byte(&
s->stream_ptr);
517 memset(
s->pixel_ptr,
P[0], 4);
518 memset(
s->pixel_ptr + 4,
P[1], 4);
519 s->pixel_ptr +=
s->stride;
532 pix = bytestream2_get_byte(&
s->stream_ptr);
534 for (y = 0; y < 8; y++) {
535 memset(
s->pixel_ptr, pix, 8);
536 s->pixel_ptr +=
s->stride;
549 sample[0] = bytestream2_get_byte(&
s->stream_ptr);
550 sample[1] = bytestream2_get_byte(&
s->stream_ptr);
552 for (y = 0; y < 8; y++) {
553 for (x = 0; x < 8; x += 2) {
554 *
s->pixel_ptr++ =
sample[ y & 1 ];
555 *
s->pixel_ptr++ =
sample[!(y & 1)];
557 s->pixel_ptr +=
s->line_inc;
569 x = bytestream2_get_byte(&
s->stream_ptr);
570 y = bytestream2_get_byte(&
s->stream_ptr);
572 ff_tlog(
s->avctx,
"motion bytes = %d, %d\n", x, y);
581 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
584 P[0] = bytestream2_get_le16(&
s->stream_ptr);
585 P[1] = bytestream2_get_le16(&
s->stream_ptr);
587 if (!(
P[0] & 0x8000)) {
589 for (y = 0; y < 8; y++) {
590 flags = bytestream2_get_byte(&
s->stream_ptr) | 0x100;
592 *pixel_ptr++ =
P[
flags & 1];
593 pixel_ptr +=
s->line_inc;
598 flags = bytestream2_get_le16(&
s->stream_ptr);
599 for (y = 0; y < 8; y += 2) {
600 for (x = 0; x < 8; x += 2, flags >>= 1) {
603 pixel_ptr[x +
s->stride] =
604 pixel_ptr[x + 1 +
s->stride] =
P[
flags & 1];
606 pixel_ptr +=
s->stride * 2;
617 unsigned int flags = 0;
618 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
622 P[0] = bytestream2_get_le16(&
s->stream_ptr);
623 P[1] = bytestream2_get_le16(&
s->stream_ptr);
625 if (!(
P[0] & 0x8000)) {
627 for (y = 0; y < 16; y++) {
631 P[0] = bytestream2_get_le16(&
s->stream_ptr);
632 P[1] = bytestream2_get_le16(&
s->stream_ptr);
634 flags = bytestream2_get_le16(&
s->stream_ptr);
637 for (x = 0; x < 4; x++, flags >>= 1)
638 *pixel_ptr++ =
P[
flags & 1];
639 pixel_ptr +=
s->stride - 4;
641 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
646 flags = bytestream2_get_le32(&
s->stream_ptr);
647 P[2] = bytestream2_get_le16(&
s->stream_ptr);
648 P[3] = bytestream2_get_le16(&
s->stream_ptr);
650 if (!(
P[2] & 0x8000)) {
654 for (y = 0; y < 16; y++) {
655 for (x = 0; x < 4; x++, flags >>= 1)
656 *pixel_ptr++ =
P[
flags & 1];
657 pixel_ptr +=
s->stride - 4;
660 pixel_ptr -= 8 *
s->stride - 4;
663 flags = bytestream2_get_le32(&
s->stream_ptr);
671 for (y = 0; y < 8; y++) {
675 flags = bytestream2_get_le32(&
s->stream_ptr);
678 for (x = 0; x < 8; x++, flags >>= 1)
679 *pixel_ptr++ =
P[
flags & 1];
680 pixel_ptr +=
s->line_inc;
693 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
696 for (x = 0; x < 4; x++)
697 P[x] = bytestream2_get_le16(&
s->stream_ptr);
699 if (!(
P[0] & 0x8000)) {
700 if (!(
P[2] & 0x8000)) {
703 for (y = 0; y < 8; y++) {
705 int flags = bytestream2_get_le16(&
s->stream_ptr);
706 for (x = 0; x < 8; x++, flags >>= 2)
707 *pixel_ptr++ =
P[
flags & 0x03];
708 pixel_ptr +=
s->line_inc;
715 flags = bytestream2_get_le32(&
s->stream_ptr);
717 for (y = 0; y < 8; y += 2) {
718 for (x = 0; x < 8; x += 2, flags >>= 2) {
721 pixel_ptr[x +
s->stride] =
722 pixel_ptr[x + 1 +
s->stride] =
P[
flags & 0x03];
724 pixel_ptr +=
s->stride * 2;
732 flags = bytestream2_get_le64(&
s->stream_ptr);
733 if (!(
P[2] & 0x8000)) {
734 for (y = 0; y < 8; y++) {
735 for (x = 0; x < 8; x += 2, flags >>= 2) {
737 pixel_ptr[x + 1] =
P[
flags & 0x03];
739 pixel_ptr +=
s->stride;
742 for (y = 0; y < 8; y += 2) {
743 for (x = 0; x < 8; x++, flags >>= 2) {
745 pixel_ptr[x +
s->stride] =
P[
flags & 0x03];
747 pixel_ptr +=
s->stride * 2;
761 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
763 for (x = 0; x < 4; x++)
764 P[x] = bytestream2_get_le16(&
s->stream_ptr);
768 if (!(
P[0] & 0x8000)) {
771 for (y = 0; y < 16; y++) {
775 for (x = 0; x < 4; x++)
776 P[x] = bytestream2_get_le16(&
s->stream_ptr);
777 flags = bytestream2_get_le32(&
s->stream_ptr);
780 for (x = 0; x < 4; x++, flags >>= 2)
781 *pixel_ptr++ =
P[
flags & 0x03];
783 pixel_ptr +=
s->stride - 4;
785 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
791 uint64_t
flags = bytestream2_get_le64(&
s->stream_ptr);
793 for (x = 4; x < 8; x++)
794 P[x] = bytestream2_get_le16(&
s->stream_ptr);
795 vert = !(
P[4] & 0x8000);
800 for (y = 0; y < 16; y++) {
801 for (x = 0; x < 4; x++, flags >>= 2)
802 *pixel_ptr++ =
P[
flags & 0x03];
805 pixel_ptr +=
s->stride - 4;
807 if (y == 7) pixel_ptr -= 8 *
s->stride - 4;
808 }
else if (y & 1) pixel_ptr +=
s->line_inc;
813 flags = bytestream2_get_le64(&
s->stream_ptr);
825 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
828 for (y = 0; y < 8; y++) {
829 for (x = 0; x < 8; x++)
830 pixel_ptr[x] = bytestream2_get_le16(&
s->stream_ptr);
831 pixel_ptr +=
s->stride;
841 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
844 for (y = 0; y < 8; y += 2) {
845 for (x = 0; x < 8; x += 2) {
848 pixel_ptr[x +
s->stride] =
849 pixel_ptr[x + 1 +
s->stride] = bytestream2_get_le16(&
s->stream_ptr);
851 pixel_ptr +=
s->stride * 2;
862 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
865 for (y = 0; y < 8; y++) {
867 P[0] = bytestream2_get_le16(&
s->stream_ptr);
868 P[1] = bytestream2_get_le16(&
s->stream_ptr);
870 for (x = 0; x < 8; x++)
871 pixel_ptr[x] =
P[x >> 2];
872 pixel_ptr +=
s->stride;
883 uint16_t *pixel_ptr = (uint16_t*)
s->pixel_ptr;
886 pix = bytestream2_get_le16(&
s->stream_ptr);
888 for (y = 0; y < 8; y++) {
889 for (x = 0; x < 8; x++)
891 pixel_ptr +=
s->stride;
927 s->pixel_ptr +=
s->stride;
931 if (
s->avctx->frame_number > 2)
941 off_x = ((uint16_t)opcode - 0xC000) %
frame->width;
942 off_y = ((uint16_t)opcode - 0xC000) /
frame->width;
944 }
else if (opcode > 0) {
945 off_x = ((uint16_t)opcode - 0x4000) %
frame->width;
946 off_y = ((uint16_t)opcode - 0x4000) /
frame->width;
963 s->stride =
frame->linesize[0];
965 s->line_inc =
s->stride - 8;
966 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->linesize[0]
967 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
973 for (y = 0; y <
s->avctx->height; y += 8) {
974 for (x = 0; x <
s->avctx->width; x += 8) {
975 opcode = bytestream2_get_le16(&decoding_map_ptr);
978 " block @ (%3d, %3d): opcode 0x%X, data ptr offset %d\n",
981 s->pixel_ptr =
frame->data[0] + x + y *
frame->linesize[0];
989 "decode finished with %d bytes left over\n",
1001 s->pixel_ptr +=
s->stride;
1011 off_x = ((uint16_t)opcode - 0xC000) %
s->cur_decode_frame->width;
1012 off_y = ((uint16_t)opcode - 0xC000) /
s->cur_decode_frame->width;
1013 copy_from(
s,
s->prev_decode_frame,
s->cur_decode_frame, off_x, off_y);
1014 }
else if (opcode > 0) {
1015 off_x = ((uint16_t)opcode - 0x4000) %
s->cur_decode_frame->width;
1016 off_y = ((uint16_t)opcode - 0x4000) /
s->cur_decode_frame->width;
1017 copy_from(
s,
s->cur_decode_frame,
s->cur_decode_frame, off_x, off_y);
1027 int pass, x, y, changed_block;
1028 int16_t opcode, skip;
1036 s->stride =
frame->linesize[0];
1038 s->line_inc =
s->stride - 8;
1039 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->linesize[0]
1040 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
1048 skip = bytestream2_get_le16(&skip_map_ptr);
1050 for (y = 0; y <
s->avctx->height; y += 8) {
1051 for (x = 0; x <
s->avctx->width; x += 8) {
1052 s->pixel_ptr =
s->cur_decode_frame->data[0] + x + y *
s->cur_decode_frame->linesize[0];
1055 if (skip != -0x8000 && skip) {
1056 opcode = bytestream2_get_le16(&decoding_map_ptr);
1062 skip = bytestream2_get_le16(&skip_map_ptr);
1070 skip = bytestream2_get_le16(&skip_map_ptr);
1071 for (y = 0; y <
s->avctx->height; y += 8) {
1072 for (x = 0; x <
s->avctx->width; x += 8) {
1074 s->pixel_ptr =
frame->data[0] + x + y*
frame->linesize[0];
1077 if (skip != -0x8000 && skip) {
1083 skip = bytestream2_get_le16(&skip_map_ptr);
1086 if (changed_block) {
1090 if (
s->avctx->frame_number)
1101 "decode finished with %d bytes left over\n",
1109 unsigned char opcode;
1118 s->stride =
frame->linesize[0];
1120 s->stride =
frame->linesize[0] >> 1;
1121 s->mv_ptr =
s->stream_ptr;
1124 s->line_inc =
s->stride - 8;
1125 s->upper_motion_limit_offset = (
s->avctx->height - 8) *
frame->linesize[0]
1126 + (
s->avctx->width - 8) * (1 +
s->is_16bpp);
1129 for (y = 0; y <
s->avctx->height; y += 8) {
1130 for (x = 0; x <
s->avctx->width; x += 8) {
1136 " block @ (%3d, %3d): encoding 0x%X, data ptr offset %d\n",
1140 s->pixel_ptr =
frame->data[0] + x
1141 + y*
frame->linesize[0];
1144 s->pixel_ptr =
frame->data[0] + x*2
1145 + y*
frame->linesize[0];
1150 s->avctx->frame_number, x, y);
1157 "decode finished with %d bytes left over\n",
1177 if (!
s->last_frame || !
s->second_last_frame ||
1178 !
s->cur_decode_frame || !
s->prev_decode_frame) {
1182 s->cur_decode_frame->width = avctx->
width;
1183 s->prev_decode_frame->width = avctx->
width;
1184 s->cur_decode_frame->height = avctx->
height;
1185 s->prev_decode_frame->height = avctx->
height;
1186 s->cur_decode_frame->format = avctx->
pix_fmt;
1187 s->prev_decode_frame->format = avctx->
pix_fmt;
1195 const uint8_t *buf = avpkt->
data;
1196 int buf_size = avpkt->
size;
1201 int video_data_size;
1210 if (!
s->cur_decode_frame->data[0]) {
1225 frame_format =
AV_RL8(buf);
1226 send_buffer =
AV_RL8(buf + 1);
1227 video_data_size =
AV_RL16(buf + 2);
1228 s->decoding_map_size =
AV_RL16(buf + 4);
1229 s->skip_map_size =
AV_RL16(buf + 6);
1231 switch (frame_format) {
1233 if (
s->decoding_map_size) {
1238 if (
s->skip_map_size) {
1249 s->decoding_map_size = ((
s->avctx->width / 8) * (
s->avctx->height / 8)) * 2;
1250 s->decoding_map = buf + 8 + 14;
1251 video_data_size -=
s->decoding_map_size + 14;
1252 if (video_data_size <= 0 || s->decoding_map_size == 0)
1255 if (buf_size < 8 + s->decoding_map_size + 14 + video_data_size)
1258 bytestream2_init(&
s->stream_ptr, buf + 8 +
s->decoding_map_size + 14, video_data_size);
1263 if (!
s->decoding_map_size) {
1268 if (!
s->skip_map_size) {
1278 if (buf_size < 8 + video_data_size + s->decoding_map_size +
s->skip_map_size)
1282 s->decoding_map = buf + 8 + video_data_size;
1283 s->skip_map = buf + 8 + video_data_size +
s->decoding_map_size;
1288 if (!
s->decoding_map_size) {
1293 if (
s->skip_map_size) {
1298 if (buf_size < 8 + video_data_size + s->decoding_map_size)
1302 s->decoding_map = buf + 8 + video_data_size;
1311 if (buf_size < 8 + s->decoding_map_size + video_data_size +
s->skip_map_size) {
1323 switch (frame_format) {
1335 *got_frame = send_buffer;
1360 .
p.
name =
"interplayvideo",