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