video: Add I420/I422/Y444_12LE/BE and GBRA video formats
[platform/upstream/gst-plugins-base.git] / gst-libs / gst / video / video-format.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_FORMAT_H__
21 #define __GST_VIDEO_FORMAT_H__
22
23 #include <gst/gst.h>
24
25 G_BEGIN_DECLS
26
27 #include <gst/video/video-enumtypes.h>
28 #include <gst/video/video-tile.h>
29
30 /**
31  * GstVideoFormat:
32  * @GST_VIDEO_FORMAT_UNKNOWN: Unknown or unset video format id
33  * @GST_VIDEO_FORMAT_ENCODED: Encoded video format. Only ever use that in caps for
34  *                            special video formats in combination with non-system
35  *                            memory GstCapsFeatures where it does not make sense
36  *                            to specify a real video format.
37  * @GST_VIDEO_FORMAT_I420: planar 4:2:0 YUV
38  * @GST_VIDEO_FORMAT_YV12: planar 4:2:0 YVU (like I420 but UV planes swapped)
39  * @GST_VIDEO_FORMAT_YUY2: packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...)
40  * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
41  * @GST_VIDEO_FORMAT_VYUY: packed 4:2:2 YUV (V0-Y0-U0-Y1 V2-Y2-U2-Y3 V4 ...)
42  * @GST_VIDEO_FORMAT_AYUV: packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...)
43  * @GST_VIDEO_FORMAT_RGBx: sparse rgb packed into 32 bit, space last
44  * @GST_VIDEO_FORMAT_BGRx: sparse reverse rgb packed into 32 bit, space last
45  * @GST_VIDEO_FORMAT_xRGB: sparse rgb packed into 32 bit, space first
46  * @GST_VIDEO_FORMAT_xBGR: sparse reverse rgb packed into 32 bit, space first
47  * @GST_VIDEO_FORMAT_RGBA: rgb with alpha channel last
48  * @GST_VIDEO_FORMAT_BGRA: reverse rgb with alpha channel last
49  * @GST_VIDEO_FORMAT_ARGB: rgb with alpha channel first
50  * @GST_VIDEO_FORMAT_ABGR: reverse rgb with alpha channel first
51  * @GST_VIDEO_FORMAT_RGB: rgb
52  * @GST_VIDEO_FORMAT_BGR: reverse rgb
53  * @GST_VIDEO_FORMAT_Y41B: planar 4:1:1 YUV
54  * @GST_VIDEO_FORMAT_Y42B: planar 4:2:2 YUV
55  * @GST_VIDEO_FORMAT_YVYU: packed 4:2:2 YUV (Y0-V0-Y1-U0 Y2-V2-Y3-U2 Y4 ...)
56  * @GST_VIDEO_FORMAT_Y444: planar 4:4:4 YUV
57  * @GST_VIDEO_FORMAT_v210: packed 4:2:2 10-bit YUV, complex format
58  * @GST_VIDEO_FORMAT_v216: packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order
59  * @GST_VIDEO_FORMAT_NV12: planar 4:2:0 YUV with interleaved UV plane
60  * @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane
61  * @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale
62  * @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first
63  * @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first
64  * @GST_VIDEO_FORMAT_v308: packed 4:4:4 YUV (Y-U-V ...)
65  * @GST_VIDEO_FORMAT_IYU2: packed 4:4:4 YUV (U-Y-V ...) (Since 1.10)
66  * @GST_VIDEO_FORMAT_RGB16: rgb 5-6-5 bits per component
67  * @GST_VIDEO_FORMAT_BGR16: reverse rgb 5-6-5 bits per component
68  * @GST_VIDEO_FORMAT_RGB15: rgb 5-5-5 bits per component
69  * @GST_VIDEO_FORMAT_BGR15: reverse rgb 5-5-5 bits per component
70  * @GST_VIDEO_FORMAT_UYVP: packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
71  * @GST_VIDEO_FORMAT_A420: planar 4:4:2:0 AYUV
72  * @GST_VIDEO_FORMAT_RGB8P: 8-bit paletted RGB
73  * @GST_VIDEO_FORMAT_YUV9: planar 4:1:0 YUV
74  * @GST_VIDEO_FORMAT_YVU9: planar 4:1:0 YUV (like YUV9 but UV planes swapped)
75  * @GST_VIDEO_FORMAT_IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...)
76  * @GST_VIDEO_FORMAT_ARGB64: rgb with alpha channel first, 16 bits per channel
77  * @GST_VIDEO_FORMAT_AYUV64: packed 4:4:4 YUV with alpha channel, 16 bits per channel (A0-Y0-U0-V0 ...)
78  * @GST_VIDEO_FORMAT_r210: packed 4:4:4 RGB, 10 bits per channel
79  * @GST_VIDEO_FORMAT_I420_10BE: planar 4:2:0 YUV, 10 bits per channel
80  * @GST_VIDEO_FORMAT_I420_10LE: planar 4:2:0 YUV, 10 bits per channel
81  * @GST_VIDEO_FORMAT_I422_10BE: planar 4:2:2 YUV, 10 bits per channel
82  * @GST_VIDEO_FORMAT_I422_10LE: planar 4:2:2 YUV, 10 bits per channel
83  * @GST_VIDEO_FORMAT_Y444_10BE: planar 4:4:4 YUV, 10 bits per channel
84  * @GST_VIDEO_FORMAT_Y444_10LE: planar 4:4:4 YUV, 10 bits per channel
85  * @GST_VIDEO_FORMAT_GBR: planar 4:4:4 RGB, 8 bits per channel
86  * @GST_VIDEO_FORMAT_GBR_10BE: planar 4:4:4 RGB, 10 bits per channel
87  * @GST_VIDEO_FORMAT_GBR_10LE: planar 4:4:4 RGB, 10 bits per channel
88  * @GST_VIDEO_FORMAT_NV16: planar 4:2:2 YUV with interleaved UV plane
89  * @GST_VIDEO_FORMAT_NV61: planar 4:2:2 YUV with interleaved VU plane (Since 1.6)
90  * @GST_VIDEO_FORMAT_NV24: planar 4:4:4 YUV with interleaved UV plane
91  * @GST_VIDEO_FORMAT_NV12_64Z32: NV12 with 64x32 tiling in zigzag pattern
92  * @GST_VIDEO_FORMAT_A420_10BE: planar 4:4:2:0 YUV, 10 bits per channel
93  * @GST_VIDEO_FORMAT_A420_10LE: planar 4:4:2:0 YUV, 10 bits per channel
94  * @GST_VIDEO_FORMAT_A422_10BE: planar 4:4:2:2 YUV, 10 bits per channel
95  * @GST_VIDEO_FORMAT_A422_10LE: planar 4:4:2:2 YUV, 10 bits per channel
96  * @GST_VIDEO_FORMAT_A444_10BE: planar 4:4:4:4 YUV, 10 bits per channel
97  * @GST_VIDEO_FORMAT_A444_10LE: planar 4:4:4:4 YUV, 10 bits per channel
98  * @GST_VIDEO_FORMAT_P010_10BE: planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel
99  * @GST_VIDEO_FORMAT_P010_10LE: planar 4:2:0 YUV with interleaved UV plane, 10 bits per channel
100  * @GST_VIDEO_FORMAT_GBRA: planar 4:4:4:4 ARGB, 8 bits per channel
101  * @GST_VIDEO_FORMAT_GBRA_10BE: planar 4:4:4:4 ARGB, 10 bits per channel
102  * @GST_VIDEO_FORMAT_GBRA_10LE: planar 4:4:4:4 ARGB, 10 bits per channel
103  * @GST_VIDEO_FORMAT_GBR_12BE: planar 4:4:4 RGB, 12 bits per channel
104  * @GST_VIDEO_FORMAT_GBR_12LE: planar 4:4:4 RGB, 12 bits per channel
105  * @GST_VIDEO_FORMAT_GBRA_12BE: planar 4:4:4:4 ARGB, 12 bits per channel
106  * @GST_VIDEO_FORMAT_GBRA_12LE: planar 4:4:4:4 ARGB, 12 bits per channel
107  * @GST_VIDEO_FORMAT_I420_12BE: planar 4:2:0 YUV, 12 bits per channel
108  * @GST_VIDEO_FORMAT_I420_12LE: planar 4:2:0 YUV, 12 bits per channel
109  * @GST_VIDEO_FORMAT_I422_12BE: planar 4:2:2 YUV, 12 bits per channel
110  * @GST_VIDEO_FORMAT_I422_12LE: planar 4:2:2 YUV, 12 bits per channel
111  * @GST_VIDEO_FORMAT_Y444_12BE: planar 4:4:4 YUV, 12 bits per channel
112  * @GST_VIDEO_FORMAT_Y444_12LE: planar 4:4:4 YUV, 12 bits per channel
113  *
114  * Enum value describing the most common video formats.
115  */
116 typedef enum {
117   GST_VIDEO_FORMAT_UNKNOWN,
118   GST_VIDEO_FORMAT_ENCODED,
119   GST_VIDEO_FORMAT_I420,
120   GST_VIDEO_FORMAT_YV12,
121   GST_VIDEO_FORMAT_YUY2,
122   GST_VIDEO_FORMAT_UYVY,
123   GST_VIDEO_FORMAT_AYUV,
124   GST_VIDEO_FORMAT_RGBx,
125   GST_VIDEO_FORMAT_BGRx,
126   GST_VIDEO_FORMAT_xRGB,
127   GST_VIDEO_FORMAT_xBGR,
128   GST_VIDEO_FORMAT_RGBA,
129   GST_VIDEO_FORMAT_BGRA,
130   GST_VIDEO_FORMAT_ARGB,
131   GST_VIDEO_FORMAT_ABGR,
132   GST_VIDEO_FORMAT_RGB,
133   GST_VIDEO_FORMAT_BGR,
134   GST_VIDEO_FORMAT_Y41B,
135   GST_VIDEO_FORMAT_Y42B,
136   GST_VIDEO_FORMAT_YVYU,
137   GST_VIDEO_FORMAT_Y444,
138   GST_VIDEO_FORMAT_v210,
139   GST_VIDEO_FORMAT_v216,
140   GST_VIDEO_FORMAT_NV12,
141   GST_VIDEO_FORMAT_NV21,
142   GST_VIDEO_FORMAT_GRAY8,
143   GST_VIDEO_FORMAT_GRAY16_BE,
144   GST_VIDEO_FORMAT_GRAY16_LE,
145   GST_VIDEO_FORMAT_v308,
146   GST_VIDEO_FORMAT_RGB16,
147   GST_VIDEO_FORMAT_BGR16,
148   GST_VIDEO_FORMAT_RGB15,
149   GST_VIDEO_FORMAT_BGR15,
150   GST_VIDEO_FORMAT_UYVP,
151   GST_VIDEO_FORMAT_A420,
152   GST_VIDEO_FORMAT_RGB8P,
153   GST_VIDEO_FORMAT_YUV9,
154   GST_VIDEO_FORMAT_YVU9,
155   GST_VIDEO_FORMAT_IYU1,
156   GST_VIDEO_FORMAT_ARGB64,
157   GST_VIDEO_FORMAT_AYUV64,
158   GST_VIDEO_FORMAT_r210,
159   GST_VIDEO_FORMAT_I420_10BE,
160   GST_VIDEO_FORMAT_I420_10LE,
161   GST_VIDEO_FORMAT_I422_10BE,
162   GST_VIDEO_FORMAT_I422_10LE,
163   GST_VIDEO_FORMAT_Y444_10BE,
164   GST_VIDEO_FORMAT_Y444_10LE,
165   GST_VIDEO_FORMAT_GBR,
166   GST_VIDEO_FORMAT_GBR_10BE,
167   GST_VIDEO_FORMAT_GBR_10LE,
168   GST_VIDEO_FORMAT_NV16,
169   GST_VIDEO_FORMAT_NV24,
170   GST_VIDEO_FORMAT_NV12_64Z32,
171   GST_VIDEO_FORMAT_A420_10BE,
172   GST_VIDEO_FORMAT_A420_10LE,
173   GST_VIDEO_FORMAT_A422_10BE,
174   GST_VIDEO_FORMAT_A422_10LE,
175   GST_VIDEO_FORMAT_A444_10BE,
176   GST_VIDEO_FORMAT_A444_10LE,
177   GST_VIDEO_FORMAT_NV61,
178   GST_VIDEO_FORMAT_P010_10BE,
179   GST_VIDEO_FORMAT_P010_10LE,
180   GST_VIDEO_FORMAT_IYU2,
181   GST_VIDEO_FORMAT_VYUY,
182   GST_VIDEO_FORMAT_GBRA,
183   GST_VIDEO_FORMAT_GBRA_10BE,
184   GST_VIDEO_FORMAT_GBRA_10LE,
185   GST_VIDEO_FORMAT_GBR_12BE,
186   GST_VIDEO_FORMAT_GBR_12LE,
187   GST_VIDEO_FORMAT_GBRA_12BE,
188   GST_VIDEO_FORMAT_GBRA_12LE,
189   GST_VIDEO_FORMAT_I420_12BE,
190   GST_VIDEO_FORMAT_I420_12LE,
191   GST_VIDEO_FORMAT_I422_12BE,
192   GST_VIDEO_FORMAT_I422_12LE,
193   GST_VIDEO_FORMAT_Y444_12BE,
194   GST_VIDEO_FORMAT_Y444_12LE,
195 } GstVideoFormat;
196
197 #define GST_VIDEO_MAX_PLANES 4
198 #define GST_VIDEO_MAX_COMPONENTS 4
199
200 typedef struct _GstVideoFormatInfo GstVideoFormatInfo;
201
202 /**
203  * GstVideoFormatFlags:
204  * @GST_VIDEO_FORMAT_FLAG_YUV: The video format is YUV, components are numbered
205  *   0=Y, 1=U, 2=V.
206  * @GST_VIDEO_FORMAT_FLAG_RGB: The video format is RGB, components are numbered
207  *   0=R, 1=G, 2=B.
208  * @GST_VIDEO_FORMAT_FLAG_GRAY: The video is gray, there is one gray component
209  *   with index 0.
210  * @GST_VIDEO_FORMAT_FLAG_ALPHA: The video format has an alpha components with
211  *   the number 3.
212  * @GST_VIDEO_FORMAT_FLAG_LE: The video format has data stored in little
213  *   endianness.
214  * @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette. The palette
215  *   is stored in the second plane and indexes are stored in the first plane.
216  * @GST_VIDEO_FORMAT_FLAG_COMPLEX: The video format has a complex layout that
217  *   can't be described with the usual information in the #GstVideoFormatInfo.
218  * @GST_VIDEO_FORMAT_FLAG_UNPACK: This format can be used in a
219  *   #GstVideoFormatUnpack and #GstVideoFormatPack function.
220  * @GST_VIDEO_FORMAT_FLAG_TILED: The format is tiled, there is tiling information
221  *   in the last plane.
222  *
223  * The different video flags that a format info can have.
224  */
225 typedef enum
226 {
227   GST_VIDEO_FORMAT_FLAG_YUV      = (1 << 0),
228   GST_VIDEO_FORMAT_FLAG_RGB      = (1 << 1),
229   GST_VIDEO_FORMAT_FLAG_GRAY     = (1 << 2),
230   GST_VIDEO_FORMAT_FLAG_ALPHA    = (1 << 3),
231   GST_VIDEO_FORMAT_FLAG_LE       = (1 << 4),
232   GST_VIDEO_FORMAT_FLAG_PALETTE  = (1 << 5),
233   GST_VIDEO_FORMAT_FLAG_COMPLEX  = (1 << 6),
234   GST_VIDEO_FORMAT_FLAG_UNPACK   = (1 << 7),
235   GST_VIDEO_FORMAT_FLAG_TILED    = (1 << 8)
236 } GstVideoFormatFlags;
237
238 /* YUV components */
239 #define GST_VIDEO_COMP_Y  0
240 #define GST_VIDEO_COMP_U  1
241 #define GST_VIDEO_COMP_V  2
242
243 /* RGB components */
244 #define GST_VIDEO_COMP_R  0
245 #define GST_VIDEO_COMP_G  1
246 #define GST_VIDEO_COMP_B  2
247
248 /* alpha component */
249 #define GST_VIDEO_COMP_A  3
250
251 /* palette components */
252 #define GST_VIDEO_COMP_INDEX    0
253 #define GST_VIDEO_COMP_PALETTE  1
254
255 #include <gst/video/video-chroma.h>
256
257 /**
258  * GstVideoPackFlags:
259  * @GST_VIDEO_PACK_FLAG_NONE: No flag
260  * @GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE: When the source has a smaller depth
261  *   than the target format, set the least significant bits of the target
262  *   to 0. This is likely sightly faster but less accurate. When this flag
263  *   is not specified, the most significant bits of the source are duplicated
264  *   in the least significant bits of the destination.
265  * @GST_VIDEO_PACK_FLAG_INTERLACED: The source is interlaced. The unpacked
266  *   format will be interlaced as well with each line containing
267  *   information from alternating fields. (Since 1.2)
268  *
269  * The different flags that can be used when packing and unpacking.
270  */
271 typedef enum
272 {
273   GST_VIDEO_PACK_FLAG_NONE           = 0,
274   GST_VIDEO_PACK_FLAG_TRUNCATE_RANGE = (1 << 0),
275   GST_VIDEO_PACK_FLAG_INTERLACED     = (1 << 1)
276 } GstVideoPackFlags;
277
278 /**
279  * GstVideoFormatUnpack:
280  * @info: a #GstVideoFormatInfo
281  * @flags: flags to control the unpacking
282  * @dest: a destination array
283  * @data: pointers to the data planes
284  * @stride: strides of the planes
285  * @x: the x position in the image to start from
286  * @y: the y position in the image to start from
287  * @width: the amount of pixels to unpack.
288  *
289  * Unpacks @width pixels from the given planes and strides containing data of
290  * format @info. The pixels will be unpacked into @dest with each component
291  * interleaved as per @info's unpack_format, which will usually be one of
292  * #GST_VIDEO_FORMAT_ARGB, #GST_VIDEO_FORMAT_AYUV, #GST_VIDEO_FORMAT_ARGB64 or
293  * #GST_VIDEO_FORMAT_AYUV64 depending on the format to unpack.
294  * @dest should at least be big enough to hold @width * bytes_per_pixel bytes
295  * where bytes_per_pixel relates to the unpack format and will usually be
296  * either 4 or 8 depending on the unpack format. bytes_per_pixel will be
297  * the same as the pixel stride for plane 0 for the above formats.
298  *
299  * For subsampled formats, the components will be duplicated in the destination
300  * array. Reconstruction of the missing components can be performed in a
301  * separate step after unpacking.
302  */
303 typedef void (*GstVideoFormatUnpack)         (const GstVideoFormatInfo *info,
304                                               GstVideoPackFlags flags, gpointer dest,
305                                               const gpointer data[GST_VIDEO_MAX_PLANES],
306                                               const gint stride[GST_VIDEO_MAX_PLANES],
307                                               gint x, gint y, gint width);
308 /**
309  * GstVideoFormatPack:
310  * @info: a #GstVideoFormatInfo
311  * @flags: flags to control the packing
312  * @src: a source array
313  * @sstride: the source array stride
314  * @data: pointers to the destination data planes
315  * @stride: strides of the destination planes
316  * @chroma_site: the chroma siting of the target when subsampled (not used)
317  * @y: the y position in the image to pack to
318  * @width: the amount of pixels to pack.
319  *
320  * Packs @width pixels from @src to the given planes and strides in the
321  * format @info. The pixels from source have each component interleaved
322  * and will be packed into the planes in @data.
323  *
324  * This function operates on pack_lines lines, meaning that @src should
325  * contain at least pack_lines lines with a stride of @sstride and @y
326  * should be a multiple of pack_lines.
327  *
328  * Subsampled formats will use the horizontally and vertically cosited
329  * component from the source. Subsampling should be performed before
330  * packing.
331  *
332  * Because this function does not have a x coordinate, it is not possible to
333  * pack pixels starting from an unaligned position. For tiled images this
334  * means that packing should start from a tile coordinate. For subsampled
335  * formats this means that a complete pixel needs to be packed.
336  */
337 /* FIXME(2.0): remove the chroma_site, it is unused and is not relevant for
338  * packing, chroma subsampling based on chroma-site should be done in a separate
339  * step before packing*/
340 typedef void (*GstVideoFormatPack)           (const GstVideoFormatInfo *info,
341                                               GstVideoPackFlags flags,
342                                               const gpointer src, gint sstride,
343                                               gpointer data[GST_VIDEO_MAX_PLANES],
344                                               const gint stride[GST_VIDEO_MAX_PLANES],
345                                               GstVideoChromaSite chroma_site,
346                                               gint y, gint width);
347
348 /**
349  * GstVideoFormatInfo:
350  * @format: #GstVideoFormat
351  * @name: string representation of the format
352  * @description: use readable description of the format
353  * @flags: #GstVideoFormatFlags
354  * @bits: The number of bits used to pack data items. This can be less than 8
355  *    when multiple pixels are stored in a byte. for values > 8 multiple bytes
356  *    should be read according to the endianness flag before applying the shift
357  *    and mask.
358  * @n_components: the number of components in the video format.
359  * @shift: the number of bits to shift away to get the component data
360  * @depth: the depth in bits for each component
361  * @pixel_stride: the pixel stride of each component. This is the amount of
362  *    bytes to the pixel immediately to the right. When bits < 8, the stride is
363  *    expressed in bits. For 24-bit RGB, this would be 3 bytes, for example,
364  *    while it would be 4 bytes for RGBx or ARGB.
365  * @n_planes: the number of planes for this format. The number of planes can be
366  *    less than the amount of components when multiple components are packed into
367  *    one plane.
368  * @plane: the plane number where a component can be found
369  * @poffset: the offset in the plane where the first pixel of the components
370  *    can be found.
371  * @w_sub: subsampling factor of the width for the component. Use
372  *     GST_VIDEO_SUB_SCALE to scale a width.
373  * @h_sub: subsampling factor of the height for the component. Use
374  *     GST_VIDEO_SUB_SCALE to scale a height.
375  * @unpack_format: the format of the unpacked pixels. This format must have the
376  *     #GST_VIDEO_FORMAT_FLAG_UNPACK flag set.
377  * @unpack_func: an unpack function for this format
378  * @pack_lines: the amount of lines that will be packed
379  * @pack_func: an pack function for this format
380  * @tile_mode: The tiling mode
381  * @tile_ws: The width of a tile, in bytes, represented as a shift
382  * @tile_hs: The height of a tile, in bytes, represented as a shift
383  *
384  * Information for a video format.
385  */
386 struct _GstVideoFormatInfo {
387   GstVideoFormat format;
388   const gchar *name;
389   const gchar *description;
390   GstVideoFormatFlags flags;
391   guint bits;
392   guint n_components;
393   guint shift[GST_VIDEO_MAX_COMPONENTS];
394   guint depth[GST_VIDEO_MAX_COMPONENTS];
395   gint  pixel_stride[GST_VIDEO_MAX_COMPONENTS];
396   guint n_planes;
397   guint plane[GST_VIDEO_MAX_COMPONENTS];
398   guint poffset[GST_VIDEO_MAX_COMPONENTS];
399   guint w_sub[GST_VIDEO_MAX_COMPONENTS];
400   guint h_sub[GST_VIDEO_MAX_COMPONENTS];
401
402   GstVideoFormat unpack_format;
403   GstVideoFormatUnpack unpack_func;
404   gint pack_lines;
405   GstVideoFormatPack pack_func;
406
407   GstVideoTileMode tile_mode;
408   guint tile_ws;
409   guint tile_hs;
410
411   /*< private >*/
412   gpointer _gst_reserved[GST_PADDING];
413 };
414
415 #define GST_VIDEO_FORMAT_INFO_FORMAT(info)       ((info)->format)
416 #define GST_VIDEO_FORMAT_INFO_NAME(info)         ((info)->name)
417 #define GST_VIDEO_FORMAT_INFO_FLAGS(info)        ((info)->flags)
418
419 #define GST_VIDEO_FORMAT_INFO_IS_YUV(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_YUV)
420 #define GST_VIDEO_FORMAT_INFO_IS_RGB(info)       ((info)->flags & GST_VIDEO_FORMAT_FLAG_RGB)
421 #define GST_VIDEO_FORMAT_INFO_IS_GRAY(info)      ((info)->flags & GST_VIDEO_FORMAT_FLAG_GRAY)
422 #define GST_VIDEO_FORMAT_INFO_HAS_ALPHA(info)    ((info)->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
423 #define GST_VIDEO_FORMAT_INFO_IS_LE(info)        ((info)->flags & GST_VIDEO_FORMAT_FLAG_LE)
424 #define GST_VIDEO_FORMAT_INFO_HAS_PALETTE(info)  ((info)->flags & GST_VIDEO_FORMAT_FLAG_PALETTE)
425 #define GST_VIDEO_FORMAT_INFO_IS_COMPLEX(info)   ((info)->flags & GST_VIDEO_FORMAT_FLAG_COMPLEX)
426 #define GST_VIDEO_FORMAT_INFO_IS_TILED(info)     ((info)->flags & GST_VIDEO_FORMAT_FLAG_TILED)
427
428 #define GST_VIDEO_FORMAT_INFO_BITS(info)         ((info)->bits)
429 #define GST_VIDEO_FORMAT_INFO_N_COMPONENTS(info) ((info)->n_components)
430 #define GST_VIDEO_FORMAT_INFO_SHIFT(info,c)      ((info)->shift[c])
431 #define GST_VIDEO_FORMAT_INFO_DEPTH(info,c)      ((info)->depth[c])
432 /**
433  * GST_VIDEO_FORMAT_INFO_PSTRIDE:
434  * @info: a #GstVideoFormatInfo
435  * @c: the component index
436  *
437  * pixel stride for the given component. This is the amount of bytes to the
438  * pixel immediately to the right, so basically bytes from one pixel to the
439  * next. When bits < 8, the stride is expressed in bits.
440  *
441  * Examples: for 24-bit RGB, the pixel stride would be 3 bytes, while it
442  * would be 4 bytes for RGBx or ARGB, and 8 bytes for ARGB64 or AYUV64.
443  * For planar formats such as I420 the pixel stride is usually 1. For
444  * YUY2 it would be 2 bytes.
445  */
446 #define GST_VIDEO_FORMAT_INFO_PSTRIDE(info,c)    ((info)->pixel_stride[c])
447 /**
448  * GST_VIDEO_FORMAT_INFO_N_PLANES:
449  * @info: a #GstVideoFormatInfo
450  *
451  * Number of planes. This is the number of planes the pixel layout is
452  * organized in in memory. The number of planes can be less than the
453  * number of components (e.g. Y,U,V,A or R, G, B, A) when multiple
454  * components are packed into one plane.
455  *
456  * Examples: RGB/RGBx/RGBA: 1 plane, 3/3/4 components;
457  * I420: 3 planes, 3 components; NV21/NV12: 2 planes, 3 components.
458  */
459 #define GST_VIDEO_FORMAT_INFO_N_PLANES(info)     ((info)->n_planes)
460 /**
461  * GST_VIDEO_FORMAT_INFO_PLANE:
462  * @info: a #GstVideoFormatInfo
463  * @c: the component index
464  *
465  * Plane number where the given component can be found. A plane may
466  * contain data for multiple components.
467  */
468 #define GST_VIDEO_FORMAT_INFO_PLANE(info,c)      ((info)->plane[c])
469 #define GST_VIDEO_FORMAT_INFO_POFFSET(info,c)    ((info)->poffset[c])
470 #define GST_VIDEO_FORMAT_INFO_W_SUB(info,c)      ((info)->w_sub[c])
471 #define GST_VIDEO_FORMAT_INFO_H_SUB(info,c)      ((info)->h_sub[c])
472
473 /* rounds up */
474 #define GST_VIDEO_SUB_SCALE(scale,val)   (-((-((gint)(val)))>>(scale)))
475
476 #define GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info,c,w)  GST_VIDEO_SUB_SCALE ((info)->w_sub[c],(w))
477 #define GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info,c,h) GST_VIDEO_SUB_SCALE ((info)->h_sub[c],(h))
478
479 #define GST_VIDEO_FORMAT_INFO_DATA(info,planes,comp) \
480   (((guint8*)(planes)[(info)->plane[comp]]) + (info)->poffset[comp])
481 /**
482  * GST_VIDEO_FORMAT_INFO_STRIDE:
483  * @info: a #GstVideoFormatInfo
484  * @strides: an array of strides
485  * @comp: the component index
486  *
487  * Row stride in bytes, that is number of bytes from the first pixel component
488  * of a row to the first pixel component in the next row. This might include
489  * some row padding (memory not actually used for anything, to make sure the
490  * beginning of the next row is aligned in a particular way).
491  */
492 #define GST_VIDEO_FORMAT_INFO_STRIDE(info,strides,comp) ((strides)[(info)->plane[comp]])
493 #define GST_VIDEO_FORMAT_INFO_OFFSET(info,offsets,comp) \
494   (((offsets)[(info)->plane[comp]]) + (info)->poffset[comp])
495
496 #define GST_VIDEO_FORMAT_INFO_TILE_MODE(info) ((info)->tile_mode)
497 #define GST_VIDEO_FORMAT_INFO_TILE_WS(info) ((info)->tile_ws)
498 #define GST_VIDEO_FORMAT_INFO_TILE_HS(info) ((info)->tile_hs)
499
500 /* format properties */
501 GstVideoFormat gst_video_format_from_masks           (gint depth, gint bpp, gint endianness,
502                                                       guint red_mask, guint green_mask,
503                                                       guint blue_mask, guint alpha_mask) G_GNUC_CONST;
504
505 GstVideoFormat gst_video_format_from_fourcc          (guint32 fourcc) G_GNUC_CONST;
506 GstVideoFormat gst_video_format_from_string          (const gchar *format) G_GNUC_CONST;
507
508 guint32        gst_video_format_to_fourcc            (GstVideoFormat format) G_GNUC_CONST;
509 const gchar *  gst_video_format_to_string            (GstVideoFormat format) G_GNUC_CONST;
510
511 const GstVideoFormatInfo *
512                gst_video_format_get_info             (GstVideoFormat format) G_GNUC_CONST;
513
514 gconstpointer  gst_video_format_get_palette          (GstVideoFormat format, gsize *size);
515
516 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]"
517 #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]"
518
519 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
520 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_LE"
521 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_BE"
522 #else
523 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_BE"
524 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_LE"
525 #endif
526
527 #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, VYUY, AYUV, RGBx, "  \
528     "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, "  \
529     "YVYU, Y444, v210, v216, NV12, NV21, NV16, NV61, NV24, GRAY8, GRAY16_BE, " \
530     "GRAY16_LE, v308, IYU2, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, " \
531     "IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE, I422_10LE, I422_10BE, " \
532     "Y444_10LE, Y444_10BE, GBR, GBR_10LE, GBR_10BE, NV12_64Z32, A420_10LE, "\
533     "A420_10BE, A422_10LE, A422_10BE, A444_10LE, A444_10BE, P010_10LE, P010_10BE, "\
534     "GBRA, GBRA_10LE, GBRA_10BE, GBRA_12LE, GBRA_12BE, GBR_12LE, GBR_12BE, GBRA_12LE, "\
535     "GBRA_12BE, I420_12LE, I420_12BE, I422_12LE, I422_12BE, Y444_12LE, Y444_12BE }"
536
537 /**
538  * GST_VIDEO_CAPS_MAKE:
539  * @format: string format that describes the pixel layout, as string
540  *     (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
541  *
542  * Generic caps string for video, for use in pad templates.
543  */
544 #define GST_VIDEO_CAPS_MAKE(format)                                     \
545     "video/x-raw, "                                                     \
546     "format = (string) " format ", "                                    \
547     "width = " GST_VIDEO_SIZE_RANGE ", "                                \
548     "height = " GST_VIDEO_SIZE_RANGE ", "                               \
549     "framerate = " GST_VIDEO_FPS_RANGE
550
551 /**
552  * GST_VIDEO_CAPS_MAKE_WITH_FEATURES:
553  * @format: string format that describes the pixel layout, as string
554  *     (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
555  * @features: Requires caps features as a string, e.g.
556  *     "memory:SystemMemory".
557  *
558  * Generic caps string for video, for use in pad templates.
559  *
560  * Since: 1.2
561  */
562 #define GST_VIDEO_CAPS_MAKE_WITH_FEATURES(features,format)              \
563     "video/x-raw(" features "), "                                       \
564     "format = (string) " format ", "                                    \
565     "width = " GST_VIDEO_SIZE_RANGE ", "                                \
566     "height = " GST_VIDEO_SIZE_RANGE ", "                               \
567     "framerate = " GST_VIDEO_FPS_RANGE
568
569 G_END_DECLS
570
571 #endif /* __GST_VIDEO_FORMAT_H__ */