Parent Directory | Revision Log
Revision 677 -
(view)
(download)
Original Path: trunk/xvidcore/src/image/colorspace.c
1 : | chl | 433 | /***************************************************************************** |
2 : | edgomez | 195 | * |
3 : | chl | 433 | * XVID MPEG-4 VIDEO CODEC |
4 : | * - colorspace conversion module - | ||
5 : | edgomez | 195 | * |
6 : | chl | 433 | * Copyright(C) 2002 Peter Ross <pross@xvid.org> |
7 : | edgomez | 605 | * 2002 Michael Militzer <isibaar@xvid.org> |
8 : | edgomez | 195 | * |
9 : | edgomez | 651 | * This file is part of XviD, a free MPEG-4 video encoder/decoder |
10 : | edgomez | 195 | * |
11 : | edgomez | 651 | * XviD is free software; you can redistribute it and/or modify it |
12 : | * under the terms of the GNU General Public License as published by | ||
13 : | chl | 433 | * the Free Software Foundation; either version 2 of the License, or |
14 : | * (at your option) any later version. | ||
15 : | edgomez | 195 | * |
16 : | chl | 433 | * This program is distributed in the hope that it will be useful, |
17 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 : | * GNU General Public License for more details. | ||
20 : | edgomez | 195 | * |
21 : | chl | 433 | * You should have received a copy of the GNU General Public License |
22 : | * along with this program; if not, write to the Free Software | ||
23 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 : | edgomez | 195 | * |
25 : | edgomez | 651 | * Under section 8 of the GNU General Public License, the copyright |
26 : | * holders of XVID explicitly forbid distribution in the following | ||
27 : | * countries: | ||
28 : | * | ||
29 : | * - Japan | ||
30 : | * - United States of America | ||
31 : | * | ||
32 : | * Linking XviD statically or dynamically with other modules is making a | ||
33 : | * combined work based on XviD. Thus, the terms and conditions of the | ||
34 : | * GNU General Public License cover the whole combination. | ||
35 : | * | ||
36 : | * As a special exception, the copyright holders of XviD give you | ||
37 : | * permission to link XviD with independent modules that communicate with | ||
38 : | * XviD solely through the VFW1.1 and DShow interfaces, regardless of the | ||
39 : | * license terms of these independent modules, and to copy and distribute | ||
40 : | * the resulting combined work under terms of your choice, provided that | ||
41 : | * every copy of the combined work is accompanied by a complete copy of | ||
42 : | * the source code of XviD (the version of XviD used to produce the | ||
43 : | * combined work), being distributed under the terms of the GNU General | ||
44 : | * Public License plus this exception. An independent module is a module | ||
45 : | * which is not derived from or based on XviD. | ||
46 : | * | ||
47 : | * Note that people who make modified versions of XviD are not obligated | ||
48 : | * to grant this special exception for their modified versions; it is | ||
49 : | * their choice whether to do so. The GNU General Public License gives | ||
50 : | * permission to release a modified version without this exception; this | ||
51 : | * exception also makes it possible to release a modified version which | ||
52 : | * carries forward this exception. | ||
53 : | * | ||
54 : | edgomez | 677 | * $Id: colorspace.c,v 1.7 2002-11-26 23:44:10 edgomez Exp $ |
55 : | edgomez | 651 | * |
56 : | chl | 433 | ****************************************************************************/ |
57 : | edgomez | 195 | |
58 : | edgomez | 677 | #include <string.h> /* memcpy */ |
59 : | edgomez | 195 | |
60 : | #include "colorspace.h" | ||
61 : | edgomez | 677 | #include "../divx4.h" /* DEC_PICTURE */ |
62 : | edgomez | 195 | |
63 : | edgomez | 677 | /* function pointers */ |
64 : | edgomez | 195 | |
65 : | /* input */ | ||
66 : | color_inputFuncPtr rgb555_to_yv12; | ||
67 : | color_inputFuncPtr rgb565_to_yv12; | ||
68 : | color_inputFuncPtr rgb24_to_yv12; | ||
69 : | color_inputFuncPtr rgb32_to_yv12; | ||
70 : | color_inputFuncPtr yuv_to_yv12; | ||
71 : | color_inputFuncPtr yuyv_to_yv12; | ||
72 : | color_inputFuncPtr uyvy_to_yv12; | ||
73 : | |||
74 : | /* output */ | ||
75 : | color_outputFuncPtr yv12_to_rgb555; | ||
76 : | color_outputFuncPtr yv12_to_rgb565; | ||
77 : | color_outputFuncPtr yv12_to_rgb24; | ||
78 : | color_outputFuncPtr yv12_to_rgb32; | ||
79 : | color_outputFuncPtr yv12_to_yuv; | ||
80 : | color_outputFuncPtr yv12_to_yuyv; | ||
81 : | color_outputFuncPtr yv12_to_uyvy; | ||
82 : | |||
83 : | #define MIN(A,B) ((A)<(B)?(A):(B)) | ||
84 : | #define MAX(A,B) ((A)>(B)?(A):(B)) | ||
85 : | |||
86 : | /* rgb -> yuv def's | ||
87 : | |||
88 : | this following constants are "official spec" | ||
89 : | Video Demystified" (ISBN 1-878707-09-4) | ||
90 : | |||
91 : | rgb<->yuv _is_ lossy, since most programs do the conversion differently | ||
92 : | |||
93 : | SCALEBITS/FIX taken from ffmpeg | ||
94 : | */ | ||
95 : | |||
96 : | #define Y_R_IN 0.257 | ||
97 : | #define Y_G_IN 0.504 | ||
98 : | #define Y_B_IN 0.098 | ||
99 : | #define Y_ADD_IN 16 | ||
100 : | |||
101 : | #define U_R_IN 0.148 | ||
102 : | #define U_G_IN 0.291 | ||
103 : | #define U_B_IN 0.439 | ||
104 : | #define U_ADD_IN 128 | ||
105 : | |||
106 : | #define V_R_IN 0.439 | ||
107 : | #define V_G_IN 0.368 | ||
108 : | #define V_B_IN 0.071 | ||
109 : | #define V_ADD_IN 128 | ||
110 : | |||
111 : | #define SCALEBITS_IN 8 | ||
112 : | #define FIX_IN(x) ((uint16_t) ((x) * (1L<<SCALEBITS_IN) + 0.5)) | ||
113 : | |||
114 : | |||
115 : | int32_t RGB_Y_tab[256]; | ||
116 : | int32_t B_U_tab[256]; | ||
117 : | int32_t G_U_tab[256]; | ||
118 : | int32_t G_V_tab[256]; | ||
119 : | int32_t R_V_tab[256]; | ||
120 : | |||
121 : | |||
122 : | /* rgb555 -> yuv 4:2:0 planar */ | ||
123 : | void | ||
124 : | rgb555_to_yv12_c(uint8_t * y_out, | ||
125 : | uint8_t * u_out, | ||
126 : | uint8_t * v_out, | ||
127 : | uint8_t * src, | ||
128 : | int width, | ||
129 : | int height, | ||
130 : | int y_stride) | ||
131 : | { | ||
132 : | int32_t src_stride = width * 2; | ||
133 : | uint32_t y_dif = y_stride - width; | ||
134 : | uint32_t uv_dif = (y_stride - width) / 2; | ||
135 : | uint32_t x, y; | ||
136 : | |||
137 : | if (height < 0) { | ||
138 : | height = -height; | ||
139 : | src += (height - 1) * src_stride; | ||
140 : | src_stride = -src_stride; | ||
141 : | } | ||
142 : | |||
143 : | |||
144 : | for (y = height / 2; y; y--) { | ||
145 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
146 : | edgomez | 195 | for (x = 0; x < (uint32_t) width; x += 2) { |
147 : | int rgb, r, g, b, r4, g4, b4; | ||
148 : | |||
149 : | rgb = *(uint16_t *) (src + x * 2); | ||
150 : | b4 = b = (rgb << 3) & 0xf8; | ||
151 : | g4 = g = (rgb >> 2) & 0xf8; | ||
152 : | r4 = r = (rgb >> 7) & 0xf8; | ||
153 : | y_out[0] = | ||
154 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
155 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
156 : | |||
157 : | rgb = *(uint16_t *) (src + x * 2 + src_stride); | ||
158 : | b4 += b = (rgb << 3) & 0xf8; | ||
159 : | g4 += g = (rgb >> 2) & 0xf8; | ||
160 : | r4 += r = (rgb >> 7) & 0xf8; | ||
161 : | y_out[y_stride] = | ||
162 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
163 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
164 : | |||
165 : | rgb = *(uint16_t *) (src + x * 2 + 2); | ||
166 : | b4 += b = (rgb << 3) & 0xf8; | ||
167 : | g4 += g = (rgb >> 2) & 0xf8; | ||
168 : | r4 += r = (rgb >> 7) & 0xf8; | ||
169 : | y_out[1] = | ||
170 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
171 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
172 : | |||
173 : | rgb = *(uint16_t *) (src + x * 2 + src_stride + 2); | ||
174 : | b4 += b = (rgb << 3) & 0xf8; | ||
175 : | g4 += g = (rgb >> 2) & 0xf8; | ||
176 : | r4 += r = (rgb >> 7) & 0xf8; | ||
177 : | y_out[y_stride + 1] = | ||
178 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
179 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
180 : | |||
181 : | *u_out++ = | ||
182 : | (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 + | ||
183 : | FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
184 : | U_ADD_IN; | ||
185 : | |||
186 : | |||
187 : | *v_out++ = | ||
188 : | (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 - | ||
189 : | FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
190 : | V_ADD_IN; | ||
191 : | |||
192 : | y_out += 2; | ||
193 : | } | ||
194 : | src += src_stride * 2; | ||
195 : | y_out += y_dif + y_stride; | ||
196 : | u_out += uv_dif; | ||
197 : | v_out += uv_dif; | ||
198 : | } | ||
199 : | } | ||
200 : | |||
201 : | |||
202 : | |||
203 : | /* rgb565_to_yuv_c | ||
204 : | NOTE: identical to rgb555 except for shift/mask | ||
205 : | not tested */ | ||
206 : | |||
207 : | void | ||
208 : | rgb565_to_yv12_c(uint8_t * y_out, | ||
209 : | uint8_t * u_out, | ||
210 : | uint8_t * v_out, | ||
211 : | uint8_t * src, | ||
212 : | int width, | ||
213 : | int height, | ||
214 : | int y_stride) | ||
215 : | { | ||
216 : | int32_t src_stride = width * 2; | ||
217 : | |||
218 : | uint32_t y_dif = y_stride - width; | ||
219 : | uint32_t uv_dif = (y_stride - width) / 2; | ||
220 : | uint32_t x, y; | ||
221 : | |||
222 : | if (height < 0) { | ||
223 : | height = -height; | ||
224 : | src += (height - 1) * src_stride; | ||
225 : | src_stride = -src_stride; | ||
226 : | } | ||
227 : | |||
228 : | |||
229 : | for (y = height / 2; y; y--) { | ||
230 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
231 : | edgomez | 195 | for (x = 0; x < (uint32_t) width; x += 2) { |
232 : | int rgb, r, g, b, r4, g4, b4; | ||
233 : | |||
234 : | rgb = *(uint16_t *) (src + x * 2); | ||
235 : | b4 = b = (rgb << 3) & 0xf8; | ||
236 : | g4 = g = (rgb >> 3) & 0xfc; | ||
237 : | r4 = r = (rgb >> 8) & 0xf8; | ||
238 : | y_out[0] = | ||
239 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
240 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
241 : | |||
242 : | rgb = *(uint16_t *) (src + x * 2 + src_stride); | ||
243 : | b4 += b = (rgb << 3) & 0xf8; | ||
244 : | g4 += g = (rgb >> 3) & 0xfc; | ||
245 : | r4 += r = (rgb >> 8) & 0xf8; | ||
246 : | y_out[y_stride] = | ||
247 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
248 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
249 : | |||
250 : | rgb = *(uint16_t *) (src + x * 2 + 2); | ||
251 : | b4 += b = (rgb << 3) & 0xf8; | ||
252 : | g4 += g = (rgb >> 3) & 0xfc; | ||
253 : | r4 += r = (rgb >> 8) & 0xf8; | ||
254 : | y_out[1] = | ||
255 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
256 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
257 : | |||
258 : | rgb = *(uint16_t *) (src + x * 2 + src_stride + 2); | ||
259 : | b4 += b = (rgb << 3) & 0xf8; | ||
260 : | g4 += g = (rgb >> 3) & 0xfc; | ||
261 : | r4 += r = (rgb >> 8) & 0xf8; | ||
262 : | y_out[y_stride + 1] = | ||
263 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
264 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
265 : | |||
266 : | *u_out++ = | ||
267 : | (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 + | ||
268 : | FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
269 : | U_ADD_IN; | ||
270 : | |||
271 : | |||
272 : | *v_out++ = | ||
273 : | (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 - | ||
274 : | FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
275 : | V_ADD_IN; | ||
276 : | |||
277 : | y_out += 2; | ||
278 : | } | ||
279 : | src += src_stride * 2; | ||
280 : | y_out += y_dif + y_stride; | ||
281 : | u_out += uv_dif; | ||
282 : | v_out += uv_dif; | ||
283 : | } | ||
284 : | } | ||
285 : | |||
286 : | |||
287 : | |||
288 : | |||
289 : | /* rgb24 -> yuv 4:2:0 planar | ||
290 : | |||
291 : | NOTE: always flips. | ||
292 : | */ | ||
293 : | |||
294 : | void | ||
295 : | rgb24_to_yv12_c(uint8_t * y_out, | ||
296 : | uint8_t * u_out, | ||
297 : | uint8_t * v_out, | ||
298 : | uint8_t * src, | ||
299 : | int width, | ||
300 : | int height, | ||
301 : | int stride) | ||
302 : | { | ||
303 : | uint32_t width3 = (width << 1) + width; /* width * 3 */ | ||
304 : | uint32_t src_dif = (width << 3) + width; /* width3 * 3 */ | ||
305 : | uint32_t y_dif = (stride << 1) - width; | ||
306 : | uint32_t uv_dif = (stride - width) >> 1; | ||
307 : | uint32_t x, y; | ||
308 : | |||
309 : | src += (height - 2) * width3; | ||
310 : | |||
311 : | |||
312 : | for (y = height >> 1; y; y--) { | ||
313 : | for (x = width >> 1; x; x--) { | ||
314 : | uint32_t r, g, b, r4, g4, b4; | ||
315 : | |||
316 : | b4 = b = src[0]; | ||
317 : | g4 = g = src[1]; | ||
318 : | r4 = r = src[2]; | ||
319 : | y_out[stride + 0] = | ||
320 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
321 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
322 : | |||
323 : | b4 += (b = src[3]); | ||
324 : | g4 += (g = src[4]); | ||
325 : | r4 += (r = src[5]); | ||
326 : | y_out[stride + 1] = | ||
327 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
328 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
329 : | |||
330 : | b4 += (b = src[width3 + 0]); | ||
331 : | g4 += (g = src[width3 + 1]); | ||
332 : | r4 += (r = src[width3 + 2]); | ||
333 : | y_out[0] = | ||
334 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
335 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
336 : | |||
337 : | b4 += (b = src[width3 + 3]); | ||
338 : | g4 += (g = src[width3 + 4]); | ||
339 : | r4 += (r = src[width3 + 5]); | ||
340 : | y_out[1] = | ||
341 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
342 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
343 : | |||
344 : | *u_out++ = | ||
345 : | (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 + | ||
346 : | FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
347 : | U_ADD_IN; | ||
348 : | |||
349 : | |||
350 : | *v_out++ = | ||
351 : | (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 - | ||
352 : | FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
353 : | V_ADD_IN; | ||
354 : | |||
355 : | |||
356 : | src += 6; | ||
357 : | y_out += 2; | ||
358 : | } | ||
359 : | src -= src_dif; | ||
360 : | y_out += y_dif; | ||
361 : | u_out += uv_dif; | ||
362 : | v_out += uv_dif; | ||
363 : | } | ||
364 : | } | ||
365 : | |||
366 : | |||
367 : | /* rgb32 -> yuv 4:2:0 planar | ||
368 : | |||
369 : | NOTE: always flips | ||
370 : | */ | ||
371 : | |||
372 : | void | ||
373 : | rgb32_to_yv12_c(uint8_t * y_out, | ||
374 : | uint8_t * u_out, | ||
375 : | uint8_t * v_out, | ||
376 : | uint8_t * src, | ||
377 : | int width, | ||
378 : | int height, | ||
379 : | int stride) | ||
380 : | { | ||
381 : | uint32_t width4 = (width << 2); /* width * 4 */ | ||
382 : | uint32_t src_dif = 3 * width4; | ||
383 : | uint32_t y_dif = (stride << 1) - width; | ||
384 : | uint32_t uv_dif = (stride - width) >> 1; | ||
385 : | uint32_t x, y; | ||
386 : | |||
387 : | src += (height - 2) * width4; | ||
388 : | |||
389 : | for (y = height >> 1; y; y--) { | ||
390 : | for (x = width >> 1; x; x--) { | ||
391 : | uint32_t r, g, b, r4, g4, b4; | ||
392 : | |||
393 : | b4 = b = src[0]; | ||
394 : | g4 = g = src[1]; | ||
395 : | r4 = r = src[2]; | ||
396 : | y_out[stride + 0] = | ||
397 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
398 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
399 : | |||
400 : | b4 += (b = src[4]); | ||
401 : | g4 += (g = src[5]); | ||
402 : | r4 += (r = src[6]); | ||
403 : | y_out[stride + 1] = | ||
404 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
405 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
406 : | |||
407 : | b4 += (b = src[width4 + 0]); | ||
408 : | g4 += (g = src[width4 + 1]); | ||
409 : | r4 += (r = src[width4 + 2]); | ||
410 : | |||
411 : | y_out[0] = | ||
412 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
413 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
414 : | |||
415 : | b4 += (b = src[width4 + 4]); | ||
416 : | g4 += (g = src[width4 + 5]); | ||
417 : | r4 += (r = src[width4 + 6]); | ||
418 : | y_out[1] = | ||
419 : | (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g + | ||
420 : | FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN; | ||
421 : | |||
422 : | *u_out++ = | ||
423 : | (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 + | ||
424 : | FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
425 : | U_ADD_IN; | ||
426 : | |||
427 : | *v_out++ = | ||
428 : | (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 - | ||
429 : | FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) + | ||
430 : | V_ADD_IN; | ||
431 : | |||
432 : | src += 8; | ||
433 : | y_out += 2; | ||
434 : | } | ||
435 : | src -= src_dif; | ||
436 : | y_out += y_dif; | ||
437 : | u_out += uv_dif; | ||
438 : | v_out += uv_dif; | ||
439 : | } | ||
440 : | } | ||
441 : | |||
442 : | /* yuv planar -> yuv 4:2:0 planar | ||
443 : | |||
444 : | NOTE: does not flip */ | ||
445 : | |||
446 : | void | ||
447 : | yuv_to_yv12_c(uint8_t * y_out, | ||
448 : | uint8_t * u_out, | ||
449 : | uint8_t * v_out, | ||
450 : | uint8_t * src, | ||
451 : | int width, | ||
452 : | int height, | ||
453 : | int stride) | ||
454 : | { | ||
455 : | uint32_t stride2 = stride >> 1; | ||
456 : | uint32_t width2 = width >> 1; | ||
457 : | uint32_t y; | ||
458 : | |||
459 : | for (y = height; y; y--) { | ||
460 : | memcpy(y_out, src, width); | ||
461 : | src += width; | ||
462 : | y_out += stride; | ||
463 : | } | ||
464 : | |||
465 : | for (y = height >> 1; y; y--) { | ||
466 : | memcpy(u_out, src, width2); | ||
467 : | src += width2; | ||
468 : | u_out += stride2; | ||
469 : | } | ||
470 : | |||
471 : | for (y = height >> 1; y; y--) { | ||
472 : | memcpy(v_out, src, width2); | ||
473 : | src += width2; | ||
474 : | v_out += stride2; | ||
475 : | } | ||
476 : | } | ||
477 : | |||
478 : | |||
479 : | |||
480 : | /* yuyv (yuv2) packed -> yuv 4:2:0 planar | ||
481 : | |||
482 : | NOTE: does not flip */ | ||
483 : | |||
484 : | void | ||
485 : | yuyv_to_yv12_c(uint8_t * y_out, | ||
486 : | uint8_t * u_out, | ||
487 : | uint8_t * v_out, | ||
488 : | uint8_t * src, | ||
489 : | int width, | ||
490 : | int height, | ||
491 : | int stride) | ||
492 : | { | ||
493 : | uint32_t width2 = width + width; | ||
494 : | uint32_t y_dif = stride - width; | ||
495 : | uint32_t uv_dif = y_dif >> 1; | ||
496 : | uint32_t x, y; | ||
497 : | |||
498 : | for (y = height >> 1; y; y--) { | ||
499 : | |||
500 : | for (x = width >> 1; x; x--) { | ||
501 : | *y_out++ = *src++; | ||
502 : | edgomez | 677 | /**u_out++ = *src++; */ |
503 : | edgomez | 195 | *u_out++ = (*(src + width2) + *src) >> 1; |
504 : | src++; | ||
505 : | *y_out++ = *src++; | ||
506 : | edgomez | 677 | /**v_out++ = *src++; */ |
507 : | edgomez | 195 | *v_out++ = (*(src + width2) + *src) >> 1; |
508 : | src++; | ||
509 : | |||
510 : | } | ||
511 : | |||
512 : | y_out += y_dif; | ||
513 : | u_out += uv_dif; | ||
514 : | v_out += uv_dif; | ||
515 : | |||
516 : | for (x = width >> 1; x; x--) { | ||
517 : | *y_out++ = *src++; | ||
518 : | src++; | ||
519 : | *y_out++ = *src++; | ||
520 : | src++; | ||
521 : | } | ||
522 : | |||
523 : | y_out += y_dif; | ||
524 : | |||
525 : | } | ||
526 : | |||
527 : | } | ||
528 : | |||
529 : | |||
530 : | |||
531 : | /* uyvy packed -> yuv 4:2:0 planar | ||
532 : | |||
533 : | NOTE: does not flip */ | ||
534 : | |||
535 : | |||
536 : | void | ||
537 : | uyvy_to_yv12_c(uint8_t * y_out, | ||
538 : | uint8_t * u_out, | ||
539 : | uint8_t * v_out, | ||
540 : | uint8_t * src, | ||
541 : | int width, | ||
542 : | int height, | ||
543 : | int stride) | ||
544 : | { | ||
545 : | uint32_t width2 = width + width; | ||
546 : | uint32_t y_dif = stride - width; | ||
547 : | uint32_t uv_dif = y_dif >> 1; | ||
548 : | uint32_t x, y; | ||
549 : | |||
550 : | for (y = height >> 1; y; y--) { | ||
551 : | |||
552 : | for (x = width >> 1; x; x--) { | ||
553 : | *u_out++ = *src++; | ||
554 : | edgomez | 677 | /* *u_out++ = (*(src+width2) + *src++) >> 1; */ |
555 : | edgomez | 195 | *y_out++ = *src++; |
556 : | edgomez | 677 | /**v_out++ = *src++; */ |
557 : | edgomez | 195 | *v_out++ = (*(src + width2) + *src) >> 1; |
558 : | src++; | ||
559 : | *y_out++ = *src++; | ||
560 : | } | ||
561 : | |||
562 : | y_out += y_dif; | ||
563 : | u_out += uv_dif;; | ||
564 : | v_out += uv_dif;; | ||
565 : | |||
566 : | for (x = width >> 1; x; x--) { | ||
567 : | src++; | ||
568 : | *y_out++ = *src++; | ||
569 : | src++; | ||
570 : | *y_out++ = *src++; | ||
571 : | } | ||
572 : | |||
573 : | y_out += y_dif; | ||
574 : | } | ||
575 : | } | ||
576 : | |||
577 : | |||
578 : | /* yuv -> rgb def's */ | ||
579 : | |||
580 : | #define RGB_Y_OUT 1.164 | ||
581 : | #define B_U_OUT 2.018 | ||
582 : | #define Y_ADD_OUT 16 | ||
583 : | |||
584 : | #define G_U_OUT 0.391 | ||
585 : | #define G_V_OUT 0.813 | ||
586 : | #define U_ADD_OUT 128 | ||
587 : | |||
588 : | #define R_V_OUT 1.596 | ||
589 : | #define V_ADD_OUT 128 | ||
590 : | |||
591 : | |||
592 : | #define SCALEBITS_OUT 13 | ||
593 : | #define FIX_OUT(x) ((uint16_t) ((x) * (1L<<SCALEBITS_OUT) + 0.5)) | ||
594 : | |||
595 : | |||
596 : | /* initialize rgb lookup tables */ | ||
597 : | |||
598 : | void | ||
599 : | colorspace_init(void) | ||
600 : | { | ||
601 : | int32_t i; | ||
602 : | |||
603 : | for (i = 0; i < 256; i++) { | ||
604 : | RGB_Y_tab[i] = FIX_OUT(RGB_Y_OUT) * (i - Y_ADD_OUT); | ||
605 : | B_U_tab[i] = FIX_OUT(B_U_OUT) * (i - U_ADD_OUT); | ||
606 : | G_U_tab[i] = FIX_OUT(G_U_OUT) * (i - U_ADD_OUT); | ||
607 : | G_V_tab[i] = FIX_OUT(G_V_OUT) * (i - V_ADD_OUT); | ||
608 : | R_V_tab[i] = FIX_OUT(R_V_OUT) * (i - V_ADD_OUT); | ||
609 : | } | ||
610 : | } | ||
611 : | |||
612 : | /* yuv 4:2:0 planar -> rgb555 + very simple error diffusion | ||
613 : | */ | ||
614 : | |||
615 : | #define MK_RGB555(R,G,B) ((MAX(0,MIN(255, R)) << 7) & 0x7c00) | \ | ||
616 : | ((MAX(0,MIN(255, G)) << 2) & 0x03e0) | \ | ||
617 : | ((MAX(0,MIN(255, B)) >> 3) & 0x001f) | ||
618 : | |||
619 : | |||
620 : | void | ||
621 : | yv12_to_rgb555_c(uint8_t * dst, | ||
622 : | int dst_stride, | ||
623 : | uint8_t * y_src, | ||
624 : | uint8_t * u_src, | ||
625 : | uint8_t * v_src, | ||
626 : | int y_stride, | ||
627 : | int uv_stride, | ||
628 : | int width, | ||
629 : | int height) | ||
630 : | { | ||
631 : | const uint32_t dst_dif = 4 * dst_stride - 2 * width; | ||
632 : | int32_t y_dif = 2 * y_stride - width; | ||
633 : | |||
634 : | uint8_t *dst2 = dst + 2 * dst_stride; | ||
635 : | uint8_t *y_src2 = y_src + y_stride; | ||
636 : | uint32_t x, y; | ||
637 : | |||
638 : | if (height < 0) { | ||
639 : | height = -height; | ||
640 : | y_src += (height - 1) * y_stride; | ||
641 : | y_src2 = y_src - y_stride; | ||
642 : | u_src += (height / 2 - 1) * uv_stride; | ||
643 : | v_src += (height / 2 - 1) * uv_stride; | ||
644 : | y_dif = -width - 2 * y_stride; | ||
645 : | uv_stride = -uv_stride; | ||
646 : | } | ||
647 : | |||
648 : | for (y = height / 2; y; y--) { | ||
649 : | int r, g, b; | ||
650 : | int r2, g2, b2; | ||
651 : | |||
652 : | r = g = b = 0; | ||
653 : | r2 = g2 = b2 = 0; | ||
654 : | |||
655 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
656 : | edgomez | 195 | for (x = 0; x < (uint32_t) width / 2; x++) { |
657 : | int u, v; | ||
658 : | int b_u, g_uv, r_v, rgb_y; | ||
659 : | |||
660 : | u = u_src[x]; | ||
661 : | v = v_src[x]; | ||
662 : | |||
663 : | b_u = B_U_tab[u]; | ||
664 : | g_uv = G_U_tab[u] + G_V_tab[v]; | ||
665 : | r_v = R_V_tab[v]; | ||
666 : | |||
667 : | rgb_y = RGB_Y_tab[*y_src]; | ||
668 : | b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
669 : | g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
670 : | r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
671 : | *(uint16_t *) dst = MK_RGB555(r, g, b); | ||
672 : | |||
673 : | y_src++; | ||
674 : | rgb_y = RGB_Y_tab[*y_src]; | ||
675 : | b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
676 : | g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
677 : | r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
678 : | *(uint16_t *) (dst + 2) = MK_RGB555(r, g, b); | ||
679 : | y_src++; | ||
680 : | |||
681 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
682 : | b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
683 : | g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
684 : | r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
685 : | *(uint16_t *) (dst2) = MK_RGB555(r2, g2, b2); | ||
686 : | y_src2++; | ||
687 : | |||
688 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
689 : | b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
690 : | g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
691 : | r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
692 : | *(uint16_t *) (dst2 + 2) = MK_RGB555(r2, g2, b2); | ||
693 : | y_src2++; | ||
694 : | |||
695 : | dst += 4; | ||
696 : | dst2 += 4; | ||
697 : | } | ||
698 : | |||
699 : | dst += dst_dif; | ||
700 : | dst2 += dst_dif; | ||
701 : | |||
702 : | y_src += y_dif; | ||
703 : | y_src2 += y_dif; | ||
704 : | |||
705 : | u_src += uv_stride; | ||
706 : | v_src += uv_stride; | ||
707 : | } | ||
708 : | } | ||
709 : | |||
710 : | |||
711 : | /* yuv 4:2:0 planar -> rgb565 + very simple error diffusion | ||
712 : | NOTE: identical to rgb555 except for shift/mask */ | ||
713 : | |||
714 : | |||
715 : | #define MK_RGB565(R,G,B) ((MAX(0,MIN(255, R)) << 8) & 0xf800) | \ | ||
716 : | ((MAX(0,MIN(255, G)) << 3) & 0x07e0) | \ | ||
717 : | ((MAX(0,MIN(255, B)) >> 3) & 0x001f) | ||
718 : | |||
719 : | void | ||
720 : | yv12_to_rgb565_c(uint8_t * dst, | ||
721 : | int dst_stride, | ||
722 : | uint8_t * y_src, | ||
723 : | uint8_t * u_src, | ||
724 : | uint8_t * v_src, | ||
725 : | int y_stride, | ||
726 : | int uv_stride, | ||
727 : | int width, | ||
728 : | int height) | ||
729 : | { | ||
730 : | const uint32_t dst_dif = 4 * dst_stride - 2 * width; | ||
731 : | int32_t y_dif = 2 * y_stride - width; | ||
732 : | |||
733 : | uint8_t *dst2 = dst + 2 * dst_stride; | ||
734 : | uint8_t *y_src2 = y_src + y_stride; | ||
735 : | uint32_t x, y; | ||
736 : | |||
737 : | edgomez | 677 | if (height < 0) { /* flip image? */ |
738 : | edgomez | 195 | height = -height; |
739 : | y_src += (height - 1) * y_stride; | ||
740 : | y_src2 = y_src - y_stride; | ||
741 : | u_src += (height / 2 - 1) * uv_stride; | ||
742 : | v_src += (height / 2 - 1) * uv_stride; | ||
743 : | y_dif = -width - 2 * y_stride; | ||
744 : | uv_stride = -uv_stride; | ||
745 : | } | ||
746 : | |||
747 : | for (y = height / 2; y; y--) { | ||
748 : | int r, g, b; | ||
749 : | int r2, g2, b2; | ||
750 : | |||
751 : | r = g = b = 0; | ||
752 : | r2 = g2 = b2 = 0; | ||
753 : | |||
754 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
755 : | edgomez | 195 | for (x = 0; x < (uint32_t) width / 2; x++) { |
756 : | int u, v; | ||
757 : | int b_u, g_uv, r_v, rgb_y; | ||
758 : | |||
759 : | u = u_src[x]; | ||
760 : | v = v_src[x]; | ||
761 : | |||
762 : | b_u = B_U_tab[u]; | ||
763 : | g_uv = G_U_tab[u] + G_V_tab[v]; | ||
764 : | r_v = R_V_tab[v]; | ||
765 : | |||
766 : | rgb_y = RGB_Y_tab[*y_src]; | ||
767 : | b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
768 : | g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
769 : | r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
770 : | *(uint16_t *) dst = MK_RGB565(r, g, b); | ||
771 : | |||
772 : | y_src++; | ||
773 : | rgb_y = RGB_Y_tab[*y_src]; | ||
774 : | b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
775 : | g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
776 : | r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
777 : | *(uint16_t *) (dst + 2) = MK_RGB565(r, g, b); | ||
778 : | y_src++; | ||
779 : | |||
780 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
781 : | b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
782 : | g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
783 : | r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
784 : | *(uint16_t *) (dst2) = MK_RGB565(r2, g2, b2); | ||
785 : | y_src2++; | ||
786 : | |||
787 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
788 : | b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT); | ||
789 : | g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT); | ||
790 : | r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT); | ||
791 : | *(uint16_t *) (dst2 + 2) = MK_RGB565(r2, g2, b2); | ||
792 : | y_src2++; | ||
793 : | |||
794 : | dst += 4; | ||
795 : | dst2 += 4; | ||
796 : | } | ||
797 : | |||
798 : | dst += dst_dif; | ||
799 : | dst2 += dst_dif; | ||
800 : | |||
801 : | y_src += y_dif; | ||
802 : | y_src2 += y_dif; | ||
803 : | |||
804 : | u_src += uv_stride; | ||
805 : | v_src += uv_stride; | ||
806 : | } | ||
807 : | } | ||
808 : | |||
809 : | |||
810 : | |||
811 : | /* yuv 4:2:0 planar -> rgb24 */ | ||
812 : | |||
813 : | void | ||
814 : | yv12_to_rgb24_c(uint8_t * dst, | ||
815 : | int dst_stride, | ||
816 : | uint8_t * y_src, | ||
817 : | uint8_t * u_src, | ||
818 : | uint8_t * v_src, | ||
819 : | int y_stride, | ||
820 : | int uv_stride, | ||
821 : | int width, | ||
822 : | int height) | ||
823 : | { | ||
824 : | const uint32_t dst_dif = 6 * dst_stride - 3 * width; | ||
825 : | int32_t y_dif = 2 * y_stride - width; | ||
826 : | |||
827 : | uint8_t *dst2 = dst + 3 * dst_stride; | ||
828 : | uint8_t *y_src2 = y_src + y_stride; | ||
829 : | uint32_t x, y; | ||
830 : | |||
831 : | edgomez | 677 | if (height < 0) { /* flip image? */ |
832 : | edgomez | 195 | height = -height; |
833 : | y_src += (height - 1) * y_stride; | ||
834 : | y_src2 = y_src - y_stride; | ||
835 : | u_src += (height / 2 - 1) * uv_stride; | ||
836 : | v_src += (height / 2 - 1) * uv_stride; | ||
837 : | y_dif = -width - 2 * y_stride; | ||
838 : | uv_stride = -uv_stride; | ||
839 : | } | ||
840 : | |||
841 : | for (y = height / 2; y; y--) { | ||
842 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
843 : | edgomez | 195 | for (x = 0; x < (uint32_t) width / 2; x++) { |
844 : | int u, v; | ||
845 : | int b_u, g_uv, r_v, rgb_y; | ||
846 : | int r, g, b; | ||
847 : | |||
848 : | u = u_src[x]; | ||
849 : | v = v_src[x]; | ||
850 : | |||
851 : | b_u = B_U_tab[u]; | ||
852 : | g_uv = G_U_tab[u] + G_V_tab[v]; | ||
853 : | r_v = R_V_tab[v]; | ||
854 : | |||
855 : | rgb_y = RGB_Y_tab[*y_src]; | ||
856 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
857 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
858 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
859 : | dst[0] = MAX(0, MIN(255, b)); | ||
860 : | dst[1] = MAX(0, MIN(255, g)); | ||
861 : | dst[2] = MAX(0, MIN(255, r)); | ||
862 : | |||
863 : | y_src++; | ||
864 : | rgb_y = RGB_Y_tab[*y_src]; | ||
865 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
866 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
867 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
868 : | dst[3] = MAX(0, MIN(255, b)); | ||
869 : | dst[4] = MAX(0, MIN(255, g)); | ||
870 : | dst[5] = MAX(0, MIN(255, r)); | ||
871 : | y_src++; | ||
872 : | |||
873 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
874 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
875 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
876 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
877 : | dst2[0] = MAX(0, MIN(255, b)); | ||
878 : | dst2[1] = MAX(0, MIN(255, g)); | ||
879 : | dst2[2] = MAX(0, MIN(255, r)); | ||
880 : | y_src2++; | ||
881 : | |||
882 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
883 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
884 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
885 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
886 : | dst2[3] = MAX(0, MIN(255, b)); | ||
887 : | dst2[4] = MAX(0, MIN(255, g)); | ||
888 : | dst2[5] = MAX(0, MIN(255, r)); | ||
889 : | y_src2++; | ||
890 : | |||
891 : | dst += 6; | ||
892 : | dst2 += 6; | ||
893 : | } | ||
894 : | |||
895 : | dst += dst_dif; | ||
896 : | dst2 += dst_dif; | ||
897 : | |||
898 : | y_src += y_dif; | ||
899 : | y_src2 += y_dif; | ||
900 : | |||
901 : | u_src += uv_stride; | ||
902 : | v_src += uv_stride; | ||
903 : | } | ||
904 : | } | ||
905 : | |||
906 : | |||
907 : | |||
908 : | /* yuv 4:2:0 planar -> rgb32 */ | ||
909 : | |||
910 : | void | ||
911 : | yv12_to_rgb32_c(uint8_t * dst, | ||
912 : | int dst_stride, | ||
913 : | uint8_t * y_src, | ||
914 : | uint8_t * v_src, | ||
915 : | uint8_t * u_src, | ||
916 : | int y_stride, | ||
917 : | int uv_stride, | ||
918 : | int width, | ||
919 : | int height) | ||
920 : | { | ||
921 : | const uint32_t dst_dif = 8 * dst_stride - 4 * width; | ||
922 : | int32_t y_dif = 2 * y_stride - width; | ||
923 : | |||
924 : | uint8_t *dst2 = dst + 4 * dst_stride; | ||
925 : | uint8_t *y_src2 = y_src + y_stride; | ||
926 : | uint32_t x, y; | ||
927 : | |||
928 : | edgomez | 677 | if (height < 0) { /* flip image? */ |
929 : | edgomez | 195 | height = -height; |
930 : | y_src += (height - 1) * y_stride; | ||
931 : | y_src2 = y_src - y_stride; | ||
932 : | u_src += (height / 2 - 1) * uv_stride; | ||
933 : | v_src += (height / 2 - 1) * uv_stride; | ||
934 : | y_dif = -width - 2 * y_stride; | ||
935 : | uv_stride = -uv_stride; | ||
936 : | } | ||
937 : | |||
938 : | for (y = height / 2; y; y--) { | ||
939 : | edgomez | 677 | /* process one 2x2 block per iteration */ |
940 : | edgomez | 195 | for (x = 0; x < (uint32_t) width / 2; x++) { |
941 : | int u, v; | ||
942 : | int b_u, g_uv, r_v, rgb_y; | ||
943 : | int r, g, b; | ||
944 : | |||
945 : | u = u_src[x]; | ||
946 : | v = v_src[x]; | ||
947 : | |||
948 : | b_u = B_U_tab[u]; | ||
949 : | g_uv = G_U_tab[u] + G_V_tab[v]; | ||
950 : | r_v = R_V_tab[v]; | ||
951 : | |||
952 : | rgb_y = RGB_Y_tab[*y_src]; | ||
953 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
954 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
955 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
956 : | dst[0] = MAX(0, MIN(255, r)); | ||
957 : | dst[1] = MAX(0, MIN(255, g)); | ||
958 : | dst[2] = MAX(0, MIN(255, b)); | ||
959 : | dst[3] = 0; | ||
960 : | |||
961 : | y_src++; | ||
962 : | rgb_y = RGB_Y_tab[*y_src]; | ||
963 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
964 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
965 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
966 : | dst[4] = MAX(0, MIN(255, r)); | ||
967 : | dst[5] = MAX(0, MIN(255, g)); | ||
968 : | dst[6] = MAX(0, MIN(255, b)); | ||
969 : | dst[7] = 0; | ||
970 : | y_src++; | ||
971 : | |||
972 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
973 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
974 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
975 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
976 : | dst2[0] = MAX(0, MIN(255, r)); | ||
977 : | dst2[1] = MAX(0, MIN(255, g)); | ||
978 : | dst2[2] = MAX(0, MIN(255, b)); | ||
979 : | dst2[3] = 0; | ||
980 : | y_src2++; | ||
981 : | |||
982 : | rgb_y = RGB_Y_tab[*y_src2]; | ||
983 : | b = (rgb_y + b_u) >> SCALEBITS_OUT; | ||
984 : | g = (rgb_y - g_uv) >> SCALEBITS_OUT; | ||
985 : | r = (rgb_y + r_v) >> SCALEBITS_OUT; | ||
986 : | dst2[4] = MAX(0, MIN(255, r)); | ||
987 : | dst2[5] = MAX(0, MIN(255, g)); | ||
988 : | dst2[6] = MAX(0, MIN(255, b)); | ||
989 : | dst2[7] = 0; | ||
990 : | y_src2++; | ||
991 : | |||
992 : | dst += 8; | ||
993 : | dst2 += 8; | ||
994 : | } | ||
995 : | |||
996 : | dst += dst_dif; | ||
997 : | dst2 += dst_dif; | ||
998 : | |||
999 : | y_src += y_dif; | ||
1000 : | y_src2 += y_dif; | ||
1001 : | |||
1002 : | u_src += uv_stride; | ||
1003 : | v_src += uv_stride; | ||
1004 : | } | ||
1005 : | } | ||
1006 : | |||
1007 : | |||
1008 : | |||
1009 : | /* yuv 4:2:0 planar -> yuv planar */ | ||
1010 : | |||
1011 : | void | ||
1012 : | yv12_to_yuv_c(uint8_t * dst, | ||
1013 : | int dst_stride, | ||
1014 : | uint8_t * y_src, | ||
1015 : | uint8_t * u_src, | ||
1016 : | uint8_t * v_src, | ||
1017 : | int y_stride, | ||
1018 : | int uv_stride, | ||
1019 : | int width, | ||
1020 : | int height) | ||
1021 : | { | ||
1022 : | uint32_t dst_stride2 = dst_stride >> 1; | ||
1023 : | uint32_t width2 = width >> 1; | ||
1024 : | uint32_t y; | ||
1025 : | |||
1026 : | if (height < 0) { | ||
1027 : | height = -height; | ||
1028 : | y_src += (height - 1) * y_stride; | ||
1029 : | u_src += (height / 2 - 1) * uv_stride; | ||
1030 : | v_src += (height / 2 - 1) * uv_stride; | ||
1031 : | y_stride = -y_stride; | ||
1032 : | uv_stride = -uv_stride; | ||
1033 : | } | ||
1034 : | |||
1035 : | for (y = height; y; y--) { | ||
1036 : | memcpy(dst, y_src, width); | ||
1037 : | dst += dst_stride; | ||
1038 : | y_src += y_stride; | ||
1039 : | } | ||
1040 : | |||
1041 : | for (y = height >> 1; y; y--) { | ||
1042 : | memcpy(dst, u_src, width2); | ||
1043 : | dst += dst_stride2; | ||
1044 : | u_src += uv_stride; | ||
1045 : | } | ||
1046 : | |||
1047 : | for (y = height >> 1; y; y--) { | ||
1048 : | memcpy(dst, v_src, width2); | ||
1049 : | dst += dst_stride2; | ||
1050 : | v_src += uv_stride; | ||
1051 : | } | ||
1052 : | } | ||
1053 : | |||
1054 : | |||
1055 : | |||
1056 : | |||
1057 : | /* yuv 4:2:0 planar -> yuyv (yuv2) packed */ | ||
1058 : | |||
1059 : | void | ||
1060 : | yv12_to_yuyv_c(uint8_t * dst, | ||
1061 : | int dst_stride, | ||
1062 : | uint8_t * y_src, | ||
1063 : | uint8_t * u_src, | ||
1064 : | uint8_t * v_src, | ||
1065 : | int y_stride, | ||
1066 : | int uv_stride, | ||
1067 : | int width, | ||
1068 : | int height) | ||
1069 : | { | ||
1070 : | const uint32_t dst_dif = 2 * (dst_stride - width); | ||
1071 : | uint32_t x, y; | ||
1072 : | |||
1073 : | if (height < 0) { | ||
1074 : | height = -height; | ||
1075 : | y_src += (height - 1) * y_stride; | ||
1076 : | u_src += (height / 2 - 1) * uv_stride; | ||
1077 : | v_src += (height / 2 - 1) * uv_stride; | ||
1078 : | y_stride = -y_stride; | ||
1079 : | uv_stride = -uv_stride; | ||
1080 : | } | ||
1081 : | |||
1082 : | for (y = 0; y < (uint32_t) height; y++) { | ||
1083 : | for (x = 0; x < (uint32_t) width / 2; x++) { | ||
1084 : | dst[0] = y_src[2 * x]; | ||
1085 : | dst[1] = u_src[x]; | ||
1086 : | dst[2] = y_src[2 * x + 1]; | ||
1087 : | dst[3] = v_src[x]; | ||
1088 : | dst += 4; | ||
1089 : | } | ||
1090 : | dst += dst_dif; | ||
1091 : | y_src += y_stride; | ||
1092 : | if (y & 1) { | ||
1093 : | u_src += uv_stride; | ||
1094 : | v_src += uv_stride; | ||
1095 : | } | ||
1096 : | } | ||
1097 : | } | ||
1098 : | |||
1099 : | |||
1100 : | |||
1101 : | /* yuv 4:2:0 planar -> uyvy packed */ | ||
1102 : | |||
1103 : | void | ||
1104 : | yv12_to_uyvy_c(uint8_t * dst, | ||
1105 : | int dst_stride, | ||
1106 : | uint8_t * y_src, | ||
1107 : | uint8_t * u_src, | ||
1108 : | uint8_t * v_src, | ||
1109 : | int y_stride, | ||
1110 : | int uv_stride, | ||
1111 : | int width, | ||
1112 : | int height) | ||
1113 : | { | ||
1114 : | const uint32_t dst_dif = 2 * (dst_stride - width); | ||
1115 : | uint32_t x, y; | ||
1116 : | |||
1117 : | if (height < 0) { | ||
1118 : | height = -height; | ||
1119 : | y_src += (height - 1) * y_stride; | ||
1120 : | u_src += (height / 2 - 1) * uv_stride; | ||
1121 : | v_src += (height / 2 - 1) * uv_stride; | ||
1122 : | y_stride = -y_stride; | ||
1123 : | uv_stride = -uv_stride; | ||
1124 : | } | ||
1125 : | |||
1126 : | for (y = 0; y < (uint32_t) height; y++) { | ||
1127 : | for (x = 0; x < (uint32_t) width / 2; x++) { | ||
1128 : | dst[0] = u_src[x]; | ||
1129 : | dst[1] = y_src[2 * x]; | ||
1130 : | dst[2] = v_src[x]; | ||
1131 : | dst[3] = y_src[2 * x + 1]; | ||
1132 : | dst += 4; | ||
1133 : | } | ||
1134 : | dst += dst_dif; | ||
1135 : | y_src += y_stride; | ||
1136 : | if (y & 1) { | ||
1137 : | u_src += uv_stride; | ||
1138 : | v_src += uv_stride; | ||
1139 : | } | ||
1140 : | } | ||
1141 : | } | ||
1142 : | |||
1143 : | |||
1144 : | /* user yuv planar -> yuv 4:2:0 planar | ||
1145 : | |||
1146 : | NOTE: does not flip */ | ||
1147 : | |||
1148 : | void | ||
1149 : | user_to_yuv_c(uint8_t * y_out, | ||
1150 : | uint8_t * u_out, | ||
1151 : | uint8_t * v_out, | ||
1152 : | int stride, | ||
1153 : | DEC_PICTURE * picture, | ||
1154 : | int width, | ||
1155 : | int height) | ||
1156 : | { | ||
1157 : | uint32_t stride2 = stride >> 1; | ||
1158 : | uint32_t width2 = width >> 1; | ||
1159 : | uint32_t y; | ||
1160 : | uint8_t *src; | ||
1161 : | |||
1162 : | src = picture->y; | ||
1163 : | for (y = height; y; y--) { | ||
1164 : | memcpy(y_out, src, width); | ||
1165 : | src += picture->stride_y; | ||
1166 : | y_out += stride; | ||
1167 : | } | ||
1168 : | |||
1169 : | src = picture->u; | ||
1170 : | for (y = height >> 1; y; y--) { | ||
1171 : | memcpy(u_out, src, width2); | ||
1172 : | src += picture->stride_uv; | ||
1173 : | u_out += stride2; | ||
1174 : | } | ||
1175 : | |||
1176 : | src = picture->v; | ||
1177 : | for (y = height >> 1; y; y--) { | ||
1178 : | memcpy(v_out, src, width2); | ||
1179 : | src += picture->stride_uv; | ||
1180 : | v_out += stride2; | ||
1181 : | } | ||
1182 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |