floating point AAN IDCT

Originally committed as revision 12233 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2008-02-26 14:59:11 +00:00
parent 60f5c96ee6
commit 6f08c541b4
7 changed files with 180 additions and 0 deletions

View File

@ -13,6 +13,7 @@ OBJS = allcodecs.o \
dsputil.o \
error_resilience.o \
eval.o \
faanidct.o \
imgconvert.o \
jrevdct.o \
mpeg12.o \

View File

@ -1326,6 +1326,7 @@ typedef struct AVCodecContext {
#define FF_IDCT_SIMPLEARMV6 17
#define FF_IDCT_SIMPLEVIS 18
#define FF_IDCT_WMV2 19
#define FF_IDCT_FAAN 20
/**
* slice count

View File

@ -36,6 +36,7 @@
#include "simple_idct.h"
#include "faandct.h"
#include "faanidct.h"
#ifndef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
@ -87,6 +88,7 @@ struct algo {
struct algo algos[] = {
DCT_ERROR( "REF-DBL", 0, fdct, fdct, NO_PERM),
DCT_ERROR("FAAN", 0, ff_faandct, fdct, FAAN_SCALE),
DCT_ERROR("FAANI", 1, ff_faanidct, idct, NO_PERM),
DCT_ERROR("IJG-AAN-INT", 0, fdct_ifast, fdct, SCALE_PERM),
DCT_ERROR("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, NO_PERM),
DCT_ERROR("REF-DBL", 1, idct, idct, NO_PERM),

View File

@ -32,6 +32,7 @@
#include "mpegvideo.h"
#include "simple_idct.h"
#include "faandct.h"
#include "faanidct.h"
#include "h263.h"
#include "snow.h"
@ -4046,6 +4047,11 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
c->idct_add= ff_wmv2_idct_add_c;
c->idct = ff_wmv2_idct_c;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else if(avctx->idct_algo==FF_IDCT_FAAN){
c->idct_put= ff_faanidct_put;
c->idct_add= ff_faanidct_add;
c->idct = ff_faanidct;
c->idct_permutation_type= FF_NO_IDCT_PERM;
}else{ //accurate/default
c->idct_put= ff_simple_idct_put;
c->idct_add= ff_simple_idct_add;

166
libavcodec/faanidct.c Normal file
View File

@ -0,0 +1,166 @@
/*
* Floating point AAN IDCT
* Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
*
* 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.1 of the License, or (at your option) any later version.
*
* 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "mpegvideo.h"
#define FLOAT float
#define B0 1.0000000000000000000000
#define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2)
#define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2)
#define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2)
#define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2)
#define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2)
#define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2)
#define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2)
#define A4 0.70710678118654752438 // cos(pi*4/16)
#define A2 0.92387953251128675613 // cos(pi*2/16)
static const FLOAT prescale[64]={
B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8,
B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8,
B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8,
B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8,
B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8,
B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8,
B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8,
B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8,
};
static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){
int i;
FLOAT tmp0, tmp1;
FLOAT s04, d04, s17, d17, s26, d26, s53, d53;
FLOAT os07, os16, os25, os34;
FLOAT od07, od16, od25, od34;
for(i=0; i<y*8; i+=y){
s17= temp[1*x + i] + temp[7*x + i];
d17= temp[1*x + i] - temp[7*x + i];
s53= temp[5*x + i] + temp[3*x + i];
d53= temp[5*x + i] - temp[3*x + i];
od07= s17 + s53;
od25= (s17 - s53)*(2*A4);
#if 0 //these 2 are equivalent
tmp0= (d17 + d53)*(2*A2);
od34= d17*( 2*B6) - tmp0;
od16= d53*(-2*B2) + tmp0;
#else
od34= d17*(2*(B6-A2)) - d53*(2*A2);
od16= d53*(2*(A2-B2)) + d17*(2*A2);
#endif
od16 -= od07;
od25 -= od16;
od34 += od25;
s26 = temp[2*x + i] + temp[6*x + i];
d26 = temp[2*x + i] - temp[6*x + i];
tmp1= d26*(2*A4) - s26;
s04= temp[0*x + i] + temp[4*x + i];
d04= temp[0*x + i] - temp[4*x + i];
os07= s04 + s26;
os34= s04 - s26;
os16= d04 + tmp1;
os25= d04 - tmp1;
if(type==0){
temp[0*x + i]= os07 + od07;
temp[7*x + i]= os07 - od07;
temp[1*x + i]= os16 + od16;
temp[6*x + i]= os16 - od16;
temp[2*x + i]= os25 + od25;
temp[5*x + i]= os25 - od25;
temp[3*x + i]= os34 - od34;
temp[4*x + i]= os34 + od34;
}else if(type==1){
data[0*x + i]= lrintf(os07 + od07);
data[7*x + i]= lrintf(os07 - od07);
data[1*x + i]= lrintf(os16 + od16);
data[6*x + i]= lrintf(os16 - od16);
data[2*x + i]= lrintf(os25 + od25);
data[5*x + i]= lrintf(os25 - od25);
data[3*x + i]= lrintf(os34 - od34);
data[4*x + i]= lrintf(os34 + od34);
}else if(type==2){
dest[0*stride + i]= av_clip_uint8(((int)dest[0*stride + i]) + lrintf(os07 + od07));
dest[7*stride + i]= av_clip_uint8(((int)dest[7*stride + i]) + lrintf(os07 - od07));
dest[1*stride + i]= av_clip_uint8(((int)dest[1*stride + i]) + lrintf(os16 + od16));
dest[6*stride + i]= av_clip_uint8(((int)dest[6*stride + i]) + lrintf(os16 - od16));
dest[2*stride + i]= av_clip_uint8(((int)dest[2*stride + i]) + lrintf(os25 + od25));
dest[5*stride + i]= av_clip_uint8(((int)dest[5*stride + i]) + lrintf(os25 - od25));
dest[3*stride + i]= av_clip_uint8(((int)dest[3*stride + i]) + lrintf(os34 - od34));
dest[4*stride + i]= av_clip_uint8(((int)dest[4*stride + i]) + lrintf(os34 + od34));
}else{
dest[0*stride + i]= av_clip_uint8(lrintf(os07 + od07));
dest[7*stride + i]= av_clip_uint8(lrintf(os07 - od07));
dest[1*stride + i]= av_clip_uint8(lrintf(os16 + od16));
dest[6*stride + i]= av_clip_uint8(lrintf(os16 - od16));
dest[2*stride + i]= av_clip_uint8(lrintf(os25 + od25));
dest[5*stride + i]= av_clip_uint8(lrintf(os25 - od25));
dest[3*stride + i]= av_clip_uint8(lrintf(os34 - od34));
dest[4*stride + i]= av_clip_uint8(lrintf(os34 + od34));
}
}
}
void ff_faanidct(DCTELEM block[64]){
FLOAT temp[64];
int i;
emms_c();
for(i=0; i<64; i++)
temp[i] = block[i] * prescale[i];
p8idct(block, temp, NULL, 0, 1, 8, 0);
p8idct(block, temp, NULL, 0, 8, 1, 1);
}
void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]){
FLOAT temp[64];
int i;
emms_c();
for(i=0; i<64; i++)
temp[i] = block[i] * prescale[i];
p8idct(block, temp, NULL, 0, 1, 8, 0);
p8idct(NULL , temp, dest, line_size, 8, 1, 2);
}
void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]){
FLOAT temp[64];
int i;
emms_c();
for(i=0; i<64; i++)
temp[i] = block[i] * prescale[i];
p8idct(block, temp, NULL, 0, 1, 8, 0);
p8idct(NULL , temp, dest, line_size, 8, 1, 3);
}

3
libavcodec/faanidct.h Normal file
View File

@ -0,0 +1,3 @@
void ff_faanidct(DCTELEM block[64]);
void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]);
void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]);

View File

@ -595,6 +595,7 @@ static const AVOption options[]={
{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"},
{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},