comparison truemotion2.c @ 9551:710cf96d899b libavcodec

TrueMotion 2 uses its own YUV-like colourspace, so convert output to proper RGB. Patch by Reimar Dffinger <latinize($name) at (MN's favourite mail provider).de>
author kostya
date Fri, 24 Apr 2009 06:44:16 +0000
parents 0dce4fe6e6f3
children d7ed9dcc78e3
comparison
equal deleted inserted replaced
9550:d418640c8d86 9551:710cf96d899b
363 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\ 363 Vo = (ctx->cur?ctx->V1:ctx->V2) + by * 2 * oVstride + bx * 2;\
364 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2; 364 Uo = (ctx->cur?ctx->U1:ctx->U2) + by * 2 * oUstride + bx * 2;
365 365
366 /* recalculate last and delta values for next blocks */ 366 /* recalculate last and delta values for next blocks */
367 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\ 367 #define TM2_RECALC_BLOCK(CHR, stride, last, CD) {\
368 CD[0] = (CHR[1] - 128) - last[1];\ 368 CD[0] = CHR[1] - last[1];\
369 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\ 369 CD[1] = (int)CHR[stride + 1] - (int)CHR[1];\
370 last[0] = (int)CHR[stride + 0] - 128;\ 370 last[0] = (int)CHR[stride + 0];\
371 last[1] = (int)CHR[stride + 1] - 128;} 371 last[1] = (int)CHR[stride + 1];}
372 372
373 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */ 373 /* common operations - add deltas to 4x4 block of luma or 2x2 blocks of chroma */
374 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last) 374 static inline void tm2_apply_deltas(TM2Context *ctx, int* Y, int stride, int *deltas, int *last)
375 { 375 {
376 int ct, d; 376 int ct, d;
394 int i, j; 394 int i, j;
395 for(j = 0; j < 2; j++){ 395 for(j = 0; j < 2; j++){
396 for(i = 0; i < 2; i++){ 396 for(i = 0; i < 2; i++){
397 CD[j] += deltas[i + j * 2]; 397 CD[j] += deltas[i + j * 2];
398 last[i] += CD[j]; 398 last[i] += CD[j];
399 data[i] = last[i] + 128; 399 data[i] = last[i];
400 } 400 }
401 data += stride; 401 data += stride;
402 } 402 }
403 } 403 }
404 404
673 { 673 {
674 int i, j; 674 int i, j;
675 int bw, bh; 675 int bw, bh;
676 int type; 676 int type;
677 int keyframe = 1; 677 int keyframe = 1;
678 uint8_t *Y, *U, *V; 678 int *Y, *U, *V;
679 int *src; 679 uint8_t *dst;
680 680
681 bw = ctx->avctx->width >> 2; 681 bw = ctx->avctx->width >> 2;
682 bh = ctx->avctx->height >> 2; 682 bh = ctx->avctx->height >> 2;
683 683
684 for(i = 0; i < TM2_NUM_STREAMS; i++) 684 for(i = 0; i < TM2_NUM_STREAMS; i++)
727 } 727 }
728 } 728 }
729 } 729 }
730 730
731 /* copy data from our buffer to AVFrame */ 731 /* copy data from our buffer to AVFrame */
732 Y = p->data[0]; 732 Y = (ctx->cur?ctx->Y2:ctx->Y1);
733 src = (ctx->cur?ctx->Y2:ctx->Y1); 733 U = (ctx->cur?ctx->U2:ctx->U1);
734 V = (ctx->cur?ctx->V2:ctx->V1);
735 dst = p->data[0];
734 for(j = 0; j < ctx->avctx->height; j++){ 736 for(j = 0; j < ctx->avctx->height; j++){
735 for(i = 0; i < ctx->avctx->width; i++){ 737 for(i = 0; i < ctx->avctx->width; i++){
736 Y[i] = av_clip_uint8(*src++); 738 int y = Y[i], u = U[i >> 1], v = V[i >> 1];
737 } 739 dst[3*i+0] = av_clip_uint8(y + v);
738 Y += p->linesize[0]; 740 dst[3*i+1] = av_clip_uint8(y);
739 } 741 dst[3*i+2] = av_clip_uint8(y + u);
740 U = p->data[2]; 742 }
741 src = (ctx->cur?ctx->U2:ctx->U1); 743 Y += ctx->avctx->width;
742 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){ 744 if (j & 1) {
743 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){ 745 U += ctx->avctx->width >> 1;
744 U[i] = av_clip_uint8(*src++); 746 V += ctx->avctx->width >> 1;
745 } 747 }
746 U += p->linesize[2]; 748 dst += p->linesize[0];
747 }
748 V = p->data[1];
749 src = (ctx->cur?ctx->V2:ctx->V1);
750 for(j = 0; j < (ctx->avctx->height + 1) >> 1; j++){
751 for(i = 0; i < (ctx->avctx->width + 1) >> 1; i++){
752 V[i] = av_clip_uint8(*src++);
753 }
754 V += p->linesize[1];
755 } 749 }
756 750
757 return keyframe; 751 return keyframe;
758 } 752 }
759 753
827 return -1; 821 return -1;
828 } 822 }
829 823
830 l->avctx = avctx; 824 l->avctx = avctx;
831 l->pic.data[0]=NULL; 825 l->pic.data[0]=NULL;
832 avctx->pix_fmt = PIX_FMT_YUV420P; 826 avctx->pix_fmt = PIX_FMT_BGR24;
833 827
834 dsputil_init(&l->dsp, avctx); 828 dsputil_init(&l->dsp, avctx);
835 829
836 l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2)); 830 l->last = av_malloc(4 * sizeof(int) * (avctx->width >> 2));
837 l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2)); 831 l->clast = av_malloc(4 * sizeof(int) * (avctx->width >> 2));