X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fvc1dsp.c;h=9bd107cdd94cd4aa267096ea263638c645aa9e09;hb=8d3348c2c4c3373bf6e1410659790d985c14b057;hp=47b69c8214e77521022dfcf918f26f57cc2544ca;hpb=ba87f0801d77c21eb1e4891ca1f846500bbb0939;p=ffmpeg diff --git a/libavcodec/vc1dsp.c b/libavcodec/vc1dsp.c index 47b69c8214e..9bd107cdd94 100644 --- a/libavcodec/vc1dsp.c +++ b/libavcodec/vc1dsp.c @@ -2,20 +2,20 @@ * VC-1 and WMV3 decoder - DSP functions * Copyright (c) 2006 Konstantin Shishkov * - * This file is part of FFmpeg. + * This file is part of Libav. * - * FFmpeg is free software; you can redistribute it and/or + * Libav is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * FFmpeg is distributed in the hope that it will be useful, + * Libav is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software + * License along with Libav; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -25,7 +25,7 @@ * */ -#include "dsputil.h" +#include "vc1dsp.h" /** Apply overlap transform to horizontal edge @@ -78,6 +78,58 @@ static void vc1_h_overlap_c(uint8_t* src, int stride) } } +static void vc1_v_s_overlap_c(DCTELEM *top, DCTELEM *bottom) +{ + int i; + int a, b, c, d; + int d1, d2; + int rnd1 = 4, rnd2 = 3; + for(i = 0; i < 8; i++) { + a = top[48]; + b = top[56]; + c = bottom[0]; + d = bottom[8]; + d1 = a - d; + d2 = a - d + b - c; + + top[48] = ((a << 3) - d1 + rnd1) >> 3; + top[56] = ((b << 3) - d2 + rnd2) >> 3; + bottom[0] = ((c << 3) + d2 + rnd1) >> 3; + bottom[8] = ((d << 3) + d1 + rnd2) >> 3; + + bottom++; + top++; + rnd2 = 7 - rnd2; + rnd1 = 7 - rnd1; + } +} + +static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right) +{ + int i; + int a, b, c, d; + int d1, d2; + int rnd1 = 4, rnd2 = 3; + for(i = 0; i < 8; i++) { + a = left[6]; + b = left[7]; + c = right[0]; + d = right[1]; + d1 = a - d; + d2 = a - d + b - c; + + left[6] = ((a << 3) - d1 + rnd1) >> 3; + left[7] = ((b << 3) - d2 + rnd2) >> 3; + right[0] = ((c << 3) + d2 + rnd1) >> 3; + right[1] = ((d << 3) + d1 + rnd2) >> 3; + + right += 8; + left += 8; + rnd2 = 7 - rnd2; + rnd1 = 7 - rnd1; + } +} + /** * VC-1 in-loop deblocking filter for one line * @param src source block type @@ -182,18 +234,19 @@ static void vc1_inv_trans_8x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; int dc = block[0]; - const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t *cm; dc = (3 * dc + 1) >> 1; dc = (3 * dc + 16) >> 5; + cm = ff_cropTbl + MAX_NEG_CROP + dc; for(i = 0; i < 8; i++){ - dest[0] = cm[dest[0]+dc]; - dest[1] = cm[dest[1]+dc]; - dest[2] = cm[dest[2]+dc]; - dest[3] = cm[dest[3]+dc]; - dest[4] = cm[dest[4]+dc]; - dest[5] = cm[dest[5]+dc]; - dest[6] = cm[dest[6]+dc]; - dest[7] = cm[dest[7]+dc]; + dest[0] = cm[dest[0]]; + dest[1] = cm[dest[1]]; + dest[2] = cm[dest[2]]; + dest[3] = cm[dest[3]]; + dest[4] = cm[dest[4]]; + dest[5] = cm[dest[5]]; + dest[6] = cm[dest[6]]; + dest[7] = cm[dest[7]]; dest += linesize; } } @@ -202,25 +255,25 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; - DCTELEM *src, *dst; + DCTELEM *src, *dst, temp[64]; src = block; - dst = block; + dst = temp; for(i = 0; i < 8; i++){ - t1 = 12 * (src[0] + src[4]) + 4; - t2 = 12 * (src[0] - src[4]) + 4; - t3 = 16 * src[2] + 6 * src[6]; - t4 = 6 * src[2] - 16 * src[6]; + t1 = 12 * (src[ 0] + src[32]) + 4; + t2 = 12 * (src[ 0] - src[32]) + 4; + t3 = 16 * src[16] + 6 * src[48]; + t4 = 6 * src[16] - 16 * src[48]; t5 = t1 + t3; t6 = t2 + t4; t7 = t2 - t4; t8 = t1 - t3; - t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7]; - t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7]; - t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7]; - t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7]; + t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56]; + t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56]; + t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; + t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; dst[0] = (t5 + t1) >> 3; dst[1] = (t6 + t2) >> 3; @@ -231,11 +284,11 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) dst[6] = (t6 - t2) >> 3; dst[7] = (t5 - t1) >> 3; - src += 8; + src += 1; dst += 8; } - src = block; + src = temp; dst = block; for(i = 0; i < 8; i++){ t1 = 12 * (src[ 0] + src[32]) + 64; @@ -273,18 +326,19 @@ static void vc1_inv_trans_8x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; int dc = block[0]; - const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t *cm; dc = ( 3 * dc + 1) >> 1; dc = (17 * dc + 64) >> 7; + cm = ff_cropTbl + MAX_NEG_CROP + dc; for(i = 0; i < 4; i++){ - dest[0] = cm[dest[0]+dc]; - dest[1] = cm[dest[1]+dc]; - dest[2] = cm[dest[2]+dc]; - dest[3] = cm[dest[3]+dc]; - dest[4] = cm[dest[4]+dc]; - dest[5] = cm[dest[5]+dc]; - dest[6] = cm[dest[6]+dc]; - dest[7] = cm[dest[7]+dc]; + dest[0] = cm[dest[0]]; + dest[1] = cm[dest[1]]; + dest[2] = cm[dest[2]]; + dest[3] = cm[dest[3]]; + dest[4] = cm[dest[4]]; + dest[5] = cm[dest[5]]; + dest[6] = cm[dest[6]]; + dest[7] = cm[dest[7]]; dest += linesize; } } @@ -350,14 +404,15 @@ static void vc1_inv_trans_4x8_dc_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; int dc = block[0]; - const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t *cm; dc = (17 * dc + 4) >> 3; dc = (12 * dc + 64) >> 7; + cm = ff_cropTbl + MAX_NEG_CROP + dc; for(i = 0; i < 8; i++){ - dest[0] = cm[dest[0]+dc]; - dest[1] = cm[dest[1]+dc]; - dest[2] = cm[dest[2]+dc]; - dest[3] = cm[dest[3]+dc]; + dest[0] = cm[dest[0]]; + dest[1] = cm[dest[1]]; + dest[2] = cm[dest[2]]; + dest[3] = cm[dest[3]]; dest += linesize; } } @@ -423,14 +478,15 @@ static void vc1_inv_trans_4x4_dc_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; int dc = block[0]; - const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t *cm; dc = (17 * dc + 4) >> 3; dc = (17 * dc + 64) >> 7; + cm = ff_cropTbl + MAX_NEG_CROP + dc; for(i = 0; i < 4; i++){ - dest[0] = cm[dest[0]+dc]; - dest[1] = cm[dest[1]+dc]; - dest[2] = cm[dest[2]+dc]; - dest[3] = cm[dest[3]+dc]; + dest[0] = cm[dest[0]]; + dest[1] = cm[dest[1]]; + dest[2] = cm[dest[2]]; + dest[3] = cm[dest[3]]; dest += linesize; } } @@ -494,8 +550,8 @@ static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, return 0; /* should not occur */ \ } -VC1_MSPEL_FILTER_16B(ver, uint8_t); -VC1_MSPEL_FILTER_16B(hor, int16_t); +VC1_MSPEL_FILTER_16B(ver, uint8_t) +VC1_MSPEL_FILTER_16B(hor, int16_t) /** Filter used to interpolate fractional pel values @@ -608,7 +664,136 @@ PUT_VC1_MSPEL(1, 3) PUT_VC1_MSPEL(2, 3) PUT_VC1_MSPEL(3, 3) -av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { +static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ + const int A=(8-x)*(8-y); + const int B=( x)*(8-y); + const int C=(8-x)*( y); + const int D=( x)*( y); + int i; + + assert(x<8 && y<8 && x>=0 && y>=0); + + for(i=0; i> 6; + dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; + dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; + dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; + dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6; + dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6; + dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6; + dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6; + dst+= stride; + src+= stride; + } +} + +static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){ + const int A=(8-x)*(8-y); + const int B=( x)*(8-y); + const int C=(8-x)*( y); + const int D=( x)*( y); + int i; + + assert(x<8 && y<8 && x>=0 && y>=0); + + for(i=0; i> 6; + dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; + dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; + dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; + dst+= stride; + src+= stride; + } +} + +#define avg2(a,b) ((a+b+1)>>1) +static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ + const int A=(8-x)*(8-y); + const int B=( x)*(8-y); + const int C=(8-x)*( y); + const int D=( x)*( y); + int i; + + assert(x<8 && y<8 && x>=0 && y>=0); + + for(i=0; i> 6)); + dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6)); + dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6)); + dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6)); + dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6)); + dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6)); + dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6)); + dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6)); + dst+= stride; + src+= stride; + } +} + +#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER + +static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count) +{ + while (count--) { + int a = src[(offset >> 16) ]; + int b = src[(offset >> 16) + 1]; + *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16); + offset += advance; + } +} + +static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, + int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2, + int alpha, int scaled, int width) +{ + int a1, b1, a2, b2; + while (width--) { + a1 = *src1a++; + if (scaled) { + b1 = *src1b++; + a1 = a1 + ((b1 - a1) * offset1 >> 16); + } + if (two_sprites) { + a2 = *src2a++; + if (scaled > 1) { + b2 = *src2b++; + a2 = a2 + ((b2 - a2) * offset2 >> 16); + } + a1 = a1 + ((a2 - a1) * alpha >> 16); + } + *dst++ = a1; + } +} + +static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width) +{ + sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width); +} + +static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width) +{ + sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width); +} + +static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, + const uint8_t *src2a, int alpha, int width) +{ + sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width); +} + +static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, + const uint8_t *src2a, const uint8_t *src2b, int offset2, + int alpha, int width) +{ + sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width); +} + +#endif + +av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) { dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c; dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c; dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c; @@ -619,6 +804,8 @@ av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c; dsp->vc1_h_overlap = vc1_h_overlap_c; dsp->vc1_v_overlap = vc1_v_overlap_c; + dsp->vc1_h_s_overlap = vc1_h_s_overlap_c; + dsp->vc1_v_s_overlap = vc1_v_s_overlap_c; dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c; dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c; dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c; @@ -626,7 +813,7 @@ av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->vc1_v_loop_filter16 = vc1_v_loop_filter16_c; dsp->vc1_h_loop_filter16 = vc1_h_loop_filter16_c; - dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c; + dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_pixels8x8_c; dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c; dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c; dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c; @@ -643,7 +830,7 @@ av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c; dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c; - dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_vc1_mspel_mc00_c; + dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_pixels8x8_c; dsp->avg_vc1_mspel_pixels_tab[ 1] = avg_vc1_mspel_mc10_c; dsp->avg_vc1_mspel_pixels_tab[ 2] = avg_vc1_mspel_mc20_c; dsp->avg_vc1_mspel_pixels_tab[ 3] = avg_vc1_mspel_mc30_c; @@ -659,4 +846,21 @@ av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c; dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c; dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c; + + dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c; + dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c; + dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c; + +#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER + dsp->sprite_h = sprite_h_c; + dsp->sprite_v_single = sprite_v_single_c; + dsp->sprite_v_double_noscale = sprite_v_double_noscale_c; + dsp->sprite_v_double_onescale = sprite_v_double_onescale_c; + dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c; +#endif + + if (HAVE_ALTIVEC) + ff_vc1dsp_init_altivec(dsp); + if (HAVE_MMX) + ff_vc1dsp_init_mmx(dsp); }