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