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 #include <stdatomic.h>
34 using std::atomic_uintptr_t
;
35 using std::memory_order_relaxed
;
36 using std::memory_order_release
;
41 * This file defines picture structures and functions in vlc
46 /** Description of a planar graphic field */
47 typedef struct plane_t
49 uint8_t *p_pixels
; /**< Start of the plane's data */
51 /* Variables used for fast memcpy operations */
52 int i_lines
; /**< Number of lines, including margins */
53 int i_pitch
; /**< Number of bytes in a line, including margins */
55 /** Size of a macropixel, defaults to 1 */
58 /* Variables used for pictures with margins */
59 int i_visible_lines
; /**< How many visible lines are there? */
60 int i_visible_pitch
; /**< How many visible pixels are there? */
65 * Maximum number of plane for a picture
67 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
69 typedef struct picture_context_t
71 void (*destroy
)(struct picture_context_t
*);
72 struct picture_context_t
*(*copy
)(struct picture_context_t
*);
75 typedef struct picture_buffer_t
83 typedef struct vlc_video_context vlc_video_context
;
91 * The properties of the picture
93 video_frame_format_t format
;
95 plane_t p
[PICTURE_PLANE_MAX
]; /**< description of the planes */
96 int i_planes
; /**< number of allocated planes */
98 /** \name Picture management properties
99 * These properties can be modified using the video output thread API,
100 * but should never be written directly */
102 vlc_tick_t date
; /**< display date */
107 /** \name Picture dynamic properties
108 * Those properties can be changed by the decoder
111 bool b_progressive
; /**< is it a progressive frame? */
112 bool b_top_field_first
; /**< which field is first */
113 unsigned int i_nb_fields
; /**< number of displayed fields */
114 picture_context_t
*context
; /**< video format-specific data pointer */
117 /** Private data - the video output plugin might want to put stuff here to
118 * keep track of the picture */
121 /** Next picture in a FIFO a pictures */
122 struct picture_t
*p_next
;
124 atomic_uintptr_t refs
;
128 * This function will create a new picture.
129 * The picture created will implement a default release management compatible
130 * with picture_Hold and picture_Release. This default management will release
131 * p_sys, gc.p_sys fields if non NULL.
133 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
;
136 * This function will create a new picture using the given format.
138 * When possible, it is preferred to use this function over picture_New
139 * as more information about the format is kept.
141 VLC_API picture_t
* picture_NewFromFormat( const video_format_t
*p_fmt
) VLC_USED
;
144 * Resource for a picture.
149 void (*pf_destroy
)(picture_t
*);
152 * XXX all fields MUST be set to the right value.
156 uint8_t *p_pixels
; /**< Start of the plane's data */
157 int i_lines
; /**< Number of lines, including margins */
158 int i_pitch
; /**< Number of bytes in a line, including margins */
159 } p
[PICTURE_PLANE_MAX
];
161 } picture_resource_t
;
164 * This function will create a new picture using the provided resource.
166 * If the resource is NULL then a plain picture_NewFromFormat is returned.
168 VLC_API picture_t
* picture_NewFromResource( const video_format_t
*, const picture_resource_t
* ) VLC_USED
;
171 * Destroys a picture without references.
173 * This function destroys a picture with zero references left.
174 * Never call this function directly. Use picture_Release() instead.
176 VLC_API
void picture_Destroy(picture_t
*picture
);
179 * Increments the picture reference count.
183 static inline picture_t
*picture_Hold(picture_t
*picture
)
185 atomic_fetch_add_explicit(&picture
->refs
, (uintptr_t)1,
186 memory_order_relaxed
);
191 * Decrements the picture reference count.
193 * If the reference count reaches zero, the picture is destroyed. If it was
194 * allocated from a pool, the underlying picture buffer will be returned to the
195 * pool. Otherwise, the picture buffer will be freed.
197 static inline void picture_Release(picture_t
*picture
)
199 uintptr_t refs
= atomic_fetch_sub_explicit(&picture
->refs
, (uintptr_t)1,
200 memory_order_release
);
201 vlc_assert(refs
> 0);
203 picture_Destroy(picture
);
207 * This function will copy all picture dynamic properties.
209 VLC_API
void picture_CopyProperties( picture_t
*p_dst
, const picture_t
*p_src
);
212 * This function will reset a picture information (properties and quantizers).
213 * It is sometimes useful for reusing pictures (like from a pool).
215 VLC_API
void picture_Reset( picture_t
* );
218 * This function will copy the picture pixels.
219 * You can safely copy between pictures that do not have the same size,
220 * only the compatible(smaller) part will be copied.
222 VLC_API
void picture_CopyPixels( picture_t
*p_dst
, const picture_t
*p_src
);
223 VLC_API
void plane_CopyPixels( plane_t
*p_dst
, const plane_t
*p_src
);
226 * This function will copy both picture dynamic properties and pixels.
227 * You have to notice that sometime a simple picture_Hold may do what
228 * you want without the copy overhead.
229 * Provided for convenience.
231 * \param p_dst pointer to the destination picture.
232 * \param p_src pointer to the source picture.
234 VLC_API
void picture_Copy( picture_t
*p_dst
, const picture_t
*p_src
);
237 * Perform a shallow picture copy
239 * This function makes a shallow copy of an existing picture. The same planes
240 * and resources will be used, and the cloned picture reference count will be
243 * \return A clone picture on success, NULL on error.
245 VLC_API picture_t
*picture_Clone(picture_t
*pic
);
248 * This function will export a picture to an encoded bitstream.
250 * pp_image will contain the encoded bitstream in psz_format format.
252 * p_fmt can be NULL otherwise it will be set with the format used for the
253 * picture before encoding.
255 * i_override_width/height allow to override the width and/or the height of the
256 * picture to be encoded:
257 * - if strictly lower than 0, the original dimension will be used.
258 * - if equal to 0, it will be deduced from the other dimension which must be
260 * - if strictly higher than 0, it will override the dimension.
261 * If at most one of them is > 0 then the picture aspect ratio will be kept.
263 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
);
266 * This function will setup all fields of a picture_t without allocating any
268 * XXX The memory must already be initialized.
269 * It does not need to be released.
271 * It will return VLC_EGENERIC if the core does not understand the requested
274 * It can be useful to get the properties of planes.
276 VLC_API
int picture_Setup( picture_t
*, const video_format_t
* );
279 /*****************************************************************************
280 * Shortcuts to access image components
281 *****************************************************************************/
293 #define Y_PIXELS p[Y_PLANE].p_pixels
294 #define Y_PITCH p[Y_PLANE].i_pitch
295 #define U_PIXELS p[U_PLANE].p_pixels
296 #define U_PITCH p[U_PLANE].i_pitch
297 #define V_PIXELS p[V_PLANE].p_pixels
298 #define V_PITCH p[V_PLANE].i_pitch
299 #define A_PIXELS p[A_PLANE].p_pixels
300 #define A_PITCH p[A_PLANE].i_pitch
303 * Swap UV planes of a Tri Planars picture.
305 * It just swap the planes information without doing any copy.
307 static inline void picture_SwapUV(picture_t
*picture
)
309 vlc_assert(picture
->i_planes
== 3);
311 plane_t tmp_plane
= picture
->p
[U_PLANE
];
312 picture
->p
[U_PLANE
] = picture
->p
[V_PLANE
];
313 picture
->p
[V_PLANE
] = tmp_plane
;
318 #endif /* VLC_PICTURE_H */