sync with ffmpeg
[mplayer/glamo.git] / libmpcodecs / vf_spp.c
blob5a6ed294e3c71606d34a8b90d23f457676d6fb79
1 /*
2 * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 * This implementation is based on an algorithm described in
23 * "Aria Nosratinia Embedded Post-Processing for
24 * Enhancement of Compressed Images (1999)"
25 * (http://citeseer.nj.nec.com/nosratinia99embedded.html)
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <inttypes.h>
33 #include <math.h>
35 #include "config.h"
37 #include "mp_msg.h"
38 #include "cpudetect.h"
40 #include "libavutil/internal.h"
41 #include "libavutil/intreadwrite.h"
42 #include "libavcodec/avcodec.h"
43 #include "libavcodec/dsputil.h"
45 #undef fprintf
46 #undef free
47 #undef malloc
49 #include "img_format.h"
50 #include "mp_image.h"
51 #include "vf.h"
52 #include "libvo/fastmemcpy.h"
54 #define XMIN(a,b) ((a) < (b) ? (a) : (b))
56 //===========================================================================//
57 static const uint8_t __attribute__((aligned(8))) dither[8][8]={
58 { 0, 48, 12, 60, 3, 51, 15, 63, },
59 { 32, 16, 44, 28, 35, 19, 47, 31, },
60 { 8, 56, 4, 52, 11, 59, 7, 55, },
61 { 40, 24, 36, 20, 43, 27, 39, 23, },
62 { 2, 50, 14, 62, 1, 49, 13, 61, },
63 { 34, 18, 46, 30, 33, 17, 45, 29, },
64 { 10, 58, 6, 54, 9, 57, 5, 53, },
65 { 42, 26, 38, 22, 41, 25, 37, 21, },
68 static const uint8_t offset[127][2]= {
69 {0,0},
70 {0,0}, {4,4},
71 {0,0}, {2,2}, {6,4}, {4,6},
72 {0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7},
74 {0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3},
75 {0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7},
77 {0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7},
78 {2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7},
79 {4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7},
80 {6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7},
82 {0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2},
83 {0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0},
84 {1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3},
85 {1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1},
86 {0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3},
87 {0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1},
88 {1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2},
89 {1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0},
92 struct vf_priv_s {
93 int log2_count;
94 int qp;
95 int mode;
96 int mpeg2;
97 int temp_stride;
98 uint8_t *src;
99 int16_t *temp;
100 AVCodecContext *avctx;
101 DSPContext dsp;
102 char *non_b_qp;
105 #define SHIFT 22
107 static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
108 int i;
109 int bias= 0; //FIXME
110 unsigned int threshold1, threshold2;
112 threshold1= qp*((1<<4) - bias) - 1;
113 threshold2= (threshold1<<1);
115 memset(dst, 0, 64*sizeof(DCTELEM));
116 dst[0]= (src[0] + 4)>>3;
118 for(i=1; i<64; i++){
119 int level= src[i];
120 if(((unsigned)(level+threshold1))>threshold2){
121 const int j= permutation[i];
122 dst[j]= (level + 4)>>3;
127 static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
128 int i;
129 int bias= 0; //FIXME
130 unsigned int threshold1, threshold2;
132 threshold1= qp*((1<<4) - bias) - 1;
133 threshold2= (threshold1<<1);
135 memset(dst, 0, 64*sizeof(DCTELEM));
136 dst[0]= (src[0] + 4)>>3;
138 for(i=1; i<64; i++){
139 int level= src[i];
140 if(((unsigned)(level+threshold1))>threshold2){
141 const int j= permutation[i];
142 if(level>0)
143 dst[j]= (level - threshold1 + 4)>>3;
144 else
145 dst[j]= (level + threshold1 + 4)>>3;
150 #if HAVE_MMX
151 static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
152 int bias= 0; //FIXME
153 unsigned int threshold1;
155 threshold1= qp*((1<<4) - bias) - 1;
157 __asm__ volatile(
158 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
159 "movq " #src0 ", %%mm0 \n\t"\
160 "movq " #src1 ", %%mm1 \n\t"\
161 "movq " #src2 ", %%mm2 \n\t"\
162 "movq " #src3 ", %%mm3 \n\t"\
163 "psubw %%mm4, %%mm0 \n\t"\
164 "psubw %%mm4, %%mm1 \n\t"\
165 "psubw %%mm4, %%mm2 \n\t"\
166 "psubw %%mm4, %%mm3 \n\t"\
167 "paddusw %%mm5, %%mm0 \n\t"\
168 "paddusw %%mm5, %%mm1 \n\t"\
169 "paddusw %%mm5, %%mm2 \n\t"\
170 "paddusw %%mm5, %%mm3 \n\t"\
171 "paddw %%mm6, %%mm0 \n\t"\
172 "paddw %%mm6, %%mm1 \n\t"\
173 "paddw %%mm6, %%mm2 \n\t"\
174 "paddw %%mm6, %%mm3 \n\t"\
175 "psubusw %%mm6, %%mm0 \n\t"\
176 "psubusw %%mm6, %%mm1 \n\t"\
177 "psubusw %%mm6, %%mm2 \n\t"\
178 "psubusw %%mm6, %%mm3 \n\t"\
179 "psraw $3, %%mm0 \n\t"\
180 "psraw $3, %%mm1 \n\t"\
181 "psraw $3, %%mm2 \n\t"\
182 "psraw $3, %%mm3 \n\t"\
184 "movq %%mm0, %%mm7 \n\t"\
185 "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\
186 "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\
187 "movq %%mm1, %%mm2 \n\t"\
188 "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\
189 "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\
190 "movq %%mm0, %%mm3 \n\t"\
191 "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\
192 "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\
193 "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\
194 "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\
196 "movq %%mm0, " #dst0 " \n\t"\
197 "movq %%mm7, " #dst1 " \n\t"\
198 "movq %%mm3, " #dst2 " \n\t"\
199 "movq %%mm1, " #dst3 " \n\t"
201 "movd %2, %%mm4 \n\t"
202 "movd %3, %%mm5 \n\t"
203 "movd %4, %%mm6 \n\t"
204 "packssdw %%mm4, %%mm4 \n\t"
205 "packssdw %%mm5, %%mm5 \n\t"
206 "packssdw %%mm6, %%mm6 \n\t"
207 "packssdw %%mm4, %%mm4 \n\t"
208 "packssdw %%mm5, %%mm5 \n\t"
209 "packssdw %%mm6, %%mm6 \n\t"
210 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
211 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
212 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
213 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
214 : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed?
216 dst[0]= (src[0] + 4)>>3;
219 static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){
220 int bias= 0; //FIXME
221 unsigned int threshold1;
223 threshold1= qp*((1<<4) - bias) - 1;
225 __asm__ volatile(
226 #undef REQUANT_CORE
227 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \
228 "movq " #src0 ", %%mm0 \n\t"\
229 "movq " #src1 ", %%mm1 \n\t"\
230 "pxor %%mm6, %%mm6 \n\t"\
231 "pxor %%mm7, %%mm7 \n\t"\
232 "pcmpgtw %%mm0, %%mm6 \n\t"\
233 "pcmpgtw %%mm1, %%mm7 \n\t"\
234 "pxor %%mm6, %%mm0 \n\t"\
235 "pxor %%mm7, %%mm1 \n\t"\
236 "psubusw %%mm4, %%mm0 \n\t"\
237 "psubusw %%mm4, %%mm1 \n\t"\
238 "pxor %%mm6, %%mm0 \n\t"\
239 "pxor %%mm7, %%mm1 \n\t"\
240 "movq " #src2 ", %%mm2 \n\t"\
241 "movq " #src3 ", %%mm3 \n\t"\
242 "pxor %%mm6, %%mm6 \n\t"\
243 "pxor %%mm7, %%mm7 \n\t"\
244 "pcmpgtw %%mm2, %%mm6 \n\t"\
245 "pcmpgtw %%mm3, %%mm7 \n\t"\
246 "pxor %%mm6, %%mm2 \n\t"\
247 "pxor %%mm7, %%mm3 \n\t"\
248 "psubusw %%mm4, %%mm2 \n\t"\
249 "psubusw %%mm4, %%mm3 \n\t"\
250 "pxor %%mm6, %%mm2 \n\t"\
251 "pxor %%mm7, %%mm3 \n\t"\
253 "paddsw %%mm5, %%mm0 \n\t"\
254 "paddsw %%mm5, %%mm1 \n\t"\
255 "paddsw %%mm5, %%mm2 \n\t"\
256 "paddsw %%mm5, %%mm3 \n\t"\
257 "psraw $3, %%mm0 \n\t"\
258 "psraw $3, %%mm1 \n\t"\
259 "psraw $3, %%mm2 \n\t"\
260 "psraw $3, %%mm3 \n\t"\
262 "movq %%mm0, %%mm7 \n\t"\
263 "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\
264 "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\
265 "movq %%mm1, %%mm2 \n\t"\
266 "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\
267 "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\
268 "movq %%mm0, %%mm3 \n\t"\
269 "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\
270 "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\
271 "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\
272 "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\
274 "movq %%mm0, " #dst0 " \n\t"\
275 "movq %%mm7, " #dst1 " \n\t"\
276 "movq %%mm3, " #dst2 " \n\t"\
277 "movq %%mm1, " #dst3 " \n\t"
279 "movd %2, %%mm4 \n\t"
280 "movd %3, %%mm5 \n\t"
281 "packssdw %%mm4, %%mm4 \n\t"
282 "packssdw %%mm5, %%mm5 \n\t"
283 "packssdw %%mm4, %%mm4 \n\t"
284 "packssdw %%mm5, %%mm5 \n\t"
285 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0))
286 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0))
287 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0))
288 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0))
289 : : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed?
292 dst[0]= (src[0] + 4)>>3;
294 #endif
296 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){
297 int y;
299 for(y=0; y<8; y++){
300 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8];
301 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8];
302 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8];
303 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8];
307 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
308 int y, x;
310 #define STORE(pos) \
311 temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\
312 if(temp & 0x100) temp= ~(temp>>31);\
313 dst[x + y*dst_stride + pos]= temp;
315 for(y=0; y<height; y++){
316 const uint8_t *d= dither[y];
317 for(x=0; x<width; x+=8){
318 int temp;
319 STORE(0);
320 STORE(1);
321 STORE(2);
322 STORE(3);
323 STORE(4);
324 STORE(5);
325 STORE(6);
326 STORE(7);
331 #if HAVE_MMX
332 static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){
333 int y;
335 for(y=0; y<height; y++){
336 uint8_t *dst1= dst;
337 int16_t *src1= src;
338 __asm__ volatile(
339 "movq (%3), %%mm3 \n\t"
340 "movq (%3), %%mm4 \n\t"
341 "movd %4, %%mm2 \n\t"
342 "pxor %%mm0, %%mm0 \n\t"
343 "punpcklbw %%mm0, %%mm3 \n\t"
344 "punpckhbw %%mm0, %%mm4 \n\t"
345 "psraw %%mm2, %%mm3 \n\t"
346 "psraw %%mm2, %%mm4 \n\t"
347 "movd %5, %%mm2 \n\t"
348 "1: \n\t"
349 "movq (%0), %%mm0 \n\t"
350 "movq 8(%0), %%mm1 \n\t"
351 "paddw %%mm3, %%mm0 \n\t"
352 "paddw %%mm4, %%mm1 \n\t"
353 "psraw %%mm2, %%mm0 \n\t"
354 "psraw %%mm2, %%mm1 \n\t"
355 "packuswb %%mm1, %%mm0 \n\t"
356 "movq %%mm0, (%1) \n\t"
357 "add $16, %0 \n\t"
358 "add $8, %1 \n\t"
359 "cmp %2, %1 \n\t"
360 " jb 1b \n\t"
361 : "+r" (src1), "+r"(dst1)
362 : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale)
364 src += src_stride;
365 dst += dst_stride;
367 // if(width != mmxw)
368 // store_slice_c(dst + mmxw, src + mmxw, dst_stride, src_stride, width - mmxw, log2_scale);
370 #endif
372 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;
374 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c;
376 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){
377 int x, y, i;
378 const int count= 1<<p->log2_count;
379 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15));
380 uint64_t __attribute__((aligned(16))) block_align[32];
381 DCTELEM *block = (DCTELEM *)block_align;
382 DCTELEM *block2= (DCTELEM *)(block_align+16);
384 if (!src || !dst) return; // HACK avoid crash for Y8 colourspace
385 for(y=0; y<height; y++){
386 int index= 8 + 8*stride + y*stride;
387 fast_memcpy(p->src + index, src + y*src_stride, width);
388 for(x=0; x<8; x++){
389 p->src[index - x - 1]= p->src[index + x ];
390 p->src[index + width + x ]= p->src[index + width - x - 1];
393 for(y=0; y<8; y++){
394 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride);
395 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride);
397 //FIXME (try edge emu)
399 for(y=0; y<height+8; y+=8){
400 memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t));
401 for(x=0; x<width+8; x+=8){
402 const int qps= 3 + is_luma;
403 int qp;
405 if(p->qp)
406 qp= p->qp;
407 else{
408 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride];
409 if(p->mpeg2) qp = FFMAX(1, qp>>1);
411 for(i=0; i<count; i++){
412 const int x1= x + offset[i+count-1][0];
413 const int y1= y + offset[i+count-1][1];
414 const int index= x1 + y1*stride;
415 p->dsp.get_pixels(block, p->src + index, stride);
416 p->dsp.fdct(block);
417 requantize(block2, block, qp, p->dsp.idct_permutation);
418 p->dsp.idct(block2);
419 add_block(p->temp + index, stride, block2);
422 if(y)
423 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);
425 #if 0
426 for(y=0; y<height; y++){
427 for(x=0; x<width; x++){
428 if((((x>>6) ^ (y>>6)) & 1) == 0)
429 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride];
430 if((x&63) == 0 || (y&63)==0)
431 dst[x + y*dst_stride] += 128;
434 #endif
435 //FIXME reorder for better caching
438 static int config(struct vf_instance_s* vf,
439 int width, int height, int d_width, int d_height,
440 unsigned int flags, unsigned int outfmt){
441 int h= (height+16+15)&(~15);
443 vf->priv->temp_stride= (width+16+15)&(~15);
444 vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t));
445 vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t));
447 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
450 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
451 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
452 // ok, we can do pp in-place (or pp disabled):
453 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
454 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
455 mpi->planes[0]=vf->dmpi->planes[0];
456 mpi->stride[0]=vf->dmpi->stride[0];
457 mpi->width=vf->dmpi->width;
458 if(mpi->flags&MP_IMGFLAG_PLANAR){
459 mpi->planes[1]=vf->dmpi->planes[1];
460 mpi->planes[2]=vf->dmpi->planes[2];
461 mpi->stride[1]=vf->dmpi->stride[1];
462 mpi->stride[2]=vf->dmpi->stride[2];
464 mpi->flags|=MP_IMGFLAG_DIRECT;
467 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
468 mp_image_t *dmpi;
470 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
471 // no DR, so get a new image! hope we'll get DR buffer:
472 dmpi=vf_get_image(vf->next,mpi->imgfmt,
473 MP_IMGTYPE_TEMP,
474 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
475 mpi->width,mpi->height);
476 vf_clone_mpi_attributes(dmpi, mpi);
477 }else{
478 dmpi=vf->dmpi;
481 vf->priv->mpeg2= mpi->qscale_type;
482 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){
483 if(!vf->priv->non_b_qp)
484 vf->priv->non_b_qp= malloc(mpi->qstride * ((mpi->h + 15) >> 4));
485 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, mpi->qstride * ((mpi->h + 15) >> 4));
487 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){
488 char *qp_tab= vf->priv->non_b_qp;
489 if((vf->priv->mode&4) || !qp_tab)
490 qp_tab= mpi->qscale;
492 if(qp_tab || vf->priv->qp){
493 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1);
494 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);
495 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);
496 }else{
497 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]);
498 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]);
499 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]);
503 #if HAVE_MMX
504 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t");
505 #endif
506 #if HAVE_MMX2
507 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t");
508 #endif
510 return vf_next_put_image(vf,dmpi, pts);
513 static void uninit(struct vf_instance_s* vf){
514 if(!vf->priv) return;
516 if(vf->priv->temp) free(vf->priv->temp);
517 vf->priv->temp= NULL;
518 if(vf->priv->src) free(vf->priv->src);
519 vf->priv->src= NULL;
520 if(vf->priv->avctx) free(vf->priv->avctx);
521 vf->priv->avctx= NULL;
522 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp);
523 vf->priv->non_b_qp= NULL;
525 free(vf->priv);
526 vf->priv=NULL;
529 //===========================================================================//
530 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
531 switch(fmt){
532 case IMGFMT_YVU9:
533 case IMGFMT_IF09:
534 case IMGFMT_YV12:
535 case IMGFMT_I420:
536 case IMGFMT_IYUV:
537 case IMGFMT_CLPL:
538 case IMGFMT_Y800:
539 case IMGFMT_Y8:
540 case IMGFMT_444P:
541 case IMGFMT_422P:
542 case IMGFMT_411P:
543 return vf_next_query_format(vf,fmt);
545 return 0;
548 static int control(struct vf_instance_s* vf, int request, void* data){
549 switch(request){
550 case VFCTRL_QUERY_MAX_PP_LEVEL:
551 return 6;
552 case VFCTRL_SET_PP_LEVEL:
553 vf->priv->log2_count= *((unsigned int*)data);
554 return CONTROL_TRUE;
556 return vf_next_control(vf,request,data);
559 static int open(vf_instance_t *vf, char* args){
561 int log2c=-1;
563 vf->config=config;
564 vf->put_image=put_image;
565 vf->get_image=get_image;
566 vf->query_format=query_format;
567 vf->uninit=uninit;
568 vf->control= control;
569 vf->priv=malloc(sizeof(struct vf_priv_s));
570 memset(vf->priv, 0, sizeof(struct vf_priv_s));
572 avcodec_init();
574 vf->priv->avctx= avcodec_alloc_context();
575 dsputil_init(&vf->priv->dsp, vf->priv->avctx);
577 vf->priv->log2_count= 3;
579 if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode);
581 if( log2c >=0 && log2c <=6 )
582 vf->priv->log2_count = log2c;
584 if(vf->priv->qp < 0)
585 vf->priv->qp = 0;
587 switch(vf->priv->mode&3){
588 default:
589 case 0: requantize= hardthresh_c; break;
590 case 1: requantize= softthresh_c; break;
593 #if HAVE_MMX
594 if(gCpuCaps.hasMMX){
595 store_slice= store_slice_mmx;
596 switch(vf->priv->mode&3){
597 case 0: requantize= hardthresh_mmx; break;
598 case 1: requantize= softthresh_mmx; break;
601 #endif
603 return 1;
606 const vf_info_t vf_info_spp = {
607 "simple postprocess",
608 "spp",
609 "Michael Niedermayer",
611 open,
612 NULL