annotate colorspace.h @ 8629:04423b2f6e0b libavcodec

cosmetics: Remove pointless period after copyright statement non-sentences.
author diego
date Mon, 19 Jan 2009 15:46:40 +0000
parents c4a4495715dd
children e9d9d946f213
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
5354
dfa6e7fa2bac create colorspace.h and use it where appropriate
benoit
parents: 5084
diff changeset
2 * Colorspace conversion defines
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 7760
diff changeset
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
15 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
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
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
21
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
22 /**
5354
dfa6e7fa2bac create colorspace.h and use it where appropriate
benoit
parents: 5084
diff changeset
23 * @file colorspace.h
dfa6e7fa2bac create colorspace.h and use it where appropriate
benoit
parents: 5084
diff changeset
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
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
26
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 5828
diff changeset
27 #ifndef AVCODEC_COLORSPACE_H
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 5828
diff changeset
28 #define AVCODEC_COLORSPACE_H
5828
1876bc447aa4 Add missing multiple inclusion guards.
diego
parents: 5354
diff changeset
29
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
30 #define SCALEBITS 10
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
31 #define ONE_HALF (1 << (SCALEBITS - 1))
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
32 #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
33
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
34 #define YUV_TO_RGB1_CCIR(cb1, cr1)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
35 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
36 cb = (cb1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
37 cr = (cr1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
38 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
39 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
40 ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
41 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
42 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
43
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
44 #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
45 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
46 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
47 r = cm[(y + r_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
48 g = cm[(y + g_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
49 b = cm[(y + b_add) >> SCALEBITS];\
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
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
52 #define YUV_TO_RGB1(cb1, cr1)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
53 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
54 cb = (cb1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
55 cr = (cr1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
56 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
57 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
58 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
59 }
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
60
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
61 #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
62 {\
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
63 y = (y1) << SCALEBITS;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
64 r = cm[(y + r_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
65 g = cm[(y + g_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
66 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
67 }
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_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
70 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
71
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
72 #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
73 (((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
74
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
75 #define C_CCIR_TO_JPEG(y)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
76 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
77
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
78 /* NOTE: the clamp is really necessary! */
1282
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
79 static inline int C_JPEG_TO_CCIR(int y) {
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
80 y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
81 if (y < 16)
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
82 y = 16;
1282
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
83 return y;
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
84 }
8988af3ae1e8 Warning and compatibility fixes.
mellum
parents: 1243
diff changeset
85
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
86
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
87 #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
88 ((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
89 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
90
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
91 #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
92 (((- 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
93 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
94
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
95 #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
96 (((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
97 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
98
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
99 #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
100 ((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
101 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
102
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
103 #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
104 (((- 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
105 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
106
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
107 #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
108 (((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
109 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
110
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 5828
diff changeset
111 #endif /* AVCODEC_COLORSPACE_H */