video: Add support for BT2020 colorspace (UHD)
[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  * @GST_VIDEO_COLOR_MATRIX_BT2020: ITU-R BT.2020 color matrix. Since: 1.6.
54  *
55  * The color matrix is used to convert between Y'PbPr and
56  * non-linear RGB (R'G'B')
57  */
58 typedef enum {
59   GST_VIDEO_COLOR_MATRIX_UNKNOWN = 0,
60   GST_VIDEO_COLOR_MATRIX_RGB,
61   GST_VIDEO_COLOR_MATRIX_FCC,
62   GST_VIDEO_COLOR_MATRIX_BT709,
63   GST_VIDEO_COLOR_MATRIX_BT601,
64   GST_VIDEO_COLOR_MATRIX_SMPTE240M,
65   GST_VIDEO_COLOR_MATRIX_BT2020
66 } GstVideoColorMatrix;
67
68 gboolean gst_video_color_matrix_get_Kr_Kb (GstVideoColorMatrix matrix, gdouble * Kr, gdouble * Kb);
69
70 /**
71  * GstVideoTransferFunction:
72  * @GST_VIDEO_TRANSFER_UNKNOWN: unknown transfer function
73  * @GST_VIDEO_TRANSFER_GAMMA10: linear RGB, gamma 1.0 curve
74  * @GST_VIDEO_TRANSFER_GAMMA18: Gamma 1.8 curve
75  * @GST_VIDEO_TRANSFER_GAMMA20: Gamma 2.0 curve
76  * @GST_VIDEO_TRANSFER_GAMMA22: Gamma 2.2 curve
77  * @GST_VIDEO_TRANSFER_BT709: Gamma 2.2 curve with a linear segment in the lower
78  *                           range
79  * @GST_VIDEO_TRANSFER_SMPTE240M: Gamma 2.2 curve with a linear segment in the
80  *                               lower range
81  * @GST_VIDEO_TRANSFER_SRGB: Gamma 2.4 curve with a linear segment in the lower
82  *                          range
83  * @GST_VIDEO_TRANSFER_GAMMA28: Gamma 2.8 curve
84  * @GST_VIDEO_TRANSFER_LOG100: Logarithmic transfer characteristic
85  *                             100:1 range
86  * @GST_VIDEO_TRANSFER_LOG316: Logarithmic transfer characteristic
87  *                             316.22777:1 range
88  * @GST_VIDEO_TRANSFER_BT2020_12: Gamma 2.2 curve with a linear segment in the lower
89  *                                range. Used for BT.2020 with 12 bits per
90  *                                component. Since: 1.6.
91  *
92  * The video transfer function defines the formula for converting between
93  * non-linear RGB (R'G'B') and linear RGB
94  */
95 typedef enum {
96   GST_VIDEO_TRANSFER_UNKNOWN = 0,
97   GST_VIDEO_TRANSFER_GAMMA10,
98   GST_VIDEO_TRANSFER_GAMMA18,
99   GST_VIDEO_TRANSFER_GAMMA20,
100   GST_VIDEO_TRANSFER_GAMMA22,
101   GST_VIDEO_TRANSFER_BT709,
102   GST_VIDEO_TRANSFER_SMPTE240M,
103   GST_VIDEO_TRANSFER_SRGB,
104   GST_VIDEO_TRANSFER_GAMMA28,
105   GST_VIDEO_TRANSFER_LOG100,
106   GST_VIDEO_TRANSFER_LOG316,
107   GST_VIDEO_TRANSFER_BT2020_12
108 } GstVideoTransferFunction;
109
110 gdouble      gst_video_color_transfer_encode (GstVideoTransferFunction func, gdouble val);
111 gdouble      gst_video_color_transfer_decode (GstVideoTransferFunction func, gdouble val);
112
113 /**
114  * GstVideoColorPrimaries:
115  * @GST_VIDEO_COLOR_PRIMARIES_UNKNOWN: unknown color primaries
116  * @GST_VIDEO_COLOR_PRIMARIES_BT709: BT709 primaries
117  * @GST_VIDEO_COLOR_PRIMARIES_BT470M: BT470M primaries
118  * @GST_VIDEO_COLOR_PRIMARIES_BT470BG: BT470BG primaries
119  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE170M: SMPTE170M primaries
120  * @GST_VIDEO_COLOR_PRIMARIES_SMPTE240M: SMPTE240M primaries
121  * @GST_VIDEO_COLOR_PRIMARIES_FILM: Generic film
122  * @GST_VIDEO_COLOR_PRIMARIES_BT2020: BT2020 primaries. Since: 1.6.
123  *
124  * The color primaries define the how to transform linear RGB values to and from
125  * the CIE XYZ colorspace.
126  */
127 typedef enum {
128   GST_VIDEO_COLOR_PRIMARIES_UNKNOWN = 0,
129   GST_VIDEO_COLOR_PRIMARIES_BT709,
130   GST_VIDEO_COLOR_PRIMARIES_BT470M,
131   GST_VIDEO_COLOR_PRIMARIES_BT470BG,
132   GST_VIDEO_COLOR_PRIMARIES_SMPTE170M,
133   GST_VIDEO_COLOR_PRIMARIES_SMPTE240M,
134   GST_VIDEO_COLOR_PRIMARIES_FILM,
135   GST_VIDEO_COLOR_PRIMARIES_BT2020
136 } GstVideoColorPrimaries;
137
138 /**
139  * GstVideoColorPrimariesInfo:
140  * @primaries: a #GstVideoColorPrimaries
141  * @Wx: reference white x coordinate
142  * @Wy: reference white y coordinate
143  * @Rx: red x coordinate
144  * @Ry: red y coordinate
145  * @Gx: green x coordinate
146  * @Gy: green y coordinate
147  * @Bx: blue x coordinate
148  * @By: blue y coordinate
149  *
150  * Structure describing the chromaticity coordinates of an RGB system. These
151  * values can be used to construct a matrix to transform RGB to and from the
152  * XYZ colorspace.
153  *
154  * Since: 1.6
155  */
156 typedef struct {
157   GstVideoColorPrimaries primaries;
158   gdouble Wx, Wy;
159   gdouble Rx, Ry;
160   gdouble Gx, Gy;
161   gdouble Bx, By;
162 } GstVideoColorPrimariesInfo;
163
164 const GstVideoColorPrimariesInfo *
165                 gst_video_color_primaries_get_info     (GstVideoColorPrimaries primaries);
166
167 /**
168  * GstVideoColorimetry:
169  * @range: the color range. This is the valid range for the samples.
170  *         It is used to convert the samples to Y'PbPr values.
171  * @matrix: the color matrix. Used to convert between Y'PbPr and
172  *          non-linear RGB (R'G'B')
173  * @transfer: the transfer function. used to convert between R'G'B' and RGB
174  * @primaries: color primaries. used to convert between R'G'B' and CIE XYZ
175  *
176  * Structure describing the color info.
177  */
178 typedef struct {
179   GstVideoColorRange        range;
180   GstVideoColorMatrix       matrix;
181   GstVideoTransferFunction  transfer;
182   GstVideoColorPrimaries    primaries;
183 } GstVideoColorimetry;
184
185 /* predefined colorimetry */
186 #define GST_VIDEO_COLORIMETRY_BT601       "bt601"
187 #define GST_VIDEO_COLORIMETRY_BT709       "bt709"
188 #define GST_VIDEO_COLORIMETRY_SMPTE240M   "smpte240m"
189 #define GST_VIDEO_COLORIMETRY_SRGB        "sRGB"
190 #define GST_VIDEO_COLORIMETRY_BT2020      "bt2020"
191
192 gboolean     gst_video_colorimetry_matches     (GstVideoColorimetry *cinfo, const gchar *color);
193 gboolean     gst_video_colorimetry_from_string (GstVideoColorimetry *cinfo, const gchar *color);
194 gchar *      gst_video_colorimetry_to_string   (GstVideoColorimetry *cinfo);
195
196 /* compute offset and scale */
197 void         gst_video_color_range_offsets     (GstVideoColorRange range,
198                                                 const GstVideoFormatInfo *info,
199                                                 gint offset[GST_VIDEO_MAX_COMPONENTS],
200                                                 gint scale[GST_VIDEO_MAX_COMPONENTS]);
201
202
203 G_END_DECLS
204
205 #endif /* __GST_VIDEO_COLOR_H__ */