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 pw_00ff: times 4 dw 255
34 mask_1101: dw -1, -1, 0, -1
35 mask_0010: dw 0, 0, -1, 0
36 mask_0110: dw 0, -1, -1, 0
37 mask_1001: dw -1, 0, 0, -1
38 mask_0100: dw 0, -1, 0, 0
42 ;-----------------------------------------------------------------------------
44 ; YUV420/YUVA420 to RGB/BGR 15/16/24/32
45 ; R = Y + ((vrCoff * (v - 128)) >> 8)
46 ; G = Y - ((ugCoff * (u - 128) + vgCoff * (v - 128)) >> 8)
47 ; B = Y + ((ubCoff * (u - 128)) >> 8)
49 ;-----------------------------------------------------------------------------
59 %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index, pa_2index
63 %define parameters index, image, pu_index, pv_index, pointer_c_dither, py_2index
82 %define y_offset [pointer_c_ditherq + 8 * 8]
83 %define u_offset [pointer_c_ditherq + 9 * 8]
84 %define v_offset [pointer_c_ditherq + 10 * 8]
85 %define ug_coff [pointer_c_ditherq + 7 * 8]
86 %define vg_coff [pointer_c_ditherq + 6 * 8]
87 %define y_coff [pointer_c_ditherq + 3 * 8]
88 %define ub_coff [pointer_c_ditherq + 5 * 8]
89 %define vr_coff [pointer_c_ditherq + 4 * 8]
91 cglobal %1_420_%2%3, GPR_num, GPR_num, reg_num, parameters
96 mova m_y, [py_2indexq + 2 * indexq]
97 movh m_u, [pu_indexq + indexq]
98 movh m_v, [pv_indexq + indexq]
111 psubsw m0, u_offset ; U = U - 128
112 psubsw m1, v_offset ; V = V - 128
126 paddsw m3, m0 ; B1 B3 B5 B7 ...
127 paddsw m5, m1 ; R1 R3 R5 R7 ...
128 paddsw m7, m2 ; G1 G3 G4 G7 ...
129 paddsw m0, m6 ; B0 B2 B4 B6 ...
130 paddsw m1, m6 ; R0 R2 R4 R6 ...
131 paddsw m2, m6 ; G0 G2 G4 G6 ...
133 %if %3 == 24 ; PACK RGB24
135 packuswb m0, m3 ; R0 R2 R4 R6 ... R1 R3 R5 R7 ...
136 packuswb m1, m5 ; B0 B2 B4 B6 ... B1 B3 B5 B7 ...
137 packuswb m2, m7 ; G0 G2 G4 G6 ... G1 G3 G5 G7 ...
141 punpcklbw m3, m2 ; R0 G0 R2 G2 R4 G4 R6 G6 R8 G8 ...
142 punpcklbw m6, m_red ; B0 R1 B2 R3 B4 R5 B6 R7 B8 R9 ...
144 punpckhbw m2, m_blue ; G1 B1 G3 B3 G5 B5 G7 B7 G9 B9 ...
145 punpcklwd m3 ,m6 ; R0 G0 B0 R1 R2 G2 B2 R3
146 punpckhwd m5, m6 ; R4 G4 B4 R5 R6 G6 B6 R7
151 pand m6, [mask_1101] ; R0 G0 B0 R1 -- -- R2 G2
153 pand m7, [mask_0110] ; -- -- R6 G6 B6 R7 -- --
155 pand m1, [mask_0100] ; -- -- G3 B3 -- -- -- --
156 psrlq m3, 48 ; B2 R3 -- -- -- -- -- --
157 pand m0, [mask_0010] ; -- -- -- -- G1 B1 -- --
158 psllq m5, 32 ; -- -- -- -- R4 G4 B4 R5
159 pand m2, [mask_1001] ; G5 B5 -- -- -- -- G7 B7
165 movntq [imageq + 8], m1
166 movntq [imageq + 16], m2
168 movd [imageq], m3 ; R0 G0 R2 G2
169 movd [imageq + 4], m2 ; G1 B1
172 movd [imageq + 6], m3 ; R2 G2 B2 R3
173 movd [imageq + 10], m2 ; G3 B3
175 movd [imageq + 12], m5 ; R4 G4 B4 R5
176 movd [imageq + 16], m2 ; G5 B5
178 movd [imageq + 20], m2 ; -- -- G7 B7
179 movd [imageq + 18], m5 ; R6 G6 B6 R7
181 %else ; PACK RGB15/16/32
187 punpcklbw m0, m3 ; B0 B1 B2 B3 ... B7
188 punpckhbw m1, m3 ; R0 R1 R2 R3 ... R7
189 punpcklbw m2, m7 ; G0 G1 G2 G3 ... G7
190 %if %3 == 32 ; PACK RGB32
193 pcmpeqd m3, m3 ; Set alpha empty
195 mova m3, [pa_2indexq + 2 * indexq] ; Load alpha
199 punpckhbw m5, m_green
200 punpcklbw m_blue, m_green
201 punpckhbw m6, m_alpha
202 punpcklbw m_red, m_alpha
205 punpcklwd m_blue, m_red
206 punpckhwd m_green, m_red
208 punpckhwd m_alpha, m6
209 mova [imageq + 0], m_blue
210 mova [imageq + 8 * time_num], m_green
211 mova [imageq + 16 * time_num], m5
212 mova [imageq + 24 * time_num], m_alpha
213 %else ; PACK RGB15/16
215 %define blue_dither [pointer_c_ditherq + 2 * 8]
216 %define green_dither [pointer_c_ditherq + 1 * 8]
217 %define red_dither [pointer_c_ditherq + 0 * 8]
225 paddusb m0, blue_dither
226 paddusb m2, green_dither
227 paddusb m1, red_dither
231 psllw m2, 3 - isRGB15
232 psrlw m3, 5 + isRGB15
243 mova [imageq + 8 * time_num], m2
244 %endif ; PACK RGB15/16
245 %endif ; PACK RGB15/16/32
247 mova m_y, [py_2indexq + 2 * indexq + 8 * time_num]
248 movh m_v, [pv_indexq + indexq + 4 * time_num]
249 movh m_u, [pu_indexq + indexq + 4 * time_num]
250 add imageq, 8 * depth * time_num
251 add indexq, 4 * time_num
259 yuv2rgb_fn yuv, rgb, 24
260 yuv2rgb_fn yuv, bgr, 24
261 yuv2rgb_fn yuv, rgb, 32
262 yuv2rgb_fn yuv, bgr, 32
263 yuv2rgb_fn yuva, rgb, 32
264 yuv2rgb_fn yuva, bgr, 32
265 yuv2rgb_fn yuv, rgb, 15
266 yuv2rgb_fn yuv, rgb, 16
269 yuv2rgb_fn yuv, rgb, 24
270 yuv2rgb_fn yuv, bgr, 24