* VC-1 and WMV3 decoder - DSP functions
* Copyright (c) 2006 Konstantin Shishkov
*
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
*
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg 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 this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "dsputil.h"
-/** Apply overlap transform to vertical edge
+/** Apply overlap transform to horizontal edge
*/
-static void vc1_v_overlap_c(uint8_t* src, int stride, int rnd)
+static void vc1_v_overlap_c(uint8_t* src, int stride)
{
int i;
int a, b, c, d;
+ int d1, d2;
+ int rnd = 1;
for(i = 0; i < 8; i++) {
a = src[-2*stride];
b = src[-stride];
c = src[0];
d = src[stride];
+ d1 = (a - d + 3 + rnd) >> 3;
+ d2 = (a - d + b - c + 4 - rnd) >> 3;
- src[-2*stride] = clip_uint8((7*a + d + 4 - rnd) >> 3);
- src[-stride] = clip_uint8((-a + 7*b + c + d + 3 + rnd) >> 3);
- src[0] = clip_uint8((a + b + 7*c - d + 4 - rnd) >> 3);
- src[stride] = clip_uint8((a + 7*d + 3 + rnd) >> 3);
+ src[-2*stride] = a - d1;
+ src[-stride] = b - d2;
+ src[0] = c + d2;
+ src[stride] = d + d1;
src++;
+ rnd = !rnd;
}
}
-/** Apply overlap transform to horizontal edge
+/** Apply overlap transform to vertical edge
*/
-static void vc1_h_overlap_c(uint8_t* src, int stride, int rnd)
+static void vc1_h_overlap_c(uint8_t* src, int stride)
{
int i;
int a, b, c, d;
+ int d1, d2;
+ int rnd = 1;
for(i = 0; i < 8; i++) {
a = src[-2];
b = src[-1];
c = src[0];
d = src[1];
+ d1 = (a - d + 3 + rnd) >> 3;
+ d2 = (a - d + b - c + 4 - rnd) >> 3;
- src[-2] = clip_uint8((7*a + d + 4 - rnd) >> 3);
- src[-1] = clip_uint8((-a + 7*b + c + d + 3 + rnd) >> 3);
- src[0] = clip_uint8((a + b + 7*c - d + 4 - rnd) >> 3);
- src[1] = clip_uint8((a + 7*d + 3 + rnd) >> 3);
+ src[-2] = a - d1;
+ src[-1] = b - d2;
+ src[0] = c + d2;
+ src[1] = d + d1;
src += stride;
+ rnd = !rnd;
}
}
/** Filter used to interpolate fractional pel values
*/
-static always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
+static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int mode, int r)
{
switch(mode){
case 0: //no shift
tptr = tmp;
for(j = 0; j < 11; j++) {
for(i = 0; i < 8; i++)
- tptr[i] = clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
+ tptr[i] = av_clip_uint8(vc1_mspel_filter(src + i, 1, m, r));
src += stride;
tptr += 8;
}
tptr = tmp + 8;
for(j = 0; j < 8; j++) {
for(i = 0; i < 8; i++)
- dst[i] = clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
+ dst[i] = av_clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r));
dst += stride;
tptr += 8;
}
vc1_mspel_mc(dst, src, stride, 0xF, rnd);
}
-/** Filter used to interpolate fractional pel values
- * except for half-pel cases for _mcXY:
- * A = (4-X)*(4-Y)
- * B = X *(4-Y)
- * C = (4-X)* Y
- * D = X * Y
- */
-#define VC1_QPEL_FILTER(src, i, stride, rnd, A, B, C, D) \
- clip_uint8((A*src[i] + B*src[i+1] + C*src[i+stride] + D*src[i+stride+1] + 8 - rnd) >> 4)
-
-/* this one is defined in dsputil.c */
-void ff_put_vc1_qpel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd);
-
-static void ff_put_vc1_qpel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 12, 4, 0, 0);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = clip_uint8((src[i] + src[i + 1] + 1 - rnd) >> 1);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 4, 12, 0, 0);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 12, 0, 4, 0);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 9, 3, 3, 1);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 6, 6, 2, 2);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 3, 9, 1, 3);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = clip_uint8((src[i] + src[i + stride] + 1 - rnd) >> 1);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 6, 2, 6, 2);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = clip_uint8((src[i] + src[i + 1] + src[i + stride] + src[i + stride + 1] + 2 - rnd) >> 2);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 2, 6, 2, 6);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 4, 0, 12, 0);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 3, 1, 9, 3);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 2, 2, 6, 6);
- dst += stride;
- src += stride;
- }
-}
-
-static void ff_put_vc1_qpel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) {
- int i, j;
- for(j = 0; j < 8; j++) {
- for(i = 0; i < 8; i++)
- dst[i] = VC1_QPEL_FILTER(src, i, stride, rnd, 1, 3, 3, 9);
- dst += stride;
- src += stride;
- }
-}
-
void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) {
dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c;
dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c;
dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c;
dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c;
dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c;
-
- dsp->put_vc1_qpel_pixels_tab[ 0] = ff_put_vc1_qpel_mc00_c;
- dsp->put_vc1_qpel_pixels_tab[ 1] = ff_put_vc1_qpel_mc10_c;
- dsp->put_vc1_qpel_pixels_tab[ 2] = ff_put_vc1_qpel_mc20_c;
- dsp->put_vc1_qpel_pixels_tab[ 3] = ff_put_vc1_qpel_mc30_c;
- dsp->put_vc1_qpel_pixels_tab[ 4] = ff_put_vc1_qpel_mc01_c;
- dsp->put_vc1_qpel_pixels_tab[ 5] = ff_put_vc1_qpel_mc11_c;
- dsp->put_vc1_qpel_pixels_tab[ 6] = ff_put_vc1_qpel_mc21_c;
- dsp->put_vc1_qpel_pixels_tab[ 7] = ff_put_vc1_qpel_mc31_c;
- dsp->put_vc1_qpel_pixels_tab[ 8] = ff_put_vc1_qpel_mc02_c;
- dsp->put_vc1_qpel_pixels_tab[ 9] = ff_put_vc1_qpel_mc12_c;
- dsp->put_vc1_qpel_pixels_tab[10] = ff_put_vc1_qpel_mc22_c;
- dsp->put_vc1_qpel_pixels_tab[11] = ff_put_vc1_qpel_mc32_c;
- dsp->put_vc1_qpel_pixels_tab[12] = ff_put_vc1_qpel_mc03_c;
- dsp->put_vc1_qpel_pixels_tab[13] = ff_put_vc1_qpel_mc13_c;
- dsp->put_vc1_qpel_pixels_tab[14] = ff_put_vc1_qpel_mc23_c;
- dsp->put_vc1_qpel_pixels_tab[15] = ff_put_vc1_qpel_mc33_c;
}