Libav 0.7.1
|
00001 /* 00002 * Colorspace conversion defines 00003 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00027 #ifndef AVUTIL_COLORSPACE_H 00028 #define AVUTIL_COLORSPACE_H 00029 00030 #define SCALEBITS 10 00031 #define ONE_HALF (1 << (SCALEBITS - 1)) 00032 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) 00033 00034 #define YUV_TO_RGB1_CCIR(cb1, cr1)\ 00035 {\ 00036 cb = (cb1) - 128;\ 00037 cr = (cr1) - 128;\ 00038 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\ 00039 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \ 00040 ONE_HALF;\ 00041 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\ 00042 } 00043 00044 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\ 00045 {\ 00046 y = ((y1) - 16) * FIX(255.0/219.0);\ 00047 r = cm[(y + r_add) >> SCALEBITS];\ 00048 g = cm[(y + g_add) >> SCALEBITS];\ 00049 b = cm[(y + b_add) >> SCALEBITS];\ 00050 } 00051 00052 #define YUV_TO_RGB1(cb1, cr1)\ 00053 {\ 00054 cb = (cb1) - 128;\ 00055 cr = (cr1) - 128;\ 00056 r_add = FIX(1.40200) * cr + ONE_HALF;\ 00057 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\ 00058 b_add = FIX(1.77200) * cb + ONE_HALF;\ 00059 } 00060 00061 #define YUV_TO_RGB2(r, g, b, y1)\ 00062 {\ 00063 y = (y1) << SCALEBITS;\ 00064 r = cm[(y + r_add) >> SCALEBITS];\ 00065 g = cm[(y + g_add) >> SCALEBITS];\ 00066 b = cm[(y + b_add) >> SCALEBITS];\ 00067 } 00068 00069 #define Y_CCIR_TO_JPEG(y)\ 00070 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS] 00071 00072 #define Y_JPEG_TO_CCIR(y)\ 00073 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) 00074 00075 #define C_CCIR_TO_JPEG(y)\ 00076 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS] 00077 00078 /* NOTE: the clamp is really necessary! */ 00079 static inline int C_JPEG_TO_CCIR(int y) { 00080 y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS); 00081 if (y < 16) 00082 y = 16; 00083 return y; 00084 } 00085 00086 00087 #define RGB_TO_Y(r, g, b) \ 00088 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \ 00089 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS) 00090 00091 #define RGB_TO_U(r1, g1, b1, shift)\ 00092 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \ 00093 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) 00094 00095 #define RGB_TO_V(r1, g1, b1, shift)\ 00096 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ 00097 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) 00098 00099 #define RGB_TO_Y_CCIR(r, g, b) \ 00100 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \ 00101 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) 00102 00103 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\ 00104 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ 00105 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) 00106 00107 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\ 00108 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ 00109 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) 00110 00111 #endif /* AVUTIL_COLORSPACE_H */