1 /*****************************************************************************
2 * chroma_common.h: YUV transformation functions
3 * Provides functions to perform the YUV conversion. The functions provided here
4 * are a complete and portable C implementation, and may be replaced in certain
5 * case by optimized functions.
6 *****************************************************************************
7 * Copyright (C) 1999, 2000 the VideoLAN team
10 * Authors: Vincent Seguin <seguin@via.ecp.fr>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
31 /* Margins and offsets in conversion tables - Margins are used in case a RGB
32 * RGB conversion would give a value outside the 0-255 range. Offsets have been
33 * calculated to avoid using the same cache line for 2 tables. conversion tables
34 * are 2*MARGIN + 256 long and stores pixels.*/
35 #define RED_MARGIN 178
36 #define GREEN_MARGIN 135
37 #define BLUE_MARGIN 224
38 #define RED_OFFSET 1501 /* 1323 to 1935 */
39 #define GREEN_OFFSET 135 /* 0 to 526 */
40 #define BLUE_OFFSET 818 /* 594 to 1298 */
41 #define RGB_TABLE_SIZE 1935 /* total table size */
43 #define GRAY_MARGIN 384
44 #define GRAY_TABLE_SIZE 1024 /* total table size */
46 #define PALETTE_TABLE_SIZE 2176 /* YUV -> 8bpp palette lookup table */
48 /* macros used for YUV pixel conversions */
50 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164))
51 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164))
52 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164))
53 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164))