33 #define TM2_ESCAPE 0x80000000
130 huff->
bits[huff->
num] = prefix;
135 if ((ret =
tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
137 if ((ret =
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
161 if ((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
163 "nodes: %i\n", huff.
nodes);
194 huff.
lens,
sizeof(
int),
sizeof(
int),
195 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
201 code->
recode = av_malloc_array(code->
length,
sizeof(
int));
206 for (i = 0; i < code->
length; i++)
235 #define TM2_OLD_HEADER_MAGIC 0x00000100
236 #define TM2_NEW_HEADER_MAGIC 0x00000101
262 if ((d < 1) || (d >
TM2_DELTAS) || (mb < 1) || (mb > 32)) {
267 for (i = 0; i < d; i++) {
269 if (v & (1 << (mb - 1)))
270 ctx->
deltas[stream_id][i] = v - (1 <<
mb);
275 ctx->
deltas[stream_id][i] = 0;
295 len = bytestream2_get_be32(&gb);
301 if (len >= INT_MAX/4-1 || len < 0 || skip > buf_size) {
306 toks = bytestream2_get_be32(&gb);
308 len = bytestream2_get_be32(&gb);
310 len = bytestream2_get_be32(&gb);
323 len = bytestream2_get_be32(&gb);
340 if ((toks < 0) || (toks > 0xFFFFFF)) {
351 len = bytestream2_get_be32(&gb);
357 for (i = 0; i < toks; i++) {
363 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS || ctx->
tokens[stream_id][i]<0) {
365 ctx->
tokens[stream_id][i], stream_id, i);
370 for (i = 0; i < toks; i++) {
372 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
374 ctx->
tokens[stream_id][i], stream_id, i);
403 #define TM2_INIT_POINTERS() \
406 int Ystride, Ustride, Vstride;\
408 Ystride = ctx->y_stride;\
409 Vstride = ctx->uv_stride;\
410 Ustride = ctx->uv_stride;\
411 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
412 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
413 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
414 last = ctx->last + bx * 4;\
415 clast = ctx->clast + bx * 4;
417 #define TM2_INIT_POINTERS_2() \
419 int oYstride, oUstride, oVstride;\
421 TM2_INIT_POINTERS();\
425 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
426 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
427 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
430 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
431 CD[0] = CHR[1] - last[1];\
432 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
433 last[0] = (int)CHR[stride + 0];\
434 last[1] = (int)CHR[stride + 1];}
442 for (j = 0; j < 4; j++){
444 for (i = 0; i < 4; i++){
445 d = deltas[i + j * 4];
448 Y[i] = av_clip_uint8(last[i]);
458 for (j = 0; j < 2; j++) {
459 for (i = 0; i < 2; i++) {
460 CD[j] += deltas[i + j * 2];
478 t = (CD[0] + CD[1]) >> 1;
479 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
480 CD[1] = CD[0] + CD[1] -
t;
494 for (i = 0; i < 4; i++) {
502 for (i = 0; i < 16; i++)
516 deltas[1] = deltas[2] = deltas[3] = 0;
520 deltas[1] = deltas[2] = deltas[3] = 0;
524 for (i = 0; i < 16; i++)
539 deltas[1] = deltas[2] = deltas[3] = 0;
543 deltas[1] = deltas[2] = deltas[3] = 0;
547 for (i = 0; i < 16; i++)
556 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
558 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
559 last[2] = (last[1] + last[3]) >> 1;
561 t1 = ctx->
D[0] + ctx->
D[1];
563 ctx->
D[1] = t1 - (t1 >> 1);
564 t2 = ctx->
D[2] + ctx->
D[3];
566 ctx->
D[3] = t2 - (t2 >> 1);
575 int left, right, diff;
580 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
583 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
587 for (i = 0; i < 16; i++)
590 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
593 left = last[-1] - ct;
599 last[0] = left + (diff >> 2);
600 last[1] = left + (diff >> 1);
601 last[2] = right - (diff >> 2);
606 ctx->
D[0] = (tp + (ct >> 2)) - left;
608 ctx->
D[1] = (tp + (ct >> 1)) - left;
610 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
612 ctx->
D[3] = (tp + ct) - left;
623 for (j = 0; j < 2; j++) {
624 for (i = 0; i < 2; i++){
628 U += Ustride;
V += Vstride;
629 Uo += oUstride; Vo += oVstride;
637 ctx->
D[0] = Yo[3] - last[3];
638 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
639 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
640 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
642 for (j = 0; j < 4; j++) {
643 for (i = 0; i < 4; i++) {
659 for (j = 0; j < 2; j++) {
660 for (i = 0; i < 2; i++) {
675 ctx->
D[0] = Yo[3] - last[3];
676 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
677 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
678 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
680 for (j = 0; j < 4; j++) {
682 for (i = 0; i < 4; i++) {
686 ctx->
D[j] = last[3] - d;
700 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
701 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
708 Yo += my * oYstride + mx;
709 Uo += (my >> 1) * oUstride + (mx >> 1);
710 Vo += (my >> 1) * oVstride + (mx >> 1);
713 for (j = 0; j < 2; j++) {
714 for (i = 0; i < 2; i++) {
729 for (j = 0; j < 4; j++) {
730 for (i = 0; i < 4; i++) {
738 ctx->
D[0] =
Y[3] - last[3];
739 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
740 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
741 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
742 for (i = 0; i < 4; i++)
743 last[i] = Y[i + Ystride * 3];
763 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
764 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
766 for (j = 0; j < bh; j++) {
767 memset(ctx->
D, 0, 4 *
sizeof(
int));
768 memset(ctx->
CD, 0, 4 *
sizeof(
int));
769 for (i = 0; i < bw; i++) {
803 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
804 U = (ctx->
cur?ctx->
U2:ctx->
U1);
805 V = (ctx->
cur?ctx->
V2:ctx->
V1);
807 for (j = 0; j < h; j++) {
808 for (i = 0; i < w; i++) {
809 int y = Y[i],
u = U[i >> 1],
v = V[i >> 1];
810 dst[3*i+0] = av_clip_uint8(y + v);
811 dst[3*i+1] = av_clip_uint8(y);
812 dst[3*i+2] = av_clip_uint8(y + u);
816 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
817 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
825 }
else if (j == h - 1) {
835 U[-2] = U[-1] = U[0];
836 V[-2] = V[-1] = V[0];
837 U[cw + 1] = U[cw] = U[cw - 1];
838 V[cw + 1] = V[cw] = V[cw - 1];
846 }
else if (j == h - 1) {
866 #define TM2_HEADER_SIZE 40
869 void *
data,
int *got_frame,
874 int buf_size = avpkt->
size & ~3;
895 if (offset >= buf_size) {
919 return (ret < 0) ? ret : buf_size;
941 l->
last = av_malloc_array(w >> 2, 4 *
sizeof(*l->
last) );
942 l->
clast = av_malloc_array(w >> 2, 4 *
sizeof(*l->
clast));
1012 .
name =
"truemotion2",