]> git.sesse.net Git - vlc/blob - plugins/yuv/video_yuv16.c
Bon, puisque �a semble commiter sous BeOS, je commite.
[vlc] / plugins / yuv / video_yuv16.c
1 /*****************************************************************************
2  * video_yuv16.c: YUV transformation functions for 16bpp
3  * Provides functions to perform the YUV conversion. The functions provided here
4  * are a complete and portable C implementation, and may be replaced in certain
5  * case by optimized functions.
6  *****************************************************************************
7  * Copyright (C) 1999, 2000 VideoLAN
8  *
9  * Authors:
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 GNU
19  * General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this program; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *****************************************************************************/
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <math.h>                                            /* exp(), pow() */
33 #include <errno.h>                                                 /* ENOMEM */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36
37 #include "config.h"
38 #include "common.h"
39 #include "threads.h"
40 #include "mtime.h"
41 #include "plugins.h"
42 #include "video.h"
43 #include "video_output.h"
44 #include "video_yuv.h"
45 #include "video_yuv_macros.h"
46
47 #include "intf_msg.h"
48
49 /*****************************************************************************
50  * ConvertY4Gray16: grayscale YUV 4:x:x to RGB 2 Bpp
51  *****************************************************************************/
52 void ConvertY4Gray16( YUV_ARGS_16BPP )
53 {
54     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
55     int         i_vertical_scaling;                 /* vertical scaling type */
56     int         i_x, i_y;                 /* horizontal and vertical indexes */
57     int         i_scale_count;                       /* scale modulo counter */
58     int         i_chroma_width;                    /* chroma width, not used */
59     u16 *       p_gray;                             /* base conversion table */
60     u16 *       p_pic_start;       /* beginning of the current line for copy */
61     u16 *       p_buffer_start;                   /* conversion buffer start */
62     u16 *       p_buffer;                       /* conversion buffer pointer */
63     int *       p_offset_start;                        /* offset array start */
64     int *       p_offset;                            /* offset array pointer */
65
66     /*
67      * Initialize some values  - i_pic_line_width will store the line skip
68      */
69     i_pic_line_width -= i_pic_width;
70     p_gray =            p_vout->yuv.yuv.p_gray16;
71     p_buffer_start =    p_vout->yuv.p_buffer;
72     p_offset_start =    p_vout->yuv.p_offset;
73     SetOffset( i_width, i_height, i_pic_width, i_pic_height,
74                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start );
75
76     /*
77      * Perform conversion
78      */
79     i_scale_count = i_pic_height;
80     for( i_y = 0; i_y < i_height; i_y++ )
81     {
82         /* Mark beginnning of line for possible later line copy, and initialize
83          * buffer */
84         p_pic_start =   p_pic;
85         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
86
87         /* Do YUV conversion to buffer - YUV picture is always formed of 16
88          * pixels wide blocks */
89         for( i_x = i_width / 16; i_x--;  )
90         {
91             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
92             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
93             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
94             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
95             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
96             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
97             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
98             *p_buffer++ = p_gray[ *p_y++ ]; *p_buffer++ = p_gray[ *p_y++ ];
99         }
100
101         /* Do horizontal and vertical scaling */
102         SCALE_WIDTH;
103         SCALE_HEIGHT(400, 2);
104     }
105 }
106
107 /*****************************************************************************
108  * ConvertYUV420RGB16: color YUV 4:2:0 to RGB 2 Bpp
109  *****************************************************************************/
110 void ConvertYUV420RGB16( YUV_ARGS_16BPP )
111 {
112     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
113     int         i_vertical_scaling;                 /* vertical scaling type */
114     int         i_x, i_y;                 /* horizontal and vertical indexes */
115     int         i_scale_count;                       /* scale modulo counter */
116     int         i_uval, i_vval;                           /* U and V samples */
117     int         i_red, i_green, i_blue;          /* U and V modified samples */
118     int         i_chroma_width;                              /* chroma width */
119     u16 *       p_yuv;                              /* base conversion table */
120     u16 *       p_ybase;                     /* Y dependant conversion table */
121     u16 *       p_pic_start;       /* beginning of the current line for copy */
122     u16 *       p_buffer_start;                   /* conversion buffer start */
123     u16 *       p_buffer;                       /* conversion buffer pointer */
124     int *       p_offset_start;                        /* offset array start */
125     int *       p_offset;                            /* offset array pointer */
126
127     /*
128      * Initialize some values  - i_pic_line_width will store the line skip
129      */
130     i_pic_line_width -= i_pic_width;
131     i_chroma_width =    i_width / 2;
132     p_yuv =             p_vout->yuv.yuv.p_rgb16;
133     p_buffer_start =    p_vout->yuv.p_buffer;
134     p_offset_start =    p_vout->yuv.p_offset;
135     SetOffset( i_width, i_height, i_pic_width, i_pic_height,
136                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start );
137
138     /*
139      * Perform conversion
140      */
141     i_scale_count = i_pic_height;
142     for( i_y = 0; i_y < i_height; i_y++ )
143     {
144         /* Mark beginnning of line for possible later line copy, and initialize
145          * buffer */
146         p_pic_start =   p_pic;
147         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
148
149         /* Do YUV conversion to buffer - YUV picture is always formed of 16
150          * pixels wide blocks */
151         for( i_x = i_width / 16; i_x--;  )
152         {
153             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
154             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
155             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
156             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
157             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
158             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
159             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
160             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
161         }
162
163         /* Do horizontal and vertical scaling */
164         SCALE_WIDTH;
165         SCALE_HEIGHT(420, 2);
166     }
167 }
168
169 /*****************************************************************************
170  * ConvertYUV422RGB16: color YUV 4:2:2 to RGB 2 Bpp
171  *****************************************************************************/
172 void ConvertYUV422RGB16( YUV_ARGS_16BPP )
173 {
174     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
175     int         i_vertical_scaling;                 /* vertical scaling type */
176     int         i_x, i_y;                 /* horizontal and vertical indexes */
177     int         i_scale_count;                       /* scale modulo counter */
178     int         i_uval, i_vval;                           /* U and V samples */
179     int         i_red, i_green, i_blue;          /* U and V modified samples */
180     int         i_chroma_width;                              /* chroma width */
181     u16 *       p_yuv;                              /* base conversion table */
182     u16 *       p_ybase;                     /* Y dependant conversion table */
183     u16 *       p_pic_start;       /* beginning of the current line for copy */
184     u16 *       p_buffer_start;                   /* conversion buffer start */
185     u16 *       p_buffer;                       /* conversion buffer pointer */
186     int *       p_offset_start;                        /* offset array start */
187     int *       p_offset;                            /* offset array pointer */
188
189     /*
190      * Initialize some values  - i_pic_line_width will store the line skip
191      */
192     i_pic_line_width -= i_pic_width;
193     i_chroma_width =    i_width / 2;
194     p_yuv =             p_vout->yuv.yuv.p_rgb16;
195     p_buffer_start =    p_vout->yuv.p_buffer;
196     p_offset_start =    p_vout->yuv.p_offset;
197     SetOffset( i_width, i_height, i_pic_width, i_pic_height,
198                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start );
199
200     /*
201      * Perform conversion
202      */
203     i_scale_count = i_pic_height;
204     for( i_y = 0; i_y < i_height; i_y++ )
205     {
206         /* Mark beginnning of line for possible later line copy, and initialize
207          * buffer */
208         p_pic_start =   p_pic;
209         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
210
211         /* Do YUV conversion to buffer - YUV picture is always formed of 16
212          * pixels wide blocks */
213         for( i_x = i_width / 16; i_x--;  )
214         {
215             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
216             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
217             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
218             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
219             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
220             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
221             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
222             CONVERT_YUV_PIXEL(2);  CONVERT_Y_PIXEL(2);
223         }
224
225         /* Do horizontal and vertical scaling */
226         SCALE_WIDTH;
227         SCALE_HEIGHT(422, 2);
228     }
229 }
230
231 /*****************************************************************************
232  * ConvertYUV444RGB16: color YUV 4:4:4 to RGB 2 Bpp
233  *****************************************************************************/
234 void ConvertYUV444RGB16( YUV_ARGS_16BPP )
235 {
236     boolean_t   b_horizontal_scaling;             /* horizontal scaling type */
237     int         i_vertical_scaling;                 /* vertical scaling type */
238     int         i_x, i_y;                 /* horizontal and vertical indexes */
239     int         i_scale_count;                       /* scale modulo counter */
240     int         i_uval, i_vval;                           /* U and V samples */
241     int         i_red, i_green, i_blue;          /* U and V modified samples */
242     int         i_chroma_width;                    /* chroma width, not used */
243     u16 *       p_yuv;                              /* base conversion table */
244     u16 *       p_ybase;                     /* Y dependant conversion table */
245     u16 *       p_pic_start;       /* beginning of the current line for copy */
246     u16 *       p_buffer_start;                   /* conversion buffer start */
247     u16 *       p_buffer;                       /* conversion buffer pointer */
248     int *       p_offset_start;                        /* offset array start */
249     int *       p_offset;                            /* offset array pointer */
250
251     /*
252      * Initialize some values  - i_pic_line_width will store the line skip
253      */
254     i_pic_line_width -= i_pic_width;
255     p_yuv =             p_vout->yuv.yuv.p_rgb16;
256     p_buffer_start =    p_vout->yuv.p_buffer;
257     p_offset_start =    p_vout->yuv.p_offset;
258     SetOffset( i_width, i_height, i_pic_width, i_pic_height,
259                &b_horizontal_scaling, &i_vertical_scaling, p_offset_start );
260
261     /*
262      * Perform conversion
263      */
264     i_scale_count = i_pic_height;
265     for( i_y = 0; i_y < i_height; i_y++ )
266     {
267         /* Mark beginnning of line for possible later line copy, and initialize
268          * buffer */
269         p_pic_start =   p_pic;
270         p_buffer =      b_horizontal_scaling ? p_buffer_start : p_pic;
271
272         /* Do YUV conversion to buffer - YUV picture is always formed of 16
273          * pixels wide blocks */
274         for( i_x = i_width / 16; i_x--;  )
275         {
276             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
277             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
278             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
279             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
280             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
281             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
282             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
283             CONVERT_YUV_PIXEL(2);  CONVERT_YUV_PIXEL(2);
284         }
285
286         /* Do horizontal and vertical scaling */
287         SCALE_WIDTH;
288         SCALE_HEIGHT(444, 2);
289     }
290 }
291