32 #define TM2_ESCAPE 0x80000000
129 huff->
bits[huff->
num] = prefix;
130 huff->
lens[huff->
num] = length;
134 if ((ret =
tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
136 if ((ret =
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
160 if ((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
162 "nodes: %i\n", huff.
nodes);
188 huff.
lens,
sizeof(
int),
sizeof(
int),
189 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
196 for (i = 0; i < code->
length; i++)
224 #define TM2_OLD_HEADER_MAGIC 0x00000100
225 #define TM2_NEW_HEADER_MAGIC 0x00000101
251 if ((d < 1) || (d >
TM2_DELTAS) || (mb < 1) || (mb > 32)) {
256 for (i = 0; i < d; i++) {
258 if (v & (1 << (mb - 1)))
259 ctx->
deltas[stream_id][i] = v - (1 <<
mb);
264 ctx->
deltas[stream_id][i] = 0;
284 len = bytestream2_get_be32(&gb);
290 if (len >= INT_MAX/4-1 || len < 0 || skip > buf_size) {
295 toks = bytestream2_get_be32(&gb);
297 len = bytestream2_get_be32(&gb);
299 len = bytestream2_get_be32(&gb);
312 len = bytestream2_get_be32(&gb);
329 if ((toks < 0) || (toks > 0xFFFFFF)) {
336 len = bytestream2_get_be32(&gb);
342 for (i = 0; i < toks; i++) {
348 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS || ctx->
tokens[stream_id][i]<0) {
350 ctx->
tokens[stream_id][i], stream_id, i);
355 for (i = 0; i < toks; i++) {
357 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
359 ctx->
tokens[stream_id][i], stream_id, i);
388 #define TM2_INIT_POINTERS() \
391 int Ystride, Ustride, Vstride;\
393 Ystride = ctx->y_stride;\
394 Vstride = ctx->uv_stride;\
395 Ustride = ctx->uv_stride;\
396 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
397 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
398 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
399 last = ctx->last + bx * 4;\
400 clast = ctx->clast + bx * 4;
402 #define TM2_INIT_POINTERS_2() \
404 int oYstride, oUstride, oVstride;\
406 TM2_INIT_POINTERS();\
410 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
411 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
412 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
415 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
416 CD[0] = CHR[1] - last[1];\
417 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
418 last[0] = (int)CHR[stride + 0];\
419 last[1] = (int)CHR[stride + 1];}
427 for (j = 0; j < 4; j++){
429 for (i = 0; i < 4; i++){
430 d = deltas[i + j * 4];
433 Y[i] = av_clip_uint8(last[i]);
443 for (j = 0; j < 2; j++) {
444 for (i = 0; i < 2; i++) {
445 CD[j] += deltas[i + j * 2];
463 t = (CD[0] + CD[1]) >> 1;
464 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
465 CD[1] = CD[0] + CD[1] -
t;
479 for (i = 0; i < 4; i++) {
487 for (i = 0; i < 16; i++)
501 deltas[1] = deltas[2] = deltas[3] = 0;
505 deltas[1] = deltas[2] = deltas[3] = 0;
509 for (i = 0; i < 16; i++)
524 deltas[1] = deltas[2] = deltas[3] = 0;
528 deltas[1] = deltas[2] = deltas[3] = 0;
532 for (i = 0; i < 16; i++)
541 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
543 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
544 last[2] = (last[1] + last[3]) >> 1;
546 t1 = ctx->
D[0] + ctx->
D[1];
548 ctx->
D[1] = t1 - (t1 >> 1);
549 t2 = ctx->
D[2] + ctx->
D[3];
551 ctx->
D[3] = t2 - (t2 >> 1);
560 int left, right,
diff;
565 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
568 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
572 for (i = 0; i < 16; i++)
575 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
578 left = last[-1] - ct;
584 last[0] = left + (diff >> 2);
585 last[1] = left + (diff >> 1);
586 last[2] = right - (diff >> 2);
591 ctx->
D[0] = (tp + (ct >> 2)) - left;
593 ctx->
D[1] = (tp + (ct >> 1)) - left;
595 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
597 ctx->
D[3] = (tp + ct) - left;
608 for (j = 0; j < 2; j++) {
609 for (i = 0; i < 2; i++){
613 U += Ustride;
V += Vstride;
614 Uo += oUstride; Vo += oVstride;
622 ctx->
D[0] = Yo[3] - last[3];
623 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
624 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
625 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
627 for (j = 0; j < 4; j++) {
628 for (i = 0; i < 4; i++) {
644 for (j = 0; j < 2; j++) {
645 for (i = 0; i < 2; i++) {
660 ctx->
D[0] = Yo[3] - last[3];
661 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
662 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
663 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
665 for (j = 0; j < 4; j++) {
667 for (i = 0; i < 4; i++) {
671 ctx->
D[j] = last[3] - d;
685 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
686 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
693 Yo += my * oYstride + mx;
694 Uo += (my >> 1) * oUstride + (mx >> 1);
695 Vo += (my >> 1) * oVstride + (mx >> 1);
698 for (j = 0; j < 2; j++) {
699 for (i = 0; i < 2; i++) {
714 for (j = 0; j < 4; j++) {
715 for (i = 0; i < 4; i++) {
723 ctx->
D[0] =
Y[3] - last[3];
724 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
725 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
726 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
727 for (i = 0; i < 4; i++)
728 last[i] = Y[i + Ystride * 3];
748 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
749 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
751 for (j = 0; j < bh; j++) {
752 memset(ctx->
D, 0, 4 *
sizeof(
int));
753 memset(ctx->
CD, 0, 4 *
sizeof(
int));
754 for (i = 0; i < bw; i++) {
788 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
789 U = (ctx->
cur?ctx->
U2:ctx->
U1);
790 V = (ctx->
cur?ctx->
V2:ctx->
V1);
792 for (j = 0; j < h; j++) {
793 for (i = 0; i < w; i++) {
794 int y = Y[i],
u = U[i >> 1],
v = V[i >> 1];
795 dst[3*i+0] = av_clip_uint8(y + v);
796 dst[3*i+1] = av_clip_uint8(y);
797 dst[3*i+2] = av_clip_uint8(y + u);
801 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
802 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
810 }
else if (j == h - 1) {
820 U[-2] = U[-1] = U[0];
821 V[-2] = V[-1] = V[0];
822 U[cw + 1] = U[cw] = U[cw - 1];
823 V[cw + 1] = V[cw] = V[cw - 1];
831 }
else if (j == h - 1) {
851 #define TM2_HEADER_SIZE 40
854 void *
data,
int *got_frame,
859 int buf_size = avpkt->
size & ~3;
883 if (offset >= buf_size) {
999 .
name =
"truemotion2",