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