Mercurial > mplayer.hg
annotate libmpcodecs/vf_spp.c @ 27757:b5a46071062a
Replace all occurrences of '__volatile__' and '__volatile' by plain 'volatile'.
We were using an inconsistent mix of the three variants and 'volatile' should
be the most correct and portable variant.
author | diego |
---|---|
date | Thu, 16 Oct 2008 20:17:56 +0000 |
parents | 08d18fe9da52 |
children | 25337a2147e7 |
rev | line source |
---|---|
11277 | 1 /* |
26727 | 2 * Copyright (C) 2003 Michael Niedermayer <michaelni@gmx.at> |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
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. | |
10 * | |
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. | |
15 * | |
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. | |
19 */ | |
11277 | 20 |
21 /* | |
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) | |
26 */ | |
27 | |
11334 | 28 |
11277 | 29 #include <stdio.h> |
30 #include <stdlib.h> | |
31 #include <string.h> | |
32 #include <inttypes.h> | |
33 #include <math.h> | |
34 | |
17012 | 35 #include "config.h" |
11335 | 36 |
17012 | 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 |
24977 | 40 #include "libavutil/intreadwrite.h" |
17012 | 41 #include "libavcodec/avcodec.h" |
42 #include "libavcodec/dsputil.h" | |
11277 | 43 |
44 #ifdef HAVE_MALLOC_H | |
45 #include <malloc.h> | |
46 #endif | |
47 | |
48 #include "img_format.h" | |
49 #include "mp_image.h" | |
50 #include "vf.h" | |
17012 | 51 #include "libvo/fastmemcpy.h" |
11277 | 52 |
53 #define XMIN(a,b) ((a) < (b) ? (a) : (b)) | |
54 | |
55 //===========================================================================// | |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
56 static const uint8_t __attribute__((aligned(8))) dither[8][8]={ |
11277 | 57 { 0, 48, 12, 60, 3, 51, 15, 63, }, |
58 { 32, 16, 44, 28, 35, 19, 47, 31, }, | |
59 { 8, 56, 4, 52, 11, 59, 7, 55, }, | |
60 { 40, 24, 36, 20, 43, 27, 39, 23, }, | |
61 { 2, 50, 14, 62, 1, 49, 13, 61, }, | |
62 { 34, 18, 46, 30, 33, 17, 45, 29, }, | |
63 { 10, 58, 6, 54, 9, 57, 5, 53, }, | |
64 { 42, 26, 38, 22, 41, 25, 37, 21, }, | |
65 }; | |
66 | |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
67 static const uint8_t offset[127][2]= { |
11298 | 68 {0,0}, |
69 {0,0}, {4,4}, | |
70 {0,0}, {2,2}, {6,4}, {4,6}, | |
71 {0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7}, | |
72 | |
73 {0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3}, | |
74 {0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7}, | |
75 | |
76 {0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7}, | |
77 {2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7}, | |
78 {4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7}, | |
79 {6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7}, | |
80 | |
11277 | 81 {0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2}, |
82 {0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0}, | |
83 {1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3}, | |
84 {1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1}, | |
85 {0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3}, | |
86 {0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1}, | |
87 {1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2}, | |
88 {1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0}, | |
89 }; | |
90 | |
91 struct vf_priv_s { | |
92 int log2_count; | |
93 int qp; | |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
94 int mode; |
11277 | 95 int mpeg2; |
96 int temp_stride; | |
97 uint8_t *src; | |
98 int16_t *temp; | |
99 AVCodecContext *avctx; | |
100 DSPContext dsp; | |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
101 char *non_b_qp; |
11277 | 102 }; |
103 | |
104 #define SHIFT 22 | |
105 | |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
106 static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ |
11277 | 107 int i; |
108 int bias= 0; //FIXME | |
109 unsigned int threshold1, threshold2; | |
11296 | 110 |
11301 | 111 threshold1= qp*((1<<4) - bias) - 1; |
11277 | 112 threshold2= (threshold1<<1); |
113 | |
114 memset(dst, 0, 64*sizeof(DCTELEM)); | |
11296 | 115 dst[0]= (src[0] + 4)>>3; |
11277 | 116 |
11296 | 117 for(i=1; i<64; i++){ |
118 int level= src[i]; | |
11277 | 119 if(((unsigned)(level+threshold1))>threshold2){ |
120 const int j= permutation[i]; | |
11296 | 121 dst[j]= (level + 4)>>3; |
11277 | 122 } |
123 } | |
124 } | |
125 | |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
126 static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
127 int i; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
128 int bias= 0; //FIXME |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
129 unsigned int threshold1, threshold2; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
130 |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
131 threshold1= qp*((1<<4) - bias) - 1; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
132 threshold2= (threshold1<<1); |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
133 |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
134 memset(dst, 0, 64*sizeof(DCTELEM)); |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
135 dst[0]= (src[0] + 4)>>3; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
136 |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
137 for(i=1; i<64; i++){ |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
138 int level= src[i]; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
139 if(((unsigned)(level+threshold1))>threshold2){ |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
140 const int j= permutation[i]; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
141 if(level>0) |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
142 dst[j]= (level - threshold1 + 4)>>3; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
143 else |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
144 dst[j]= (level + threshold1 + 4)>>3; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
145 } |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
146 } |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
147 } |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
148 |
11301 | 149 #ifdef HAVE_MMX |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
150 static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ |
11301 | 151 int bias= 0; //FIXME |
152 unsigned int threshold1; | |
153 | |
154 threshold1= qp*((1<<4) - bias) - 1; | |
155 | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
156 __asm__ volatile( |
11301 | 157 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ |
158 "movq " #src0 ", %%mm0 \n\t"\ | |
159 "movq " #src1 ", %%mm1 \n\t"\ | |
160 "movq " #src2 ", %%mm2 \n\t"\ | |
161 "movq " #src3 ", %%mm3 \n\t"\ | |
162 "psubw %%mm4, %%mm0 \n\t"\ | |
163 "psubw %%mm4, %%mm1 \n\t"\ | |
164 "psubw %%mm4, %%mm2 \n\t"\ | |
165 "psubw %%mm4, %%mm3 \n\t"\ | |
166 "paddusw %%mm5, %%mm0 \n\t"\ | |
167 "paddusw %%mm5, %%mm1 \n\t"\ | |
168 "paddusw %%mm5, %%mm2 \n\t"\ | |
169 "paddusw %%mm5, %%mm3 \n\t"\ | |
170 "paddw %%mm6, %%mm0 \n\t"\ | |
171 "paddw %%mm6, %%mm1 \n\t"\ | |
172 "paddw %%mm6, %%mm2 \n\t"\ | |
173 "paddw %%mm6, %%mm3 \n\t"\ | |
174 "psubusw %%mm6, %%mm0 \n\t"\ | |
175 "psubusw %%mm6, %%mm1 \n\t"\ | |
176 "psubusw %%mm6, %%mm2 \n\t"\ | |
177 "psubusw %%mm6, %%mm3 \n\t"\ | |
178 "psraw $3, %%mm0 \n\t"\ | |
179 "psraw $3, %%mm1 \n\t"\ | |
180 "psraw $3, %%mm2 \n\t"\ | |
181 "psraw $3, %%mm3 \n\t"\ | |
182 \ | |
183 "movq %%mm0, %%mm7 \n\t"\ | |
184 "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\ | |
185 "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\ | |
186 "movq %%mm1, %%mm2 \n\t"\ | |
187 "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\ | |
188 "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\ | |
189 "movq %%mm0, %%mm3 \n\t"\ | |
190 "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\ | |
191 "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\ | |
13393 | 192 "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\ |
11301 | 193 "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\ |
194 \ | |
195 "movq %%mm0, " #dst0 " \n\t"\ | |
196 "movq %%mm7, " #dst1 " \n\t"\ | |
197 "movq %%mm3, " #dst2 " \n\t"\ | |
198 "movq %%mm1, " #dst3 " \n\t" | |
199 | |
200 "movd %2, %%mm4 \n\t" | |
201 "movd %3, %%mm5 \n\t" | |
202 "movd %4, %%mm6 \n\t" | |
203 "packssdw %%mm4, %%mm4 \n\t" | |
204 "packssdw %%mm5, %%mm5 \n\t" | |
205 "packssdw %%mm6, %%mm6 \n\t" | |
206 "packssdw %%mm4, %%mm4 \n\t" | |
207 "packssdw %%mm5, %%mm5 \n\t" | |
208 "packssdw %%mm6, %%mm6 \n\t" | |
209 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0)) | |
210 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0)) | |
211 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0)) | |
212 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0)) | |
213 : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed? | |
214 ); | |
215 dst[0]= (src[0] + 4)>>3; | |
216 } | |
11994 | 217 |
218 static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ | |
219 int bias= 0; //FIXME | |
220 unsigned int threshold1; | |
221 | |
222 threshold1= qp*((1<<4) - bias) - 1; | |
223 | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
224 __asm__ volatile( |
11994 | 225 #undef REQUANT_CORE |
226 #define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ | |
227 "movq " #src0 ", %%mm0 \n\t"\ | |
228 "movq " #src1 ", %%mm1 \n\t"\ | |
229 "pxor %%mm6, %%mm6 \n\t"\ | |
230 "pxor %%mm7, %%mm7 \n\t"\ | |
231 "pcmpgtw %%mm0, %%mm6 \n\t"\ | |
232 "pcmpgtw %%mm1, %%mm7 \n\t"\ | |
233 "pxor %%mm6, %%mm0 \n\t"\ | |
234 "pxor %%mm7, %%mm1 \n\t"\ | |
235 "psubusw %%mm4, %%mm0 \n\t"\ | |
236 "psubusw %%mm4, %%mm1 \n\t"\ | |
237 "pxor %%mm6, %%mm0 \n\t"\ | |
238 "pxor %%mm7, %%mm1 \n\t"\ | |
239 "movq " #src2 ", %%mm2 \n\t"\ | |
240 "movq " #src3 ", %%mm3 \n\t"\ | |
241 "pxor %%mm6, %%mm6 \n\t"\ | |
242 "pxor %%mm7, %%mm7 \n\t"\ | |
243 "pcmpgtw %%mm2, %%mm6 \n\t"\ | |
244 "pcmpgtw %%mm3, %%mm7 \n\t"\ | |
245 "pxor %%mm6, %%mm2 \n\t"\ | |
246 "pxor %%mm7, %%mm3 \n\t"\ | |
247 "psubusw %%mm4, %%mm2 \n\t"\ | |
248 "psubusw %%mm4, %%mm3 \n\t"\ | |
249 "pxor %%mm6, %%mm2 \n\t"\ | |
250 "pxor %%mm7, %%mm3 \n\t"\ | |
251 \ | |
252 "paddsw %%mm5, %%mm0 \n\t"\ | |
253 "paddsw %%mm5, %%mm1 \n\t"\ | |
254 "paddsw %%mm5, %%mm2 \n\t"\ | |
255 "paddsw %%mm5, %%mm3 \n\t"\ | |
256 "psraw $3, %%mm0 \n\t"\ | |
257 "psraw $3, %%mm1 \n\t"\ | |
258 "psraw $3, %%mm2 \n\t"\ | |
259 "psraw $3, %%mm3 \n\t"\ | |
260 \ | |
261 "movq %%mm0, %%mm7 \n\t"\ | |
262 "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\ | |
263 "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\ | |
264 "movq %%mm1, %%mm2 \n\t"\ | |
265 "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\ | |
266 "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\ | |
267 "movq %%mm0, %%mm3 \n\t"\ | |
268 "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\ | |
269 "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\ | |
13393 | 270 "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\ |
11994 | 271 "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\ |
272 \ | |
273 "movq %%mm0, " #dst0 " \n\t"\ | |
274 "movq %%mm7, " #dst1 " \n\t"\ | |
275 "movq %%mm3, " #dst2 " \n\t"\ | |
276 "movq %%mm1, " #dst3 " \n\t" | |
277 | |
278 "movd %2, %%mm4 \n\t" | |
279 "movd %3, %%mm5 \n\t" | |
280 "packssdw %%mm4, %%mm4 \n\t" | |
281 "packssdw %%mm5, %%mm5 \n\t" | |
282 "packssdw %%mm4, %%mm4 \n\t" | |
283 "packssdw %%mm5, %%mm5 \n\t" | |
284 REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0)) | |
285 REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0)) | |
286 REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0)) | |
287 REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0)) | |
288 : : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed? | |
289 ); | |
290 | |
291 dst[0]= (src[0] + 4)>>3; | |
292 } | |
11301 | 293 #endif |
294 | |
11277 | 295 static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){ |
11280 | 296 int y; |
11277 | 297 |
298 for(y=0; y<8; y++){ | |
11280 | 299 *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8]; |
300 *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8]; | |
301 *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8]; | |
302 *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8]; | |
11277 | 303 } |
304 } | |
305 | |
11305 | 306 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 | 307 int y, x; |
308 | |
309 #define STORE(pos) \ | |
310 temp= ((src[x + y*src_stride + pos]<<log2_scale) + d[pos])>>6;\ | |
311 if(temp & 0x100) temp= ~(temp>>31);\ | |
312 dst[x + y*dst_stride + pos]= temp; | |
313 | |
11305 | 314 for(y=0; y<height; y++){ |
12157 | 315 const uint8_t *d= dither[y]; |
11299 | 316 for(x=0; x<width; x+=8){ |
317 int temp; | |
318 STORE(0); | |
319 STORE(1); | |
320 STORE(2); | |
321 STORE(3); | |
322 STORE(4); | |
323 STORE(5); | |
324 STORE(6); | |
325 STORE(7); | |
326 } | |
327 } | |
328 } | |
329 | |
330 #ifdef HAVE_MMX | |
11305 | 331 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 | 332 int y; |
333 | |
11305 | 334 for(y=0; y<height; y++){ |
11299 | 335 uint8_t *dst1= dst; |
336 int16_t *src1= src; | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
337 __asm__ volatile( |
11299 | 338 "movq (%3), %%mm3 \n\t" |
339 "movq (%3), %%mm4 \n\t" | |
340 "movd %4, %%mm2 \n\t" | |
341 "pxor %%mm0, %%mm0 \n\t" | |
342 "punpcklbw %%mm0, %%mm3 \n\t" | |
343 "punpckhbw %%mm0, %%mm4 \n\t" | |
344 "psraw %%mm2, %%mm3 \n\t" | |
345 "psraw %%mm2, %%mm4 \n\t" | |
346 "movd %5, %%mm2 \n\t" | |
347 "1: \n\t" | |
348 "movq (%0), %%mm0 \n\t" | |
349 "movq 8(%0), %%mm1 \n\t" | |
350 "paddw %%mm3, %%mm0 \n\t" | |
351 "paddw %%mm4, %%mm1 \n\t" | |
352 "psraw %%mm2, %%mm0 \n\t" | |
353 "psraw %%mm2, %%mm1 \n\t" | |
354 "packuswb %%mm1, %%mm0 \n\t" | |
355 "movq %%mm0, (%1) \n\t" | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
13393
diff
changeset
|
356 "add $16, %0 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
13393
diff
changeset
|
357 "add $8, %1 \n\t" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
13393
diff
changeset
|
358 "cmp %2, %1 \n\t" |
11299 | 359 " jb 1b \n\t" |
360 : "+r" (src1), "+r"(dst1) | |
361 : "r"(dst + width), "r"(dither[y]), "g"(log2_scale), "g"(6-log2_scale) | |
362 ); | |
363 src += src_stride; | |
364 dst += dst_stride; | |
365 } | |
366 // if(width != mmxw) | |
367 // store_slice_c(dst + mmxw, src + mmxw, dst_stride, src_stride, width - mmxw, log2_scale); | |
368 } | |
369 #endif | |
370 | |
11305 | 371 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 | 372 |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
373 static void (*requantize)(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation)= hardthresh_c; |
11301 | 374 |
11277 | 375 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){ |
376 int x, y, i; | |
377 const int count= 1<<p->log2_count; | |
11307 | 378 const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); |
17082 | 379 uint64_t __attribute__((aligned(16))) block_align[32]; |
11277 | 380 DCTELEM *block = (DCTELEM *)block_align; |
381 DCTELEM *block2= (DCTELEM *)(block_align+16); | |
11301 | 382 |
13729 | 383 if (!src || !dst) return; // HACK avoid crash for Y8 colourspace |
11277 | 384 for(y=0; y<height; y++){ |
11299 | 385 int index= 8 + 8*stride + y*stride; |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
20585
diff
changeset
|
386 fast_memcpy(p->src + index, src + y*src_stride, width); |
11277 | 387 for(x=0; x<8; x++){ |
388 p->src[index - x - 1]= p->src[index + x ]; | |
389 p->src[index + width + x ]= p->src[index + width - x - 1]; | |
390 } | |
391 } | |
392 for(y=0; y<8; y++){ | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
20585
diff
changeset
|
393 fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride); |
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
20585
diff
changeset
|
394 fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride); |
11277 | 395 } |
396 //FIXME (try edge emu) | |
397 | |
398 for(y=0; y<height+8; y+=8){ | |
11299 | 399 memset(p->temp + (8+y)*stride, 0, 8*stride*sizeof(int16_t)); |
11277 | 400 for(x=0; x<width+8; x+=8){ |
401 const int qps= 3 + is_luma; | |
402 int qp; | |
403 | |
404 if(p->qp) | |
405 qp= p->qp; | |
406 else{ | |
407 qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride]; | |
24552
c9c2e550a449
MPEG-2 blocks at qp 1 get overfiltered by spp, apparently because "qp>>1" turns
diego
parents:
23457
diff
changeset
|
408 if(p->mpeg2) qp = FFMAX(1, qp>>1); |
11277 | 409 } |
410 for(i=0; i<count; i++){ | |
11298 | 411 const int x1= x + offset[i+count-1][0]; |
412 const int y1= y + offset[i+count-1][1]; | |
11277 | 413 const int index= x1 + y1*stride; |
414 p->dsp.get_pixels(block, p->src + index, stride); | |
415 p->dsp.fdct(block); | |
416 requantize(block2, block, qp, p->dsp.idct_permutation); | |
417 p->dsp.idct(block2); | |
418 add_block(p->temp + index, stride, block2); | |
419 } | |
420 } | |
11299 | 421 if(y) |
11305 | 422 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 | 423 } |
11295 | 424 #if 0 |
425 for(y=0; y<height; y++){ | |
426 for(x=0; x<width; x++){ | |
427 if((((x>>6) ^ (y>>6)) & 1) == 0) | |
428 dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride]; | |
429 if((x&63) == 0 || (y&63)==0) | |
430 dst[x + y*dst_stride] += 128; | |
431 } | |
432 } | |
433 #endif | |
11277 | 434 //FIXME reorder for better caching |
435 } | |
436 | |
437 static int config(struct vf_instance_s* vf, | |
438 int width, int height, int d_width, int d_height, | |
439 unsigned int flags, unsigned int outfmt){ | |
11305 | 440 int h= (height+16+15)&(~15); |
11277 | 441 |
442 vf->priv->temp_stride= (width+16+15)&(~15); | |
11305 | 443 vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t)); |
444 vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t)); | |
11277 | 445 |
446 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
447 } | |
448 | |
449 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
450 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change | |
451 // ok, we can do pp in-place (or pp disabled): | |
452 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
16018
bdf1b4ecb906
use stored dimensions instead of visible one when (vf_)get_image is called
iive
parents:
15965
diff
changeset
|
453 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); |
11277 | 454 mpi->planes[0]=vf->dmpi->planes[0]; |
455 mpi->stride[0]=vf->dmpi->stride[0]; | |
456 mpi->width=vf->dmpi->width; | |
457 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
458 mpi->planes[1]=vf->dmpi->planes[1]; | |
459 mpi->planes[2]=vf->dmpi->planes[2]; | |
460 mpi->stride[1]=vf->dmpi->stride[1]; | |
461 mpi->stride[2]=vf->dmpi->stride[2]; | |
462 } | |
463 mpi->flags|=MP_IMGFLAG_DIRECT; | |
464 } | |
465 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
466 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
11277 | 467 mp_image_t *dmpi; |
468 | |
469 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ | |
470 // no DR, so get a new image! hope we'll get DR buffer: | |
14022
803be9a78854
removing strange csp matching code (was copy&pasted from vf_pp where it originated from arpi 2.5 years ago) -> fixes spp+scale+x11 crash
michael
parents:
13729
diff
changeset
|
471 dmpi=vf_get_image(vf->next,mpi->imgfmt, |
12631
6cbccc0c7d7b
Fix memory corruption, noticable at reallocate image
iive
parents:
12163
diff
changeset
|
472 MP_IMGTYPE_TEMP, |
6cbccc0c7d7b
Fix memory corruption, noticable at reallocate image
iive
parents:
12163
diff
changeset
|
473 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
16018
bdf1b4ecb906
use stored dimensions instead of visible one when (vf_)get_image is called
iive
parents:
15965
diff
changeset
|
474 mpi->width,mpi->height); |
12631
6cbccc0c7d7b
Fix memory corruption, noticable at reallocate image
iive
parents:
12163
diff
changeset
|
475 vf_clone_mpi_attributes(dmpi, mpi); |
6cbccc0c7d7b
Fix memory corruption, noticable at reallocate image
iive
parents:
12163
diff
changeset
|
476 }else{ |
13149 | 477 dmpi=vf->dmpi; |
12631
6cbccc0c7d7b
Fix memory corruption, noticable at reallocate image
iive
parents:
12163
diff
changeset
|
478 } |
11277 | 479 |
480 vf->priv->mpeg2= mpi->qscale_type; | |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
481 if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){ |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
482 if(!vf->priv->non_b_qp) |
20585 | 483 vf->priv->non_b_qp= malloc(mpi->qstride * ((mpi->h + 15) >> 4)); |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
20585
diff
changeset
|
484 fast_memcpy(vf->priv->non_b_qp, mpi->qscale, mpi->qstride * ((mpi->h + 15) >> 4)); |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
485 } |
11307 | 486 if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
487 char *qp_tab= vf->priv->non_b_qp; |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
488 if((vf->priv->mode&4) || !qp_tab) |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
489 qp_tab= mpi->qscale; |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
490 |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
491 if(qp_tab || vf->priv->qp){ |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
492 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1); |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
493 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); |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
494 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); |
11477
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
495 }else{ |
9785bff83777
memcpy pix instead of black screen if no DR and codec provides no qscale table
michael
parents:
11335
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 } |
11307 | 500 } |
11277 | 501 |
502 #ifdef HAVE_MMX | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
503 if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); |
11277 | 504 #endif |
505 #ifdef HAVE_MMX2 | |
27754
08d18fe9da52
Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents:
26727
diff
changeset
|
506 if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); |
11277 | 507 #endif |
508 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17523
diff
changeset
|
509 return vf_next_put_image(vf,dmpi, pts); |
11277 | 510 } |
511 | |
512 static void uninit(struct vf_instance_s* vf){ | |
513 if(!vf->priv) return; | |
514 | |
515 if(vf->priv->temp) free(vf->priv->temp); | |
516 vf->priv->temp= NULL; | |
517 if(vf->priv->src) free(vf->priv->src); | |
518 vf->priv->src= NULL; | |
519 if(vf->priv->avctx) free(vf->priv->avctx); | |
520 vf->priv->avctx= NULL; | |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
521 if(vf->priv->non_b_qp) free(vf->priv->non_b_qp); |
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
522 vf->priv->non_b_qp= NULL; |
11277 | 523 |
524 free(vf->priv); | |
525 vf->priv=NULL; | |
526 } | |
527 | |
528 //===========================================================================// | |
529 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
11307 | 530 switch(fmt){ |
531 case IMGFMT_YVU9: | |
532 case IMGFMT_IF09: | |
11277 | 533 case IMGFMT_YV12: |
534 case IMGFMT_I420: | |
535 case IMGFMT_IYUV: | |
11307 | 536 case IMGFMT_CLPL: |
537 case IMGFMT_Y800: | |
538 case IMGFMT_Y8: | |
539 case IMGFMT_444P: | |
540 case IMGFMT_422P: | |
541 case IMGFMT_411P: | |
542 return vf_next_query_format(vf,fmt); | |
543 } | |
544 return 0; | |
11277 | 545 } |
546 | |
11307 | 547 static int control(struct vf_instance_s* vf, int request, void* data){ |
548 switch(request){ | |
549 case VFCTRL_QUERY_MAX_PP_LEVEL: | |
550 return 6; | |
551 case VFCTRL_SET_PP_LEVEL: | |
552 vf->priv->log2_count= *((unsigned int*)data); | |
553 return CONTROL_TRUE; | |
554 } | |
555 return vf_next_control(vf,request,data); | |
556 } | |
557 | |
11277 | 558 static int open(vf_instance_t *vf, char* args){ |
12157 | 559 |
14022
803be9a78854
removing strange csp matching code (was copy&pasted from vf_pp where it originated from arpi 2.5 years ago) -> fixes spp+scale+x11 crash
michael
parents:
13729
diff
changeset
|
560 int log2c=-1; |
12157 | 561 |
11277 | 562 vf->config=config; |
563 vf->put_image=put_image; | |
564 vf->get_image=get_image; | |
565 vf->query_format=query_format; | |
566 vf->uninit=uninit; | |
11307 | 567 vf->control= control; |
11277 | 568 vf->priv=malloc(sizeof(struct vf_priv_s)); |
569 memset(vf->priv, 0, sizeof(struct vf_priv_s)); | |
11280 | 570 |
571 avcodec_init(); | |
572 | |
11277 | 573 vf->priv->avctx= avcodec_alloc_context(); |
574 dsputil_init(&vf->priv->dsp, vf->priv->avctx); | |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
575 |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
576 vf->priv->log2_count= 3; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
577 |
12157 | 578 if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode); |
579 | |
580 if( log2c >=0 && log2c <=6 ) | |
581 vf->priv->log2_count = log2c; | |
582 | |
583 if(vf->priv->qp < 0) | |
584 vf->priv->qp = 0; | |
585 | |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
586 switch(vf->priv->mode&3){ |
12157 | 587 default: |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
588 case 0: requantize= hardthresh_c; break; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
589 case 1: requantize= softthresh_c; break; |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
590 } |
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
591 |
11304 | 592 #ifdef HAVE_MMX |
11299 | 593 if(gCpuCaps.hasMMX){ |
594 store_slice= store_slice_mmx; | |
17110
ba9bf9beb23f
prevent flicker, to get old behaviour use spp=x:y:4 / x:y:5
michael
parents:
17082
diff
changeset
|
595 switch(vf->priv->mode&3){ |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
596 case 0: requantize= hardthresh_mmx; break; |
11994 | 597 case 1: requantize= softthresh_mmx; break; |
11993
4e2d99dbef78
spp soft thresholding patch by (James Crowson <jbcrowso at ncsu dot edu>)
michael
parents:
11568
diff
changeset
|
598 } |
11299 | 599 } |
11304 | 600 #endif |
11299 | 601 |
11277 | 602 return 1; |
603 } | |
604 | |
25221 | 605 const vf_info_t vf_info_spp = { |
11277 | 606 "simple postprocess", |
607 "spp", | |
608 "Michael Niedermayer", | |
609 "", | |
610 open, | |
611 NULL | |
612 }; |