videooverlaycomposition: add some _get_argb and _get_ayuv functions
[platform/upstream/gstreamer.git] / gst-libs / gst / video / video-overlay-composition.h
1 /* GStreamer Video Overlay Composition
2  * Copyright (C) 2011 Intel Corporation
3  * Copyright (C) 2011 Collabora Ltd.
4  * Copyright (C) 2011 Tim-Philipp Müller <tim centricular net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #ifndef __GST_VIDEO_OVERLAY_COMPOSITION_H__
23 #define __GST_VIDEO_OVERLAY_COMPOSITION_H__
24
25 #include <gst/gst.h>
26 #include <gst/video/video.h>
27
28 G_BEGIN_DECLS
29
30 /**
31  * GstVideoOverlayRectangle:
32  *
33  * An opaque video overlay rectangle object. A rectangle contains a single
34  * overlay rectangle which can be added to a composition.
35  */
36 #define GST_TYPE_VIDEO_OVERLAY_RECTANGLE                        \
37   (gst_video_overlay_rectangle_get_type ())
38 #define GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj)                   \
39   ((GstVideoOverlayRectangle *)(obj)
40 #define GST_VIDEO_OVERLAY_RECTANGLE(obj)                        \
41   (GST_VIDEO_OVERLAY_RECTANGLE_CAST(obj))
42 #define GST_IS_VIDEO_OVERLAY_RECTANGLE(obj)                     \
43   (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_RECTANGLE))
44
45 typedef struct _GstVideoOverlayRectangle      GstVideoOverlayRectangle;
46
47 /**
48  * gst_video_overlay_rectangle_ref:
49  * @comp: a a #GstVideoOverlayRectangle.
50  *
51  * Increases the refcount of the given rectangle by one.
52  *
53  * Note that the refcount affects the writeability
54  * of @comp, use gst_video_overlay_rectangle_copy() to ensure a rectangle can
55  * be modified (there is no gst_video_overlay_rectangle_make_writable() because
56  * it is unlikely that someone will hold the single reference to the rectangle
57  * and not know that that's the case).
58  *
59  * Returns: (transfer full): @comp
60  */
61 #ifdef _FOOL_GTK_DOC_
62 G_INLINE_FUNC GstVideoOverlayRectangle *
63 gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp);
64 #endif
65
66 static inline GstVideoOverlayRectangle *
67 gst_video_overlay_rectangle_ref (GstVideoOverlayRectangle * comp)
68 {
69   return (GstVideoOverlayRectangle *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
70 }
71
72 /**
73  * gst_video_overlay_rectangle_unref:
74  * @comp: (transfer full): a #GstVideoOverlayRectangle.
75  *
76  * Decreases the refcount of the rectangle. If the refcount reaches 0, the
77  * rectangle will be freed.
78  */
79 #ifdef _FOOL_GTK_DOC_
80 G_INLINE_FUNC void
81 gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp);
82 #endif
83
84 static inline void
85 gst_video_overlay_rectangle_unref (GstVideoOverlayRectangle * comp)
86 {
87   gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
88 }
89
90 /**
91  * GstVideoOverlayFormatFlags:
92  * @GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE: no flags
93  * @GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA: RGB are premultiplied by A/255.
94  * @GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA: a global-alpha value != 1 is set.
95  *
96  * Overlay format flags.
97  */
98 typedef enum {
99   GST_VIDEO_OVERLAY_FORMAT_FLAG_NONE = 0,
100   GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA = 1,
101   GST_VIDEO_OVERLAY_FORMAT_FLAG_GLOBAL_ALPHA = 2
102 } GstVideoOverlayFormatFlags;
103
104 /**
105   * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB:
106   *
107   * Supported RGB overlay video format.
108   */
109 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
110 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB      GST_VIDEO_FORMAT_BGRA
111 #else
112 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_RGB      GST_VIDEO_FORMAT_ARGB
113 #endif
114
115 /**
116   * GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV:
117   *
118   * Supported YUV overlay video format.
119   */
120 #define GST_VIDEO_OVERLAY_COMPOSITION_FORMAT_YUV      GST_VIDEO_FORMAT_AYUV
121
122 GType                        gst_video_overlay_rectangle_get_type (void);
123
124 GstVideoOverlayRectangle *   gst_video_overlay_rectangle_new_raw  (GstBuffer * pixels,
125                                                                    gint render_x, gint render_y,
126                                                                    guint render_width, guint render_height,
127                                                                    GstVideoOverlayFormatFlags flags);
128
129 GstVideoOverlayRectangle *   gst_video_overlay_rectangle_copy     (GstVideoOverlayRectangle * rectangle);
130
131 guint                        gst_video_overlay_rectangle_get_seqnum (GstVideoOverlayRectangle  * rectangle);
132
133 void                         gst_video_overlay_rectangle_set_render_rectangle     (GstVideoOverlayRectangle  * rectangle,
134                                                                                    gint                        render_x,
135                                                                                    gint                        render_y,
136                                                                                    guint                       render_width,
137                                                                                    guint                       render_height);
138
139 gboolean                     gst_video_overlay_rectangle_get_render_rectangle     (GstVideoOverlayRectangle  * rectangle,
140                                                                                    gint                      * render_x,
141                                                                                    gint                      * render_y,
142                                                                                    guint                     * render_width,
143                                                                                    guint                     * render_height);
144
145 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_raw           (GstVideoOverlayRectangle  * rectangle,
146                                                                                    GstVideoOverlayFormatFlags  flags);
147
148 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_argb          (GstVideoOverlayRectangle  * rectangle,
149                                                                                    GstVideoOverlayFormatFlags  flags);
150
151 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_ayuv          (GstVideoOverlayRectangle  * rectangle,
152                                                                                    GstVideoOverlayFormatFlags  flags);
153
154 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_unscaled_raw  (GstVideoOverlayRectangle  * rectangle,
155                                                                                    GstVideoOverlayFormatFlags  flags);
156
157 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_unscaled_argb (GstVideoOverlayRectangle  * rectangle,
158                                                                                    GstVideoOverlayFormatFlags  flags);
159
160 GstBuffer *                  gst_video_overlay_rectangle_get_pixels_unscaled_ayuv (GstVideoOverlayRectangle  * rectangle,
161                                                                                    GstVideoOverlayFormatFlags  flags);
162
163 GstVideoOverlayFormatFlags   gst_video_overlay_rectangle_get_flags                (GstVideoOverlayRectangle  * rectangle);
164
165 gfloat                       gst_video_overlay_rectangle_get_global_alpha         (GstVideoOverlayRectangle  * rectangle);
166 void                         gst_video_overlay_rectangle_set_global_alpha         (GstVideoOverlayRectangle  * rectangle,
167                                                                                    gfloat                      global_alpha);
168
169 /**
170  * GstVideoOverlayComposition:
171  *
172  * An opaque video overlay composition object. A composition contains
173  * multiple overlay rectangles.
174  */
175 #define GST_TYPE_VIDEO_OVERLAY_COMPOSITION                      \
176   (gst_video_overlay_composition_get_type ())
177 #define GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj)                 \
178   ((GstVideoOverlayComposition *)(obj)
179 #define GST_VIDEO_OVERLAY_COMPOSITION(obj)                      \
180   (GST_VIDEO_OVERLAY_COMPOSITION_CAST(obj))
181 #define GST_IS_VIDEO_OVERLAY_COMPOSITION(obj)                   \
182   (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_VIDEO_OVERLAY_COMPOSITION))
183
184 typedef struct _GstVideoOverlayComposition      GstVideoOverlayComposition;
185
186 /**
187  * gst_video_overlay_composition_ref:
188  * @comp: a a #GstVideoOverlayComposition.
189  *
190  * Increases the refcount of the given composition by one.
191  *
192  * Note that the refcount affects the writeability
193  * of @comp, use gst_video_overlay_composition_make_writable() to ensure
194  * a composition and its rectangles can be modified.
195  *
196  * Returns: (transfer full): @comp
197  */
198 #ifdef _FOOL_GTK_DOC_
199 G_INLINE_FUNC GstVideoOverlayComposition *
200 gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp);
201 #endif
202
203 static inline GstVideoOverlayComposition *
204 gst_video_overlay_composition_ref (GstVideoOverlayComposition * comp)
205 {
206   return (GstVideoOverlayComposition *) gst_mini_object_ref (GST_MINI_OBJECT_CAST (comp));
207 }
208
209 /**
210  * gst_video_overlay_composition_unref:
211  * @comp: (transfer full): a #GstVideoOverlayComposition.
212  *
213  * Decreases the refcount of the composition. If the refcount reaches 0, the
214  * composition will be freed.
215  */
216 #ifdef _FOOL_GTK_DOC_
217 G_INLINE_FUNC void
218 gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp);
219 #endif
220
221 static inline void
222 gst_video_overlay_composition_unref (GstVideoOverlayComposition * comp)
223 {
224   gst_mini_object_unref (GST_MINI_OBJECT_CAST (comp));
225 }
226
227 GType                        gst_video_overlay_composition_get_type (void);
228
229 GstVideoOverlayComposition * gst_video_overlay_composition_copy          (GstVideoOverlayComposition * comp);
230
231 GstVideoOverlayComposition * gst_video_overlay_composition_make_writable (GstVideoOverlayComposition * comp);
232
233 GstVideoOverlayComposition * gst_video_overlay_composition_new           (GstVideoOverlayRectangle * rectangle);
234
235 void                         gst_video_overlay_composition_add_rectangle (GstVideoOverlayComposition * comp,
236                                                                           GstVideoOverlayRectangle   * rectangle);
237
238 guint                        gst_video_overlay_composition_n_rectangles  (GstVideoOverlayComposition * comp);
239
240 GstVideoOverlayRectangle *   gst_video_overlay_composition_get_rectangle (GstVideoOverlayComposition * comp, guint n);
241
242 guint                        gst_video_overlay_composition_get_seqnum    (GstVideoOverlayComposition * comp);
243
244 /* blend composition onto raw video buffer */
245
246 gboolean                     gst_video_overlay_composition_blend         (GstVideoOverlayComposition * comp,
247                                                                           GstVideoFrame              * video_buf);
248
249 /* attach/retrieve composition from buffers */
250
251 #define GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE \
252     (gst_video_overlay_composition_meta_api_get_type())
253 #define GST_VIDEO_OVERLAY_COMPOSITION_META_INFO \
254     (gst_video_overlay_composition_meta_get_info())
255
256 typedef struct _GstVideoOverlayCompositionMeta GstVideoOverlayCompositionMeta;
257
258 /**
259  * GstVideoOverlayCompositionMeta:
260  * @meta: parent #GstMeta
261  * @overlay: the attached #GstVideoOverlayComposition
262  *
263  * Extra buffer metadata describing image overlay data.
264  */
265 struct _GstVideoOverlayCompositionMeta
266 {
267   GstMeta meta;
268
269   GstVideoOverlayComposition *overlay;
270 };
271
272 GType gst_video_overlay_composition_meta_api_get_type (void);
273 const GstMetaInfo *gst_video_overlay_composition_meta_get_info (void);
274
275 GstVideoOverlayCompositionMeta * gst_buffer_add_video_overlay_composition_meta (GstBuffer                  * buf,
276                                                                                 GstVideoOverlayComposition * comp);
277
278 #define gst_buffer_get_video_overlay_composition_meta(b) \
279   ((GstVideoOverlayCompositionMeta*)gst_buffer_get_meta((b),GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE))
280 #define gst_buffer_remove_video_overlay_composition_meta(b,m) \
281   gst_buffer_remove_meta((b),((GstMeta *) m))
282
283 G_END_DECLS
284
285 #endif /* __GST_VIDEO_OVERLAY_COMPOSITION_H__ */