Mercurial > mplayer.hg
annotate postproc/yuv2rgb_template.c @ 5599:3dde5e5eef90
syncfb, mp1e, opendivx removed/disabled
author | arpi |
---|---|
date | Sat, 13 Apr 2002 17:28:33 +0000 |
parents | dd78203ea703 |
children | e7635c03910f |
rev | line source |
---|---|
2732 | 1 |
2 /* | |
3 * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology" | |
4 * | |
5 * Copyright (C) 2000, Silicon Integrated System Corp. | |
6 * All Rights Reserved. | |
7 * | |
8 * Author: Olie Lho <ollie@sis.com.tw> | |
9 * | |
10 * This file is part of mpeg2dec, a free MPEG-2 video decoder | |
11 * | |
12 * mpeg2dec is free software; you can redistribute it and/or modify | |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2, or (at your option) | |
15 * any later version. | |
16 * | |
17 * mpeg2dec is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with GNU Make; see the file COPYING. If not, write to | |
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 * | |
2749 | 26 * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) |
3143 | 27 * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support) |
2732 | 28 */ |
29 | |
3143 | 30 #undef MOVNTQ |
31 #undef EMMS | |
32 #undef SFENCE | |
2732 | 33 |
3143 | 34 #ifdef HAVE_3DNOW |
35 /* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */ | |
36 #define EMMS "femms" | |
37 #else | |
38 #define EMMS "emms" | |
39 #endif | |
2739 | 40 |
3143 | 41 #ifdef HAVE_MMX2 |
42 #define MOVNTQ "movntq" | |
43 #define SFENCE "sfence" | |
44 #else | |
45 #define MOVNTQ "movq" | |
46 #define SFENCE "/nop" | |
47 #endif | |
2739 | 48 |
2734 | 49 #define YUV2RGB \ |
50 /* Do the multiply part of the conversion for even and odd pixels, | |
51 register usage: | |
52 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, | |
53 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, | |
54 mm6 -> Y even, mm7 -> Y odd */\ | |
55 /* convert the chroma part */\ | |
56 "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ | |
57 "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ | |
58 \ | |
4285 | 59 "psubsw "MANGLE(mmx_80w)", %%mm0;" /* Cb -= 128 */ \ |
60 "psubsw "MANGLE(mmx_80w)", %%mm1;" /* Cr -= 128 */ \ | |
2734 | 61 \ |
62 "psllw $3, %%mm0;" /* Promote precision */ \ | |
63 "psllw $3, %%mm1;" /* Promote precision */ \ | |
64 \ | |
65 "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ | |
66 "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ | |
67 \ | |
4285 | 68 "pmulhw "MANGLE(mmx_U_green)", %%mm2;" /* Mul Cb with green coeff -> Cb green */ \ |
69 "pmulhw "MANGLE(mmx_V_green)", %%mm3;" /* Mul Cr with green coeff -> Cr green */ \ | |
2734 | 70 \ |
4285 | 71 "pmulhw "MANGLE(mmx_U_blue)", %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\ |
72 "pmulhw "MANGLE(mmx_V_red)", %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\ | |
2734 | 73 \ |
74 "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\ | |
75 \ | |
76 /* convert the luma part */\ | |
4285 | 77 "psubusb "MANGLE(mmx_10w)", %%mm6;" /* Y -= 16 */\ |
2734 | 78 \ |
79 "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ | |
4285 | 80 "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\ |
2734 | 81 \ |
82 "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\ | |
83 \ | |
84 "psllw $3, %%mm6;" /* Promote precision */\ | |
85 "psllw $3, %%mm7;" /* Promote precision */\ | |
86 \ | |
4285 | 87 "pmulhw "MANGLE(mmx_Y_coeff)", %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\ |
88 "pmulhw "MANGLE(mmx_Y_coeff)", %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\ | |
2734 | 89 \ |
90 /* Do the addition part of the conversion for even and odd pixels, | |
91 register usage: | |
92 mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, | |
93 mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, | |
94 mm6 -> Y even, mm7 -> Y odd */\ | |
95 "movq %%mm0, %%mm3;" /* Copy Cblue */\ | |
96 "movq %%mm1, %%mm4;" /* Copy Cred */\ | |
97 "movq %%mm2, %%mm5;" /* Copy Cgreen */\ | |
98 \ | |
99 "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\ | |
100 "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\ | |
101 \ | |
102 "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\ | |
103 "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\ | |
104 \ | |
105 "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\ | |
106 "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\ | |
107 \ | |
108 /* Limit RGB even to 0..255 */\ | |
109 "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\ | |
110 "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\ | |
111 "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\ | |
112 \ | |
113 /* Limit RGB odd to 0..255 */\ | |
114 "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\ | |
115 "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\ | |
116 "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\ | |
117 \ | |
118 /* Interleave RGB even and odd */\ | |
119 "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\ | |
120 "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\ | |
121 "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\ | |
122 | |
123 | |
3143 | 124 static inline void RENAME(yuv420_rgb16) (uint8_t * image, uint8_t * py, |
2732 | 125 uint8_t * pu, uint8_t * pv, |
126 int h_size, int v_size, | |
127 int rgb_stride, int y_stride, int uv_stride) | |
128 { | |
129 int even = 1; | |
130 int x, y; | |
131 | |
132 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
133 | |
134 for (y = v_size; --y >= 0; ) { | |
135 uint8_t *_image = image; | |
136 uint8_t *_py = py; | |
137 uint8_t *_pu = pu; | |
138 uint8_t *_pv = pv; | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
139 int internal_h_size= h_size; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
140 int aligned_h_size= (h_size+7)&~7; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
141 |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
142 if(rgb_stride >= aligned_h_size*2) internal_h_size= aligned_h_size; |
2732 | 143 |
2749 | 144 b5Dither= dither8[y&1]; |
145 g6Dither= dither4[y&1]; | |
146 g5Dither= dither8[y&1]; | |
147 r5Dither= dither8[(y+1)&1]; | |
148 | |
2732 | 149 /* load data for start of next scan line */ |
150 __asm__ __volatile__ ( | |
2734 | 151 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
152 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
153 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
2732 | 154 |
155 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
156 | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
157 for (x = internal_h_size >> 3; --x >= 0; ) { |
2732 | 158 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 |
159 pixels in each iteration */ | |
160 | |
161 __asm__ __volatile__ ( | |
2736 | 162 /* no speed diference on my p3@500 with prefetch, |
163 * if it is faster for anyone with -benchmark then tell me | |
164 PREFETCH" 64(%0) \n\t" | |
165 PREFETCH" 64(%1) \n\t" | |
166 PREFETCH" 64(%2) \n\t" | |
167 */ | |
2734 | 168 YUV2RGB |
2732 | 169 |
2749 | 170 #ifdef DITHER1XBPP |
4285 | 171 "paddusb "MANGLE(b5Dither)", %%mm0;" |
172 "paddusb "MANGLE(g6Dither)", %%mm2;" | |
173 "paddusb "MANGLE(r5Dither)", %%mm1;" | |
2749 | 174 #endif |
2732 | 175 /* mask unneeded bits off */ |
4285 | 176 "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ |
177 "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */ | |
178 "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ | |
2732 | 179 |
2736 | 180 "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ |
2734 | 181 "pxor %%mm4, %%mm4;" /* zero mm4 */ |
2732 | 182 |
2734 | 183 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ |
184 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ | |
2732 | 185 |
186 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
2734 | 187 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ |
188 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
2732 | 189 |
2736 | 190 "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ |
2734 | 191 "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ |
2732 | 192 |
2734 | 193 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ |
194 MOVNTQ " %%mm0, (%3);" /* store pixel 0-3 */ | |
2732 | 195 |
196 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
2734 | 197 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ |
198 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
2732 | 199 |
2736 | 200 "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ |
2734 | 201 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
2732 | 202 |
2734 | 203 "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ |
204 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
2732 | 205 |
2734 | 206 MOVNTQ " %%mm5, 8 (%3);" /* store pixel 4-7 */ |
2732 | 207 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); |
208 | |
209 _py += 8; | |
210 _pu += 4; | |
211 _pv += 4; | |
212 _image += 16; | |
213 } | |
214 | |
215 if (!even) { | |
216 pu += uv_stride; | |
217 pv += uv_stride; | |
218 } | |
219 | |
220 py += y_stride; | |
221 image += rgb_stride; | |
222 | |
223 even = (!even); | |
224 } | |
225 | |
226 __asm__ __volatile__ (EMMS); | |
227 } | |
228 | |
3143 | 229 static inline void RENAME(yuv420_rgb15) (uint8_t * image, uint8_t * py, |
2735 | 230 uint8_t * pu, uint8_t * pv, |
231 int h_size, int v_size, | |
232 int rgb_stride, int y_stride, int uv_stride) | |
233 { | |
234 int even = 1; | |
235 int x, y; | |
236 | |
237 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
238 | |
239 for (y = v_size; --y >= 0; ) { | |
240 uint8_t *_image = image; | |
241 uint8_t *_py = py; | |
242 uint8_t *_pu = pu; | |
243 uint8_t *_pv = pv; | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
244 int internal_h_size= h_size; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
245 int aligned_h_size= (h_size+7)&~7; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
246 |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
247 if(rgb_stride >= aligned_h_size*2) internal_h_size= aligned_h_size; |
2735 | 248 |
2749 | 249 b5Dither= dither8[y&1]; |
250 g6Dither= dither4[y&1]; | |
251 g5Dither= dither8[y&1]; | |
252 r5Dither= dither8[(y+1)&1]; | |
253 | |
2735 | 254 /* load data for start of next scan line */ |
255 __asm__ __volatile__ ( | |
256 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
257 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
258 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
259 | |
260 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
261 | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
262 for (x = internal_h_size >> 3; --x >= 0; ) { |
2735 | 263 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 |
264 pixels in each iteration */ | |
265 | |
266 __asm__ __volatile__ ( | |
267 YUV2RGB | |
268 | |
2749 | 269 #ifdef DITHER1XBPP |
4285 | 270 "paddusb "MANGLE(b5Dither)", %%mm0 \n\t" |
271 "paddusb "MANGLE(g5Dither)", %%mm2 \n\t" | |
272 "paddusb "MANGLE(r5Dither)", %%mm1 \n\t" | |
2749 | 273 #endif |
274 | |
2735 | 275 /* mask unneeded bits off */ |
4285 | 276 "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ |
277 "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */ | |
278 "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ | |
2735 | 279 |
2736 | 280 "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ |
2735 | 281 "psrlw $1,%%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */ |
282 "pxor %%mm4, %%mm4;" /* zero mm4 */ | |
283 | |
284 "movq %%mm0, %%mm5;" /* Copy B7-B0 */ | |
285 "movq %%mm2, %%mm7;" /* Copy G7-G0 */ | |
286 | |
287 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
288 "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */ | |
289 "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
290 | |
291 "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ | |
292 "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ | |
293 | |
294 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
295 MOVNTQ " %%mm0, (%3);" /* store pixel 0-3 */ | |
296 | |
297 /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ | |
298 "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */ | |
299 "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ | |
300 | |
301 "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ | |
302 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
303 | |
304 "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ | |
305 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
306 | |
307 MOVNTQ " %%mm5, 8 (%3);" /* store pixel 4-7 */ | |
308 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
309 | |
310 _py += 8; | |
311 _pu += 4; | |
312 _pv += 4; | |
313 _image += 16; | |
314 } | |
315 | |
316 if (!even) { | |
317 pu += uv_stride; | |
318 pv += uv_stride; | |
319 } | |
320 | |
321 py += y_stride; | |
322 image += rgb_stride; | |
323 | |
324 even = (!even); | |
325 } | |
326 | |
327 __asm__ __volatile__ (EMMS); | |
328 } | |
329 | |
3143 | 330 static inline void RENAME(yuv420_rgb24) (uint8_t * image, uint8_t * py, |
2734 | 331 uint8_t * pu, uint8_t * pv, |
332 int h_size, int v_size, | |
333 int rgb_stride, int y_stride, int uv_stride) | |
334 { | |
335 int even = 1; | |
336 int x, y; | |
337 | |
338 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
339 | |
340 for (y = v_size; --y >= 0; ) { | |
341 uint8_t *_image = image; | |
342 uint8_t *_py = py; | |
343 uint8_t *_pu = pu; | |
344 uint8_t *_pv = pv; | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
345 int internal_h_size= h_size; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
346 int aligned_h_size= (h_size+7)&~7; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
347 |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
348 if(rgb_stride >= aligned_h_size*3) internal_h_size= aligned_h_size; |
2734 | 349 |
350 /* load data for start of next scan line */ | |
351 __asm__ __volatile__ ( | |
352 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
353 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
354 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
355 | |
356 : : "r" (_py), "r" (_pu), "r" (_pv)); | |
357 | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
358 for (x = internal_h_size >> 3; --x >= 0; ) { |
2734 | 359 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 |
360 pixels in each iteration */ | |
361 | |
362 __asm__ __volatile__ ( | |
363 YUV2RGB | |
2739 | 364 /* mm0=B, %%mm2=G, %%mm1=R */ |
365 #ifdef HAVE_MMX2 | |
4285 | 366 "movq "MANGLE(M24A)", %%mm4 \n\t" |
367 "movq "MANGLE(M24C)", %%mm7 \n\t" | |
2739 | 368 "pshufw $0x50, %%mm0, %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */ |
369 "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */ | |
370 "pshufw $0x00, %%mm1, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */ | |
2734 | 371 |
2739 | 372 "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */ |
373 "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */ | |
374 "pand %%mm7, %%mm6 \n\t" /* R1 R0 */ | |
375 | |
376 "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */ | |
377 "por %%mm5, %%mm6 \n\t" | |
378 "por %%mm3, %%mm6 \n\t" | |
379 MOVNTQ" %%mm6, (%3) \n\t" | |
380 | |
381 "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */ | |
382 "pshufw $0xA5, %%mm0, %%mm5 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */ | |
383 "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */ | |
384 "pshufw $0xA5, %%mm1, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */ | |
385 | |
4285 | 386 "pand "MANGLE(M24B)", %%mm5 \n\t" /* B5 B4 B3 */ |
2739 | 387 "pand %%mm7, %%mm3 \n\t" /* G4 G3 */ |
388 "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */ | |
389 | |
390 "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */ | |
391 "por %%mm3, %%mm6 \n\t" | |
392 MOVNTQ" %%mm6, 8(%3) \n\t" | |
393 | |
394 "pshufw $0xFF, %%mm0, %%mm5 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */ | |
395 "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */ | |
396 "pshufw $0xFA, %%mm1, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */ | |
397 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
398 | |
399 "pand %%mm7, %%mm5 \n\t" /* B7 B6 */ | |
400 "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */ | |
4285 | 401 "pand "MANGLE(M24B)", %%mm6 \n\t" /* R7 R6 R5 */ |
2739 | 402 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ |
403 \ | |
404 "por %%mm5, %%mm3 \n\t" | |
405 "por %%mm3, %%mm6 \n\t" | |
406 MOVNTQ" %%mm6, 16(%3) \n\t" | |
407 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
408 "pxor %%mm4, %%mm4 \n\t" | |
409 | |
410 #else | |
411 | |
2734 | 412 "pxor %%mm4, %%mm4 \n\t" |
413 "movq %%mm0, %%mm5 \n\t" /* B */ | |
414 "movq %%mm1, %%mm6 \n\t" /* R */ | |
415 "punpcklbw %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */ | |
416 "punpcklbw %%mm4, %%mm1 \n\t" /* 0R0R0R0R 0 */ | |
417 "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */ | |
418 "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */ | |
419 "movq %%mm0, %%mm7 \n\t" /* GBGBGBGB 0 */ | |
420 "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */ | |
421 "punpcklwd %%mm1, %%mm7 \n\t" /* 0RGB0RGB 0 */ | |
422 "punpckhwd %%mm1, %%mm0 \n\t" /* 0RGB0RGB 1 */ | |
423 "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */ | |
424 "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */ | |
425 | |
426 "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */ | |
427 "movq %%mm0, %%mm6 \n\t" /* 0RGB0RGB 1 */ | |
428 "movq %%mm5, %%mm1 \n\t" /* 0RGB0RGB 2 */ | |
429 "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */ | |
430 | |
431 "psllq $40, %%mm7 \n\t" /* RGB00000 0 */ | |
432 "psllq $40, %%mm0 \n\t" /* RGB00000 1 */ | |
433 "psllq $40, %%mm5 \n\t" /* RGB00000 2 */ | |
434 "psllq $40, %%mm3 \n\t" /* RGB00000 3 */ | |
435 | |
436 "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */ | |
437 "punpckhdq %%mm6, %%mm0 \n\t" /* 0RGBRGB0 1 */ | |
438 "punpckhdq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */ | |
439 "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */ | |
440 | |
441 "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */ | |
442 "movq %%mm0, %%mm6 \n\t" /* 0RGBRGB0 1 */ | |
443 "psllq $40, %%mm0 \n\t" /* GB000000 1 */ | |
444 "por %%mm0, %%mm7 \n\t" /* GBRGBRGB 0 */ | |
445 MOVNTQ" %%mm7, (%3) \n\t" | |
446 | |
447 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
448 | |
449 "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */ | |
450 "movq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */ | |
451 "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */ | |
452 "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */ | |
453 MOVNTQ" %%mm6, 8(%3) \n\t" | |
454 | |
455 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
456 | |
457 "psrlq $40, %%mm1 \n\t" /* 000000RG 2 */ | |
458 "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */ | |
459 "por %%mm3, %%mm1 \n\t" /* RGBRGBRG 2 */ | |
460 MOVNTQ" %%mm1, 16(%3) \n\t" | |
461 | |
462 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
463 "pxor %%mm4, %%mm4 \n\t" | |
2739 | 464 #endif |
2734 | 465 |
466 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
467 | |
468 _py += 8; | |
469 _pu += 4; | |
470 _pv += 4; | |
471 _image += 24; | |
472 } | |
473 | |
474 if (!even) { | |
475 pu += uv_stride; | |
476 pv += uv_stride; | |
477 } | |
478 | |
479 py += y_stride; | |
480 image += rgb_stride; | |
481 | |
482 even = (!even); | |
483 } | |
484 | |
485 __asm__ __volatile__ (EMMS); | |
486 } | |
487 | |
488 | |
3143 | 489 static inline void RENAME(yuv420_argb32) (uint8_t * image, uint8_t * py, |
2732 | 490 uint8_t * pu, uint8_t * pv, |
491 int h_size, int v_size, | |
492 int rgb_stride, int y_stride, int uv_stride) | |
493 { | |
494 int even = 1; | |
495 int x, y; | |
496 | |
497 __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); | |
498 | |
499 for (y = v_size; --y >= 0; ) { | |
500 uint8_t *_image = image; | |
501 uint8_t *_py = py; | |
502 uint8_t *_pu = pu; | |
503 uint8_t *_pv = pv; | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
504 int internal_h_size= h_size; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
505 int aligned_h_size= (h_size+7)&~7; |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
506 |
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
507 if(rgb_stride >= aligned_h_size*4) internal_h_size= aligned_h_size; |
2732 | 508 |
509 /* load data for start of next scan line */ | |
510 __asm__ __volatile__ | |
511 ( | |
512 "movd (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ | |
513 "movd (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
514 "movq (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
515 : : "r" (_py), "r" (_pu), "r" (_pv) | |
516 ); | |
517 | |
5533
dd78203ea703
fixing black stripe at right if width%8!=0 && stride%8==0 reported by kabi
michael
parents:
4285
diff
changeset
|
518 for (x = internal_h_size >> 3; --x >= 0; ) { |
2732 | 519 /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 |
520 pixels in each iteration */ | |
521 __asm__ __volatile__ ( | |
2734 | 522 YUV2RGB |
523 /* convert RGB plane to RGB packed format, | |
2732 | 524 mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0, |
525 mm4 -> GB, mm5 -> AR pixel 4-7, | |
526 mm6 -> GB, mm7 -> AR pixel 0-3 */ | |
2734 | 527 "pxor %%mm3, %%mm3;" /* zero mm3 */ |
2732 | 528 |
2734 | 529 "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
530 "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ | |
2732 | 531 |
2734 | 532 "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
533 "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ | |
2732 | 534 |
2734 | 535 "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ |
536 "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */ | |
2732 | 537 |
2734 | 538 "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */ |
539 MOVNTQ " %%mm6, (%3);" /* Store ARGB1 ARGB0 */ | |
2732 | 540 |
2734 | 541 "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
542 "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ | |
2732 | 543 |
2734 | 544 "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */ |
545 MOVNTQ " %%mm6, 8 (%3);" /* Store ARGB3 ARGB2 */ | |
2732 | 546 |
2734 | 547 "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ |
548 "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */ | |
549 | |
550 "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */ | |
551 MOVNTQ " %%mm4, 16 (%3);" /* Store ARGB5 ARGB4 */ | |
2732 | 552 |
2734 | 553 "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ |
554 "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ | |
2732 | 555 |
2734 | 556 "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */ |
557 MOVNTQ " %%mm4, 24 (%3);" /* Store ARGB7 ARGB6 */ | |
2732 | 558 |
2734 | 559 "movd 4 (%1), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ |
560 "movd 4 (%2), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ | |
2732 | 561 |
2734 | 562 "pxor %%mm4, %%mm4;" /* zero mm4 */ |
563 "movq 8 (%0), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ | |
2732 | 564 |
565 : : "r" (_py), "r" (_pu), "r" (_pv), "r" (_image)); | |
566 | |
567 _py += 8; | |
568 _pu += 4; | |
569 _pv += 4; | |
570 _image += 32; | |
571 } | |
572 | |
573 if (!even) { | |
574 pu += uv_stride; | |
575 pv += uv_stride; | |
576 } | |
577 | |
578 py += y_stride; | |
579 image += rgb_stride; | |
580 | |
581 even = (!even); | |
582 } | |
583 | |
584 __asm__ __volatile__ (EMMS); | |
585 } | |
586 | |
3143 | 587 yuv2rgb_fun RENAME(yuv2rgb_init) (int bpp, int mode) |
2732 | 588 { |
3143 | 589 if (bpp == 15 && mode == MODE_RGB) return RENAME(yuv420_rgb15); |
590 if (bpp == 16 && mode == MODE_RGB) return RENAME(yuv420_rgb16); | |
591 if (bpp == 24 && mode == MODE_RGB) return RENAME(yuv420_rgb24); | |
592 if (bpp == 32 && mode == MODE_RGB) return RENAME(yuv420_argb32); | |
2732 | 593 return NULL; // Fallback to C. |
594 } | |
595 |