35 #define TM2_ESCAPE 0x80000000
132 huff->
bits[huff->
num] = prefix;
137 if ((ret =
tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
139 if ((ret =
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
163 if ((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
165 "nodes: %i\n", huff.
nodes);
196 huff.
lens,
sizeof(
int),
sizeof(
int),
197 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
208 for (i = 0; i < code->
length; i++)
237 #define TM2_OLD_HEADER_MAGIC 0x00000100
238 #define TM2_NEW_HEADER_MAGIC 0x00000101
266 if ((d < 1) || (d >
TM2_DELTAS) || (mb < 1)) {
271 for (i = 0; i < d; i++) {
273 if (v & (1 << (mb - 1)))
274 ctx->
deltas[stream_id][i] = v - (1 <<
mb);
279 ctx->
deltas[stream_id][i] = 0;
299 len = bytestream2_get_be32(&gb);
305 if (len >= INT_MAX/4-1 || len < 0 || skip > buf_size) {
310 toks = bytestream2_get_be32(&gb);
312 len = bytestream2_get_be32(&gb);
314 len = bytestream2_get_be32(&gb);
327 len = bytestream2_get_be32(&gb);
344 if ((toks < 0) || (toks > 0xFFFFFF)) {
355 len = bytestream2_get_be32(&gb);
361 for (i = 0; i < toks; i++) {
367 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS || ctx->
tokens[stream_id][i]<0) {
369 ctx->
tokens[stream_id][i], stream_id, i);
374 for (i = 0; i < toks; i++) {
376 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
378 ctx->
tokens[stream_id][i], stream_id, i);
407 #define TM2_INIT_POINTERS() \
410 int Ystride, Ustride, Vstride;\
412 Ystride = ctx->y_stride;\
413 Vstride = ctx->uv_stride;\
414 Ustride = ctx->uv_stride;\
415 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
416 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
417 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
418 last = ctx->last + bx * 4;\
419 clast = ctx->clast + bx * 4;
421 #define TM2_INIT_POINTERS_2() \
423 int oYstride, oUstride, oVstride;\
425 TM2_INIT_POINTERS();\
429 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
430 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
431 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
434 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
435 CD[0] = CHR[1] - last[1];\
436 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
437 last[0] = (int)CHR[stride + 0];\
438 last[1] = (int)CHR[stride + 1];}
446 for (j = 0; j < 4; j++){
448 for (i = 0; i < 4; i++){
449 d = deltas[i + j * 4];
452 Y[i] = av_clip_uint8(last[i]);
462 for (j = 0; j < 2; j++) {
463 for (i = 0; i < 2; i++) {
464 CD[j] += deltas[i + j * 2];
482 t = (CD[0] + CD[1]) >> 1;
483 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
484 CD[1] = CD[0] + CD[1] - t;
498 for (i = 0; i < 4; i++) {
506 for (i = 0; i < 16; i++)
520 deltas[1] = deltas[2] = deltas[3] = 0;
524 deltas[1] = deltas[2] = deltas[3] = 0;
528 for (i = 0; i < 16; i++)
543 deltas[1] = deltas[2] = deltas[3] = 0;
547 deltas[1] = deltas[2] = deltas[3] = 0;
551 for (i = 0; i < 16; i++)
560 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
562 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
563 last[2] = (last[1] + last[3]) >> 1;
565 t1 = ctx->
D[0] + ctx->
D[1];
567 ctx->
D[1] = t1 - (t1 >> 1);
568 t2 = ctx->
D[2] + ctx->
D[3];
570 ctx->
D[3] = t2 - (t2 >> 1);
579 int left, right, diff;
584 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
587 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
591 for (i = 0; i < 16; i++)
594 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
597 left = last[-1] - ct;
603 last[0] = left + (diff >> 2);
604 last[1] = left + (diff >> 1);
605 last[2] = right - (diff >> 2);
610 ctx->
D[0] = (tp + (ct >> 2)) - left;
612 ctx->
D[1] = (tp + (ct >> 1)) - left;
614 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
616 ctx->
D[3] = (tp + ct) - left;
627 for (j = 0; j < 2; j++) {
628 for (i = 0; i < 2; i++){
632 U += Ustride;
V += Vstride;
633 Uo += oUstride; Vo += oVstride;
641 ctx->
D[0] = Yo[3] - last[3];
642 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
643 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
644 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
646 for (j = 0; j < 4; j++) {
647 for (i = 0; i < 4; i++) {
663 for (j = 0; j < 2; j++) {
664 for (i = 0; i < 2; i++) {
679 ctx->
D[0] = Yo[3] - last[3];
680 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
681 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
682 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
684 for (j = 0; j < 4; j++) {
686 for (i = 0; i < 4; i++) {
690 ctx->
D[j] = last[3] - d;
704 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
705 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
712 Yo += my * oYstride + mx;
713 Uo += (my >> 1) * oUstride + (mx >> 1);
714 Vo += (my >> 1) * oVstride + (mx >> 1);
717 for (j = 0; j < 2; j++) {
718 for (i = 0; i < 2; i++) {
733 for (j = 0; j < 4; j++) {
734 for (i = 0; i < 4; i++) {
742 ctx->
D[0] =
Y[3] - last[3];
743 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
744 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
745 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
746 for (i = 0; i < 4; i++)
747 last[i] = Y[i + Ystride * 3];
767 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
768 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
770 for (j = 0; j < bh; j++) {
771 memset(ctx->
D, 0, 4 *
sizeof(
int));
772 memset(ctx->
CD, 0, 4 *
sizeof(
int));
773 for (i = 0; i < bw; i++) {
807 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
808 U = (ctx->
cur?ctx->
U2:ctx->
U1);
809 V = (ctx->
cur?ctx->
V2:ctx->
V1);
811 for (j = 0; j < h; j++) {
812 for (i = 0; i < w; i++) {
813 int y = Y[i],
u = U[i >> 1],
v = V[i >> 1];
814 dst[3*i+0] = av_clip_uint8(y + v);
815 dst[3*i+1] = av_clip_uint8(y);
816 dst[3*i+2] = av_clip_uint8(y + u);
820 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
821 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
829 }
else if (j == h - 1) {
839 U[-2] = U[-1] = U[0];
840 V[-2] = V[-1] = V[0];
841 U[cw + 1] = U[cw] = U[cw - 1];
842 V[cw + 1] = V[cw] = V[cw - 1];
850 }
else if (j == h - 1) {
870 #define TM2_HEADER_SIZE 40
873 void *
data,
int *got_frame,
878 int buf_size = avpkt->
size & ~3;
900 if (offset >= buf_size) {
924 return (ret < 0) ? ret : buf_size;
1017 .
name =
"truemotion2",