]> git.sesse.net Git - vlc/blob - include/video.h
* ./plugins/chroma/i420_rgb8.c: plain C 8 bpp transformation.
[vlc] / include / video.h
1 /*****************************************************************************
2  * video.h: common video definitions
3  * This header is required by all modules which have to handle pictures. It
4  * includes all common video types and constants.
5  *****************************************************************************
6  * Copyright (C) 1999, 2000 VideoLAN
7  * $Id: video.h,v 1.47 2002/03/17 17:00:38 sam Exp $
8  *
9  * Authors: Vincent Seguin <seguin@via.ecp.fr>
10  *
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.
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 General Public License for more details.
20  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 /*****************************************************************************
27  * plane_t: description of a planar graphic field
28  *****************************************************************************/
29 typedef struct plane_s
30 {
31     u8 *p_pixels;                               /* Start of the plane's data */
32
33     /* Variables used for fast memcpy operations */
34     int i_lines;                                          /* Number of lines */
35     int i_pitch;             /* Number of bytes in a line, including margins */
36
37     /* Size of a macropixel, defaults to 1 */
38     int i_pixel_bytes;
39
40     /* Is there a margin ? defaults to no */
41     boolean_t b_margin;
42
43     /* Variables used for pictures with margins */
44     int i_visible_bytes;                 /* How many real pixels are there ? */
45     boolean_t b_hidden;           /* Are we allowed to write to the margin ? */
46
47 } plane_t;
48
49 /*****************************************************************************
50  * picture_t: video picture
51  *****************************************************************************
52  * Any picture destined to be displayed by a video output thread should be
53  * stored in this structure from it's creation to it's effective display.
54  * Picture type and flags should only be modified by the output thread. Note
55  * that an empty picture MUST have its flags set to 0.
56  *****************************************************************************/
57 typedef struct picture_s
58 {
59     /* Picture data - data can always be freely modified, but p_data may
60      * NEVER be modified. A direct buffer can be handled as the plugin
61      * wishes, it can even swap p_pixels buffers. */
62     u8             *p_data;
63     plane_t         p[ VOUT_MAX_PLANES ];       /* description of the planes */
64     int             i_planes;                  /* number of allocated planes */
65
66     /* Type and flags - should NOT be modified except by the vout thread */
67     int             i_status;                               /* picture flags */
68     int             i_type;                  /* is picture a direct buffer ? */
69     int             i_matrix_coefficients;     /* in YUV type, encoding type */
70
71     /* Picture management properties - these properties can be modified using
72      * the video output thread API, but should never be written directly */
73     int             i_refcount;                    /* link reference counter */
74     mtime_t         date;                                    /* display date */
75
76     /* Picture dynamic properties - those properties can be changed by the
77      * decoder */
78     boolean_t       b_progressive;            /* is it a progressive frame ? */
79     boolean_t       b_repeat_first_field;                         /* RFF bit */
80     boolean_t       b_top_field_first;               /* which field is first */
81
82     /* The picture heap we are attached to */
83     struct picture_heap_s* p_heap;
84
85     /* Private data - the video output plugin might want to put stuff here to
86      * keep track of the picture */
87     struct picture_sys_s *p_sys;
88
89 } picture_t;
90
91 /*****************************************************************************
92  * picture_heap_t: video picture heap, either render (to store pictures used
93  * by the decoder) or output (to store pictures displayed by the vout plugin)
94  *****************************************************************************/
95 typedef struct picture_heap_s
96 {
97     int i_pictures;                                     /* current heap size */
98
99     /* Picture static properties - those properties are fixed at initialization
100      * and should NOT be modified */
101     int i_width;                                            /* picture width */
102     int i_height;                                          /* picture height */
103     u32 i_chroma;                                          /* picture chroma */
104     int i_aspect;                                            /* aspect ratio */
105
106     /* Real pictures */
107     picture_t*      pp_picture[VOUT_MAX_PICTURES];               /* pictures */
108
109     /* Stuff used for truecolor RGB planes */
110     int i_rmask, i_rrshift, i_lrshift;
111     int i_gmask, i_rgshift, i_lgshift;
112     int i_bmask, i_rbshift, i_lbshift;
113
114     /* Stuff used for palettized RGB planes */
115     void (* pf_setpalette) ( struct vout_thread_s *, u16 *, u16 *, u16 * );
116
117 } picture_heap_t;
118
119 /* RGB2PIXEL: assemble RGB components to a pixel value, returns a u32 */
120 #define RGB2PIXEL( p_vout, i_r, i_g, i_b )                                    \
121     (((((u32)i_r) >> p_vout->output.i_rrshift) << p_vout->output.i_lrshift) | \
122      ((((u32)i_g) >> p_vout->output.i_rgshift) << p_vout->output.i_lgshift) | \
123      ((((u32)i_b) >> p_vout->output.i_rbshift) << p_vout->output.i_lbshift))
124
125 /*****************************************************************************
126  * Flags used to describe the status of a picture
127  *****************************************************************************/
128
129 /* Picture type */
130 #define EMPTY_PICTURE           0                            /* empty buffer */
131 #define MEMORY_PICTURE          100                 /* heap-allocated buffer */
132 #define DIRECT_PICTURE          200                         /* direct buffer */
133
134 /* Picture status */
135 #define FREE_PICTURE            0                  /* free and not allocated */
136 #define RESERVED_PICTURE        1                  /* allocated and reserved */
137 #define RESERVED_DATED_PICTURE  2              /* waiting for DisplayPicture */
138 #define RESERVED_DISP_PICTURE   3               /* waiting for a DatePicture */
139 #define READY_PICTURE           4                       /* ready for display */
140 #define DISPLAYED_PICTURE       5            /* been displayed but is linked */
141 #define DESTROYED_PICTURE       6              /* allocated but no more used */
142
143 /*****************************************************************************
144  * Flags used to describe picture format - see http://www.webartz.com/fourcc/
145  *****************************************************************************/
146
147 /* Packed RGB formats */
148 #define FOURCC_BI_RGB        0x00000000                      /* RGB for 8bpp */
149 #define FOURCC_RGB2          0x32424752                  /* alias for BI_RGB */
150 #define FOURCC_BI_BITFIELDS  0x00000003            /* RGB, for 16, 24, 32bpp */
151 #define FOURCC_RV15          0x35315652    /* RGB 15bpp, 0x1f, 0x7e0, 0xf800 */
152 #define FOURCC_RV16          0x36315652    /* RGB 16bpp, 0x1f, 0x3e0, 0x7c00 */
153 #define FOURCC_RV24          0x34325652 /* RGB 24bpp, 0xff, 0xff00, 0xff0000 */
154 #define FOURCC_RV32          0x32335652 /* RGB 32bpp, 0xff, 0xff00, 0xff0000 */
155
156 /* Planar YUV formats */
157 #define FOURCC_I420          0x30323449               /* Planar 4:2:0, Y:U:V */
158 #define FOURCC_IYUV          0x56555949                    /* alias for I420 */
159 #define FOURCC_YV12          0x32315659               /* Planar 4:2:0, Y:V:U */
160
161 /* Packed YUV formats */
162 #define FOURCC_IUYV          0x56595549 /* Packed 4:2:2, U:Y:V:Y, interlaced */
163 #define FOURCC_UYVY          0x59565955             /* Packed 4:2:2, U:Y:V:Y */
164 #define FOURCC_UYNV          0x564e5955                    /* alias for UYVY */
165 #define FOURCC_Y422          0x32323459                    /* alias for UYVY */
166 #define FOURCC_cyuv          0x76757963   /* Packed 4:2:2, U:Y:V:Y, reverted */
167 #define FOURCC_YUY2          0x32595559             /* Packed 4:2:2, Y:U:Y:V */
168 #define FOURCC_YUNV          0x564e5559                    /* alias for YUY2 */
169 #define FOURCC_YVYU          0x55585659             /* Packed 4:2:2, Y:V:Y:U */
170 #define FOURCC_Y211          0x31313259             /* Packed 2:1:1, Y:U:Y:V */
171
172 /* Custom formats which we use but which don't exist in the fourcc database */
173 #define FOURCC_YMGA          0x41474d59  /* Planar Y, packed UV, from Matrox */
174 #define FOURCC_I422          0x32323449               /* Planar 4:2:2, Y:U:V */
175 #define FOURCC_I444          0x34343449               /* Planar 4:4:4, Y:U:V */
176
177 /* Plane indices */
178 #define Y_PLANE      0
179 #define U_PLANE      1
180 #define V_PLANE      2
181
182 /* Shortcuts */
183 #define Y_PIXELS     p[Y_PLANE].p_pixels
184 #define U_PIXELS     p[U_PLANE].p_pixels
185 #define V_PIXELS     p[V_PLANE].p_pixels
186
187 static __inline__ int vout_ChromaCmp( u32 i_chroma, u32 i_amorhc )
188 {
189     /* If they are the same, they are the same ! */
190     if( i_chroma == i_amorhc )
191     {
192         return 1;
193     }
194
195     /* Check for equivalence classes */
196     switch( i_chroma )
197     {
198         case FOURCC_I420:
199         case FOURCC_IYUV:
200         case FOURCC_YV12:
201             switch( i_amorhc )
202             {
203                 case FOURCC_I420:
204                 case FOURCC_IYUV:
205                 case FOURCC_YV12:
206                     return 1;
207
208                 default:
209                     return 0;
210             }
211
212         case FOURCC_UYVY:
213         case FOURCC_UYNV:
214         case FOURCC_Y422:
215             switch( i_amorhc )
216             {
217                 case FOURCC_UYVY:
218                 case FOURCC_UYNV:
219                 case FOURCC_Y422:
220                     return 1;
221
222                 default:
223                     return 0;
224             }
225
226         case FOURCC_YUY2:
227         case FOURCC_YUNV:
228             switch( i_amorhc )
229             {
230                 case FOURCC_YUY2:
231                 case FOURCC_YUNV:
232                     return 1;
233
234                 default:
235                     return 0;
236             }
237
238         default:
239             return 0;
240     }
241 }
242
243 /*****************************************************************************
244  * vout_CopyPicture: copy a picture to another one
245  *****************************************************************************
246  * This function takes advantage of the image format, and reduces the
247  * number of calls to memcpy() to the minimum. Source and destination
248  * images must have same width, height, and chroma.
249  *****************************************************************************/
250 static __inline__ void vout_CopyPicture( picture_t *p_src, picture_t *p_dest )
251 {
252     int i;
253
254     for( i = 0; i < p_src->i_planes ; i++ )
255     {
256         if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
257         {
258             if( p_src->p[i].b_margin )
259             {
260                 /* If p_src->b_margin is set, p_dest->b_margin must be set */
261                 if( p_dest->p[i].b_hidden )
262                 {
263                     /* There are margins, but they are hidden : perfect ! */
264                     FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
265                                  p_src->p[i].i_pitch * p_src->p[i].i_lines );
266                     continue;
267                 }
268                 else
269                 {
270                     /* We can't directly copy the margin. Too bad. */
271                 }
272             }
273             else
274             {
275                 /* Same pitch, no margins : perfect ! */
276                 FAST_MEMCPY( p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
277                              p_src->p[i].i_pitch * p_src->p[i].i_lines );
278                 continue;
279             }
280         }
281         else
282         {
283             /* Pitch values are different */
284         }
285
286         /* We need to proceed line by line */
287         {
288             u8 *p_in = p_src->p[i].p_pixels, *p_out = p_dest->p[i].p_pixels;
289             int i_line;
290
291             for( i_line = p_src->p[i].i_lines; i_line--; )
292             {
293                 FAST_MEMCPY( p_out, p_in, p_src->p[i].i_visible_bytes );
294                 p_in += p_src->p[i].i_pitch;
295                 p_out += p_dest->p[i].i_pitch;
296             }
297         }
298     }
299 }
300
301 /*****************************************************************************
302  * subpicture_t: video subtitle
303  *****************************************************************************
304  * Any subtitle destined to be displayed by a video output thread should
305  * be stored in this structure from it's creation to it's effective display.
306  * Subtitle type and flags should only be modified by the output thread. Note
307  * that an empty subtitle MUST have its flags set to 0.
308  *****************************************************************************/
309 typedef struct subpicture_s
310 {
311     /* Type and flags - should NOT be modified except by the vout thread */
312     int             i_type;                                          /* type */
313     int             i_status;                                       /* flags */
314     int             i_size;                                     /* data size */
315     struct subpicture_s *   p_next;         /* next subtitle to be displayed */
316
317     /* Date properties */
318     mtime_t         i_start;                    /* beginning of display date */
319     mtime_t         i_stop;                           /* end of display date */
320     boolean_t       b_ephemer;             /* does the subtitle have a TTL ? */
321
322     /* Display properties - these properties are only indicative and may be
323      * changed by the video output thread, or simply ignored depending of the
324      * subtitle type. */
325     int             i_x;                   /* offset from alignment position */
326     int             i_y;                   /* offset from alignment position */
327     int             i_width;                                /* picture width */
328     int             i_height;                              /* picture height */
329
330 #if 0
331     /* Additionnal properties depending of the subpicture type */
332     union
333     {
334         /* Text subpictures properties - text is stored in data area, in ASCIIZ
335          * format */
336         struct
337         {
338             p_vout_font_t       p_font;            /* font, NULL for default */
339             int                 i_style;                       /* text style */
340             u32                 i_char_color;             /* character color */
341             u32                 i_border_color;              /* border color */
342             u32                 i_bg_color;              /* background color */
343         } text;
344     } type;
345 #endif
346
347     /* The subpicture rendering routine */
348     void ( *pf_render ) ( const struct vout_thread_s *, picture_t *,
349                           const struct subpicture_s * );
350
351     /* Private data - the subtitle plugin might want to put stuff here to
352      * keep track of the subpicture */
353     struct subpicture_sys_s *p_sys;                       /* subpicture data */
354
355 } subpicture_t;
356
357 /* Subpicture type */
358 #define EMPTY_SUBPICTURE       0     /* subtitle slot is empty and available */
359 #define MEMORY_SUBPICTURE      100            /* subpicture stored in memory */
360
361 /* Subpicture status */
362 #define FREE_SUBPICTURE        0                   /* free and not allocated */
363 #define RESERVED_SUBPICTURE    1                   /* allocated and reserved */
364 #define READY_SUBPICTURE       2                        /* ready for display */
365 #define DESTROYED_SUBPICTURE   3           /* allocated but not used anymore */
366