]> git.sesse.net Git - vlc/blob - include/vlc_picture.h
Move vlc_atomic_t to <vlc_atomic.h> and correct definition
[vlc] / include / vlc_picture.h
1 /*****************************************************************************
2  * vlc_picture.h: picture definitions
3  *****************************************************************************
4  * Copyright (C) 1999 - 2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@via.ecp.fr>
9  *          Olivier Aubert <oaubert 47 videolan d07 org>
10  *
11  * This program is free software; you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation; either version 2.1 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef VLC_PICTURE_H
27 #define VLC_PICTURE_H 1
28
29 /**
30  * \file
31  * This file defines picture structures and functions in vlc
32  */
33
34 #include <vlc_es.h>
35 #include <vlc_atomic.h>
36
37 /** Description of a planar graphic field */
38 typedef struct plane_t
39 {
40     uint8_t *p_pixels;                        /**< Start of the plane's data */
41
42     /* Variables used for fast memcpy operations */
43     int i_lines;           /**< Number of lines, including margins */
44     int i_pitch;           /**< Number of bytes in a line, including margins */
45
46     /** Size of a macropixel, defaults to 1 */
47     int i_pixel_pitch;
48
49     /* Variables used for pictures with margins */
50     int i_visible_lines;            /**< How many visible lines are there ? */
51     int i_visible_pitch;            /**< How many visible pixels are there ? */
52
53 } plane_t;
54
55 /**
56  * Maximum number of plane for a picture
57  */
58 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
59
60
61 /**
62  * A private definition to help overloading picture release
63  */
64 typedef struct picture_gc_sys_t picture_gc_sys_t;
65
66 /**
67  * Video picture
68  */
69 struct picture_t
70 {
71     /**
72      * The properties of the picture
73      */
74     video_frame_format_t format;
75
76     void           *p_data_orig;                /**< pointer before memalign */
77     plane_t         p[PICTURE_PLANE_MAX];     /**< description of the planes */
78     int             i_planes;                /**< number of allocated planes */
79
80     /** \name Picture management properties
81      * These properties can be modified using the video output thread API,
82      * but should never be written directly */
83     /**@{*/
84     mtime_t         date;                                  /**< display date */
85     bool            b_force;
86     /**@}*/
87
88     /** \name Picture dynamic properties
89      * Those properties can be changed by the decoder
90      * @{
91      */
92     bool            b_progressive;          /**< is it a progressive frame ? */
93     bool            b_top_field_first;             /**< which field is first */
94     unsigned int    i_nb_fields;                  /**< # of displayed fields */
95     int8_t         *p_q;                           /**< quantification table */
96     int             i_qstride;                    /**< quantification stride */
97     int             i_qtype;                       /**< quantification style */
98     /**@}*/
99
100     /** Private data - the video output plugin might want to put stuff here to
101      * keep track of the picture */
102     picture_sys_t * p_sys;
103
104     /** This way the picture_Release can be overloaded */
105     struct
106     {
107         vlc_atomic_t refcount;
108         void (*pf_destroy)( picture_t * );
109         picture_gc_sys_t *p_sys;
110     } gc;
111
112     /** Next picture in a FIFO a pictures */
113     struct picture_t *p_next;
114 };
115
116 /**
117  * This function will create a new picture.
118  * The picture created will implement a default release management compatible
119  * with picture_Hold and picture_Release. This default management will release
120  * p_sys, p_q, p_data_orig fields if non NULL.
121  */
122 VLC_API picture_t * picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den ) VLC_USED;
123
124 /**
125  * This function will create a new picture using the given format.
126  *
127  * When possible, it is preferred to use this function over picture_New
128  * as more information about the format is kept.
129  */
130 VLC_API picture_t * picture_NewFromFormat( const video_format_t *p_fmt ) VLC_USED;
131
132 /**
133  * Resource for a picture.
134  */
135 typedef struct
136 {
137     picture_sys_t *p_sys;
138
139     /* Plane resources
140      * XXX all fields MUST be set to the right value.
141      */
142     struct
143     {
144         uint8_t *p_pixels;  /**< Start of the plane's data */
145         int i_lines;        /**< Number of lines, including margins */
146         int i_pitch;        /**< Number of bytes in a line, including margins */
147     } p[PICTURE_PLANE_MAX];
148
149 } picture_resource_t;
150
151 /**
152  * This function will create a new picture using the provided resource.
153  *
154  * If the resource is NULL then a plain picture_NewFromFormat is returned.
155  */
156 VLC_API picture_t * picture_NewFromResource( const video_format_t *, const picture_resource_t * ) VLC_USED;
157
158 /**
159  * This function will increase the picture reference count.
160  * It will not have any effect on picture obtained from vout
161  *
162  * It returns the given picture for convenience.
163  */
164 VLC_API picture_t *picture_Hold( picture_t *p_picture );
165
166 /**
167  * This function will release a picture.
168  * It will not have any effect on picture obtained from vout
169  */
170 VLC_API void picture_Release( picture_t *p_picture );
171
172 /**
173  * This function will return true if you are not the only owner of the
174  * picture.
175  *
176  * It is only valid if it is created using picture_New.
177  */
178 VLC_API bool picture_IsReferenced( picture_t *p_picture );
179
180 /**
181  * This function will copy all picture dynamic properties.
182  */
183 VLC_API void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src );
184
185 /**
186  * This function will reset a picture information (properties and quantizers).
187  * It is sometimes useful for reusing pictures (like from a pool).
188  */
189 VLC_API void picture_Reset( picture_t * );
190
191 /**
192  * This function will copy the picture pixels.
193  * You can safely copy between pictures that do not have the same size,
194  * only the compatible(smaller) part will be copied.
195  */
196 VLC_API void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src );
197 VLC_API void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src );
198
199 /**
200  * This function will copy both picture dynamic properties and pixels.
201  * You have to notice that sometime a simple picture_Hold may do what
202  * you want without the copy overhead.
203  * Provided for convenience.
204  *
205  * \param p_dst pointer to the destination picture.
206  * \param p_src pointer to the source picture.
207  */
208 VLC_API void picture_Copy( picture_t *p_dst, const picture_t *p_src );
209
210 /**
211  * This function will export a picture to an encoded bitstream.
212  *
213  * pp_image will contain the encoded bitstream in psz_format format.
214  *
215  * p_fmt can be NULL otherwise it will be set with the format used for the
216  * picture before encoding.
217  *
218  * i_override_width/height allow to override the width and/or the height of the
219  * picture to be encoded:
220  *  - if strictly lower than 0, the original dimension will be used.
221  *  - if equal to 0, it will be deduced from the other dimension which must be
222  *  different to 0.
223  *  - if strictly higher than 0, it will override the dimension.
224  * If at most one of them is > 0 then the picture aspect ratio will be kept.
225  */
226 VLC_API int picture_Export( vlc_object_t *p_obj, block_t **pp_image, video_format_t *p_fmt, picture_t *p_picture, vlc_fourcc_t i_format, int i_override_width, int i_override_height );
227
228 /**
229  * This function will setup all fields of a picture_t without allocating any
230  * memory.
231  * XXX The memory must already be initialized.
232  * It does not need to be released.
233  *
234  * It will return VLC_EGENERIC if the core does not understand the requested
235  * format.
236  *
237  * It can be useful to get the properties of planes.
238  */
239 VLC_API int picture_Setup( picture_t *, vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den );
240
241
242 /**
243  * This function will blend a given subpicture onto a picture.
244  *
245  * The subpicture and all its region must:
246  *  - be absolute.
247  *  - not be ephemere.
248  *  - not have the fade flag.
249  *  - contains only picture (no text rendering).
250  */
251 VLC_API void picture_BlendSubpicture( picture_t *, filter_t *p_blend, subpicture_t * );
252
253
254 /*****************************************************************************
255  * Flags used to describe the status of a picture
256  *****************************************************************************/
257
258 /* Quantification type */
259 enum
260 {
261     QTYPE_NONE,
262
263     QTYPE_MPEG1,
264     QTYPE_MPEG2,
265     QTYPE_H264,
266 };
267
268 /*****************************************************************************
269  * Shortcuts to access image components
270  *****************************************************************************/
271
272 /* Plane indices */
273 enum
274 {
275     Y_PLANE = 0,
276     U_PLANE = 1,
277     V_PLANE = 2,
278     A_PLANE = 3,
279 };
280
281 /* Shortcuts */
282 #define Y_PIXELS     p[Y_PLANE].p_pixels
283 #define Y_PITCH      p[Y_PLANE].i_pitch
284 #define U_PIXELS     p[U_PLANE].p_pixels
285 #define U_PITCH      p[U_PLANE].i_pitch
286 #define V_PIXELS     p[V_PLANE].p_pixels
287 #define V_PITCH      p[V_PLANE].i_pitch
288 #define A_PIXELS     p[A_PLANE].p_pixels
289 #define A_PITCH      p[A_PLANE].i_pitch
290
291 /**@}*/
292
293 #endif /* VLC_PICTURE_H */