video-color: make sRGB colorimetry the default for RGB
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video-color.h
1 /* GStreamer
2  * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GST_VIDEO_COLOR_H__
21 #define __GST_VIDEO_COLOR_H__
22
23 #include <gst/gst.h>
24
25 #include <gst/video/video-format.h>
26
27 G_BEGIN_DECLS
28
29 /**
30  * GstVideoColorRange:
31  * @GST_VIDEO_COLOR_RANGE_UNKNOWN: unknown range
32  * @GST_VIDEO_COLOR_RANGE_0_255: [0..255] for 8 bit components
33  * @GST_VIDEO_COLOR_RANGE_16_235: [16..235] for 8 bit components. Chroma has
34  *                 [16..240] range.
35  *
36  * Possible color range values. These constants are defined for 8 bit color
37  * values and can be scaled for other bit depths.
38  */
39 typedef enum {
40   GST_VIDEO_COLOR_RANGE_UNKNOWN = 0,
41   GST_VIDEO_COLOR_RANGE_0_255,
42   GST_VIDEO_COLOR_RANGE_16_235
43 } GstVideoColorRange;
44
45 /**
46  * GstVideoColorMatrix:
47  * @GST_VIDEO_COLOR_MATRIX_UNKNOWN: unknown matrix
48  * @GST_VIDEO_COLOR_MATRIX_RGB: identity matrix
49  * @GST_VIDEO_COLOR_MATRIX_FCC: FCC color matrix
50  * @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix
51  * @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix
52  * @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
53  *
54  * The color matrix is used to convert between Y'PbPr and
55  * non-linear RGB (R'G'B')
56  */
57 typedef enum {
58   GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
59   GST_VIDEO_COLOR_MATRIX_RGB,
60   GST_VIDEO_COLOR_MATRIX_FCC,
61   GST_VIDEO_COLOR_MATRIX_BT709,
62   GST_VIDEO_COLOR_MATRIX_BT601,
63   GST_VIDEO_COLOR_MATRIX_SMPTE240M
64 } GstVideoColorMatrix;
65
66 gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb);
67
68 /**
69  * GstVideoTransferFunction:
70  * @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
71  * @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
72  * @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
73  * @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
74  * @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
75  * @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
76  *                           range
77  * @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
78  *                               lower range
79  * @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
80  *                          range
81  * @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve
82  * @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
83  *                             100:1 range
84  * @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
85  *                             316.22777:1 range
86  *
87  * The video transfer function defines the formula for converting between
88  * non-linear RGB (R'G'B') and linear RGB
89  */
90 typedef enum {
91   GST_VIDEO_TRANSFER_UNKNOWN = 0,
92   GST_VIDEO_TRANSFER_GAMMA10,
93   GST_VIDEO_TRANSFER_GAMMA18,
94   GST_VIDEO_TRANSFER_GAMMA20,
95   GST_VIDEO_TRANSFER_GAMMA22,
96   GST_VIDEO_TRANSFER_BT709,
97   GST_VIDEO_TRANSFER_SMPTE240M,
98   GST_VIDEO_TRANSFER_SRGB,
99   GST_VIDEO_TRANSFER_GAMMA28,
100   GST_VIDEO_TRANSFER_LOG100,
101   GST_VIDEO_TRANSFER_LOG316
102 } GstVideoTransferFunction;
103
104 gdouble      gst_video_color_transfer_encode (GstVideoTransferFunction func, gdouble val);
105 gdouble      gst_video_color_transfer_decode (GstVideoTransferFunction func, gdouble val);
106
107 /**
108  * GstVideoColorPrimaries:
109  * @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
110  * @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries
111  * @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries
112  * @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries
113  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
114  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
115  * @GST_VIDEO_COLOR_PRIMARIES_FILM: Generic film
116  *
117  * The color primaries define the how to transform linear RGB values to and from
118  * the CIE XYZ colorspace.
119  */
120 typedef enum {
121   GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
122   GST_VIDEO_COLOR_PRIMARIES_BT709,
123   GST_VIDEO_COLOR_PRIMARIES_BT470M,
124   GST_VIDEO_COLOR_PRIMARIES_BT470BG,
125   GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
126   GST_VIDEO_COLOR_PRIMARIES_SMPTE240M,
127   GST_VIDEO_COLOR_PRIMARIES_FILM
128 } GstVideoColorPrimaries;
129
130 /**
131  * GstVideoColorimetry:
132  * @range: the color range. This is the valid range for the samples.
133  *         It is used to convert the samples to Y'PbPr values.
134  * @matrix: the color matrix. Used to convert between Y'PbPr and
135  *          non-linear RGB (R'G'B')
136  * @transfer: the transfer function. used to convert between R'G'B' and RGB
137  * @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
138  *
139  * Structure describing the color info.
140  */
141 typedef struct {
142   GstVideoColorRange        range;
143   GstVideoColorMatrix       matrix;
144   GstVideoTransferFunction  transfer;
145   GstVideoColorPrimaries    primaries;
146 } GstVideoColorimetry;
147
148 /* predefined colorimetry */
149 #define GST_VIDEO_COLORIMETRY_BT601       "bt601"
150 #define GST_VIDEO_COLORIMETRY_BT709       "bt709"
151 #define GST_VIDEO_COLORIMETRY_SMPTE240M   "smpte240m"
152 #define GST_VIDEO_COLORIMETRY_SRGB        "sRGB"
153
154 gboolean     gst_video_colorimetry_matches     (GstVideoColorimetry *cinfo, const gchar *color);
155 gboolean     gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
156 gchar *      gst_video_colorimetry_to_string   (GstVideoColorimetry *cinfo);
157
158 /* compute offset and scale */
159 void         gst_video_color_range_offsets     (GstVideoColorRange range,
160                                                 const GstVideoFormatInfo *info,
161                                                 gint offset[GST_VIDEO_MAX_COMPONENTS],
162                                                 gint scale[GST_VIDEO_MAX_COMPONENTS]);
163
164
165 G_END_DECLS
166
167 #endif /* __GST_VIDEO_COLOR_H__ */