2004-03-08 02:13:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 the ffmpeg project
|
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2004-03-08 02:13:45 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 15:30:46 +00:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2004-03-08 02:13:45 +00:00
|
|
|
*
|
2006-10-07 15:30:46 +00:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2004-03-08 02:13:45 +00:00
|
|
|
* 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
|
2006-10-07 15:30:46 +00:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-01-12 22:43:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-03-08 02:13:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file vp3dsp.c
|
2005-12-17 18:14:38 +00:00
|
|
|
* Standard C DSP-oriented functions cribbed from the original VP3
|
2004-03-08 02:13:45 +00:00
|
|
|
* source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "avcodec.h"
|
2004-05-18 17:09:46 +00:00
|
|
|
#include "dsputil.h"
|
2004-03-08 02:13:45 +00:00
|
|
|
|
|
|
|
#define IdctAdjustBeforeShift 8
|
|
|
|
#define xC1S7 64277
|
|
|
|
#define xC2S6 60547
|
|
|
|
#define xC3S5 54491
|
|
|
|
#define xC4S4 46341
|
|
|
|
#define xC5S3 36410
|
|
|
|
#define xC6S2 25080
|
|
|
|
#define xC7S1 12785
|
|
|
|
|
2006-07-19 23:17:18 +00:00
|
|
|
#define M(a,b) (((a) * (b))>>16)
|
|
|
|
|
2005-05-17 11:12:04 +00:00
|
|
|
static always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type)
|
2004-03-08 02:13:45 +00:00
|
|
|
{
|
2005-05-17 11:12:04 +00:00
|
|
|
int16_t *ip = input;
|
|
|
|
uint8_t *cm = cropTbl + MAX_NEG_CROP;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;
|
|
|
|
int Ed, Gd, Add, Bdd, Fd, Hd;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2005-08-14 15:42:40 +00:00
|
|
|
int i;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2004-03-08 02:13:45 +00:00
|
|
|
/* Inverse DCT on the rows now */
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
/* Check for non-zero values */
|
|
|
|
if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) {
|
2006-07-19 23:21:20 +00:00
|
|
|
A = M(xC1S7, ip[1]) + M(xC7S1, ip[7]);
|
|
|
|
B = M(xC7S1, ip[1]) - M(xC1S7, ip[7]);
|
|
|
|
C = M(xC3S5, ip[3]) + M(xC5S3, ip[5]);
|
|
|
|
D = M(xC3S5, ip[5]) - M(xC5S3, ip[3]);
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Ad = M(xC4S4, (A - C));
|
|
|
|
Bd = M(xC4S4, (B - D));
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Cd = A + C;
|
|
|
|
Dd = B + D;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
E = M(xC4S4, (ip[0] + ip[4]));
|
|
|
|
F = M(xC4S4, (ip[0] - ip[4]));
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]);
|
|
|
|
H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]);
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Ed = E - G;
|
|
|
|
Gd = E + G;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Add = F + Ad;
|
|
|
|
Bdd = Bd - H;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Fd = F - Ad;
|
|
|
|
Hd = Bd + H;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
|
|
|
/* Final sequence of operations over-write original inputs. */
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[0] = Gd + Cd ;
|
|
|
|
ip[7] = Gd - Cd ;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[1] = Add + Hd;
|
|
|
|
ip[2] = Add - Hd;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[3] = Ed + Dd ;
|
|
|
|
ip[4] = Ed - Dd ;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[5] = Fd + Bdd;
|
|
|
|
ip[6] = Fd - Bdd;
|
2004-03-08 02:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ip += 8; /* next row */
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-05-17 11:12:04 +00:00
|
|
|
ip = input;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
|
|
|
for ( i = 0; i < 8; i++) {
|
|
|
|
/* Check for non-zero values (bitwise or faster than ||) */
|
2005-05-17 11:12:04 +00:00
|
|
|
if ( ip[1 * 8] | ip[2 * 8] | ip[3 * 8] |
|
2004-03-08 02:13:45 +00:00
|
|
|
ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) {
|
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
A = M(xC1S7, ip[1*8]) + M(xC7S1, ip[7*8]);
|
|
|
|
B = M(xC7S1, ip[1*8]) - M(xC1S7, ip[7*8]);
|
|
|
|
C = M(xC3S5, ip[3*8]) + M(xC5S3, ip[5*8]);
|
|
|
|
D = M(xC3S5, ip[5*8]) - M(xC5S3, ip[3*8]);
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Ad = M(xC4S4, (A - C));
|
|
|
|
Bd = M(xC4S4, (B - D));
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Cd = A + C;
|
|
|
|
Dd = B + D;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:51:11 +00:00
|
|
|
E = M(xC4S4, (ip[0*8] + ip[4*8])) + 8;
|
|
|
|
F = M(xC4S4, (ip[0*8] - ip[4*8])) + 8;
|
|
|
|
|
|
|
|
if(type==1){ //HACK
|
|
|
|
E += 16*128;
|
|
|
|
F += 16*128;
|
|
|
|
}
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]);
|
|
|
|
H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]);
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Ed = E - G;
|
|
|
|
Gd = E + G;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Add = F + Ad;
|
|
|
|
Bdd = Bd - H;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
Fd = F - Ad;
|
|
|
|
Hd = Bd + H;
|
2004-03-08 02:13:45 +00:00
|
|
|
|
|
|
|
/* Final sequence of operations over-write original inputs. */
|
2005-05-17 11:12:04 +00:00
|
|
|
if(type==0){
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[0*8] = (Gd + Cd ) >> 4;
|
|
|
|
ip[7*8] = (Gd - Cd ) >> 4;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[1*8] = (Add + Hd ) >> 4;
|
|
|
|
ip[2*8] = (Add - Hd ) >> 4;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[3*8] = (Ed + Dd ) >> 4;
|
|
|
|
ip[4*8] = (Ed - Dd ) >> 4;
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
ip[5*8] = (Fd + Bdd ) >> 4;
|
|
|
|
ip[6*8] = (Fd - Bdd ) >> 4;
|
2005-05-17 11:12:04 +00:00
|
|
|
}else if(type==1){
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[0*stride] = cm[(Gd + Cd ) >> 4];
|
|
|
|
dst[7*stride] = cm[(Gd - Cd ) >> 4];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[1*stride] = cm[(Add + Hd ) >> 4];
|
|
|
|
dst[2*stride] = cm[(Add - Hd ) >> 4];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[3*stride] = cm[(Ed + Dd ) >> 4];
|
|
|
|
dst[4*stride] = cm[(Ed - Dd ) >> 4];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[5*stride] = cm[(Fd + Bdd ) >> 4];
|
|
|
|
dst[6*stride] = cm[(Fd - Bdd ) >> 4];
|
2005-05-17 11:12:04 +00:00
|
|
|
}else{
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd ) >> 4)];
|
|
|
|
dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd ) >> 4)];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)];
|
|
|
|
dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd ) >> 4)];
|
|
|
|
dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd ) >> 4)];
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2006-07-19 23:21:20 +00:00
|
|
|
dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)];
|
|
|
|
dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)];
|
2005-05-17 11:12:04 +00:00
|
|
|
}
|
2004-03-08 02:13:45 +00:00
|
|
|
|
|
|
|
} else {
|
2005-05-17 11:12:04 +00:00
|
|
|
if(type==0){
|
2005-12-17 18:14:38 +00:00
|
|
|
ip[0*8] =
|
|
|
|
ip[1*8] =
|
|
|
|
ip[2*8] =
|
|
|
|
ip[3*8] =
|
|
|
|
ip[4*8] =
|
|
|
|
ip[5*8] =
|
2005-05-17 11:12:04 +00:00
|
|
|
ip[6*8] =
|
|
|
|
ip[7*8] = ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
|
|
|
|
}else if(type==1){
|
|
|
|
dst[0*stride]=
|
|
|
|
dst[1*stride]=
|
|
|
|
dst[2*stride]=
|
|
|
|
dst[3*stride]=
|
|
|
|
dst[4*stride]=
|
|
|
|
dst[5*stride]=
|
|
|
|
dst[6*stride]=
|
|
|
|
dst[7*stride]= 128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
|
|
|
|
}else{
|
|
|
|
if(ip[0*8]){
|
|
|
|
int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20);
|
|
|
|
dst[0*stride] = cm[dst[0*stride] + v];
|
|
|
|
dst[1*stride] = cm[dst[1*stride] + v];
|
|
|
|
dst[2*stride] = cm[dst[2*stride] + v];
|
|
|
|
dst[3*stride] = cm[dst[3*stride] + v];
|
|
|
|
dst[4*stride] = cm[dst[4*stride] + v];
|
|
|
|
dst[5*stride] = cm[dst[5*stride] + v];
|
|
|
|
dst[6*stride] = cm[dst[6*stride] + v];
|
|
|
|
dst[7*stride] = cm[dst[7*stride] + v];
|
|
|
|
}
|
|
|
|
}
|
2004-03-08 02:13:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ip++; /* next column */
|
2005-05-17 11:12:04 +00:00
|
|
|
dst++;
|
2004-03-08 02:13:45 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-17 11:12:04 +00:00
|
|
|
|
|
|
|
void ff_vp3_idct_c(DCTELEM *block/* align 16*/){
|
|
|
|
idct(NULL, 0, block, 0);
|
|
|
|
}
|
2005-12-17 18:14:38 +00:00
|
|
|
|
2005-05-17 11:12:04 +00:00
|
|
|
void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
|
|
|
|
idct(dest, line_size, block, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/){
|
|
|
|
idct(dest, line_size, block, 2);
|
|
|
|
}
|