00001 /***************************************************************************** 00002 * chroma_common.h: YUV transformation functions 00003 * Provides functions to perform the YUV conversion. The functions provided here 00004 * are a complete and portable C implementation, and may be replaced in certain 00005 * case by optimized functions. 00006 ***************************************************************************** 00007 * Copyright (C) 1999, 2000 the VideoLAN team 00008 * $Id: i420_rgb_c.h 11664 2005-07-09 06:17:09Z courmisch $ 00009 * 00010 * Authors: Vincent Seguin <[email protected]> 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Constants 00029 *****************************************************************************/ 00030 00031 /* Margins and offsets in conversion tables - Margins are used in case a RGB 00032 * RGB conversion would give a value outside the 0-255 range. Offsets have been 00033 * calculated to avoid using the same cache line for 2 tables. conversion tables 00034 * are 2*MARGIN + 256 long and stores pixels.*/ 00035 #define RED_MARGIN 178 00036 #define GREEN_MARGIN 135 00037 #define BLUE_MARGIN 224 00038 #define RED_OFFSET 1501 /* 1323 to 1935 */ 00039 #define GREEN_OFFSET 135 /* 0 to 526 */ 00040 #define BLUE_OFFSET 818 /* 594 to 1298 */ 00041 #define RGB_TABLE_SIZE 1935 /* total table size */ 00042 00043 #define GRAY_MARGIN 384 00044 #define GRAY_TABLE_SIZE 1024 /* total table size */ 00045 00046 #define PALETTE_TABLE_SIZE 2176 /* YUV -> 8bpp palette lookup table */ 00047 00048 /* macros used for YUV pixel conversions */ 00049 #define SHIFT 20 00050 #define U_GREEN_COEF ((int)(-0.391 * (1<<SHIFT) / 1.164)) 00051 #define U_BLUE_COEF ((int)(2.018 * (1<<SHIFT) / 1.164)) 00052 #define V_RED_COEF ((int)(1.596 * (1<<SHIFT) / 1.164)) 00053 #define V_GREEN_COEF ((int)(-0.813 * (1<<SHIFT) / 1.164)) 00054