Mercurial > mplayer.hg
annotate libmpcodecs/vf_spp.c @ 11568:cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
author | alex |
---|---|
date | Sun, 07 Dec 2003 15:30:25 +0000 |
parents | 9785bff83777 |
children | 4e2d99dbef78 |
rev | line source |
---|---|
11277 | 1 /* |
2 Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at> | |
3 | |
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. | |
8 | |
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. | |
13 | |
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 /* | |
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) | |
24 */ | |
25 | |
11334 | 26 |
11277 | 27 #include <stdio.h> |
28 #include <stdlib.h> | |
29 #include <string.h> | |
30 #include <inttypes.h> | |
31 #include <math.h> | |
32 | |
33 #include "../config.h" | |
11335 | 34 |
35 #ifdef USE_LIBAVCODEC | |
36 | |
11277 | 37 #include "../mp_msg.h" |
38 #include "../cpudetect.h" | |
11568
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
39 |
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
40 #ifdef USE_LIBAVCODEC_SO |
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
41 #include <ffmpeg/avcodec.h> |
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
42 #include <ffmpeg/dsputil.h> |
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
43 #else |
11277 | 44 #include "../libavcodec/avcodec.h" |
45 #include "../libavcodec/dsputil.h" | |
11568
cf76671b3d77
Fix compilation if lavc is compiled as a shared lib. Patch by Panagiotis Issaris <takis@lumumba.luc.ac.be>
alex
parents:
11477
diff
changeset
|
46 #endif |
11277 | 47 |
48 #ifdef HAVE_MALLOC_H | |
49 #include <malloc.h> | |
50 #endif | |
51 | |
52 #include "img_format.h" | |
53 #include "mp_image.h" | |
54 #include "vf.h" | |
55 #include "../libvo/fastmemcpy.h" | |
56 | |
57 #define XMIN(a,b) ((a) < (b) ? (a) : (b)) | |
58 | |
59 //===========================================================================// | |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
60 static const uint8_t __attribute__((aligned(8))) dither[8][8]={ |
11277 | 61 { 0, 48, 12, 60, 3, 51, 15, 63, }, |
62 { 32, 16, 44, 28, 35, 19, 47, 31, }, | |
63 { 8, 56, 4, 52, 11, 59, 7, 55, }, | |
64 { 40, 24, 36, 20, 43, 27, 39, 23, }, | |
65 { 2, 50, 14, 62, 1, 49, 13, 61, }, | |
66 { 34, 18, 46, 30, 33, 17, 45, 29, }, | |
67 { 10, 58, 6, 54, 9, 57, 5, 53, }, | |
68 { 42, 26, 38, 22, 41, 25, 37, 21, }, | |
69 }; | |
70 | |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
71 static const uint8_t offset[127][2]= { |
11298 | 72 {0,0}, |
73 {0,0}, {4,4}, | |
74 {0,0}, {2,2}, {6,4}, {4,6}, | |
75 {0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7}, | |
76 | |
77 {0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3}, | |
78 {0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7}, | |
79 | |
80 {0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7}, | |
81 {2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7}, | |
82 {4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7}, | |
83 {6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7}, | |
84 | |
11277 | 85 {0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2}, |
86 {0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0}, | |
87 {1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3}, | |
88 {1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1}, | |
89 {0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3}, | |
90 {0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1}, | |
91 {1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2}, | |
92 {1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0}, | |
93 }; | |
94 | |
95 struct vf_priv_s { | |
96 int log2_count; | |
97 int qp; | |
98 int mpeg2; | |
99 unsigned int outfmt; | |
100 int temp_stride; | |
101 uint8_t *src; | |
102 int16_t *temp; | |
103 AVCodecContext *avctx; | |
104 DSPContext dsp; | |
105 }; | |
106 | |
107 #define SHIFT 22 | |
108 | |
11301 | 109 static void requantize_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ |
11277 | 110 int i; |
111 int bias= 0; //FIXME | |
112 unsigned int threshold1, threshold2; | |
11296 | 113 |
11301 | 114 threshold1= qp*((1<<4) - bias) - 1; |
11277 | 115 threshold2= (threshold1<<1); |
116 | |
117 memset(dst, 0, 64*sizeof(DCTELEM)); | |
11296 | 118 dst[0]= (src[0] + 4)>>3; |
11277 | 119 |
11296 | 120 for(i=1; i<64; i++){ |
121 int level= src[i]; | |
11277 | 122 if(((unsigned)(level+threshold1))>threshold2){ |
123 const int j= permutation[i]; | |
11296 | 124 dst[j]= (level + 4)>>3; |
11277 | 125 } |
126 } | |
127 } | |
128 | |
11301 | 129 #ifdef HAVE_MMX |
130 static void requantize_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ | |
131 int bias= 0; //FIXME | |
132 unsigned int threshold1; | |
133 | |
134 threshold1= qp*((1<<4) - bias) - 1; | |
135 | |
136 asm volatile( | |
137 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ | |
138 "movq " #src0 ", %%mm0 \n\t"\ | |
139 "movq " #src1 ", %%mm1 \n\t"\ | |
140 "movq " #src2 ", %%mm2 \n\t"\ | |
141 "movq " #src3 ", %%mm3 \n\t"\ | |
142 "psubw %%mm4, %%mm0 \n\t"\ | |
143 "psubw %%mm4, %%mm1 \n\t"\ | |
144 "psubw %%mm4, %%mm2 \n\t"\ | |
145 "psubw %%mm4, %%mm3 \n\t"\ | |
146 "paddusw %%mm5, %%mm0 \n\t"\ | |
147 "paddusw %%mm5, %%mm1 \n\t"\ | |
148 "paddusw %%mm5, %%mm2 \n\t"\ | |
149 "paddusw %%mm5, %%mm3 \n\t"\ | |
150 "paddw %%mm6, %%mm0 \n\t"\ | |
151 "paddw %%mm6, %%mm1 \n\t"\ | |
152 "paddw %%mm6, %%mm2 \n\t"\ | |
153 "paddw %%mm6, %%mm3 \n\t"\ | |
154 "psubusw %%mm6, %%mm0 \n\t"\ | |
155 "psubusw %%mm6, %%mm1 \n\t"\ | |
156 "psubusw %%mm6, %%mm2 \n\t"\ | |
157 "psubusw %%mm6, %%mm3 \n\t"\ | |
158 "psraw $3, %%mm0 \n\t"\ | |
159 "psraw $3, %%mm1 \n\t"\ | |
160 "psraw $3, %%mm2 \n\t"\ | |
161 "psraw $3, %%mm3 \n\t"\ | |
162 \ | |
163 "movq %%mm0, %%mm7 \n\t"\ | |
164 "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\ | |
165 "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\ | |
166 "movq %%mm1, %%mm2 \n\t"\ | |
167 "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\ | |
168 "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\ | |
169 "movq %%mm0, %%mm3 \n\t"\ | |
170 "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\ | |
171 "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\ | |
172 "punpcklwd %%mm1, %%mm7 \n\t" /*B*/\ | |
173 "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\ | |
174 \ | |
175 "movq %%mm0, " #dst0 " \n\t"\ | |
176 "movq %%mm7, " #dst1 " \n\t"\ | |
177 "movq %%mm3, " #dst2 " \n\t"\ | |
178 "movq %%mm1, " #dst3 " \n\t" | |
179 | |
180 "movd %2, %%mm4 \n\t" | |
181 "movd %3, %%mm5 \n\t" | |
182 "movd %4, %%mm6 \n\t" | |
183 "packssdw %%mm4, %%mm4 \n\t" | |
184 "packssdw %%mm5, %%mm5 \n\t" | |
185 "packssdw %%mm6, %%mm6 \n\t" | |
186 "packssdw %%mm4, %%mm4 \n\t" | |
187 "packssdw %%mm5, %%mm5 \n\t" | |
188 "packssdw %%mm6, %%mm6 \n\t" | |
189 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0)) | |
190 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0)) | |
191 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0)) | |
192 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0)) | |
193 : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed? | |
194 ); | |
195 dst[0]= (src[0] + 4)>>3; | |
196 } | |
197 #endif | |
198 | |
11277 | 199 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){ |
11280 | 200 int y; |
11277 | 201 |
202 for(y=0; y<8; y++){ | |
11280 | 203 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8]; |
204 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8]; | |
205 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8]; | |
206 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8]; | |
11277 | 207 } |
208 } | |
209 | |
11305 | 210 static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){ |
11299 | 211 int y, x; |
212 | |
213 #define STORE(pos) \ | |
214 temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\ | |
215 if(temp & 0x100) temp= ~(temp>>31);\ | |
216 dst[x + y*dst_stride + pos]= temp; | |
217 | |
11305 | 218 for(y=0; y<height; y++){ |
11299 | 219 uint8_t *d= dither[y]; |
220 for(x=0; x<width; x+=8){ | |
221 int temp; | |
222 STORE(0); | |
223 STORE(1); | |
224 STORE(2); | |
225 STORE(3); | |
226 STORE(4); | |
227 STORE(5); | |
228 STORE(6); | |
229 STORE(7); | |
230 } | |
231 } | |
232 } | |
233 | |
234 #ifdef HAVE_MMX | |
11305 | 235 static void store_slice_mmx(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){ |
11299 | 236 int y; |
237 | |
11305 | 238 for(y=0; y<height; y++){ |
11299 | 239 uint8_t *dst1= dst; |
240 int16_t *src1= src; | |
241 asm volatile( | |
242 "movq (%3), %%mm3 \n\t" | |
243 "movq (%3), %%mm4 \n\t" | |
244 "movd %4, %%mm2 \n\t" | |
245 "pxor %%mm0, %%mm0 \n\t" | |
246 "punpcklbw %%mm0, %%mm3 \n\t" | |
247 "punpckhbw %%mm0, %%mm4 \n\t" | |
248 "psraw %%mm2, %%mm3 \n\t" | |
249 "psraw %%mm2, %%mm4 \n\t" | |
250 "movd %5, %%mm2 \n\t" | |
251 "1: \n\t" | |
252 "movq (%0), %%mm0 \n\t" | |
253 "movq 8(%0), %%mm1 \n\t" | |
254 "paddw %%mm3, %%mm0 \n\t" | |
255 "paddw %%mm4, %%mm1 \n\t" | |
256 "psraw %%mm2, %%mm0 \n\t" | |
257 "psraw %%mm2, %%mm1 \n\t" | |
258 "packuswb %%mm1, %%mm0 \n\t" | |
259 "movq %%mm0, (%1) \n\t" | |
260 "addl $16, %0 \n\t" | |
261 "addl $8, %1 \n\t" | |
262 "cmpl %2, %1 \n\t" | |
263 " jb 1b \n\t" | |
264 : "+r" (src1), "+r"(dst1) | |
265 : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale) | |
266 ); | |
267 src += src_stride; | |
268 dst += dst_stride; | |
269 } | |
270 // if(width != mmxw) | |
271 // store_slice_c(dst + mmxw, src + mmxw, dst_stride, src_stride, width - mmxw, log2_scale); | |
272 } | |
273 #endif | |
274 | |
11305 | 275 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; |
11299 | 276 |
11301 | 277 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= requantize_c; |
278 | |
11277 | 279 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){ |
280 int x, y, i; | |
281 const int count= 1<<p->log2_count; | |
11307 | 282 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); |
11277 | 283 uint64_t block_align[32]; |
284 DCTELEM *block = (DCTELEM *)block_align; | |
285 DCTELEM *block2= (DCTELEM *)(block_align+16); | |
11301 | 286 |
11277 | 287 for(y=0; y<height; y++){ |
11299 | 288 int index= 8 + 8*stride + y*stride; |
289 memcpy(p->src + index, src + y*src_stride, width); | |
11277 | 290 for(x=0; x<8; x++){ |
291 p->src[index - x - 1]= p->src[index + x ]; | |
292 p->src[index + width + x ]= p->src[index + width - x - 1]; | |
293 } | |
294 } | |
295 for(y=0; y<8; y++){ | |
296 memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride); | |
11281 | 297 memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride); |
11277 | 298 } |
299 //FIXME (try edge emu) | |
300 | |
301 for(y=0; y<height+8; y+=8){ | |
11299 | 302 memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t)); |
11277 | 303 for(x=0; x<width+8; x+=8){ |
304 const int qps= 3 + is_luma; | |
305 int qp; | |
306 | |
307 if(p->qp) | |
308 qp= p->qp; | |
309 else{ | |
310 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride]; | |
311 if(p->mpeg2) qp>>=1; | |
312 } | |
313 for(i=0; i<count; i++){ | |
11298 | 314 const int x1= x + offset[i+count-1][0]; |
315 const int y1= y + offset[i+count-1][1]; | |
11277 | 316 const int index= x1 + y1*stride; |
317 p->dsp.get_pixels(block, p->src + index, stride); | |
318 p->dsp.fdct(block); | |
319 requantize(block2, block, qp, p->dsp.idct_permutation); | |
320 p->dsp.idct(block2); | |
321 add_block(p->temp + index, stride, block2); | |
322 } | |
323 } | |
11299 | 324 if(y) |
11305 | 325 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); |
11277 | 326 } |
11295 | 327 #if 0 |
328 for(y=0; y<height; y++){ | |
329 for(x=0; x<width; x++){ | |
330 if((((x>>6) ^ (y>>6)) & 1) == 0) | |
331 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride]; | |
332 if((x&63) == 0 || (y&63)==0) | |
333 dst[x + y*dst_stride] += 128; | |
334 } | |
335 } | |
336 #endif | |
11277 | 337 //FIXME reorder for better caching |
338 } | |
339 | |
340 static int config(struct vf_instance_s* vf, | |
341 int width, int height, int d_width, int d_height, | |
342 unsigned int flags, unsigned int outfmt){ | |
11305 | 343 int h= (height+16+15)&(~15); |
11277 | 344 |
345 vf->priv->temp_stride= (width+16+15)&(~15); | |
11305 | 346 vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t)); |
347 vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t)); | |
11277 | 348 |
349 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
350 } | |
351 | |
352 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
353 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
354 if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ | |
355 // ok, we can do pp in-place (or pp disabled): | |
356 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
357 mpi->type, mpi->flags, mpi->w, mpi->h); | |
358 mpi->planes[0]=vf->dmpi->planes[0]; | |
359 mpi->stride[0]=vf->dmpi->stride[0]; | |
360 mpi->width=vf->dmpi->width; | |
361 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
362 mpi->planes[1]=vf->dmpi->planes[1]; | |
363 mpi->planes[2]=vf->dmpi->planes[2]; | |
364 mpi->stride[1]=vf->dmpi->stride[1]; | |
365 mpi->stride[2]=vf->dmpi->stride[2]; | |
366 } | |
367 mpi->flags|=MP_IMGFLAG_DIRECT; | |
368 } | |
369 | |
370 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
371 mp_image_t *dmpi; | |
372 | |
373 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
374 // no DR, so get a new image! hope we'll get DR buffer: | |
375 vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt, | |
11307 | 376 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
11277 | 377 mpi->w,mpi->h); |
378 } | |
379 | |
380 dmpi= vf->dmpi; | |
381 | |
382 vf->priv->mpeg2= mpi->qscale_type; | |
11307 | 383 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
11308
0c8d12a58a29
skip filter if codec doesnt provide the QP array and user didnt force a QP (fixes diegos segfault)
michael
parents:
11307
diff
changeset
|
384 if(mpi->qscale || vf->priv->qp){ |
11307 | 385 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, mpi->qscale, mpi->qstride, 1); |
386 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, mpi->qscale, mpi->qstride, 0); | |
387 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, mpi->qscale, mpi->qstride, 0); | |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
388 }else{ |
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
389 memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); |
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
390 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]); |
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
391 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]); |
11308
0c8d12a58a29
skip filter if codec doesnt provide the QP array and user didnt force a QP (fixes diegos segfault)
michael
parents:
11307
diff
changeset
|
392 } |
11307 | 393 } |
11277 | 394 vf_clone_mpi_attributes(dmpi, mpi); |
395 | |
396 #ifdef HAVE_MMX | |
397 if(gCpuCaps.hasMMX) asm volatile ("emms\n\t"); | |
398 #endif | |
399 #ifdef HAVE_MMX2 | |
400 if(gCpuCaps.hasMMX2) asm volatile ("sfence\n\t"); | |
401 #endif | |
402 | |
403 return vf_next_put_image(vf,dmpi); | |
404 } | |
405 | |
406 static void uninit(struct vf_instance_s* vf){ | |
407 if(!vf->priv) return; | |
408 | |
409 if(vf->priv->temp) free(vf->priv->temp); | |
410 vf->priv->temp= NULL; | |
411 if(vf->priv->src) free(vf->priv->src); | |
412 vf->priv->src= NULL; | |
413 if(vf->priv->avctx) free(vf->priv->avctx); | |
414 vf->priv->avctx= NULL; | |
415 | |
416 free(vf->priv); | |
417 vf->priv=NULL; | |
418 } | |
419 | |
420 //===========================================================================// | |
421 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
11307 | 422 switch(fmt){ |
423 case IMGFMT_YVU9: | |
424 case IMGFMT_IF09: | |
11277 | 425 case IMGFMT_YV12: |
426 case IMGFMT_I420: | |
427 case IMGFMT_IYUV: | |
11307 | 428 case IMGFMT_CLPL: |
429 case IMGFMT_Y800: | |
430 case IMGFMT_Y8: | |
431 case IMGFMT_NV12: | |
432 case IMGFMT_444P: | |
433 case IMGFMT_422P: | |
434 case IMGFMT_411P: | |
435 return vf_next_query_format(vf,fmt); | |
436 } | |
437 return 0; | |
11277 | 438 } |
439 | |
440 static unsigned int fmt_list[]={ | |
11307 | 441 IMGFMT_YVU9, |
442 IMGFMT_IF09, | |
443 IMGFMT_YV12, | |
444 IMGFMT_I420, | |
445 IMGFMT_IYUV, | |
446 IMGFMT_CLPL, | |
447 IMGFMT_Y800, | |
448 IMGFMT_Y8, | |
449 IMGFMT_NV12, | |
450 IMGFMT_444P, | |
451 IMGFMT_422P, | |
452 IMGFMT_411P, | |
453 0 | |
11277 | 454 }; |
455 | |
11307 | 456 static int control(struct vf_instance_s* vf, int request, void* data){ |
457 switch(request){ | |
458 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
459 return 6; | |
460 case VFCTRL_SET_PP_LEVEL: | |
461 vf->priv->log2_count= *((unsigned int*)data); | |
462 return CONTROL_TRUE; | |
463 } | |
464 return vf_next_control(vf,request,data); | |
465 } | |
466 | |
11277 | 467 static int open(vf_instance_t *vf, char* args){ |
468 vf->config=config; | |
469 vf->put_image=put_image; | |
470 vf->get_image=get_image; | |
471 vf->query_format=query_format; | |
472 vf->uninit=uninit; | |
11307 | 473 vf->control= control; |
11277 | 474 vf->priv=malloc(sizeof(struct vf_priv_s)); |
475 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
11280 | 476 |
477 avcodec_init(); | |
478 | |
11277 | 479 vf->priv->avctx= avcodec_alloc_context(); |
480 dsputil_init(&vf->priv->dsp, vf->priv->avctx); | |
11304 | 481 #ifdef HAVE_MMX |
11299 | 482 if(gCpuCaps.hasMMX){ |
483 store_slice= store_slice_mmx; | |
11301 | 484 requantize= requantize_mmx; |
11299 | 485 } |
11304 | 486 #endif |
11299 | 487 |
11307 | 488 vf->priv->log2_count= 3; |
11277 | 489 |
490 if (args) sscanf(args, "%d:%d", &vf->priv->log2_count, &vf->priv->qp); | |
491 | |
492 // check csp: | |
493 vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); | |
494 if(!vf->priv->outfmt) | |
495 { | |
496 uninit(vf); | |
497 return 0; // no csp match :( | |
498 } | |
499 | |
500 return 1; | |
501 } | |
502 | |
503 vf_info_t vf_info_spp = { | |
504 "simple postprocess", | |
505 "spp", | |
506 "Michael Niedermayer", | |
507 "", | |
508 open, | |
509 NULL | |
510 }; | |
511 | |
11335 | 512 #endif //USE_LIBAVCODEC |