Mercurial > libavcodec.hg
comparison colorspace.h @ 5354:dfa6e7fa2bac libavcodec
create colorspace.h and use it where appropriate
patch by Ian Caulfield: /ian caulfield gmail com/
author | benoit |
---|---|
date | Tue, 17 Jul 2007 12:33:14 +0000 |
parents | imgconvert.c@9930b7031cb2 |
children | 1876bc447aa4 |
comparison
equal
deleted
inserted
replaced
5353:7e4703e16bbd | 5354:dfa6e7fa2bac |
---|---|
1 /* | |
2 * Colorspace conversion defines | |
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard. | |
4 * | |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
22 /** | |
23 * @file colorspace.h | |
24 * Various defines for YUV<->RGB conversion | |
25 */ | |
26 | |
27 #define SCALEBITS 10 | |
28 #define ONE_HALF (1 << (SCALEBITS - 1)) | |
29 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) | |
30 | |
31 #define YUV_TO_RGB1_CCIR(cb1, cr1)\ | |
32 {\ | |
33 cb = (cb1) - 128;\ | |
34 cr = (cr1) - 128;\ | |
35 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\ | |
36 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \ | |
37 ONE_HALF;\ | |
38 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\ | |
39 } | |
40 | |
41 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\ | |
42 {\ | |
43 y = ((y1) - 16) * FIX(255.0/219.0);\ | |
44 r = cm[(y + r_add) >> SCALEBITS];\ | |
45 g = cm[(y + g_add) >> SCALEBITS];\ | |
46 b = cm[(y + b_add) >> SCALEBITS];\ | |
47 } | |
48 | |
49 #define YUV_TO_RGB1(cb1, cr1)\ | |
50 {\ | |
51 cb = (cb1) - 128;\ | |
52 cr = (cr1) - 128;\ | |
53 r_add = FIX(1.40200) * cr + ONE_HALF;\ | |
54 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\ | |
55 b_add = FIX(1.77200) * cb + ONE_HALF;\ | |
56 } | |
57 | |
58 #define YUV_TO_RGB2(r, g, b, y1)\ | |
59 {\ | |
60 y = (y1) << SCALEBITS;\ | |
61 r = cm[(y + r_add) >> SCALEBITS];\ | |
62 g = cm[(y + g_add) >> SCALEBITS];\ | |
63 b = cm[(y + b_add) >> SCALEBITS];\ | |
64 } | |
65 | |
66 #define Y_CCIR_TO_JPEG(y)\ | |
67 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS] | |
68 | |
69 #define Y_JPEG_TO_CCIR(y)\ | |
70 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) | |
71 | |
72 #define C_CCIR_TO_JPEG(y)\ | |
73 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS] | |
74 | |
75 /* NOTE: the clamp is really necessary! */ | |
76 static inline int C_JPEG_TO_CCIR(int y) { | |
77 y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS); | |
78 if (y < 16) | |
79 y = 16; | |
80 return y; | |
81 } | |
82 | |
83 | |
84 #define RGB_TO_Y(r, g, b) \ | |
85 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \ | |
86 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS) | |
87 | |
88 #define RGB_TO_U(r1, g1, b1, shift)\ | |
89 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \ | |
90 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) | |
91 | |
92 #define RGB_TO_V(r1, g1, b1, shift)\ | |
93 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ | |
94 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) | |
95 | |
96 #define RGB_TO_Y_CCIR(r, g, b) \ | |
97 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \ | |
98 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) | |
99 | |
100 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\ | |
101 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ | |
102 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) | |
103 | |
104 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\ | |
105 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ | |
106 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) | |
107 |