video-color: Add bt601 transfer function
[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. Order of coefficients is
49  * actually GBR, also IEC 61966-2-1 (sRGB)
50  * @GST_VIDEO_COLOR_MATRIX_FCC: FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
51  * @GST_VIDEO_COLOR_MATRIX_BT709: ITU-R BT.709 color matrix, also ITU-R BT1361
52  * / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
53  * @GST_VIDEO_COLOR_MATRIX_BT601: ITU-R BT.601 color matrix, also SMPTE170M / ITU-R BT1358 525 / ITU-R BT1700 NTSC
54  * @GST_VIDEO_COLOR_MATRIX_SMPTE240M: SMPTE 240M color matrix
55  * @GST_VIDEO_COLOR_MATRIX_BT2020: ITU-R BT.2020 color matrix. Since: 1.6
56  *
57  * The color matrix is used to convert between Y'PbPr and
58  * non-linear RGB (R'G'B')
59  */
60 typedef enum {
61   GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
62   GST_VIDEO_COLOR_MATRIX_RGB,
63   GST_VIDEO_COLOR_MATRIX_FCC,
64   GST_VIDEO_COLOR_MATRIX_BT709,
65   GST_VIDEO_COLOR_MATRIX_BT601,
66   GST_VIDEO_COLOR_MATRIX_SMPTE240M,
67   GST_VIDEO_COLOR_MATRIX_BT2020
68 } GstVideoColorMatrix;
69
70 GST_VIDEO_API
71 gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb);
72
73 /**
74  * GstVideoTransferFunction:
75  * @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
76  * @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
77  * @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
78  * @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
79  * @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
80  * @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
81  *                           range, also ITU-R BT470M / ITU-R BT1700 625 PAL &
82  *                           SECAM / ITU-R BT1361
83  * @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
84  *                               lower range
85  * @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
86  *                          range. IEC 61966-2-1 (sRGB or sYCC)
87  * @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve, also ITU-R BT470BG
88  * @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
89  *                             100:1 range
90  * @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
91  *                             316.22777:1 range (100 * sqrt(10) : 1)
92  * @GST_VIDEO_TRANSFER_BT2020_12: Gamma 2.2 curve with a linear segment in the lower
93  *                                range. Used for BT.2020 with 12 bits per
94  *                                component. Since: 1.6
95  * @GST_VIDEO_TRANSFER_ADOBERGB: Gamma 2.19921875. Since: 1.8
96  * @GST_VIDEO_TRANSFER_BT2020_10: Rec. ITU-R BT.2020-2 with 10 bits per component.
97  *                                (functionally the same as the values
98  *                                GST_VIDEO_TRANSFER_BT709 and GST_VIDEO_TRANSFER_BT601).
99  *                                Since: 1.18
100  * @GST_VIDEO_TRANSFER_SMPTE2084: SMPTE ST 2084 for 10, 12, 14, and 16-bit systems.
101  *                                Known as perceptual quantization (PQ)
102  *                                Since: 1.18
103  * @GST_VIDEO_TRANSFER_ARIB_STD_B67: Association of Radio Industries and Businesses (ARIB)
104  *                                   STD-B67 and Rec. ITU-R BT.2100-1 hybrid loggamma (HLG) system
105  *                                   Since: 1.18
106  * @GST_VIDEO_TRANSFER_BT601: also known as SMPTE170M / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
107  *                            Functionally the same as the values
108  *                            GST_VIDEO_TRANSFER_BT709, and GST_VIDEO_TRANSFER_BT2020_10.
109  *                            Since: 1.18
110  *
111  * The video transfer function defines the formula for converting between
112  * non-linear RGB (R'G'B') and linear RGB
113  */
114 typedef enum {
115   GST_VIDEO_TRANSFER_UNKNOWN = 0,
116   GST_VIDEO_TRANSFER_GAMMA10,
117   GST_VIDEO_TRANSFER_GAMMA18,
118   GST_VIDEO_TRANSFER_GAMMA20,
119   GST_VIDEO_TRANSFER_GAMMA22,
120   GST_VIDEO_TRANSFER_BT709,
121   GST_VIDEO_TRANSFER_SMPTE240M,
122   GST_VIDEO_TRANSFER_SRGB,
123   GST_VIDEO_TRANSFER_GAMMA28,
124   GST_VIDEO_TRANSFER_LOG100,
125   GST_VIDEO_TRANSFER_LOG316,
126   GST_VIDEO_TRANSFER_BT2020_12,
127   GST_VIDEO_TRANSFER_ADOBERGB,
128   GST_VIDEO_TRANSFER_BT2020_10,
129   GST_VIDEO_TRANSFER_SMPTE2084,
130   GST_VIDEO_TRANSFER_ARIB_STD_B67,
131   /**
132    * GST_VIDEO_TRANSFER_BT601:
133    * also known as SMPTE170M / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
134    * Since: 1.18
135    */
136   GST_VIDEO_TRANSFER_BT601
137 } GstVideoTransferFunction;
138
139 GST_VIDEO_API
140 gdouble      gst_video_color_transfer_encode (GstVideoTransferFunction func, gdouble val);
141
142 GST_VIDEO_API
143 gdouble      gst_video_color_transfer_decode (GstVideoTransferFunction func, gdouble val);
144
145 /**
146  * GstVideoColorPrimaries:
147  * @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
148  * @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries, also ITU-R BT1361 / IEC
149  * 61966-2-4 / SMPTE RP177 Annex B
150  * @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries, also FCC Title 47 Code
151  * of Federal Regulations 73.682 (a)(20)
152  * @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries, also ITU-R BT601-6
153  * 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM
154  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries, also ITU-R
155  * BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
156  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
157  * @GST_VIDEO_COLOR_PRIMARIES_FILM: Generic film (colour filters using
158  * Illuminant C)
159  * @GST_VIDEO_COLOR_PRIMARIES_BT2020: ITU-R BT2020 primaries. Since: 1.6
160  * @GST_VIDEO_COLOR_PRIMARIES_ADOBERGB: Adobe RGB primaries. Since: 1.8
161  * @GST_VIDEO_COLOR_PRIMARIES_SMPTEST428: SMPTE ST 428 primaries (CIE 1931
162  * XYZ). Since: 1.16
163  * @GST_VIDEO_COLOR_PRIMARIES_SMPTERP431: SMPTE RP 431 primaries (ST 431-2
164  * (2011) / DCI P3). Since: 1.16
165  * @GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432: SMPTE EG 432 primaries (ST 432-1
166  * (2010) / P3 D65). Since: 1.16
167  * @GST_VIDEO_COLOR_PRIMARIES_EBU3213: EBU 3213 primaries (JEDEC P22
168  * phosphors). Since: 1.16
169  *
170  * The color primaries define the how to transform linear RGB values to and from
171  * the CIE XYZ colorspace.
172  */
173 typedef enum {
174   GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
175   GST_VIDEO_COLOR_PRIMARIES_BT709,
176   GST_VIDEO_COLOR_PRIMARIES_BT470M,
177   GST_VIDEO_COLOR_PRIMARIES_BT470BG,
178   GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
179   GST_VIDEO_COLOR_PRIMARIES_SMPTE240M,
180   GST_VIDEO_COLOR_PRIMARIES_FILM,
181   GST_VIDEO_COLOR_PRIMARIES_BT2020,
182   GST_VIDEO_COLOR_PRIMARIES_ADOBERGB,
183   GST_VIDEO_COLOR_PRIMARIES_SMPTEST428,
184   GST_VIDEO_COLOR_PRIMARIES_SMPTERP431,
185   GST_VIDEO_COLOR_PRIMARIES_SMPTEEG432,
186   GST_VIDEO_COLOR_PRIMARIES_EBU3213,
187 } GstVideoColorPrimaries;
188
189 /**
190  * GstVideoColorPrimariesInfo:
191  * @primaries: a #GstVideoColorPrimaries
192  * @Wx: reference white x coordinate
193  * @Wy: reference white y coordinate
194  * @Rx: red x coordinate
195  * @Ry: red y coordinate
196  * @Gx: green x coordinate
197  * @Gy: green y coordinate
198  * @Bx: blue x coordinate
199  * @By: blue y coordinate
200  *
201  * Structure describing the chromaticity coordinates of an RGB system. These
202  * values can be used to construct a matrix to transform RGB to and from the
203  * XYZ colorspace.
204  *
205  * Since: 1.6
206  */
207 typedef struct {
208   GstVideoColorPrimaries primaries;
209   gdouble Wx, Wy;
210   gdouble Rx, Ry;
211   gdouble Gx, Gy;
212   gdouble Bx, By;
213 } GstVideoColorPrimariesInfo;
214
215 GST_VIDEO_API
216 const GstVideoColorPrimariesInfo *
217                 gst_video_color_primaries_get_info     (GstVideoColorPrimaries primaries);
218
219 /**
220  * GstVideoColorimetry:
221  * @range: the color range. This is the valid range for the samples.
222  *         It is used to convert the samples to Y'PbPr values.
223  * @matrix: the color matrix. Used to convert between Y'PbPr and
224  *          non-linear RGB (R'G'B')
225  * @transfer: the transfer function. used to convert between R'G'B' and RGB
226  * @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
227  *
228  * Structure describing the color info.
229  */
230 typedef struct {
231   GstVideoColorRange        range;
232   GstVideoColorMatrix       matrix;
233   GstVideoTransferFunction  transfer;
234   GstVideoColorPrimaries    primaries;
235 } GstVideoColorimetry;
236
237 /* predefined colorimetry */
238 #define GST_VIDEO_COLORIMETRY_BT601       "bt601"
239 #define GST_VIDEO_COLORIMETRY_BT709       "bt709"
240 #define GST_VIDEO_COLORIMETRY_SMPTE240M   "smpte240m"
241 #define GST_VIDEO_COLORIMETRY_SRGB        "sRGB"
242 #define GST_VIDEO_COLORIMETRY_BT2020      "bt2020"
243 #define GST_VIDEO_COLORIMETRY_BT2020_10   "bt2020-10"
244 #define GST_VIDEO_COLORIMETRY_BT2100_PQ   "bt2100-pq"
245 #define GST_VIDEO_COLORIMETRY_BT2100_HLG  "bt2100-hlg"
246
247 GST_VIDEO_API
248 gboolean     gst_video_colorimetry_matches     (const GstVideoColorimetry *cinfo, const gchar *color);
249
250 GST_VIDEO_API
251 gboolean     gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
252
253 GST_VIDEO_API
254 gchar *      gst_video_colorimetry_to_string   (const GstVideoColorimetry *cinfo);
255
256 GST_VIDEO_API
257 gboolean     gst_video_colorimetry_is_equal    (const GstVideoColorimetry *cinfo, const GstVideoColorimetry *other);
258
259 /* compute offset and scale */
260
261 GST_VIDEO_API
262 void         gst_video_color_range_offsets     (GstVideoColorRange range,
263                                                 const GstVideoFormatInfo *info,
264                                                 gint offset[GST_VIDEO_MAX_COMPONENTS],
265                                                 gint scale[GST_VIDEO_MAX_COMPONENTS]);
266
267 /* conversion between GStreamer color{matrix,transfer,primaries} enum and
268  * values defined by ISO/IEC 23001-8 and ITU-T H.273 specification.
269  * Also H264 and H265 specifications follow the color{matrix,transfer,primaries}
270  * values */
271
272 GST_VIDEO_API
273 guint                     gst_video_color_matrix_to_iso      (GstVideoColorMatrix matrix);
274
275 GST_VIDEO_API
276 guint                     gst_video_color_transfer_to_iso    (GstVideoTransferFunction func);
277
278 GST_VIDEO_API
279 guint                     gst_video_color_primaries_to_iso   (GstVideoColorPrimaries primaries);
280
281 GST_VIDEO_API
282 GstVideoColorMatrix       gst_video_color_matrix_from_iso    (guint value);
283
284 GST_VIDEO_API
285 GstVideoTransferFunction  gst_video_color_transfer_from_iso  (guint value);
286
287 GST_VIDEO_API
288 GstVideoColorPrimaries    gst_video_color_primaries_from_iso (guint value);
289
290 G_END_DECLS
291
292 #endif /* __GST_VIDEO_COLOR_H__ */