1 |
/************************************************************************** |
/***************************************************************************** |
2 |
* |
* |
3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* colorspace conversions |
* - Colorspace conversion functions - |
5 |
|
* |
6 |
|
* Copyright(C) 2001-2003 Peter Ross <pross@xvid.org> |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
20 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
* |
|
|
*************************************************************************/ |
|
|
|
|
|
/************************************************************************** |
|
|
* |
|
|
* History: |
|
21 |
* |
* |
22 |
* 14.04.2002 added user_to_yuv_c() |
* $Id: colorspace.c,v 1.10 2004-04-12 14:05:08 edgomez Exp $ |
|
* 30.02.2002 out_yuv dst_stride2 fix |
|
|
* 26.02.2002 rgb555, rgb565 |
|
|
* 24.11.2001 accuracy improvement to yuyv/vyuy conversion |
|
|
* 28.10.2001 total rewrite <pross@cs.rmit.edu.au> |
|
23 |
* |
* |
24 |
**************************************************************************/ |
****************************************************************************/ |
25 |
|
|
26 |
#include <string.h> // memcpy |
#include <string.h> /* memcpy */ |
27 |
|
|
28 |
#include "../global.h" |
#include "../global.h" |
|
#include "../divx4.h" // DEC_PICTURE |
|
29 |
#include "colorspace.h" |
#include "colorspace.h" |
30 |
|
|
31 |
// function pointers |
/* function pointers */ |
32 |
|
|
33 |
/* input */ |
/* input */ |
34 |
packedFuncPtr rgb555_to_yv12; |
packedFuncPtr rgb555_to_yv12; |
37 |
packedFuncPtr bgra_to_yv12; |
packedFuncPtr bgra_to_yv12; |
38 |
packedFuncPtr abgr_to_yv12; |
packedFuncPtr abgr_to_yv12; |
39 |
packedFuncPtr rgba_to_yv12; |
packedFuncPtr rgba_to_yv12; |
40 |
|
packedFuncPtr argb_to_yv12; |
41 |
packedFuncPtr yuv_to_yv12; |
packedFuncPtr yuv_to_yv12; |
42 |
packedFuncPtr yuyv_to_yv12; |
packedFuncPtr yuyv_to_yv12; |
43 |
packedFuncPtr uyvy_to_yv12; |
packedFuncPtr uyvy_to_yv12; |
48 |
packedFuncPtr bgrai_to_yv12; |
packedFuncPtr bgrai_to_yv12; |
49 |
packedFuncPtr abgri_to_yv12; |
packedFuncPtr abgri_to_yv12; |
50 |
packedFuncPtr rgbai_to_yv12; |
packedFuncPtr rgbai_to_yv12; |
51 |
|
packedFuncPtr argbi_to_yv12; |
52 |
packedFuncPtr yuyvi_to_yv12; |
packedFuncPtr yuyvi_to_yv12; |
53 |
packedFuncPtr uyvyi_to_yv12; |
packedFuncPtr uyvyi_to_yv12; |
54 |
|
|
59 |
packedFuncPtr yv12_to_bgra; |
packedFuncPtr yv12_to_bgra; |
60 |
packedFuncPtr yv12_to_abgr; |
packedFuncPtr yv12_to_abgr; |
61 |
packedFuncPtr yv12_to_rgba; |
packedFuncPtr yv12_to_rgba; |
62 |
|
packedFuncPtr yv12_to_argb; |
63 |
packedFuncPtr yv12_to_yuv; |
packedFuncPtr yv12_to_yuv; |
64 |
packedFuncPtr yv12_to_yuyv; |
packedFuncPtr yv12_to_yuyv; |
65 |
packedFuncPtr yv12_to_uyvy; |
packedFuncPtr yv12_to_uyvy; |
70 |
packedFuncPtr yv12_to_bgrai; |
packedFuncPtr yv12_to_bgrai; |
71 |
packedFuncPtr yv12_to_abgri; |
packedFuncPtr yv12_to_abgri; |
72 |
packedFuncPtr yv12_to_rgbai; |
packedFuncPtr yv12_to_rgbai; |
73 |
|
packedFuncPtr yv12_to_argbi; |
74 |
packedFuncPtr yv12_to_yuyvi; |
packedFuncPtr yv12_to_yuyvi; |
75 |
packedFuncPtr yv12_to_uyvyi; |
packedFuncPtr yv12_to_uyvyi; |
76 |
|
|
292 |
MAKE_COLORSPACE(bgra_to_yv12_c, 4,2,2, RGB_TO_YV12, 2,1,0, 0) |
MAKE_COLORSPACE(bgra_to_yv12_c, 4,2,2, RGB_TO_YV12, 2,1,0, 0) |
293 |
MAKE_COLORSPACE(abgr_to_yv12_c, 4,2,2, RGB_TO_YV12, 3,2,1, 0) |
MAKE_COLORSPACE(abgr_to_yv12_c, 4,2,2, RGB_TO_YV12, 3,2,1, 0) |
294 |
MAKE_COLORSPACE(rgba_to_yv12_c, 4,2,2, RGB_TO_YV12, 0,1,2, 0) |
MAKE_COLORSPACE(rgba_to_yv12_c, 4,2,2, RGB_TO_YV12, 0,1,2, 0) |
295 |
|
MAKE_COLORSPACE(argb_to_yv12_c, 4,2,2, RGB_TO_YV12, 1,2,3, 0) |
296 |
MAKE_COLORSPACE(yuyv_to_yv12_c, 2,2,2, YUYV_TO_YV12, 0,1,2,3) |
MAKE_COLORSPACE(yuyv_to_yv12_c, 2,2,2, YUYV_TO_YV12, 0,1,2,3) |
297 |
MAKE_COLORSPACE(uyvy_to_yv12_c, 2,2,2, YUYV_TO_YV12, 1,0,3,2) |
MAKE_COLORSPACE(uyvy_to_yv12_c, 2,2,2, YUYV_TO_YV12, 1,0,3,2) |
298 |
|
|
302 |
MAKE_COLORSPACE(bgrai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 2,1,0, 0) |
MAKE_COLORSPACE(bgrai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 2,1,0, 0) |
303 |
MAKE_COLORSPACE(abgri_to_yv12_c, 4,2,4, RGBI_TO_YV12, 3,2,1, 0) |
MAKE_COLORSPACE(abgri_to_yv12_c, 4,2,4, RGBI_TO_YV12, 3,2,1, 0) |
304 |
MAKE_COLORSPACE(rgbai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 0,1,2, 0) |
MAKE_COLORSPACE(rgbai_to_yv12_c, 4,2,4, RGBI_TO_YV12, 0,1,2, 0) |
305 |
|
MAKE_COLORSPACE(argbi_to_yv12_c, 4,2,4, RGBI_TO_YV12, 1,2,3, 0) |
306 |
MAKE_COLORSPACE(yuyvi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 0,1,2,3) |
MAKE_COLORSPACE(yuyvi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 0,1,2,3) |
307 |
MAKE_COLORSPACE(uyvyi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 1,0,3,2) |
MAKE_COLORSPACE(uyvyi_to_yv12_c, 2,2,4, YUYVI_TO_YV12, 1,0,3,2) |
308 |
|
|
339 |
((MAX(0,MIN(255, B)) >> 3) & 0x001f) |
((MAX(0,MIN(255, B)) >> 3) & 0x001f) |
340 |
|
|
341 |
#define WRITE_RGB16(ROW,UV_ROW,C1) \ |
#define WRITE_RGB16(ROW,UV_ROW,C1) \ |
342 |
rgb_y = RGB_Y_tab[ y_ptr[y_stride + 0] ]; \ |
rgb_y = RGB_Y_tab[ y_ptr[y_stride*(ROW) + 0] ]; \ |
343 |
b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \ |
b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \ |
344 |
g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \ |
g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \ |
345 |
r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \ |
r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \ |
346 |
*(uint16_t *) (x_ptr+((ROW)*x_stride)+0) = C1(r[ROW], g[ROW], b[ROW]); \ |
*(uint16_t *) (x_ptr+((ROW)*x_stride)+0) = C1(r[ROW], g[ROW], b[ROW]); \ |
347 |
rgb_y = RGB_Y_tab[ y_ptr[y_stride + 1] ]; \ |
rgb_y = RGB_Y_tab[ y_ptr[y_stride*(ROW) + 1] ]; \ |
348 |
b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \ |
b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT); \ |
349 |
g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \ |
g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT); \ |
350 |
r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \ |
r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT); \ |
446 |
MAKE_COLORSPACE(yv12_to_bgra_c, 4,2,2, YV12_TO_RGB, 2,1,0,3) |
MAKE_COLORSPACE(yv12_to_bgra_c, 4,2,2, YV12_TO_RGB, 2,1,0,3) |
447 |
MAKE_COLORSPACE(yv12_to_abgr_c, 4,2,2, YV12_TO_RGB, 3,2,1,0) |
MAKE_COLORSPACE(yv12_to_abgr_c, 4,2,2, YV12_TO_RGB, 3,2,1,0) |
448 |
MAKE_COLORSPACE(yv12_to_rgba_c, 4,2,2, YV12_TO_RGB, 0,1,2,3) |
MAKE_COLORSPACE(yv12_to_rgba_c, 4,2,2, YV12_TO_RGB, 0,1,2,3) |
449 |
|
MAKE_COLORSPACE(yv12_to_argb_c, 4,2,2, YV12_TO_RGB, 1,2,3,0) |
450 |
MAKE_COLORSPACE(yv12_to_yuyv_c, 2,2,2, YV12_TO_YUYV, 0,1,2,3) |
MAKE_COLORSPACE(yv12_to_yuyv_c, 2,2,2, YV12_TO_YUYV, 0,1,2,3) |
451 |
MAKE_COLORSPACE(yv12_to_uyvy_c, 2,2,2, YV12_TO_YUYV, 1,0,3,2) |
MAKE_COLORSPACE(yv12_to_uyvy_c, 2,2,2, YV12_TO_YUYV, 1,0,3,2) |
452 |
|
|
456 |
MAKE_COLORSPACE(yv12_to_bgrai_c, 4,2,4, YV12_TO_RGBI, 2,1,0,3) |
MAKE_COLORSPACE(yv12_to_bgrai_c, 4,2,4, YV12_TO_RGBI, 2,1,0,3) |
457 |
MAKE_COLORSPACE(yv12_to_abgri_c, 4,2,4, YV12_TO_RGBI, 3,2,1,0) |
MAKE_COLORSPACE(yv12_to_abgri_c, 4,2,4, YV12_TO_RGBI, 3,2,1,0) |
458 |
MAKE_COLORSPACE(yv12_to_rgbai_c, 4,2,4, YV12_TO_RGBI, 0,1,2,3) |
MAKE_COLORSPACE(yv12_to_rgbai_c, 4,2,4, YV12_TO_RGBI, 0,1,2,3) |
459 |
|
MAKE_COLORSPACE(yv12_to_argbi_c, 4,2,4, YV12_TO_RGBI, 1,2,3,0) |
460 |
MAKE_COLORSPACE(yv12_to_yuyvi_c, 2,2,4, YV12_TO_YUYVI, 0,1,2,3) |
MAKE_COLORSPACE(yv12_to_yuyvi_c, 2,2,4, YV12_TO_YUYVI, 0,1,2,3) |
461 |
MAKE_COLORSPACE(yv12_to_uyvyi_c, 2,2,4, YV12_TO_YUYVI, 1,0,3,2) |
MAKE_COLORSPACE(yv12_to_uyvyi_c, 2,2,4, YV12_TO_YUYVI, 1,0,3,2) |
462 |
|
|