Mercurial > libavcodec.hg
annotate colorspace.h @ 5800:9c4c865e9974 libavcodec
oops... mpegvideo_enc also depends on motion_est and ratecontrol
author | aurel |
---|---|
date | Tue, 09 Oct 2007 05:39:49 +0000 |
parents | dfa6e7fa2bac |
children | 1876bc447aa4 |
rev | line source |
---|---|
0 | 1 /* |
5354 | 2 * Colorspace conversion defines |
989
fe9083c56733
simplified code (need automatic testing) - added primitive new format support.
bellard
parents:
940
diff
changeset
|
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard. |
0 | 4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
429 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | |
0 | 16 * |
429 | 17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3646
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
1106 | 21 |
22 /** | |
5354 | 23 * @file colorspace.h |
24 * Various defines for YUV<->RGB conversion | |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
25 */ |
1106 | 26 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
27 #define SCALEBITS 10 |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
28 #define ONE_HALF (1 << (SCALEBITS - 1)) |
2979 | 29 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5)) |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
30 |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
31 #define YUV_TO_RGB1_CCIR(cb1, cr1)\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
32 {\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
33 cb = (cb1) - 128;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
34 cr = (cr1) - 128;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
35 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
36 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
37 ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
38 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
39 } |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
40 |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
41 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
42 {\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
43 y = ((y1) - 16) * FIX(255.0/219.0);\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
44 r = cm[(y + r_add) >> SCALEBITS];\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
45 g = cm[(y + g_add) >> SCALEBITS];\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
46 b = cm[(y + b_add) >> SCALEBITS];\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
47 } |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
48 |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
49 #define YUV_TO_RGB1(cb1, cr1)\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
50 {\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
51 cb = (cb1) - 128;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
52 cr = (cr1) - 128;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
53 r_add = FIX(1.40200) * cr + ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
54 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
55 b_add = FIX(1.77200) * cb + ONE_HALF;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
56 } |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
57 |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
58 #define YUV_TO_RGB2(r, g, b, y1)\ |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
59 {\ |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
60 y = (y1) << SCALEBITS;\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
61 r = cm[(y + r_add) >> SCALEBITS];\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
62 g = cm[(y + g_add) >> SCALEBITS];\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
63 b = cm[(y + b_add) >> SCALEBITS];\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
64 } |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
65 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
66 #define Y_CCIR_TO_JPEG(y)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
67 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS] |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
68 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
69 #define Y_JPEG_TO_CCIR(y)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
70 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
71 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
72 #define C_CCIR_TO_JPEG(y)\ |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
73 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS] |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
74 |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
75 /* NOTE: the clamp is really necessary! */ |
1282 | 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) | |
2979 | 79 y = 16; |
1282 | 80 return y; |
81 } | |
82 | |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
83 |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
84 #define RGB_TO_Y(r, g, b) \ |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
85 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \ |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
86 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS) |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
87 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
88 #define RGB_TO_U(r1, g1, b1, shift)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
89 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \ |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
90 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
91 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
92 #define RGB_TO_V(r1, g1, b1, shift)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
93 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
94 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
95 |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
96 #define RGB_TO_Y_CCIR(r, g, b) \ |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
97 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \ |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
98 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) |
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
99 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
100 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
101 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
102 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
103 |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
104 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\ |
1202
8b49a7ee4e4e
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents:
1199
diff
changeset
|
105 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ |
1203
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
106 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) |
80c73b9b0ba2
accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents:
1202
diff
changeset
|
107 |