2 * Copyright (C) <2011> Wim Taymans <wim.taymans@gmail.com>
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.
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.
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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef __GST_VIDEO_FORMAT_H__
21 #define __GST_VIDEO_FORMAT_H__
27 #include <gst/video/video-enumtypes.h>
31 * @GST_VIDEO_FORMAT_UNKNOWN: Unknown or unset video format id
32 * @GST_VIDEO_FORMAT_ENCODED: Encoded video format
33 * @GST_VIDEO_FORMAT_I420: planar 4:2:0 YUV
34 * @GST_VIDEO_FORMAT_YV12: planar 4:2:0 YVU (like I420 but UV planes swapped)
35 * @GST_VIDEO_FORMAT_YUY2: packed 4:2:2 YUV (Y0-U0-Y1-V0 Y2-U2-Y3-V2 Y4 ...)
36 * @GST_VIDEO_FORMAT_UYVY: packed 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...)
37 * @GST_VIDEO_FORMAT_AYUV: packed 4:4:4 YUV with alpha channel (A0-Y0-U0-V0 ...)
38 * @GST_VIDEO_FORMAT_RGBx: sparse rgb packed into 32 bit, space last
39 * @GST_VIDEO_FORMAT_BGRx: sparse reverse rgb packed into 32 bit, space last
40 * @GST_VIDEO_FORMAT_xRGB: sparse rgb packed into 32 bit, space first
41 * @GST_VIDEO_FORMAT_xBGR: sparse reverse rgb packed into 32 bit, space first
42 * @GST_VIDEO_FORMAT_RGBA: rgb with alpha channel last
43 * @GST_VIDEO_FORMAT_BGRA: reverse rgb with alpha channel last
44 * @GST_VIDEO_FORMAT_ARGB: rgb with alpha channel first
45 * @GST_VIDEO_FORMAT_ABGR: reverse rgb with alpha channel first
46 * @GST_VIDEO_FORMAT_RGB: rgb
47 * @GST_VIDEO_FORMAT_BGR: reverse rgb
48 * @GST_VIDEO_FORMAT_Y41B: planar 4:1:1 YUV (Since: 0.10.18)
49 * @GST_VIDEO_FORMAT_Y42B: planar 4:2:2 YUV (Since: 0.10.18)
50 * @GST_VIDEO_FORMAT_YVYU: packed 4:2:2 YUV (Y0-V0-Y1-U0 Y2-V2-Y3-U2 Y4 ...) (Since: 0.10.23)
51 * @GST_VIDEO_FORMAT_Y444: planar 4:4:4 YUV (Since: 0.10.24)
52 * @GST_VIDEO_FORMAT_v210: packed 4:2:2 10-bit YUV, complex format (Since: 0.10.24)
53 * @GST_VIDEO_FORMAT_v216: packed 4:2:2 16-bit YUV, Y0-U0-Y1-V1 order (Since: 0.10.24)
54 * @GST_VIDEO_FORMAT_NV12: planar 4:2:0 YUV with interleaved UV plane (Since: 0.10.26)
55 * @GST_VIDEO_FORMAT_NV21: planar 4:2:0 YUV with interleaved VU plane (Since: 0.10.26)
56 * @GST_VIDEO_FORMAT_GRAY8: 8-bit grayscale (Since: 0.10.29)
57 * @GST_VIDEO_FORMAT_GRAY16_BE: 16-bit grayscale, most significant byte first (Since: 0.10.29)
58 * @GST_VIDEO_FORMAT_GRAY16_LE: 16-bit grayscale, least significant byte first (Since: 0.10.29)
59 * @GST_VIDEO_FORMAT_v308: packed 4:4:4 YUV (Since: 0.10.29)
60 * @GST_VIDEO_FORMAT_RGB16: rgb 5-6-5 bits per component (Since: 0.10.30)
61 * @GST_VIDEO_FORMAT_BGR16: reverse rgb 5-6-5 bits per component (Since: 0.10.30)
62 * @GST_VIDEO_FORMAT_RGB15: rgb 5-5-5 bits per component (Since: 0.10.30)
63 * @GST_VIDEO_FORMAT_BGR15: reverse rgb 5-5-5 bits per component (Since: 0.10.30)
64 * @GST_VIDEO_FORMAT_UYVP: packed 10-bit 4:2:2 YUV (U0-Y0-V0-Y1 U2-Y2-V2-Y3 U4 ...) (Since: 0.10.31)
65 * @GST_VIDEO_FORMAT_A420: planar 4:4:2:0 AYUV (Since: 0.10.31)
66 * @GST_VIDEO_FORMAT_RGB8P: 8-bit paletted RGB (Since: 0.10.32)
67 * @GST_VIDEO_FORMAT_YUV9: planar 4:1:0 YUV (Since: 0.10.32)
68 * @GST_VIDEO_FORMAT_YVU9: planar 4:1:0 YUV (like YUV9 but UV planes swapped) (Since: 0.10.32)
69 * @GST_VIDEO_FORMAT_IYU1: packed 4:1:1 YUV (Cb-Y0-Y1-Cr-Y2-Y3 ...) (Since: 0.10.32)
70 * @GST_VIDEO_FORMAT_ARGB64: rgb with alpha channel first, 16 bits per channel (Since: 0.10.33)
71 * @GST_VIDEO_FORMAT_AYUV64: packed 4:4:4 YUV with alpha channel, 16 bits per channel (A0-Y0-U0-V0 ...) (Since: 0.10.33)
72 * @GST_VIDEO_FORMAT_r210: packed 4:4:4 RGB, 10 bits per channel (Since: 0.10.33)
73 * @GST_VIDEO_FORMAT_I420_10BE: planar 4:2:0 YUV, 10 bits per channel
74 * @GST_VIDEO_FORMAT_I420_10LE: planar 4:2:0 YUV, 10 bits per channel
76 * Enum value describing the most common video formats.
79 GST_VIDEO_FORMAT_UNKNOWN,
80 GST_VIDEO_FORMAT_ENCODED,
81 GST_VIDEO_FORMAT_I420,
82 GST_VIDEO_FORMAT_YV12,
83 GST_VIDEO_FORMAT_YUY2,
84 GST_VIDEO_FORMAT_UYVY,
85 GST_VIDEO_FORMAT_AYUV,
86 GST_VIDEO_FORMAT_RGBx,
87 GST_VIDEO_FORMAT_BGRx,
88 GST_VIDEO_FORMAT_xRGB,
89 GST_VIDEO_FORMAT_xBGR,
90 GST_VIDEO_FORMAT_RGBA,
91 GST_VIDEO_FORMAT_BGRA,
92 GST_VIDEO_FORMAT_ARGB,
93 GST_VIDEO_FORMAT_ABGR,
96 GST_VIDEO_FORMAT_Y41B,
97 GST_VIDEO_FORMAT_Y42B,
98 GST_VIDEO_FORMAT_YVYU,
99 GST_VIDEO_FORMAT_Y444,
100 GST_VIDEO_FORMAT_v210,
101 GST_VIDEO_FORMAT_v216,
102 GST_VIDEO_FORMAT_NV12,
103 GST_VIDEO_FORMAT_NV21,
104 GST_VIDEO_FORMAT_GRAY8,
105 GST_VIDEO_FORMAT_GRAY16_BE,
106 GST_VIDEO_FORMAT_GRAY16_LE,
107 GST_VIDEO_FORMAT_v308,
108 GST_VIDEO_FORMAT_RGB16,
109 GST_VIDEO_FORMAT_BGR16,
110 GST_VIDEO_FORMAT_RGB15,
111 GST_VIDEO_FORMAT_BGR15,
112 GST_VIDEO_FORMAT_UYVP,
113 GST_VIDEO_FORMAT_A420,
114 GST_VIDEO_FORMAT_RGB8P,
115 GST_VIDEO_FORMAT_YUV9,
116 GST_VIDEO_FORMAT_YVU9,
117 GST_VIDEO_FORMAT_IYU1,
118 GST_VIDEO_FORMAT_ARGB64,
119 GST_VIDEO_FORMAT_AYUV64,
120 GST_VIDEO_FORMAT_r210,
121 GST_VIDEO_FORMAT_I420_10BE,
122 GST_VIDEO_FORMAT_I420_10LE
125 #define GST_VIDEO_MAX_PLANES 4
126 #define GST_VIDEO_MAX_COMPONENTS 4
128 typedef struct _GstVideoFormatInfo GstVideoFormatInfo;
131 * GstVideoChromaSite:
132 * @GST_VIDEO_CHROMA_SITE_UNKNOWN: unknown cositing
133 * @GST_VIDEO_CHROMA_SITE_NONE: no cositing
134 * @GST_VIDEO_CHROMA_SITE_H_COSITED: chroma is horizontally cosited
135 * @GST_VIDEO_CHROMA_SITE_V_COSITED: chroma is vertically cosited
136 * @GST_VIDEO_CHROMA_SITE_ALT_LINE: choma samples are sited on alternate lines
137 * @GST_VIDEO_CHROMA_SITE_COSITED: chroma samples cosited with luma samples
138 * @GST_VIDEO_CHROMA_SITE_JPEG: jpeg style cositing, also for mpeg1 and mjpeg
139 * @GST_VIDEO_CHROMA_SITE_MPEG2: mpeg2 style cositing
140 * @GST_VIDEO_CHROMA_SITE_DV: DV style cositing
142 * Various Chroma sitings.
145 GST_VIDEO_CHROMA_SITE_UNKNOWN = 0,
146 GST_VIDEO_CHROMA_SITE_NONE = (1 << 0),
147 GST_VIDEO_CHROMA_SITE_H_COSITED = (1 << 1),
148 GST_VIDEO_CHROMA_SITE_V_COSITED = (1 << 2),
149 GST_VIDEO_CHROMA_SITE_ALT_LINE = (1 << 3),
150 /* some common chroma cositing */
151 GST_VIDEO_CHROMA_SITE_COSITED = (GST_VIDEO_CHROMA_SITE_H_COSITED | GST_VIDEO_CHROMA_SITE_V_COSITED),
152 GST_VIDEO_CHROMA_SITE_JPEG = (GST_VIDEO_CHROMA_SITE_NONE),
153 GST_VIDEO_CHROMA_SITE_MPEG2 = (GST_VIDEO_CHROMA_SITE_H_COSITED),
154 GST_VIDEO_CHROMA_SITE_DV = (GST_VIDEO_CHROMA_SITE_COSITED | GST_VIDEO_CHROMA_SITE_ALT_LINE),
155 } GstVideoChromaSite;
157 GstVideoChromaSite gst_video_chroma_from_string (const gchar * s);
158 const gchar * gst_video_chroma_to_string (GstVideoChromaSite site);
161 * GstVideoFormatFlags:
162 * @GST_VIDEO_FORMAT_FLAG_YUV: The video format is YUV, components are numbered
164 * @GST_VIDEO_FORMAT_FLAG_RGB: The video format is RGB, components are numbered
166 * @GST_VIDEO_FORMAT_FLAG_GRAY: The video is gray, there is one gray component
168 * @GST_VIDEO_FORMAT_FLAG_ALPHA: The video format has an alpha components with
170 * @GST_VIDEO_FORMAT_FLAG_LE: The video format has data stored in little
172 * @GST_VIDEO_FORMAT_FLAG_PALETTE: The video format has a palette. The palette
173 * is stored in the second plane and indexes are stored in the first plane.
174 * @GST_VIDEO_FORMAT_FLAG_COMPLEX: The video format has a complex layout that
175 * can't be described with the usual information in the #GstVideoFormatInfo.
177 * The different video flags that a format info can have.
181 GST_VIDEO_FORMAT_FLAG_YUV = (1 << 0),
182 GST_VIDEO_FORMAT_FLAG_RGB = (1 << 1),
183 GST_VIDEO_FORMAT_FLAG_GRAY = (1 << 2),
184 GST_VIDEO_FORMAT_FLAG_ALPHA = (1 << 3),
185 GST_VIDEO_FORMAT_FLAG_LE = (1 << 4),
186 GST_VIDEO_FORMAT_FLAG_PALETTE = (1 << 5),
187 GST_VIDEO_FORMAT_FLAG_COMPLEX = (1 << 6)
188 } GstVideoFormatFlags;
191 #define GST_VIDEO_COMP_Y 0
192 #define GST_VIDEO_COMP_U 1
193 #define GST_VIDEO_COMP_V 2
196 #define GST_VIDEO_COMP_R 0
197 #define GST_VIDEO_COMP_G 1
198 #define GST_VIDEO_COMP_B 2
200 /* alpha component */
201 #define GST_VIDEO_COMP_A 3
203 /* palette components */
204 #define GST_VIDEO_COMP_INDEX 0
205 #define GST_VIDEO_COMP_PALETTE 1
209 * @GST_VIDEO_PACK_FLAG_NONE: No flag
211 * The different flags that can be used when packing and unpacking.
215 GST_VIDEO_PACK_FLAG_NONE = 0
219 * GstVideoFormatUnpack:
220 * @info: a #GstVideoFormatInfo
221 * @flags: flags to control the unpacking
222 * @dest: a destination array
223 * @data: pointers to the data planes
224 * @stride: strides of the planes
225 * @x: the x position in the image to start from
226 * @y: the y position in the image to start from
227 * @width: the amount of pixels to unpack.
229 * Unpacks @width pixels from the given planes and strides containing data of
230 * format @info. The pixels will be unpacked into @dest which each component
231 * interleaved. @dest should at least be big enough to hold @width *
232 * n_components * size(unpack_format) bytes.
234 typedef void (*GstVideoFormatUnpack) (const GstVideoFormatInfo *info,
235 GstVideoPackFlags flags, gpointer dest,
236 const gpointer data[GST_VIDEO_MAX_PLANES],
237 const gint stride[GST_VIDEO_MAX_PLANES],
238 gint x, gint y, gint width);
240 * GstVideoFormatPack:
241 * @info: a #GstVideoFormatInfo
242 * @flags: flags to control the packing
243 * @src: a source array
244 * @sstride: the source array stride
245 * @data: pointers to the destination data planes
246 * @stride: strides of the destination planes
247 * @chroma_site: the chroma siting of the target when subsampled
248 * @y: the y position in the image to pack to
249 * @width: the amount of pixels to pack.
251 * Packs @width pixels from @src to the given planes and strides in the
252 * format @info. The pixels from source have each component interleaved
253 * and will be packed into the planes in @data.
255 * When @info refers to a format with a h_sub != 0, this function operates on
256 * (1 << h_sub) lines meaning that @src should contain at least (1 << h_sub)
257 * lines with a stride of @sstride and @y should be a multiple of (1 << h_sub).
259 typedef void (*GstVideoFormatPack) (const GstVideoFormatInfo *info,
260 GstVideoPackFlags flags,
261 const gpointer src, gint sstride,
262 gpointer data[GST_VIDEO_MAX_PLANES],
263 const gint stride[GST_VIDEO_MAX_PLANES],
264 GstVideoChromaSite chroma_site,
268 * GstVideoFormatInfo:
269 * @format: #GstVideoFormat
270 * @name: string representation of the format
271 * @description: use readable description of the format
272 * @flags: #GstVideoFormatFlags
273 * @bits: The number of bits used to pack data items. This can be less than 8
274 * when multiple pixels are stored in a byte. for values > 8 multiple bytes
275 * should be read according to the endianness flag before applying the shift
277 * @n_components: the number of components in the video format.
278 * @shift: the number of bits to shift away to get the component data
279 * @depth: the depth in bits for each component
280 * @pixel_stride: the pixel stride of each component. This is the amount of
281 * bytes to the pixel immediately to the right. When bits < 8, the stride is
283 * @n_planes: the number of planes for this format. The number of planes can be
284 * less than the amount of components when multiple components are packed into
286 * @plane: the plane number where a component can be found
287 * @poffset: the offset in the plane where the first pixel of the components
288 * can be found. If bits < 8 the amount is specified in bits.
289 * @w_sub: subsampling factor of the width for the component. Use
290 * GST_VIDEO_SUB_SCALE to scale a width.
291 * @h_sub: subsampling factor of the height for the component. Use
292 * GST_VIDEO_SUB_SCALE to scale a height.
293 * @unpack_format: the format of the unpacked pixels.
294 * @unpack_func: an unpack function for this format
295 * @pack_func: an pack function for this format
297 * Information for a video format.
299 struct _GstVideoFormatInfo {
300 GstVideoFormat format;
302 const gchar *description;
303 GstVideoFormatFlags flags;
306 guint shift[GST_VIDEO_MAX_COMPONENTS];
307 guint depth[GST_VIDEO_MAX_COMPONENTS];
308 gint pixel_stride[GST_VIDEO_MAX_COMPONENTS];
310 guint plane[GST_VIDEO_MAX_COMPONENTS];
311 guint poffset[GST_VIDEO_MAX_COMPONENTS];
312 guint w_sub[GST_VIDEO_MAX_COMPONENTS];
313 guint h_sub[GST_VIDEO_MAX_COMPONENTS];
315 GstVideoFormat unpack_format;
316 GstVideoFormatUnpack unpack_func;
317 GstVideoFormatPack pack_func;
319 gpointer _gst_reserved[GST_PADDING];
322 #define GST_VIDEO_FORMAT_INFO_FORMAT(info) ((info)->format)
323 #define GST_VIDEO_FORMAT_INFO_NAME(info) ((info)->name)
324 #define GST_VIDEO_FORMAT_INFO_FLAGS(info) ((info)->flags)
326 #define GST_VIDEO_FORMAT_INFO_IS_YUV(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_YUV)
327 #define GST_VIDEO_FORMAT_INFO_IS_RGB(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_RGB)
328 #define GST_VIDEO_FORMAT_INFO_IS_GRAY(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_GRAY)
329 #define GST_VIDEO_FORMAT_INFO_HAS_ALPHA(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_ALPHA)
330 #define GST_VIDEO_FORMAT_INFO_IS_LE(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_LE)
331 #define GST_VIDEO_FORMAT_INFO_HAS_PALETTE(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_PALETTE)
332 #define GST_VIDEO_FORMAT_INFO_IS_COMPLEX(info) ((info)->flags & GST_VIDEO_FORMAT_FLAG_COMPLEX)
334 #define GST_VIDEO_FORMAT_INFO_BITS(info) ((info)->bits)
335 #define GST_VIDEO_FORMAT_INFO_N_COMPONENTS(info) ((info)->n_components)
336 #define GST_VIDEO_FORMAT_INFO_SHIFT(info,c) ((info)->shift[c])
337 #define GST_VIDEO_FORMAT_INFO_DEPTH(info,c) ((info)->depth[c])
338 #define GST_VIDEO_FORMAT_INFO_PSTRIDE(info,c) ((info)->pixel_stride[c])
339 #define GST_VIDEO_FORMAT_INFO_N_PLANES(info) ((info)->n_planes)
340 #define GST_VIDEO_FORMAT_INFO_PLANE(info,c) ((info)->plane[c])
341 #define GST_VIDEO_FORMAT_INFO_POFFSET(info,c) ((info)->poffset[c])
342 #define GST_VIDEO_FORMAT_INFO_W_SUB(info,c) ((info)->w_sub[c])
343 #define GST_VIDEO_FORMAT_INFO_H_SUB(info,c) ((info)->h_sub[c])
346 #define GST_VIDEO_SUB_SCALE(scale,val) (-((-((gint)(val)))>>(scale)))
348 #define GST_VIDEO_FORMAT_INFO_SCALE_WIDTH(info,c,w) GST_VIDEO_SUB_SCALE ((info)->w_sub[c],(w))
349 #define GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT(info,c,h) GST_VIDEO_SUB_SCALE ((info)->h_sub[c],(h))
351 #define GST_VIDEO_FORMAT_INFO_DATA(info,planes,comp) \
352 (((guint8*)(planes)[(info)->plane[comp]]) + (info)->poffset[comp])
353 #define GST_VIDEO_FORMAT_INFO_STRIDE(info,strides,comp) ((strides)[(info)->plane[comp]])
354 #define GST_VIDEO_FORMAT_INFO_OFFSET(info,offsets,comp) \
355 (((offsets)[(info)->plane[comp]]) + (info)->poffset[comp])
357 /* format properties */
358 GstVideoFormat gst_video_format_from_masks (gint depth, gint bpp, gint endianness,
359 gint red_mask, gint green_mask,
360 gint blue_mask, gint alpha_mask) G_GNUC_CONST;
362 GstVideoFormat gst_video_format_from_fourcc (guint32 fourcc) G_GNUC_CONST;
363 GstVideoFormat gst_video_format_from_string (const gchar *format) G_GNUC_CONST;
365 guint32 gst_video_format_to_fourcc (GstVideoFormat format) G_GNUC_CONST;
366 const gchar * gst_video_format_to_string (GstVideoFormat format) G_GNUC_CONST;
368 const GstVideoFormatInfo *
369 gst_video_format_get_info (GstVideoFormat format) G_GNUC_CONST;
371 #define GST_VIDEO_SIZE_RANGE "(int) [ 1, max ]"
372 #define GST_VIDEO_FPS_RANGE "(fraction) [ 0, max ]"
374 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
375 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_LE"
376 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_BE"
378 # define GST_VIDEO_NE(s) G_STRINGIFY(s)"_BE"
379 # define GST_VIDEO_OE(s) G_STRINGIFY(s)"_LE"
382 #define GST_VIDEO_FORMATS_ALL "{ I420, YV12, YUY2, UYVY, AYUV, RGBx, " \
383 "BGRx, xRGB, xBGR, RGBA, BGRA, ARGB, ABGR, RGB, BGR, Y41B, Y42B, " \
384 "YVYU, Y444, v210, v216, NV12, NV21, GRAY8, GRAY16_BE, GRAY16_LE, " \
385 "v308, RGB16, BGR16, RGB15, BGR15, UYVP, A420, RGB8P, YUV9, YVU9, " \
386 "IYU1, ARGB64, AYUV64, r210, I420_10LE, I420_10BE }"
389 * GST_VIDEO_CAPS_MAKE:
390 * @format: string format that describes the pixel layout, as string
391 * (e.g. "I420", "RGB", "YV12", "YUY2", "AYUV", etc.)
393 * Generic caps string for video, for use in pad templates.
395 #define GST_VIDEO_CAPS_MAKE(format) \
397 "format = (string) " format ", " \
398 "width = " GST_VIDEO_SIZE_RANGE ", " \
399 "height = " GST_VIDEO_SIZE_RANGE ", " \
400 "framerate = " GST_VIDEO_FPS_RANGE
404 #endif /* __GST_VIDEO_FORMAT_H__ */