32 #define TM2_ESCAPE 0x80000000
110 huff->
bits[huff->
num] = prefix;
111 huff->
lens[huff->
num] = length;
117 if(
tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
141 if((huff.
nodes <= 0) || (huff.
nodes > 0x10000)) {
169 huff.
lens,
sizeof(
int),
sizeof(
int),
170 huff.
bits,
sizeof(uint32_t),
sizeof(uint32_t), 0);
180 for(i = 0; i < code->
length; i++)
208 #define TM2_OLD_HEADER_MAGIC 0x00000100
209 #define TM2_NEW_HEADER_MAGIC 0x00000101
234 if((d < 1) || (d >
TM2_DELTAS) || (mb < 1) || (mb > 32)) {
239 for(i = 0; i < d; i++) {
241 if(v & (1 << (mb - 1)))
242 ctx->
deltas[stream_id][i] = v - (1 <<
mb);
244 ctx->
deltas[stream_id][i] = v;
247 ctx->
deltas[stream_id][i] = 0;
267 len = bytestream2_get_be32(&gb);
273 if (len >= INT_MAX/4-1 || len < 0 || skip > buf_size) {
278 toks = bytestream2_get_be32(&gb);
280 len = bytestream2_get_be32(&gb);
282 len = bytestream2_get_be32(&gb);
295 len = bytestream2_get_be32(&gb);
312 if((toks < 0) || (toks > 0xFFFFFF)){
319 len = bytestream2_get_be32(&gb);
325 for(i = 0; i < toks; i++) {
331 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS || ctx->
tokens[stream_id][i]<0) {
333 ctx->
tokens[stream_id][i], stream_id, i);
338 for(i = 0; i < toks; i++) {
340 if (stream_id <= TM2_MOT && ctx->tokens[stream_id][i] >=
TM2_DELTAS) {
342 ctx->
tokens[stream_id][i], stream_id, i);
370 #define TM2_INIT_POINTERS() \
373 int Ystride, Ustride, Vstride;\
375 Ystride = ctx->y_stride;\
376 Vstride = ctx->uv_stride;\
377 Ustride = ctx->uv_stride;\
378 Y = (ctx->cur?ctx->Y2:ctx->Y1) + by * 4 * Ystride + bx * 4;\
379 V = (ctx->cur?ctx->V2:ctx->V1) + by * 2 * Vstride + bx * 2;\
380 U = (ctx->cur?ctx->U2:ctx->U1) + by * 2 * Ustride + bx * 2;\
381 last = ctx->last + bx * 4;\
382 clast = ctx->clast + bx * 4;
384 #define TM2_INIT_POINTERS_2() \
386 int oYstride, oUstride, oVstride;\
388 TM2_INIT_POINTERS();\
392 Yo = (ctx->cur?ctx->Y1:ctx->Y2) + by * 4 * oYstride + bx * 4;\
393 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
394 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
397 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
398 CD[0] = CHR[1] - last[1];\
399 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
400 last[0] = (int)CHR[stride + 0];\
401 last[1] = (int)CHR[stride + 1];}
409 for(j = 0; j < 4; j++){
411 for(i = 0; i < 4; i++){
412 d = deltas[i + j * 4];
415 Y[i] = av_clip_uint8(last[i]);
425 for(j = 0; j < 2; j++){
426 for(i = 0; i < 2; i++){
427 CD[j] += deltas[i + j * 2];
445 t = (CD[0] + CD[1]) >> 1;
446 l = (prev - CD[0] - CD[1] + clast[1]) >> 1;
447 CD[1] = CD[0] + CD[1] -
t;
461 for(i = 0; i < 4; i++) {
469 for(i = 0; i < 16; i++)
483 deltas[1] = deltas[2] = deltas[3] = 0;
487 deltas[1] = deltas[2] = deltas[3] = 0;
491 for(i = 0; i < 16; i++)
506 deltas[1] = deltas[2] = deltas[3] = 0;
510 deltas[1] = deltas[2] = deltas[3] = 0;
514 for(i = 0; i < 16; i++)
523 last[0] = (last[-1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3] + last[1]) >> 1;
525 last[0] = (last[1] - ctx->
D[0] - ctx->
D[1] - ctx->
D[2] - ctx->
D[3])>> 1;
526 last[2] = (last[1] + last[3]) >> 1;
528 t1 = ctx->
D[0] + ctx->
D[1];
530 ctx->
D[1] = t1 - (t1 >> 1);
531 t2 = ctx->
D[2] + ctx->
D[3];
533 ctx->
D[3] = t2 - (t2 >> 1);
542 int left, right,
diff;
547 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
550 deltas[0] = deltas[1] = deltas[2] = deltas[3] = 0;
554 for(i = 0; i < 16; i++)
557 ct = ctx->
D[0] + ctx->
D[1] + ctx->
D[2] + ctx->
D[3];
560 left = last[-1] - ct;
566 last[0] = left + (diff >> 2);
567 last[1] = left + (diff >> 1);
568 last[2] = right - (diff >> 2);
573 ctx->
D[0] = (tp + (ct >> 2)) - left;
575 ctx->
D[1] = (tp + (ct >> 1)) - left;
577 ctx->
D[2] = ((tp + ct) - (ct >> 2)) - left;
579 ctx->
D[3] = (tp + ct) - left;
590 for(j = 0; j < 2; j++){
591 for(i = 0; i < 2; i++){
595 U += Ustride;
V += Vstride;
596 Uo += oUstride; Vo += oVstride;
604 ctx->
D[0] = Yo[3] - last[3];
605 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
606 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
607 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
609 for(j = 0; j < 4; j++){
610 for(i = 0; i < 4; i++){
626 for(j = 0; j < 2; j++){
627 for(i = 0; i < 2; i++){
631 U += Ustride;
V += Vstride;
632 Uo += oUstride; Vo += oVstride;
640 ctx->
D[0] = Yo[3] - last[3];
641 ctx->
D[1] = Yo[3 + oYstride] - Yo[3];
642 ctx->
D[2] = Yo[3 + oYstride * 2] - Yo[3 + oYstride];
643 ctx->
D[3] = Yo[3 + oYstride * 3] - Yo[3 + oYstride * 2];
645 for(j = 0; j < 4; j++){
647 for(i = 0; i < 4; i++){
651 ctx->
D[j] = last[3] - d;
665 mx = av_clip(mx, -(bx * 4 + 4), ctx->
avctx->
width - bx * 4);
666 my = av_clip(my, -(by * 4 + 4), ctx->
avctx->
height - by * 4);
673 Yo += my * oYstride + mx;
674 Uo += (my >> 1) * oUstride + (mx >> 1);
675 Vo += (my >> 1) * oVstride + (mx >> 1);
678 for(j = 0; j < 2; j++){
679 for(i = 0; i < 2; i++){
683 U += Ustride;
V += Vstride;
684 Uo += oUstride; Vo += oVstride;
692 for(j = 0; j < 4; j++){
693 for(i = 0; i < 4; i++){
701 ctx->
D[0] =
Y[3] - last[3];
702 ctx->
D[1] =
Y[3 + Ystride] -
Y[3];
703 ctx->
D[2] = Y[3 + Ystride * 2] - Y[3 + Ystride];
704 ctx->
D[3] = Y[3 + Ystride * 3] - Y[3 + Ystride * 2];
705 for(i = 0; i < 4; i++)
706 last[i] = Y[i + Ystride * 3];
726 memset(ctx->
last, 0, 4 * bw *
sizeof(
int));
727 memset(ctx->
clast, 0, 4 * bw *
sizeof(
int));
729 for(j = 0; j < bh; j++) {
730 memset(ctx->
D, 0, 4 *
sizeof(
int));
731 memset(ctx->
CD, 0, 4 *
sizeof(
int));
732 for(i = 0; i < bw; i++) {
766 Y = (ctx->
cur?ctx->
Y2:ctx->
Y1);
767 U = (ctx->
cur?ctx->
U2:ctx->
U1);
768 V = (ctx->
cur?ctx->
V2:ctx->
V1);
770 for(j = 0; j < h; j++){
771 for(i = 0; i < w; i++){
772 int y = Y[i], u = U[i >> 1], v = V[i >> 1];
773 dst[3*i+0] = av_clip_uint8(y + v);
774 dst[3*i+1] = av_clip_uint8(y);
775 dst[3*i+2] = av_clip_uint8(y + u);
779 Y[-4] = Y[-3] = Y[-2] = Y[-1] = Y[0];
780 Y[w + 3] = Y[w + 2] = Y[w + 1] = Y[w] = Y[w - 1];
788 }
else if (j == h - 1) {
798 U[-2] = U[-1] = U[0];
799 V[-2] = V[-1] = V[0];
800 U[cw + 1] = U[cw] = U[cw - 1];
801 V[cw + 1] = V[cw] = V[cw - 1];
809 }
else if (j == h - 1) {
829 #define TM2_HEADER_SIZE 40
832 void *
data,
int *got_frame,
836 int buf_size = avpkt->
size & ~3;
860 if (offset >= buf_size) {
972 .
name =
"truemotion2",