[svn] / tags / branch-release-1-0 / xvidcore / src / image / x86_asm / colorspace_rgb_mmx.asm Repository:
ViewVC logotype

Annotation of /tags/branch-release-1-0/xvidcore/src/image/x86_asm/colorspace_rgb_mmx.asm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 908 - (view) (download)

1 : edgomez 851 ;/**************************************************************************
2 :     ; *
3 :     ; * XVID MPEG-4 VIDEO CODEC
4 :     ; * colorspace rgb
5 :     ; *
6 :     ; * This program 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 :     ; * This program 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
17 :     ; * along with this program; if not, write to the Free Software
18 :     ; * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 :     ; *
20 :     ; *************************************************************************/
21 :    
22 :     ;/**************************************************************************
23 :     ; *
24 :     ; * History:
25 :     ; *
26 :     ; * 10.10.2001 initial version; (c)2002 peter ross <pross@xvid.org>
27 :     ; *
28 :     ; *************************************************************************/
29 :    
30 :    
31 :     bits 32
32 :    
33 :     %macro cglobal 1
34 :     %ifdef PREFIX
35 :     global _%1
36 :     %define %1 _%1
37 :     %else
38 :     global %1
39 :     %endif
40 :     %endmacro
41 :    
42 :    
43 :     section .data
44 :     align 16
45 :    
46 :     ;===========================================================================
47 :     ; RGB->YV12 yuv constants
48 :     ;===========================================================================
49 :     %define Y_R 0.257
50 :     %define Y_G 0.504
51 :     %define Y_B 0.098
52 :     %define Y_ADD 16
53 :    
54 :     %define U_R 0.148
55 :     %define U_G 0.291
56 :     %define U_B 0.439
57 :     %define U_ADD 128
58 :    
59 :     %define V_R 0.439
60 :     %define V_G 0.368
61 :     %define V_B 0.071
62 :     %define V_ADD 128
63 :    
64 :     ;===========================================================================
65 :     ; RGB->YV12 multiplication matrices
66 :     ;===========================================================================
67 :     ; FIX(Y_B) FIX(Y_G) FIX(Y_R)
68 :     y_mul dw 25, 129, 66, 0
69 :     u_mul dw 112, -74, -38, 0
70 :     v_mul dw -18, -94, 112, 0
71 :    
72 :    
73 :     ;===========================================================================
74 :     ; YV12->RGB data
75 :     ;===========================================================================
76 :     %define SCALEBITS 6
77 :     Y_SUB dw 16, 16, 16, 16
78 :     U_SUB dw 128, 128, 128, 128
79 :     V_SUB dw 128, 128, 128, 128
80 :    
81 :     Y_MUL dw 74, 74, 74, 74
82 :    
83 :     UG_MUL dw 25, 25, 25, 25
84 :     VG_MUL dw 52, 52, 52, 52
85 :    
86 :     UB_MUL dw 129, 129, 129, 129
87 :     VR_MUL dw 102, 102, 102, 102
88 :    
89 :    
90 :    
91 :     section .text
92 :    
93 :     %include "colorspace_mmx.inc"
94 :    
95 :    
96 :     ;------------------------------------------------------------------------------
97 :     ; BGR_TO_YV12( BYTES )
98 :     ;
99 :     ; BYTES 3=bgr(24bit), 4=bgra(32-bit)
100 :     ;
101 :     ; bytes=3/4, pixels = 2, vpixels=2
102 :     ;------------------------------------------------------------------------------
103 :     %macro BGR_TO_YV12_INIT 2
104 :     movq mm7, [y_mul]
105 :     %endmacro
106 :    
107 :    
108 :     %macro BGR_TO_YV12 2
109 :     ; y_out
110 :     pxor mm4, mm4
111 :     pxor mm5, mm5
112 :     movd mm0, [edi] ; x_ptr[0...]
113 :     movd mm2, [edi+edx] ; x_ptr[x_stride...]
114 :     punpcklbw mm0, mm4 ; [ |b |g |r ]
115 :     punpcklbw mm2, mm5 ; [ |b |g |r ]
116 :     movq mm6, mm0 ; = [ |b4|g4|r4]
117 :     paddw mm6, mm2 ; +[ |b4|g4|r4]
118 :     pmaddwd mm0, mm7 ; *= Y_MUL
119 :     pmaddwd mm2, mm7 ; *= Y_MUL
120 :     movq mm4, mm0 ; [r]
121 :     movq mm5, mm2 ; [r]
122 :     psrlq mm4, 32 ; +[g]
123 :     psrlq mm5, 32 ; +[g]
124 :     paddd mm0, mm4 ; +[b]
125 :     paddd mm2, mm5 ; +[b]
126 :    
127 :     pxor mm4, mm4
128 :     pxor mm5, mm5
129 :     movd mm1, [edi+%1] ; src[%1...]
130 :     movd mm3, [edi+edx+%1] ; src[x_stride+%1...]
131 :     punpcklbw mm1, mm4 ; [ |b |g |r ]
132 :     punpcklbw mm3, mm5 ; [ |b |g |r ]
133 :     paddw mm6, mm1 ; +[ |b4|g4|r4]
134 :     paddw mm6, mm3 ; +[ |b4|g4|r4]
135 :     pmaddwd mm1, mm7 ; *= Y_MUL
136 :     pmaddwd mm3, mm7 ; *= Y_MUL
137 :     movq mm4, mm1 ; [r]
138 :     movq mm5, mm3 ; [r]
139 :     psrlq mm4, 32 ; +[g]
140 :     psrlq mm5, 32 ; +[g]
141 :     paddd mm1, mm4 ; +[b]
142 :     paddd mm3, mm5 ; +[b]
143 :    
144 :     push edx
145 :    
146 :     movd edx, mm0
147 :     shr edx, 8
148 :     add edx, Y_ADD
149 :     mov [esi], dl ; y_ptr[0]
150 :    
151 :     movd edx, mm1
152 :     shr edx, 8
153 :     add edx, Y_ADD
154 :     mov [esi + 1], dl ; y_ptr[1]
155 :    
156 :     movd edx, mm2
157 :     shr edx, 8
158 :     add edx, Y_ADD
159 :     mov [esi + eax + 0], dl ; y_ptr[y_stride + 0]
160 :    
161 :     movd edx, mm3
162 :     shr edx, 8
163 :     add edx, Y_ADD
164 :     mov [esi + eax + 1], dl ; y_ptr[y_stride + 1]
165 :    
166 :     ; u_ptr, v_ptr
167 :    
168 :     movq mm0, mm6 ; = [ |b4|g4|r4]
169 :     pmaddwd mm6, [v_mul] ; *= V_MUL
170 :     pmaddwd mm0, [u_mul] ; *= U_MUL
171 :     movq mm1, mm0
172 :     movq mm2, mm6
173 :     psrlq mm1, 32
174 :     psrlq mm2, 32
175 :     paddd mm0, mm1
176 :     paddd mm2, mm6
177 :    
178 :     movd edx, mm0
179 :     shr edx, 10
180 :     add edx, U_ADD
181 :     mov [ebx], dl
182 :    
183 :     movd edx, mm2
184 :     shr edx, 10
185 :     add edx, V_ADD
186 :     mov [ecx], dl
187 :    
188 :     pop edx
189 :     %endmacro
190 :     ;------------------------------------------------------------------------------
191 :    
192 :    
193 :    
194 :    
195 :    
196 :     ;------------------------------------------------------------------------------
197 :     ; YV12_TO_BGR( BYTES )
198 :     ;
199 :     ; BYTES 3=bgr(24-bit), 4=bgra(32-bit)
200 :     ;
201 :     ; bytes=3/4, pixels = 8, vpixels=2
202 :     ;------------------------------------------------------------------------------
203 :     %macro YV12_TO_BGR_INIT 2
204 :     pxor mm7, mm7 ; clear mm7
205 :     %endmacro
206 :    
207 :    
208 :     %macro YV12_TO_BGR 2
209 :     %define TEMP_Y1 esp
210 :     %define TEMP_Y2 esp + 8
211 :     %define TEMP_G1 esp + 16
212 :     %define TEMP_G2 esp + 24
213 :     %define TEMP_B1 esp + 32
214 :     %define TEMP_B2 esp + 40
215 :     movd mm2, [ebx] ; u_ptr[0]
216 :     movd mm3, [ecx] ; v_ptr[0]
217 :    
218 :     punpcklbw mm2, mm7 ; u3u2u1u0 -> mm2
219 :     punpcklbw mm3, mm7 ; v3v2v1v0 -> mm3
220 :    
221 :     psubsw mm2, [U_SUB] ; U - 128
222 :     psubsw mm3, [V_SUB] ; V - 128
223 :    
224 :     movq mm4, mm2
225 :     movq mm5, mm3
226 :    
227 :     pmullw mm2, [UG_MUL]
228 :     pmullw mm3, [VG_MUL]
229 :    
230 :     movq mm6, mm2 ; u3u2u1u0 -> mm6
231 :     punpckhwd mm2, mm2 ; u3u3u2u2 -> mm2
232 :     punpcklwd mm6, mm6 ; u1u1u0u0 -> mm6
233 :    
234 :     pmullw mm4, [UB_MUL] ; B_ADD -> mm4
235 :    
236 :     movq mm0, mm3
237 :     punpckhwd mm3, mm3 ; v3v3v2v2 -> mm2
238 :     punpcklwd mm0, mm0 ; v1v1v0v0 -> mm6
239 :    
240 :     paddsw mm2, mm3
241 :     paddsw mm6, mm0
242 :    
243 :     pmullw mm5, [VR_MUL] ; R_ADD -> mm5
244 :    
245 :     movq mm0, [esi] ; y7y6y5y4y3y2y1y0 -> mm0
246 :    
247 :     movq mm1, mm0
248 :     punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1
249 :     punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0
250 :    
251 :     psubsw mm0, [Y_SUB] ; Y - Y_SUB
252 :     psubsw mm1, [Y_SUB] ; Y - Y_SUB
253 :    
254 :     pmullw mm1, [Y_MUL]
255 :     pmullw mm0, [Y_MUL]
256 :    
257 :     movq [TEMP_Y2], mm1 ; y7y6y5y4 -> mm3
258 :     movq [TEMP_Y1], mm0 ; y3y2y1y0 -> mm7
259 :    
260 :     psubsw mm1, mm2 ; g7g6g5g4 -> mm1
261 :     psubsw mm0, mm6 ; g3g2g1g0 -> mm0
262 :    
263 :     psraw mm1, SCALEBITS
264 :     psraw mm0, SCALEBITS
265 :    
266 :     packuswb mm0, mm1 ;g7g6g5g4g3g2g1g0 -> mm0
267 :    
268 :     movq [TEMP_G1], mm0
269 :    
270 :     movq mm0, [esi+eax] ; y7y6y5y4y3y2y1y0 -> mm0
271 :    
272 :     movq mm1, mm0
273 :    
274 :     punpckhbw mm1, mm7 ; y7y6y5y4 -> mm1
275 :     punpcklbw mm0, mm7 ; y3y2y1y0 -> mm0
276 :    
277 :     psubsw mm0, [Y_SUB] ; Y - Y_SUB
278 :     psubsw mm1, [Y_SUB] ; Y - Y_SUB
279 :    
280 :     pmullw mm1, [Y_MUL]
281 :     pmullw mm0, [Y_MUL]
282 :    
283 :     movq mm3, mm1
284 :     psubsw mm1, mm2 ; g7g6g5g4 -> mm1
285 :    
286 :     movq mm2, mm0
287 :     psubsw mm0, mm6 ; g3g2g1g0 -> mm0
288 :    
289 :     psraw mm1, SCALEBITS
290 :     psraw mm0, SCALEBITS
291 :    
292 :     packuswb mm0, mm1 ; g7g6g5g4g3g2g1g0 -> mm0
293 :    
294 :     movq [TEMP_G2], mm0
295 :    
296 :     movq mm0, mm4
297 :     punpckhwd mm4, mm4 ; u3u3u2u2 -> mm2
298 :     punpcklwd mm0, mm0 ; u1u1u0u0 -> mm6
299 :    
300 :     movq mm1, mm3 ; y7y6y5y4 -> mm1
301 :     paddsw mm3, mm4 ; b7b6b5b4 -> mm3
302 :    
303 :     movq mm7, mm2 ; y3y2y1y0 -> mm7
304 :    
305 :     paddsw mm2, mm0 ; b3b2b1b0 -> mm2
306 :    
307 :     psraw mm3, SCALEBITS
308 :     psraw mm2, SCALEBITS
309 :    
310 :     packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2
311 :    
312 :     movq [TEMP_B2], mm2
313 :    
314 :     movq mm3, [TEMP_Y2]
315 :     movq mm2, [TEMP_Y1]
316 :    
317 :     movq mm6, mm3 ; TEMP_Y2 -> mm6
318 :     paddsw mm3, mm4 ; b7b6b5b4 -> mm3
319 :    
320 :     movq mm4, mm2 ; TEMP_Y1 -> mm4
321 :     paddsw mm2, mm0 ; b3b2b1b0 -> mm2
322 :    
323 :     psraw mm3, SCALEBITS
324 :     psraw mm2, SCALEBITS
325 :    
326 :     packuswb mm2, mm3 ; b7b6b5b4b3b2b1b0 -> mm2
327 :    
328 :     movq [TEMP_B1], mm2
329 :    
330 :     movq mm0, mm5
331 :     punpckhwd mm5, mm5 ; v3v3v2v2 -> mm5
332 :     punpcklwd mm0, mm0 ; v1v1v0v0 -> mm0
333 :    
334 :     paddsw mm1, mm5 ; r7r6r5r4 -> mm1
335 :     paddsw mm7, mm0 ; r3r2r1r0 -> mm7
336 :    
337 :     psraw mm1, SCALEBITS
338 :     psraw mm7, SCALEBITS
339 :    
340 :     packuswb mm7, mm1 ; r7r6r5r4r3r2r1r0 -> mm7 (TEMP_R2)
341 :    
342 :     paddsw mm6, mm5 ; r7r6r5r4 -> mm6
343 :     paddsw mm4, mm0 ; r3r2r1r0 -> mm4
344 :    
345 :     psraw mm6, SCALEBITS
346 :     psraw mm4, SCALEBITS
347 :    
348 :     packuswb mm4, mm6 ; r7r6r5r4r3r2r1r0 -> mm4 (TEMP_R1)
349 :    
350 :     movq mm0, [TEMP_B1]
351 :     movq mm1, [TEMP_G1]
352 :    
353 :     movq mm6, mm7
354 :    
355 :     movq mm2, mm0
356 :     punpcklbw mm2, mm4 ; r3b3r2b2r1b1r0b0 -> mm2
357 :     punpckhbw mm0, mm4 ; r7b7r6b6r5b5r4b4 -> mm0
358 :    
359 :     pxor mm7, mm7
360 :    
361 :     movq mm3, mm1
362 :     punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1
363 :     punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3
364 :    
365 :     movq mm4, mm2
366 :     punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2
367 :     punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4
368 :    
369 :     movq mm5, mm0
370 :     punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0
371 :     punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5
372 :    
373 :     %if %1 == 3 ; BGR (24-bit)
374 :     movd [edi], mm2
375 :     psrlq mm2, 32
376 :    
377 :     movd [edi + 3], mm2
378 :     movd [edi + 6], mm4
379 :    
380 :     psrlq mm4, 32
381 :    
382 :     movd [edi + 9], mm4
383 :     movd [edi + 12], mm0
384 :    
385 :     psrlq mm0, 32
386 :    
387 :     movd [edi + 15], mm0
388 :     movd [edi + 18], mm5
389 :    
390 :     psrlq mm5, 32
391 :    
392 :     movd [edi + 21], mm5
393 :    
394 :     movq mm0, [TEMP_B2]
395 :     movq mm1, [TEMP_G2]
396 :    
397 :     movq mm2, mm0
398 :     punpcklbw mm2, mm6 ; r3b3r2b2r1b1r0b0 -> mm2
399 :     punpckhbw mm0, mm6 ; r7b7r6b6r5b5r4b4 -> mm0
400 :    
401 :     movq mm3, mm1
402 :     punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1
403 :     punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3
404 :    
405 :     movq mm4, mm2
406 :     punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2
407 :     punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4
408 :    
409 :     movq mm5, mm0
410 :     punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0
411 :     punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5
412 :    
413 :     movd [edi+edx], mm2
414 :     psrlq mm2, 32
415 :    
416 :     movd [edi+edx + 3], mm2
417 :     movd [edi+edx + 6], mm4
418 :    
419 :     psrlq mm4, 32
420 :    
421 :     movd [edi+edx + 9], mm4
422 :     movd [edi+edx + 12], mm0
423 :    
424 :     psrlq mm0, 32
425 :    
426 :     movd [edi+edx + 15], mm0
427 :     movd [edi+edx + 18], mm5
428 :    
429 :     psrlq mm5, 32
430 :    
431 :     movd [edi+edx + 21], mm5
432 :    
433 :     %else ; BGRA (32-bit)
434 :     movq [edi], mm2
435 :     movq [edi + 8], mm4
436 :     movq [edi + 16], mm0
437 :     movq [edi + 24], mm5
438 :    
439 :     movq mm0, [TEMP_B2]
440 :     movq mm1, [TEMP_G2]
441 :    
442 :     movq mm2, mm0
443 :     punpcklbw mm2, mm6 ; r3b3r2b2r1b1r0b0 -> mm2
444 :     punpckhbw mm0, mm6 ; r7b7r6b6r5b5r4b4 -> mm0
445 :    
446 :     movq mm3, mm1
447 :     punpcklbw mm1, mm7 ; 0g30g20g10g0 -> mm1
448 :     punpckhbw mm3, mm7 ; 0g70g60g50g4 -> mm3
449 :    
450 :     movq mm4, mm2
451 :     punpcklbw mm2, mm1 ; 0r1g1b10r0g0b0 -> mm2
452 :     punpckhbw mm4, mm1 ; 0r3g3b30r2g2b2 -> mm4
453 :    
454 :     movq mm5, mm0
455 :     punpcklbw mm0, mm3 ; 0r5g5b50r4g4b4 -> mm0
456 :     punpckhbw mm5, mm3 ; 0r7g7b70r6g6b6 -> mm5
457 :    
458 :     movq [edi + edx], mm2
459 :     movq [edi + edx + 8], mm4
460 :     movq [edi + edx + 16], mm0
461 :     movq [edi + edx + 24], mm5
462 :     %endif
463 :    
464 :     %undef TEMP_Y1
465 :     %undef TEMP_Y2
466 :     %undef TEMP_G1
467 :     %undef TEMP_G2
468 :     %undef TEMP_B1
469 :     %undef TEMP_B2
470 :     %endmacro
471 :     ;------------------------------------------------------------------------------
472 :    
473 :    
474 :    
475 :    
476 :     ; input
477 :    
478 :     MAKE_COLORSPACE bgr_to_yv12_mmx,0, 3,2,2, BGR_TO_YV12, 3, -1
479 :     MAKE_COLORSPACE bgra_to_yv12_mmx,0, 4,2,2, BGR_TO_YV12, 4, -1
480 :    
481 :     ; output
482 :    
483 :     MAKE_COLORSPACE yv12_to_bgr_mmx,48, 3,8,2, YV12_TO_BGR, 3, -1
484 :     MAKE_COLORSPACE yv12_to_bgra_mmx,48, 4,8,2, YV12_TO_BGR, 4, -1
485 :    

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4