1 /*****************************************************************************
2 * vlc_picture.h: picture definitions
3 *****************************************************************************
4 * Copyright (C) 1999 - 2009 VLC authors and VideoLAN
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 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.
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.
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 *****************************************************************************/
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)
65 * The properties of the picture
67 video_frame_format_t format
;
69 plane_t p
[PICTURE_PLANE_MAX
]; /**< description of the planes */
70 int i_planes
; /**< number of allocated planes */
72 /** \name Picture management properties
73 * These properties can be modified using the video output thread API,
74 * but should never be written directly */
76 mtime_t date
; /**< display date */
80 /** \name Picture dynamic properties
81 * Those properties can be changed by the decoder
84 bool b_progressive
; /**< is it a progressive frame ? */
85 bool b_top_field_first
; /**< which field is first */
86 unsigned int i_nb_fields
; /**< # of displayed fields */
87 void * context
; /**< video format-specific data pointer,
88 * must point to a (void (*)(void*)) pointer to free the context */
91 /** Private data - the video output plugin might want to put stuff here to
92 * keep track of the picture */
93 picture_sys_t
* p_sys
;
95 /** Next picture in a FIFO a pictures */
96 struct picture_t
*p_next
;
100 * This function will create a new picture.
101 * The picture created will implement a default release management compatible
102 * with picture_Hold and picture_Release. This default management will release
103 * p_sys, gc.p_sys fields if non NULL.
105 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
;
108 * This function will create a new picture using the given format.
110 * When possible, it is preferred to use this function over picture_New
111 * as more information about the format is kept.
113 VLC_API picture_t
* picture_NewFromFormat( const video_format_t
*p_fmt
) VLC_USED
;
116 * Resource for a picture.
120 picture_sys_t
*p_sys
;
121 void (*pf_destroy
)(picture_t
*);
124 * XXX all fields MUST be set to the right value.
128 uint8_t *p_pixels
; /**< Start of the plane's data */
129 int i_lines
; /**< Number of lines, including margins */
130 int i_pitch
; /**< Number of bytes in a line, including margins */
131 } p
[PICTURE_PLANE_MAX
];
133 } picture_resource_t
;
136 * This function will create a new picture using the provided resource.
138 * If the resource is NULL then a plain picture_NewFromFormat is returned.
140 VLC_API picture_t
* picture_NewFromResource( const video_format_t
*, const picture_resource_t
* ) VLC_USED
;
143 * This function will increase the picture reference count.
144 * It will not have any effect on picture obtained from vout
146 * It returns the given picture for convenience.
148 VLC_API picture_t
*picture_Hold( picture_t
*p_picture
);
151 * This function will release a picture.
152 * It will not have any effect on picture obtained from vout
154 VLC_API
void picture_Release( picture_t
*p_picture
);
157 * This function will return true if you are not the only owner of the
160 * It is only valid if it is created using picture_New.
162 VLC_API
bool picture_IsReferenced( picture_t
*p_picture
);
165 * This function will copy all picture dynamic properties.
167 VLC_API
void picture_CopyProperties( picture_t
*p_dst
, const picture_t
*p_src
);
170 * This function will reset a picture information (properties and quantizers).
171 * It is sometimes useful for reusing pictures (like from a pool).
173 VLC_API
void picture_Reset( picture_t
* );
176 * This function will copy the picture pixels.
177 * You can safely copy between pictures that do not have the same size,
178 * only the compatible(smaller) part will be copied.
180 VLC_API
void picture_CopyPixels( picture_t
*p_dst
, const picture_t
*p_src
);
181 VLC_API
void plane_CopyPixels( plane_t
*p_dst
, const plane_t
*p_src
);
184 * This function will copy both picture dynamic properties and pixels.
185 * You have to notice that sometime a simple picture_Hold may do what
186 * you want without the copy overhead.
187 * Provided for convenience.
189 * \param p_dst pointer to the destination picture.
190 * \param p_src pointer to the source picture.
192 VLC_API
void picture_Copy( picture_t
*p_dst
, const picture_t
*p_src
);
195 * This function will export a picture to an encoded bitstream.
197 * pp_image will contain the encoded bitstream in psz_format format.
199 * p_fmt can be NULL otherwise it will be set with the format used for the
200 * picture before encoding.
202 * i_override_width/height allow to override the width and/or the height of the
203 * picture to be encoded:
204 * - if strictly lower than 0, the original dimension will be used.
205 * - if equal to 0, it will be deduced from the other dimension which must be
207 * - if strictly higher than 0, it will override the dimension.
208 * If at most one of them is > 0 then the picture aspect ratio will be kept.
210 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
);
213 * This function will setup all fields of a picture_t without allocating any
215 * XXX The memory must already be initialized.
216 * It does not need to be released.
218 * It will return VLC_EGENERIC if the core does not understand the requested
221 * It can be useful to get the properties of planes.
223 VLC_API
int picture_Setup( picture_t
*, const video_format_t
* );
226 /*****************************************************************************
227 * Shortcuts to access image components
228 *****************************************************************************/
240 #define Y_PIXELS p[Y_PLANE].p_pixels
241 #define Y_PITCH p[Y_PLANE].i_pitch
242 #define U_PIXELS p[U_PLANE].p_pixels
243 #define U_PITCH p[U_PLANE].i_pitch
244 #define V_PIXELS p[V_PLANE].p_pixels
245 #define V_PITCH p[V_PLANE].i_pitch
246 #define A_PIXELS p[A_PLANE].p_pixels
247 #define A_PITCH p[A_PLANE].i_pitch
251 #endif /* VLC_PICTURE_H */