VLC  3.0.21
vlc_picture.h
Go to the documentation of this file.
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 
36 /** Description of a planar graphic field */
37 typedef struct plane_t
38 {
39  uint8_t *p_pixels; /**< Start of the plane's data */
40 
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 */
44 
45  /** Size of a macropixel, defaults to 1 */
47 
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 ? */
51 
52 } plane_t;
53 
54 /**
55  * Maximum number of plane for a picture
56  */
57 #define PICTURE_PLANE_MAX (VOUT_MAX_PLANES)
58 
59 typedef struct picture_context_t
60 {
61  void (*destroy)(struct picture_context_t *);
62  struct picture_context_t *(*copy)(struct picture_context_t *);
64 
65 /**
66  * Video picture
67  */
68 struct picture_t
69 {
70  /**
71  * The properties of the picture
72  */
74 
75  plane_t p[PICTURE_PLANE_MAX]; /**< description of the planes */
76  int i_planes; /**< number of allocated planes */
77 
78  /** \name Picture management properties
79  * These properties can be modified using the video output thread API,
80  * but should never be written directly */
81  /**@{*/
82  vlc_tick_t date; /**< display date */
83  bool b_force;
84  /**@}*/
85 
86  /** \name Picture dynamic properties
87  * Those properties can be changed by the decoder
88  * @{
89  */
90  bool b_progressive; /**< is it a progressive frame ? */
91  bool b_top_field_first; /**< which field is first */
92  unsigned int i_nb_fields; /**< # of displayed fields */
93  picture_context_t *context; /**< video format-specific data pointer */
94  /**@}*/
95 
96  /** Private data - the video output plugin might want to put stuff here to
97  * keep track of the picture */
99 
100  /** Next picture in a FIFO a pictures */
101  struct picture_t *p_next;
102 };
103 
104 /**
105  * This function will create a new picture.
106  * The picture created will implement a default release management compatible
107  * with picture_Hold and picture_Release. This default management will release
108  * p_sys, gc.p_sys fields if non NULL.
109  */
110 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;
111 
112 /**
113  * This function will create a new picture using the given format.
114  *
115  * When possible, it is preferred to use this function over picture_New
116  * as more information about the format is kept.
117  */
119 
120 /**
121  * Resource for a picture.
122  */
123 typedef struct
124 {
126  void (*pf_destroy)(picture_t *);
127 
128  /* Plane resources
129  * XXX all fields MUST be set to the right value.
130  */
131  struct
132  {
133  uint8_t *p_pixels; /**< Start of the plane's data */
134  int i_lines; /**< Number of lines, including margins */
135  int i_pitch; /**< Number of bytes in a line, including margins */
136  } p[PICTURE_PLANE_MAX];
137 
139 
140 /**
141  * This function will create a new picture using the provided resource.
142  *
143  * If the resource is NULL then a plain picture_NewFromFormat is returned.
144  */
146 
147 /**
148  * This function will increase the picture reference count.
149  * It will not have any effect on picture obtained from vout
150  *
151  * It returns the given picture for convenience.
152  */
153 VLC_API picture_t *picture_Hold( picture_t *p_picture );
154 
155 /**
156  * This function will release a picture.
157  * It will not have any effect on picture obtained from vout
158  */
159 VLC_API void picture_Release( picture_t *p_picture );
160 
161 /**
162  * This function will copy all picture dynamic properties.
163  */
164 VLC_API void picture_CopyProperties( picture_t *p_dst, const picture_t *p_src );
165 
166 /**
167  * This function will reset a picture information (properties and quantizers).
168  * It is sometimes useful for reusing pictures (like from a pool).
169  */
171 
172 /**
173  * This function will copy the picture pixels.
174  * You can safely copy between pictures that do not have the same size,
175  * only the compatible(smaller) part will be copied.
176  */
177 VLC_API void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src );
178 VLC_API void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src );
179 
180 /**
181  * This function will copy both picture dynamic properties and pixels.
182  * You have to notice that sometime a simple picture_Hold may do what
183  * you want without the copy overhead.
184  * Provided for convenience.
185  *
186  * \param p_dst pointer to the destination picture.
187  * \param p_src pointer to the source picture.
188  */
189 VLC_API void picture_Copy( picture_t *p_dst, const picture_t *p_src );
190 
191 /**
192  * Perform a shallow picture copy
193  *
194  * This function makes a shallow copy of an existing picture. The same planes
195  * and resources will be used, and the cloned picture reference count will be
196  * incremented.
197  *
198  * \return A clone picture on success, NULL on error.
199  */
201 
202 /**
203  * This function will export a picture to an encoded bitstream.
204  *
205  * pp_image will contain the encoded bitstream in psz_format format.
206  *
207  * p_fmt can be NULL otherwise it will be set with the format used for the
208  * picture before encoding.
209  *
210  * i_override_width/height allow to override the width and/or the height of the
211  * picture to be encoded:
212  * - if strictly lower than 0, the original dimension will be used.
213  * - if equal to 0, it will be deduced from the other dimension which must be
214  * different to 0.
215  * - if strictly higher than 0, it will override the dimension.
216  * If at most one of them is > 0 then the picture aspect ratio will be kept.
217  */
218 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 );
219 
220 /**
221  * This function will setup all fields of a picture_t without allocating any
222  * memory.
223  * XXX The memory must already be initialized.
224  * It does not need to be released.
225  *
226  * It will return VLC_EGENERIC if the core does not understand the requested
227  * format.
228  *
229  * It can be useful to get the properties of planes.
230  */
232 
233 
234 /*****************************************************************************
235  * Shortcuts to access image components
236  *****************************************************************************/
237 
238 /* Plane indices */
239 enum
240 {
241  Y_PLANE = 0,
242  U_PLANE = 1,
243  V_PLANE = 2,
244  A_PLANE = 3,
245 };
246 
247 /* Shortcuts */
248 #define Y_PIXELS p[Y_PLANE].p_pixels
249 #define Y_PITCH p[Y_PLANE].i_pitch
250 #define U_PIXELS p[U_PLANE].p_pixels
251 #define U_PITCH p[U_PLANE].i_pitch
252 #define V_PIXELS p[V_PLANE].p_pixels
253 #define V_PITCH p[V_PLANE].i_pitch
254 #define A_PIXELS p[A_PLANE].p_pixels
255 #define A_PITCH p[A_PLANE].i_pitch
256 
257 /**@}*/
258 
259 #endif /* VLC_PICTURE_H */
picture_CopyPixels
void picture_CopyPixels(picture_t *p_dst, const picture_t *p_src)
This function will copy the picture pixels.
Definition: picture.c:362
picture_t::b_progressive
bool b_progressive
is it a progressive frame ?
Definition: vlc_picture.h:90
picture_sys_t
struct picture_sys_t picture_sys_t
Definition: vlc_common.h:250
vlc_es.h
VLC_API
#define VLC_API
Definition: fourcc_gen.c:30
picture_t::format
video_frame_format_t format
The properties of the picture.
Definition: vlc_picture.h:73
plane_t::i_pixel_pitch
int i_pixel_pitch
Size of a macropixel, defaults to 1.
Definition: vlc_picture.h:46
picture_resource_t::i_lines
int i_lines
Number of lines, including margins.
Definition: vlc_picture.h:134
PICTURE_PLANE_MAX
#define PICTURE_PLANE_MAX
Maximum number of plane for a picture.
Definition: vlc_picture.h:57
vlc_common.h
picture_context_t::destroy
void(* destroy)(struct picture_context_t *)
Definition: vlc_picture.h:61
picture_t::i_nb_fields
unsigned int i_nb_fields
Definition: vlc_picture.h:92
plane_t
struct plane_t plane_t
Description of a planar graphic field.
vlc_tick_t
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_common.h:150
Y_PLANE
Definition: vlc_picture.h:241
picture_Clone
picture_t * picture_Clone(picture_t *pic)
Perform a shallow picture copy.
Definition: picture.c:387
video_format_t
video format description
Definition: vlc_es.h:325
picture_resource_t::p_sys
picture_sys_t * p_sys
Definition: vlc_picture.h:125
picture_resource_t
Resource for a picture.
Definition: vlc_picture.h:123
A_PLANE
Definition: vlc_picture.h:244
picture_t::date
vlc_tick_t date
display date
Definition: vlc_picture.h:82
picture_t::context
picture_context_t * context
video format-specific data pointer
Definition: vlc_picture.h:93
picture_Release
void picture_Release(picture_t *p_picture)
This function will release a picture.
Definition: picture.c:300
plane_t::i_visible_lines
int i_visible_lines
How many visible lines are there ?
Definition: vlc_picture.h:49
picture_t
Video picture.
Definition: vlc_picture.h:68
picture_Reset
void picture_Reset(picture_t *)
This function will reset a picture information (properties and quantizers).
Definition: picture.c:127
picture_t::p_next
struct picture_t * p_next
Next picture in a FIFO a pictures.
Definition: vlc_picture.h:101
plane_t::i_lines
int i_lines
Number of lines, including margins.
Definition: vlc_picture.h:42
picture_t::i_planes
int i_planes
number of allocated planes
Definition: vlc_picture.h:76
picture_context_t
struct picture_context_t picture_context_t
plane_t::i_pitch
int i_pitch
Number of bytes in a line, including margins.
Definition: vlc_picture.h:43
picture_Setup
int picture_Setup(picture_t *, const video_format_t *)
This function will setup all fields of a picture_t without allocating any memory.
picture_CopyProperties
void picture_CopyProperties(picture_t *p_dst, const picture_t *p_src)
This function will copy all picture dynamic properties.
Definition: picture.c:352
picture_t::b_top_field_first
bool b_top_field_first
which field is first
Definition: vlc_picture.h:91
picture_Hold
picture_t * picture_Hold(picture_t *p_picture)
This function will increase the picture reference count.
Definition: picture.c:290
picture_t::b_force
bool b_force
Definition: vlc_picture.h:83
picture_context_t
Definition: vlc_picture.h:59
picture_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)
This function will export a picture to an encoded bitstream.
Definition: picture.c:414
picture_NewFromFormat
picture_t * picture_NewFromFormat(const video_format_t *p_fmt)
This function will create a new picture using the given format.
Definition: picture.c:271
U_PLANE
Definition: vlc_picture.h:242
vlc_object_t
The main vlc_object_t structure.
Definition: vlc_objects.h:39
plane_t::i_visible_pitch
int i_visible_pitch
How many visible pixels are there ?
Definition: vlc_picture.h:50
picture_Copy
void picture_Copy(picture_t *p_dst, const picture_t *p_src)
This function will copy both picture dynamic properties and pixels.
Definition: picture.c:373
plane_t
Description of a planar graphic field.
Definition: vlc_picture.h:37
plane_t::p_pixels
uint8_t * p_pixels
Start of the plane's data.
Definition: vlc_picture.h:39
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:31
V_PLANE
Definition: vlc_picture.h:243
picture_t::p_sys
picture_sys_t * p_sys
Private data - the video output plugin might want to put stuff here to keep track of the picture.
Definition: vlc_picture.h:98
picture_NewFromResource
picture_t * picture_NewFromResource(const video_format_t *, const picture_resource_t *)
This function will create a new picture using the provided resource.
Definition: picture.c:207
picture_New
picture_t * picture_New(vlc_fourcc_t i_chroma, int i_width, int i_height, int i_sar_num, int i_sar_den)
This function will create a new picture.
Definition: picture.c:276
plane_CopyPixels
void plane_CopyPixels(plane_t *p_dst, const plane_t *p_src)
Definition: picture.c:317
picture_resource_t::p_pixels
uint8_t * p_pixels
Start of the plane's data.
Definition: vlc_picture.h:133
picture_resource_t::i_pitch
int i_pitch
Number of bytes in a line, including margins.
Definition: vlc_picture.h:135
picture_t::p
plane_t p[(5)]
description of the planes
Definition: vlc_picture.h:75
block_t
Definition: vlc_block.h:111
vlc_fourcc_t
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:32
p
#define p(t)