1 ;******************************************************************************
2 ;* software YUV to RGB converter
4 ;* Copyright (C) 2001-2007 Michael Niedermayer
5 ;* (c) 2010 Konstantin Shishkov
7 ;* This file is part of FFmpeg.
9 ;* FFmpeg is free software; you can redistribute it and/or
10 ;* modify it under the terms of the GNU Lesser General Public
11 ;* License as published by the Free Software Foundation; either
12 ;* version 2.1 of the License, or (at your option) any later version.
14 ;* FFmpeg is distributed in the hope that it will be useful,
15 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;* Lesser General Public License for more details.
19 ;* You should have received a copy of the GNU Lesser General Public
20 ;* License along with FFmpeg; if not, write to the Free Software
21 ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ;******************************************************************************
24 %include "libavutil/x86/x86util.asm"
28 ; below variables are named like mask_dwXY, which means to preserve dword No.X & No.Y
29 mask_dw036 : db -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0
30 mask_dw147 : db 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1
31 mask_dw25 : db 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0
32 rgb24_shuf1: db 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5, 10, 11
33 rgb24_shuf2: db 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15, 4, 5
34 rgb24_shuf3: db 4, 5, 10, 11, 0, 1, 6, 7, 12, 13, 2, 3, 8, 9, 14, 15
35 pw_00ff: times 8 dw 255
36 pb_f8: times 16 db 248
37 pb_e0: times 16 db 224
41 mask_1101: dw -1, -1, 0, -1
42 mask_0010: dw 0, 0, -1, 0
43 mask_0110: dw 0, -1, -1, 0
44 mask_1001: dw -1, 0, 0, -1
45 mask_0100: dw 0, -1, 0, 0
49 ;-----------------------------------------------------------------------------
51 ; YUV420/YUVA420 to RGB/BGR 15/16/24/32
52 ; R = Y + ((vrCoff * (v - 128)) >> 8)
53 ; G = Y - ((ugCoff * (u - 128) + vgCoff * (v - 128)) >> 8)
54 ; B = Y + ((ubCoff * (u - 128)) >> 8)
56 ;-----------------------------------------------------------------------------
70 %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index, pa_2index
73 %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index
77 %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index
97 %define y_offset [pointer_c_ditherq + 8 * 8]
98 %define u_offset [pointer_c_ditherq + 9 * 8]
99 %define v_offset [pointer_c_ditherq + 10 * 8]
100 %define ug_coff [pointer_c_ditherq + 7 * 8]
101 %define vg_coff [pointer_c_ditherq + 6 * 8]
102 %define y_coff [pointer_c_ditherq + 3 * 8]
103 %define ub_coff [pointer_c_ditherq + 5 * 8]
104 %define vr_coff [pointer_c_ditherq + 4 * 8]
109 %define my_offset [pointer_c_ditherq + 8 * 8]
110 %define mu_offset [pointer_c_ditherq + 9 * 8]
111 %define mv_offset [pointer_c_ditherq + 10 * 8]
112 %define mug_coff [pointer_c_ditherq + 7 * 8]
113 %define mvg_coff [pointer_c_ditherq + 6 * 8]
114 %define my_coff [pointer_c_ditherq + 3 * 8]
115 %define mub_coff [pointer_c_ditherq + 5 * 8]
116 %define mvr_coff [pointer_c_ditherq + 4 * 8]
127 %endif ; ARCH_X86_32/64
128 %endif ; coeff define mmsize == 8/16
130 cglobal %1_420_%2%3, GPR_num, GPR_num, reg_num, parameters
133 movsxd indexq, indexd
135 VBROADCASTSD y_offset, [pointer_c_ditherq + 8 * 8]
136 VBROADCASTSD u_offset, [pointer_c_ditherq + 9 * 8]
137 VBROADCASTSD v_offset, [pointer_c_ditherq + 10 * 8]
138 VBROADCASTSD ug_coff, [pointer_c_ditherq + 7 * 8]
139 VBROADCASTSD vg_coff, [pointer_c_ditherq + 6 * 8]
140 VBROADCASTSD y_coff, [pointer_c_ditherq + 3 * 8]
141 VBROADCASTSD ub_coff, [pointer_c_ditherq + 5 * 8]
142 VBROADCASTSD vr_coff, [pointer_c_ditherq + 4 * 8]
146 movu m_y, [py_2indexq + 2 * indexq]
147 movh m_u, [pu_indexq + indexq]
148 movh m_v, [pv_indexq + indexq]
160 %if (ARCH_X86_32 && mmsize == 16)
161 VBROADCASTSD m2, mu_offset
162 VBROADCASTSD m3, mv_offset
163 VBROADCASTSD m4, my_offset
164 psubsw m0, m2 ; U = U - 128
165 psubsw m1, m3 ; V = V - 128
168 VBROADCASTSD m2, mug_coff
169 VBROADCASTSD m3, mvg_coff
170 VBROADCASTSD m4, my_coff
171 VBROADCASTSD m5, mub_coff
177 VBROADCASTSD m4, mvr_coff
179 %else ; ARCH_X86_64 || mmsize == 8
180 psubsw m0, u_offset ; U = U - 128
181 psubsw m1, v_offset ; V = V - 128
196 paddsw m3, m0 ; B1 B3 B5 B7 ...
197 paddsw m5, m1 ; R1 R3 R5 R7 ...
198 paddsw m7, m2 ; G1 G3 G4 G7 ...
199 paddsw m0, m6 ; B0 B2 B4 B6 ...
200 paddsw m1, m6 ; R0 R2 R4 R6 ...
201 paddsw m2, m6 ; G0 G2 G4 G6 ...
203 %if %3 == 24 ; PACK RGB24
205 packuswb m0, m3 ; R0 R2 R4 R6 ... R1 R3 R5 R7 ...
206 packuswb m1, m5 ; B0 B2 B4 B6 ... B1 B3 B5 B7 ...
207 packuswb m2, m7 ; G0 G2 G4 G6 ... G1 G3 G5 G7 ...
211 punpcklbw m3, m2 ; R0 G0 R2 G2 R4 G4 R6 G6 R8 G8 ...
212 punpcklbw m6, m_red ; B0 R1 B2 R3 B4 R5 B6 R7 B8 R9 ...
214 punpckhbw m2, m_blue ; G1 B1 G3 B3 G5 B5 G7 B7 G9 B9 ...
216 punpcklwd m3 ,m6 ; R0 G0 B0 R1 R2 G2 B2 R3
217 punpckhwd m5, m6 ; R4 G4 B4 R5 R6 G6 B6 R7
222 pand m6, [mask_1101] ; R0 G0 B0 R1 -- -- R2 G2
224 pand m7, [mask_0110] ; -- -- R6 G6 B6 R7 -- --
226 pand m1, [mask_0100] ; -- -- G3 B3 -- -- -- --
227 psrlq m3, 48 ; B2 R3 -- -- -- -- -- --
228 pand m0, [mask_0010] ; -- -- -- -- G1 B1 -- --
229 psllq m5, 32 ; -- -- -- -- R4 G4 B4 R5
230 pand m2, [mask_1001] ; G5 B5 -- -- -- -- G7 B7
236 movntq [imageq + 8], m1
237 movntq [imageq + 16], m2
239 movd [imageq], m3 ; R0 G0 R2 G2
240 movd [imageq + 4], m2 ; G1 B1
243 movd [imageq + 6], m3 ; R2 G2 B2 R3
244 movd [imageq + 10], m2 ; G3 B3
246 movd [imageq + 12], m5 ; R4 G4 B4 R5
247 movd [imageq + 16], m2 ; G5 B5
249 movd [imageq + 20], m2 ; -- -- G7 B7
250 movd [imageq + 18], m5 ; R6 G6 B6 R7
253 pshufb m3, [rgb24_shuf1] ; r0 g0 r6 g6 r12 g12 r2 g2 r8 g8 r14 g14 r4 g4 r10 g10
254 pshufb m6, [rgb24_shuf2] ; b10 r11 b0 r1 b6 r7 b12 r13 b2 r3 b8 r9 b14 r15 b4 r5
255 pshufb m2, [rgb24_shuf3] ; g5 b5 g11 b11 g1 b1 g7 b7 g13 b13 g3 b3 g9 b9 g15 b15
256 mova m7, [mask_dw036]
257 mova m4, [mask_dw147]
259 pand m0, m7, m3 ; r0 g0 --- --- --- --- r2 g2 --- --- --- --- r4 g4 --- ---
260 pand m1, m4, m6 ; --- --- b0 r1 --- --- --- --- b2 r3 --- --- --- --- b4 r5
262 pand m1, m5, m2 ; --- --- --- --- g1 b1 --- --- --- --- g3 b3 --- --- --- ---
263 por m0, m1 ; r0 g0 b0 r1 g1 b1 r2 g2 b2 r3 g3 b3 r4 g4 b4 r5
264 pand m1, m7, m2 ; g5 b5 --- --- --- --- g7 b7 --- --- --- --- g9 b9 --- ---
265 pand m7, m6 ; b10 r11 --- --- --- --- b12 r13 --- --- --- --- b14 r15 --- ---
266 pand m6, m5 ; --- --- --- --- b6 r7 --- --- --- --- b8 r9 --- --- --- ---
268 pand m6, m4, m3 ; --- --- r6 g6 --- --- --- --- r8 g8 --- --- --- --- r10 g10
269 pand m2, m4 ; --- --- g11 b11 --- --- --- --- g13 b13 --- --- --- --- g15 b15
270 pand m3, m5 ; --- --- --- --- r12 g12 --- --- --- --- r14 g14 --- --- --- ---
272 por m1, m6 ; g5 b5 r6 g6 b6 r7 g7 b7 r8 g8 b8 r9 g9 b9 r10 g10
273 por m2, m3 ; b10 r11 g11 b11 r12 g12 b12 r13 g13 b13 r14 g14 b14 r15 g15 b15
275 movu [imageq + 16], m1
276 movu [imageq + 32], m2
278 %else ; PACK RGB15/16/32
284 punpcklbw m0, m3 ; B0 B1 B2 B3 ... B7
285 punpckhbw m1, m3 ; R0 R1 R2 R3 ... R7
286 punpcklbw m2, m7 ; G0 G1 G2 G3 ... G7
287 %if %3 == 32 ; PACK RGB32
290 pcmpeqd m3, m3 ; Set alpha empty
292 movu m3, [pa_2indexq + 2 * indexq] ; Load alpha
296 punpckhbw m5, m_green
297 punpcklbw m_blue, m_green
298 punpckhbw m6, m_alpha
299 punpcklbw m_red, m_alpha
302 punpcklwd m_blue, m_red
303 punpckhwd m_green, m_red
305 punpckhwd m_alpha, m6
306 movu [imageq + 0], m_blue
307 movu [imageq + 8 * time_num], m_green
308 movu [imageq + 16 * time_num], m5
309 movu [imageq + 24 * time_num], m_alpha
310 %else ; PACK RGB15/16
313 %define red_dither m3
314 %define green_dither m4
315 %define blue_dither m5
316 VBROADCASTSD red_dither, [pointer_c_ditherq + 0 * 8]
317 VBROADCASTSD green_dither, [pointer_c_ditherq + 1 * 8]
318 VBROADCASTSD blue_dither, [pointer_c_ditherq + 2 * 8]
319 %else ; cpuflag(mmx/mmxext)
320 %define blue_dither [pointer_c_ditherq + 2 * 8]
321 %define green_dither [pointer_c_ditherq + 1 * 8]
322 %define red_dither [pointer_c_ditherq + 0 * 8]
331 paddusb m0, blue_dither
332 paddusb m2, green_dither
333 paddusb m1, red_dither
337 psllw m2, 3 - isRGB15
338 psrlw m3, 5 + isRGB15
349 movu [imageq + 8 * time_num], m2
350 %endif ; PACK RGB15/16
351 %endif ; PACK RGB15/16/32
353 add imageq, 8 * depth * time_num
354 add indexq, 4 * time_num
362 yuv2rgb_fn yuv, rgb, 32
363 yuv2rgb_fn yuv, bgr, 32
364 yuv2rgb_fn yuva, rgb, 32
365 yuv2rgb_fn yuva, bgr, 32
366 yuv2rgb_fn yuv, rgb, 15
367 yuv2rgb_fn yuv, rgb, 16
370 yuv2rgb_fn yuv, rgb, 24
371 yuv2rgb_fn yuv, bgr, 24
374 yuv2rgb_fn yuv, rgb, 24
375 yuv2rgb_fn yuv, bgr, 24
376 yuv2rgb_fn yuv, rgb, 32
377 yuv2rgb_fn yuv, bgr, 32
378 yuv2rgb_fn yuva, rgb, 32
379 yuv2rgb_fn yuva, bgr, 32
380 yuv2rgb_fn yuv, rgb, 15
381 yuv2rgb_fn yuv, rgb, 16