1 /*****************************************************************************
2 * vlc_picture.h: picture definitions
3 *****************************************************************************
4 * Copyright (C) 1999 - 2009 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@via.ecp.fr>
9 * Olivier Aubert <oaubert 47 videolan d07 org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
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 General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
27 #define VLC_PICTURE_H 1
31 * This file defines picture structures and functions in vlc
36 /** Description of a planar graphic field */
37 typedef struct plane_t
39 uint8_t *p_pixels
; /**< Start of the plane's data */
41 /* Variables used for fast memcpy operations */
42 int i_lines
; /**< Number of lines, including margins */
43 int i_pitch
; /**< Number of bytes in a line, including margins */
45 /** Size of a macropixel, defaults to 1 */
48 /* Variables used for pictures with margins */
49 int i_visible_lines
; /**< How many visible lines are there ? */
50 int i_visible_pitch
; /**< How many visible pixels are there ? */
55 * Maximum number of plane for a picture
57 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
60 * A private definition to help overloading picture release
62 typedef struct picture_release_sys_t picture_release_sys_t
;
67 * Any picture destined to be displayed by a video output thread should be
68 * stored in this structure from it's creation to it's effective display.
69 * Picture type and flags should only be modified by the output thread. Note
70 * that an empty picture MUST have its flags set to 0.
75 * The properties of the picture
77 video_frame_format_t format
;
79 /** Picture data - data can always be freely modified, but p_data may
80 * NEVER be modified. A direct buffer can be handled as the plugin
81 * wishes, it can even swap p_pixels buffers. */
83 void *p_data_orig
; /**< pointer before memalign */
84 plane_t p
[PICTURE_PLANE_MAX
]; /**< description of the planes */
85 int i_planes
; /**< number of allocated planes */
87 /** \name Type and flags
88 * Should NOT be modified except by the vout thread
90 int i_status
; /**< picture flags */
91 int i_type
; /**< is picture a direct buffer ? */
92 bool b_slow
; /**< is picture in slow memory ? */
95 /** \name Picture management properties
96 * These properties can be modified using the video output thread API,
97 * but should never be written directly */
99 unsigned i_refcount
; /**< link reference counter */
100 mtime_t date
; /**< display date */
104 /** \name Picture dynamic properties
105 * Those properties can be changed by the decoder
108 bool b_progressive
; /**< is it a progressive frame ? */
109 unsigned int i_nb_fields
; /**< # of displayed fields */
110 bool b_top_field_first
; /**< which field is first */
111 int8_t *p_q
; /**< quantification table */
112 int i_qstride
; /**< quantification stride */
113 int i_qtype
; /**< quantification style */
116 /* Some vouts require the picture to be locked before it can be modified */
117 int (* pf_lock
) ( vout_thread_t
*, picture_t
* );
118 int (* pf_unlock
) ( vout_thread_t
*, picture_t
* );
120 /** Private data - the video output plugin might want to put stuff here to
121 * keep track of the picture */
122 picture_sys_t
* p_sys
;
124 /** This way the picture_Release can be overloaded */
125 void (*pf_release
)( picture_t
* );
126 picture_release_sys_t
*p_release_sys
;
128 /** Next picture in a FIFO a pictures */
129 struct picture_t
*p_next
;
133 * This function will create a new picture.
134 * The picture created will implement a default release management compatible
135 * with picture_Hold and picture_Release. This default management will release
136 * p_sys, p_q, p_data_orig fields if non NULL.
138 VLC_EXPORT( picture_t
*, picture_New
, ( vlc_fourcc_t i_chroma
, int i_width
, int i_height
, int i_aspect
) );
141 * This function will create a new picture using the given format.
143 * When possible, it is prefered to use this function over picture_New
144 * as more information about the format is kept.
146 VLC_EXPORT( picture_t
*, picture_NewFromFormat
, ( const video_format_t
*p_fmt
) );
149 * Resource for a picture.
153 picture_sys_t
*p_sys
;
156 * XXX all fields MUST be set to the right value.
160 uint8_t *p_pixels
; /**< Start of the plane's data */
161 int i_lines
; /**< Number of lines, including margins */
162 int i_pitch
; /**< Number of bytes in a line, including margins */
163 } p
[PICTURE_PLANE_MAX
];
165 } picture_resource_t
;
168 * This function will create a new picture using the provided resource.
170 * If the resource is NULL then a plain picture_NewFromFormat is returned.
172 VLC_EXPORT( picture_t
*, picture_NewFromResource
, ( const video_format_t
*, const picture_resource_t
* ) );
175 * This function will force the destruction a picture.
176 * The value of the picture reference count should be 0 before entering this
178 * Unless used for reimplementing pf_release, you should not use this
179 * function but picture_Release.
181 VLC_EXPORT( void, picture_Delete
, ( picture_t
* ) );
184 * This function will increase the picture reference count.
185 * It will not have any effect on picture obtained from vout
187 * It returns the given picture for convenience.
189 static inline picture_t
*picture_Hold( picture_t
*p_picture
)
191 if( p_picture
->pf_release
)
192 p_picture
->i_refcount
++;
196 * This function will release a picture.
197 * It will not have any effect on picture obtained from vout
199 static inline void picture_Release( picture_t
*p_picture
)
201 /* FIXME why do we let pf_release handle the i_refcount ? */
202 if( p_picture
->pf_release
)
203 p_picture
->pf_release( p_picture
);
207 * This function will return true if you are not the only owner of the
210 * It is only valid if it is created using picture_New.
212 static inline bool picture_IsReferenced( picture_t
*p_picture
)
214 return p_picture
->i_refcount
> 1;
218 * Cleanup quantization matrix data and set to 0
220 static inline void picture_CleanupQuant( picture_t
*p_pic
)
224 p_pic
->i_qstride
= 0;
229 * This function will copy all picture dynamic properties.
231 static inline void picture_CopyProperties( picture_t
*p_dst
, const picture_t
*p_src
)
233 p_dst
->date
= p_src
->date
;
234 p_dst
->b_force
= p_src
->b_force
;
236 p_dst
->b_progressive
= p_src
->b_progressive
;
237 p_dst
->i_nb_fields
= p_src
->i_nb_fields
;
238 p_dst
->b_top_field_first
= p_src
->b_top_field_first
;
240 /* FIXME: copy ->p_q and ->p_qstride */
244 * This function will reset a picture informations (properties and quantizers).
245 * It is sometimes usefull for reusing pictures (like from a pool).
247 VLC_EXPORT( void, picture_Reset
, ( picture_t
* ) );
250 * This function will copy the picture pixels.
251 * You can safely copy between pictures that do not have the same size,
252 * only the compatible(smaller) part will be copied.
254 VLC_EXPORT( void, picture_CopyPixels
, ( picture_t
*p_dst
, const picture_t
*p_src
) );
255 VLC_EXPORT( void, plane_CopyPixels
, ( plane_t
*p_dst
, const plane_t
*p_src
) );
258 * This function will copy both picture dynamic properties and pixels.
259 * You have to notice that sometime a simple picture_Hold may do what
260 * you want without the copy overhead.
261 * Provided for convenience.
263 * \param p_dst pointer to the destination picture.
264 * \param p_src pointer to the source picture.
266 static inline void picture_Copy( picture_t
*p_dst
, const picture_t
*p_src
)
268 picture_CopyPixels( p_dst
, p_src
);
269 picture_CopyProperties( p_dst
, p_src
);
273 * This function will export a picture to an encoded bitstream.
275 * pp_image will contain the encoded bitstream in psz_format format.
277 * p_fmt can be NULL otherwise it will be set with the format used for the
278 * picture before encoding.
280 * i_override_width/height allow to override the width and/or the height of the
281 * picture to be encoded:
282 * - if strictly lower than 0, the original dimension will be used.
283 * - if equal to 0, it will be deduced from the other dimension which must be
285 * - if strictly higher than 0, it will override the dimension.
286 * If at most one of them is > 0 then the picture aspect ratio will be kept.
288 VLC_EXPORT( 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
) );
291 * This function will setup all fields of a picture_t without allocating any
293 * XXX The memory must already be initialized.
294 * It does not need to be released.
296 * It will return VLC_EGENERIC if the core does not understand the requested
299 * It can be usefull to get the properties of planes.
301 VLC_EXPORT( int, picture_Setup
, ( picture_t
*, vlc_fourcc_t i_chroma
, int i_width
, int i_height
, int i_aspect
) );
303 /*****************************************************************************
304 * Flags used to describe the status of a picture
305 *****************************************************************************/
308 * FIXME are the values meaningfull ? */
311 EMPTY_PICTURE
= 0, /* empty buffer */
312 MEMORY_PICTURE
= 100, /* heap-allocated buffer */
313 DIRECT_PICTURE
= 200, /* direct buffer */
319 FREE_PICTURE
, /* free and not allocated */
320 RESERVED_PICTURE
, /* allocated and reserved */
321 READY_PICTURE
, /* ready for display */
322 DISPLAYED_PICTURE
, /* been displayed but is linked */
323 DESTROYED_PICTURE
, /* allocated but no more used */
326 /* Quantification type */
336 /*****************************************************************************
337 * Shortcuts to access image components
338 *****************************************************************************/
350 #define Y_PIXELS p[Y_PLANE].p_pixels
351 #define Y_PITCH p[Y_PLANE].i_pitch
352 #define U_PIXELS p[U_PLANE].p_pixels
353 #define U_PITCH p[U_PLANE].i_pitch
354 #define V_PIXELS p[V_PLANE].p_pixels
355 #define V_PITCH p[V_PLANE].i_pitch
356 #define A_PIXELS p[A_PLANE].p_pixels
357 #define A_PITCH p[A_PLANE].i_pitch
361 #endif /* VLC_PICTURE_H */