00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 #include <inttypes.h>
00033 #include <math.h>
00034
00035 #include "config.h"
00036
00037 #include "mp_msg.h"
00038 #include "cpudetect.h"
00039
00040 #include "libavutil/internal.h"
00041 #include "libavutil/intreadwrite.h"
00042 #include "libavcodec/avcodec.h"
00043 #include "libavcodec/dsputil.h"
00044
00045 #undef fprintf
00046 #undef free
00047 #undef malloc
00048
00049 #include "img_format.h"
00050 #include "mp_image.h"
00051 #include "vf.h"
00052 #include "vd_ffmpeg.h"
00053 #include "libvo/fastmemcpy.h"
00054
00055 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
00056
00057
00058 static const uint8_t __attribute__((aligned(8))) dither[8][8]={
00059 { 0, 48, 12, 60, 3, 51, 15, 63, },
00060 { 32, 16, 44, 28, 35, 19, 47, 31, },
00061 { 8, 56, 4, 52, 11, 59, 7, 55, },
00062 { 40, 24, 36, 20, 43, 27, 39, 23, },
00063 { 2, 50, 14, 62, 1, 49, 13, 61, },
00064 { 34, 18, 46, 30, 33, 17, 45, 29, },
00065 { 10, 58, 6, 54, 9, 57, 5, 53, },
00066 { 42, 26, 38, 22, 41, 25, 37, 21, },
00067 };
00068
00069 static const uint8_t offset[127][2]= {
00070 {0,0},
00071 {0,0}, {4,4},
00072 {0,0}, {2,2}, {6,4}, {4,6},
00073 {0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7},
00074
00075 {0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3},
00076 {0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7},
00077
00078 {0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7},
00079 {2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7},
00080 {4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7},
00081 {6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7},
00082
00083 {0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2},
00084 {0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0},
00085 {1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3},
00086 {1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1},
00087 {0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3},
00088 {0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1},
00089 {1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2},
00090 {1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0},
00091 };
00092
00093 struct vf_priv_s {
00094 int log2_count;
00095 int qp;
00096 int mode;
00097 int mpeg2;
00098 int temp_stride;
00099 uint8_t *src;
00100 int16_t *temp;
00101 AVCodecContext *avctx;
00102 DSPContext dsp;
00103 char *non_b_qp;
00104 };
00105
00106 #define SHIFT 22
00107
00108 static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
00109 int i;
00110 int bias= 0;
00111 unsigned int threshold1, threshold2;
00112
00113 threshold1= qp*((1<<4) - bias) - 1;
00114 threshold2= (threshold1<<1);
00115
00116 memset(dst, 0, 64*sizeof(DCTELEM));
00117 dst[0]= (src[0] + 4)>>3;
00118
00119 for(i=1; i<64; i++){
00120 int level= src[i];
00121 if(((unsigned)(level+threshold1))>threshold2){
00122 const int j= permutation[i];
00123 dst[j]= (level + 4)>>3;
00124 }
00125 }
00126 }
00127
00128 static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
00129 int i;
00130 int bias= 0;
00131 unsigned int threshold1, threshold2;
00132
00133 threshold1= qp*((1<<4) - bias) - 1;
00134 threshold2= (threshold1<<1);
00135
00136 memset(dst, 0, 64*sizeof(DCTELEM));
00137 dst[0]= (src[0] + 4)>>3;
00138
00139 for(i=1; i<64; i++){
00140 int level= src[i];
00141 if(((unsigned)(level+threshold1))>threshold2){
00142 const int j= permutation[i];
00143 if(level>0)
00144 dst[j]= (level - threshold1 + 4)>>3;
00145 else
00146 dst[j]= (level + threshold1 + 4)>>3;
00147 }
00148 }
00149 }
00150
00151 #if HAVE_MMX
00152 static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
00153 int bias= 0;
00154 unsigned int threshold1;
00155
00156 threshold1= qp*((1<<4) - bias) - 1;
00157
00158 __asm__ volatile(
00159 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
00160 "movq " #src0 ", %%mm0 \n\t"\
00161 "movq " #src1 ", %%mm1 \n\t"\
00162 "movq " #src2 ", %%mm2 \n\t"\
00163 "movq " #src3 ", %%mm3 \n\t"\
00164 "psubw %%mm4, %%mm0 \n\t"\
00165 "psubw %%mm4, %%mm1 \n\t"\
00166 "psubw %%mm4, %%mm2 \n\t"\
00167 "psubw %%mm4, %%mm3 \n\t"\
00168 "paddusw %%mm5, %%mm0 \n\t"\
00169 "paddusw %%mm5, %%mm1 \n\t"\
00170 "paddusw %%mm5, %%mm2 \n\t"\
00171 "paddusw %%mm5, %%mm3 \n\t"\
00172 "paddw %%mm6, %%mm0 \n\t"\
00173 "paddw %%mm6, %%mm1 \n\t"\
00174 "paddw %%mm6, %%mm2 \n\t"\
00175 "paddw %%mm6, %%mm3 \n\t"\
00176 "psubusw %%mm6, %%mm0 \n\t"\
00177 "psubusw %%mm6, %%mm1 \n\t"\
00178 "psubusw %%mm6, %%mm2 \n\t"\
00179 "psubusw %%mm6, %%mm3 \n\t"\
00180 "psraw $3, %%mm0 \n\t"\
00181 "psraw $3, %%mm1 \n\t"\
00182 "psraw $3, %%mm2 \n\t"\
00183 "psraw $3, %%mm3 \n\t"\
00184 \
00185 "movq %%mm0, %%mm7 \n\t"\
00186 "punpcklwd %%mm2, %%mm0 \n\t" \
00187 "punpckhwd %%mm2, %%mm7 \n\t" \
00188 "movq %%mm1, %%mm2 \n\t"\
00189 "punpcklwd %%mm3, %%mm1 \n\t" \
00190 "punpckhwd %%mm3, %%mm2 \n\t" \
00191 "movq %%mm0, %%mm3 \n\t"\
00192 "punpcklwd %%mm1, %%mm0 \n\t" \
00193 "punpckhwd %%mm7, %%mm3 \n\t" \
00194 "punpcklwd %%mm2, %%mm7 \n\t" \
00195 "punpckhwd %%mm2, %%mm1 \n\t" \
00196 \
00197 "movq %%mm0, " #dst0 " \n\t"\
00198 "movq %%mm7, " #dst1 " \n\t"\
00199 "movq %%mm3, " #dst2 " \n\t"\
00200 "movq %%mm1, " #dst3 " \n\t"
00201
00202 "movd %2, %%mm4 \n\t"
00203 "movd %3, %%mm5 \n\t"
00204 "movd %4, %%mm6 \n\t"
00205 "packssdw %%mm4, %%mm4 \n\t"
00206 "packssdw %%mm5, %%mm5 \n\t"
00207 "packssdw %%mm6, %%mm6 \n\t"
00208 "packssdw %%mm4, %%mm4 \n\t"
00209 "packssdw %%mm5, %%mm5 \n\t"
00210 "packssdw %%mm6, %%mm6 \n\t"
00211 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
00212 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
00213 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
00214 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
00215 : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4)
00216 );
00217 dst[0]= (src[0] + 4)>>3;
00218 }
00219
00220 static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
00221 int bias= 0;
00222 unsigned int threshold1;
00223
00224 threshold1= qp*((1<<4) - bias) - 1;
00225
00226 __asm__ volatile(
00227 #undef REQUANT_CORE
00228 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
00229 "movq " #src0 ", %%mm0 \n\t"\
00230 "movq " #src1 ", %%mm1 \n\t"\
00231 "pxor %%mm6, %%mm6 \n\t"\
00232 "pxor %%mm7, %%mm7 \n\t"\
00233 "pcmpgtw %%mm0, %%mm6 \n\t"\
00234 "pcmpgtw %%mm1, %%mm7 \n\t"\
00235 "pxor %%mm6, %%mm0 \n\t"\
00236 "pxor %%mm7, %%mm1 \n\t"\
00237 "psubusw %%mm4, %%mm0 \n\t"\
00238 "psubusw %%mm4, %%mm1 \n\t"\
00239 "pxor %%mm6, %%mm0 \n\t"\
00240 "pxor %%mm7, %%mm1 \n\t"\
00241 "movq " #src2 ", %%mm2 \n\t"\
00242 "movq " #src3 ", %%mm3 \n\t"\
00243 "pxor %%mm6, %%mm6 \n\t"\
00244 "pxor %%mm7, %%mm7 \n\t"\
00245 "pcmpgtw %%mm2, %%mm6 \n\t"\
00246 "pcmpgtw %%mm3, %%mm7 \n\t"\
00247 "pxor %%mm6, %%mm2 \n\t"\
00248 "pxor %%mm7, %%mm3 \n\t"\
00249 "psubusw %%mm4, %%mm2 \n\t"\
00250 "psubusw %%mm4, %%mm3 \n\t"\
00251 "pxor %%mm6, %%mm2 \n\t"\
00252 "pxor %%mm7, %%mm3 \n\t"\
00253 \
00254 "paddsw %%mm5, %%mm0 \n\t"\
00255 "paddsw %%mm5, %%mm1 \n\t"\
00256 "paddsw %%mm5, %%mm2 \n\t"\
00257 "paddsw %%mm5, %%mm3 \n\t"\
00258 "psraw $3, %%mm0 \n\t"\
00259 "psraw $3, %%mm1 \n\t"\
00260 "psraw $3, %%mm2 \n\t"\
00261 "psraw $3, %%mm3 \n\t"\
00262 \
00263 "movq %%mm0, %%mm7 \n\t"\
00264 "punpcklwd %%mm2, %%mm0 \n\t" \
00265 "punpckhwd %%mm2, %%mm7 \n\t" \
00266 "movq %%mm1, %%mm2 \n\t"\
00267 "punpcklwd %%mm3, %%mm1 \n\t" \
00268 "punpckhwd %%mm3, %%mm2 \n\t" \
00269 "movq %%mm0, %%mm3 \n\t"\
00270 "punpcklwd %%mm1, %%mm0 \n\t" \
00271 "punpckhwd %%mm7, %%mm3 \n\t" \
00272 "punpcklwd %%mm2, %%mm7 \n\t" \
00273 "punpckhwd %%mm2, %%mm1 \n\t" \
00274 \
00275 "movq %%mm0, " #dst0 " \n\t"\
00276 "movq %%mm7, " #dst1 " \n\t"\
00277 "movq %%mm3, " #dst2 " \n\t"\
00278 "movq %%mm1, " #dst3 " \n\t"
00279
00280 "movd %2, %%mm4 \n\t"
00281 "movd %3, %%mm5 \n\t"
00282 "packssdw %%mm4, %%mm4 \n\t"
00283 "packssdw %%mm5, %%mm5 \n\t"
00284 "packssdw %%mm4, %%mm4 \n\t"
00285 "packssdw %%mm5, %%mm5 \n\t"
00286 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
00287 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
00288 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
00289 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
00290 : : "r" (src), "r" (dst), "g" (threshold1), "rm" (4)
00291 );
00292
00293 dst[0]= (src[0] + 4)>>3;
00294 }
00295 #endif
00296
00297 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
00298 int y;
00299
00300 for(y=0; y<8; y++){
00301 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
00302 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
00303 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
00304 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
00305 }
00306 }
00307
00308 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
00309 int y, x;
00310
00311 #define STORE(pos) \
00312 temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\
00313 if(temp & 0x100) temp= ~(temp>>31);\
00314 dst[x + y*dst_stride + pos]= temp;
00315
00316 for(y=0; y<height; y++){
00317 const uint8_t *d= dither[y];
00318 for(x=0; x<width; x+=8){
00319 int temp;
00320 STORE(0);
00321 STORE(1);
00322 STORE(2);
00323 STORE(3);
00324 STORE(4);
00325 STORE(5);
00326 STORE(6);
00327 STORE(7);
00328 }
00329 }
00330 }
00331
00332 #if HAVE_MMX
00333 static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
00334 int y;
00335
00336 for(y=0; y<height; y++){
00337 uint8_t *dst1= dst;
00338 int16_t *src1= src;
00339 __asm__ volatile(
00340 "movq (%3), %%mm3 \n\t"
00341 "movq (%3), %%mm4 \n\t"
00342 "movd %4, %%mm2 \n\t"
00343 "pxor %%mm0, %%mm0 \n\t"
00344 "punpcklbw %%mm0, %%mm3 \n\t"
00345 "punpckhbw %%mm0, %%mm4 \n\t"
00346 "psraw %%mm2, %%mm3 \n\t"
00347 "psraw %%mm2, %%mm4 \n\t"
00348 "movd %5, %%mm2 \n\t"
00349 "1: \n\t"
00350 "movq (%0), %%mm0 \n\t"
00351 "movq 8(%0), %%mm1 \n\t"
00352 "paddw %%mm3, %%mm0 \n\t"
00353 "paddw %%mm4, %%mm1 \n\t"
00354 "psraw %%mm2, %%mm0 \n\t"
00355 "psraw %%mm2, %%mm1 \n\t"
00356 "packuswb %%mm1, %%mm0 \n\t"
00357 "movq %%mm0, (%1) \n\t"
00358 "add $16, %0 \n\t"
00359 "add $8, %1 \n\t"
00360 "cmp %2, %1 \n\t"
00361 " jb 1b \n\t"
00362 : "+r" (src1), "+r"(dst1)
00363 : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale)
00364 );
00365 src += src_stride;
00366 dst += dst_stride;
00367 }
00368
00369
00370 }
00371 #endif
00372
00373 static void (*store_slice)(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale)= store_slice_c;
00374
00375 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c;
00376
00377 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){
00378 int x, y, i;
00379 const int count= 1<<p->log2_count;
00380 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
00381 uint64_t __attribute__((aligned(16))) block_align[32];
00382 DCTELEM *block = (DCTELEM *)block_align;
00383 DCTELEM *block2= (DCTELEM *)(block_align+16);
00384
00385 if (!src || !dst) return;
00386 for(y=0; y<height; y++){
00387 int index= 8 + 8*stride + y*stride;
00388 fast_memcpy(p->src + index, src + y*src_stride, width);
00389 for(x=0; x<8; x++){
00390 p->src[index - x - 1]= p->src[index + x ];
00391 p->src[index + width + x ]= p->src[index + width - x - 1];
00392 }
00393 }
00394 for(y=0; y<8; y++){
00395 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
00396 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
00397 }
00398
00399
00400 for(y=0; y<height+8; y+=8){
00401 memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t));
00402 for(x=0; x<width+8; x+=8){
00403 const int qps= 3 + is_luma;
00404 int qp;
00405
00406 if(p->qp)
00407 qp= p->qp;
00408 else{
00409 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
00410 qp = FFMAX(1, norm_qscale(qp, p->mpeg2));
00411 }
00412 for(i=0; i<count; i++){
00413 const int x1= x + offset[i+count-1][0];
00414 const int y1= y + offset[i+count-1][1];
00415 const int index= x1 + y1*stride;
00416 p->dsp.get_pixels(block, p->src + index, stride);
00417 p->dsp.fdct(block);
00418 requantize(block2, block, qp, p->dsp.idct_permutation);
00419 p->dsp.idct(block2);
00420 add_block(p->temp + index, stride, block2);
00421 }
00422 }
00423 if(y)
00424 store_slice(dst + (y-8)*dst_stride, p->temp + 8 + y*stride, dst_stride, stride, width, XMIN(8, height+8-y), 6-p->log2_count);
00425 }
00426 #if 0
00427 for(y=0; y<height; y++){
00428 for(x=0; x<width; x++){
00429 if((((x>>6) ^ (y>>6)) & 1) == 0)
00430 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride];
00431 if((x&63) == 0 || (y&63)==0)
00432 dst[x + y*dst_stride] += 128;
00433 }
00434 }
00435 #endif
00436
00437 }
00438
00439 static int config(struct vf_instance *vf,
00440 int width, int height, int d_width, int d_height,
00441 unsigned int flags, unsigned int outfmt){
00442 int h= (height+16+15)&(~15);
00443
00444 vf->priv->temp_stride= (width+16+15)&(~15);
00445 vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t));
00446 vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
00447
00448 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
00449 }
00450
00451 static void get_image(struct vf_instance *vf, mp_image_t *mpi){
00452 if(mpi->flags&MP_IMGFLAG_PRESERVE) return;
00453
00454 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
00455 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
00456 mpi->planes[0]=vf->dmpi->planes[0];
00457 mpi->stride[0]=vf->dmpi->stride[0];
00458 mpi->width=vf->dmpi->width;
00459 if(mpi->flags&MP_IMGFLAG_PLANAR){
00460 mpi->planes[1]=vf->dmpi->planes[1];
00461 mpi->planes[2]=vf->dmpi->planes[2];
00462 mpi->stride[1]=vf->dmpi->stride[1];
00463 mpi->stride[2]=vf->dmpi->stride[2];
00464 }
00465 mpi->flags|=MP_IMGFLAG_DIRECT;
00466 }
00467
00468 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
00469 mp_image_t *dmpi;
00470
00471 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
00472
00473 dmpi=vf_get_image(vf->next,mpi->imgfmt,
00474 MP_IMGTYPE_TEMP,
00475 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
00476 mpi->width,mpi->height);
00477 vf_clone_mpi_attributes(dmpi, mpi);
00478 }else{
00479 dmpi=vf->dmpi;
00480 }
00481
00482 vf->priv->mpeg2= mpi->qscale_type;
00483 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
00484 int w = mpi->qstride;
00485 int h = (mpi->h + 15) >> 4;
00486 if (!w) {
00487 w = (mpi->w + 15) >> 4;
00488 h = 1;
00489 }
00490 if(!vf->priv->non_b_qp)
00491 vf->priv->non_b_qp= malloc(w*h);
00492 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h);
00493 }
00494 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
00495 char *qp_tab= vf->priv->non_b_qp;
00496 if((vf->priv->mode&4) || !qp_tab)
00497 qp_tab= mpi->qscale;
00498
00499 if(qp_tab || vf->priv->qp){
00500 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
00501 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
00502 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0);
00503 }else{
00504 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
00505 memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]);
00506 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]);
00507 }
00508 }
00509
00510 #if HAVE_MMX
00511 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
00512 #endif
00513 #if HAVE_MMX2
00514 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
00515 #endif
00516
00517 return vf_next_put_image(vf,dmpi, pts);
00518 }
00519
00520 static void uninit(struct vf_instance *vf){
00521 if(!vf->priv) return;
00522
00523 free(vf->priv->temp);
00524 vf->priv->temp= NULL;
00525 free(vf->priv->src);
00526 vf->priv->src= NULL;
00527 free(vf->priv->avctx);
00528 vf->priv->avctx= NULL;
00529 free(vf->priv->non_b_qp);
00530 vf->priv->non_b_qp= NULL;
00531
00532 free(vf->priv);
00533 vf->priv=NULL;
00534 }
00535
00536
00537 static int query_format(struct vf_instance *vf, unsigned int fmt){
00538 switch(fmt){
00539 case IMGFMT_YVU9:
00540 case IMGFMT_IF09:
00541 case IMGFMT_YV12:
00542 case IMGFMT_I420:
00543 case IMGFMT_IYUV:
00544 case IMGFMT_CLPL:
00545 case IMGFMT_Y800:
00546 case IMGFMT_Y8:
00547 case IMGFMT_444P:
00548 case IMGFMT_422P:
00549 case IMGFMT_411P:
00550 return vf_next_query_format(vf,fmt);
00551 }
00552 return 0;
00553 }
00554
00555 static int control(struct vf_instance *vf, int request, void* data){
00556 switch(request){
00557 case VFCTRL_QUERY_MAX_PP_LEVEL:
00558 return 6;
00559 case VFCTRL_SET_PP_LEVEL:
00560 vf->priv->log2_count= *((unsigned int*)data);
00561 return CONTROL_TRUE;
00562 }
00563 return vf_next_control(vf,request,data);
00564 }
00565
00566 static int vf_open(vf_instance_t *vf, char *args){
00567
00568 int log2c=-1;
00569
00570 vf->config=config;
00571 vf->put_image=put_image;
00572 vf->get_image=get_image;
00573 vf->query_format=query_format;
00574 vf->uninit=uninit;
00575 vf->control= control;
00576 vf->priv=malloc(sizeof(struct vf_priv_s));
00577 memset(vf->priv, 0, sizeof(struct vf_priv_s));
00578
00579 init_avcodec();
00580
00581 vf->priv->avctx= avcodec_alloc_context();
00582 dsputil_init(&vf->priv->dsp, vf->priv->avctx);
00583
00584 vf->priv->log2_count= 3;
00585
00586 if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
00587
00588 if( log2c >=0 && log2c <=6 )
00589 vf->priv->log2_count = log2c;
00590
00591 if(vf->priv->qp < 0)
00592 vf->priv->qp = 0;
00593
00594 switch(vf->priv->mode&3){
00595 default:
00596 case 0: requantize= hardthresh_c; break;
00597 case 1: requantize= softthresh_c; break;
00598 }
00599
00600 #if HAVE_MMX
00601 if(gCpuCaps.hasMMX){
00602 store_slice= store_slice_mmx;
00603 switch(vf->priv->mode&3){
00604 case 0: requantize= hardthresh_mmx; break;
00605 case 1: requantize= softthresh_mmx; break;
00606 }
00607 }
00608 #endif
00609
00610 return 1;
00611 }
00612
00613 const vf_info_t vf_info_spp = {
00614 "simple postprocess",
00615 "spp",
00616 "Michael Niedermayer",
00617 "",
00618 vf_open,
00619 NULL
00620 };