[cvs] / xvidcore / src / image / colorspace.c Repository:
ViewVC logotype

Diff of /xvidcore/src/image/colorspace.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3.2.2, Thu Nov 7 10:28:15 2002 UTC revision 1.6, Sun Nov 17 00:20:30 2002 UTC
# Line 1  Line 1 
1  /**************************************************************************  /*****************************************************************************
2   *   *
3   *      XVID MPEG-4 VIDEO CODEC   *      XVID MPEG-4 VIDEO CODEC
4   *      colorspace conversions   *  - colorspace conversion module -
5   *   *
6   *      This program is free software; you can redistribute it and/or modify   *  Copyright(C) 2002 Peter Ross <pross@xvid.org>
7   *      it under the terms of the GNU General Public License as published by   *               2002 Michael Militzer <isibaar@xvid.org>
8     *
9     *  This file is part of XviD, a free MPEG-4 video encoder/decoder
10     *
11     *  XviD is free software; you can redistribute it and/or modify it
12     *  under the terms of the GNU General Public License as published by
13   *      the Free Software Foundation; either version 2 of the License, or   *      the Free Software Foundation; either version 2 of the License, or
14   *      (at your option) any later version.   *      (at your option) any later version.
15   *   *
# Line 15  Line 20 
20   *   *
21   *      You should have received a copy of the GNU General Public License   *      You should have received a copy of the GNU General Public License
22   *      along with this program; if not, write to the Free Software   *      along with this program; if not, write to the Free Software
23   *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24   *   *
25   *************************************************************************/   *  Under section 8 of the GNU General Public License, the copyright
26     *  holders of XVID explicitly forbid distribution in the following
27  /**************************************************************************   *  countries:
28     *
29     *    - Japan
30     *    - United States of America
31     *
32     *  Linking XviD statically or dynamically with other modules is making a
33     *  combined work based on XviD.  Thus, the terms and conditions of the
34     *  GNU General Public License cover the whole combination.
35   *   *
36   *      History:   *  As a special exception, the copyright holders of XviD give you
37     *  permission to link XviD with independent modules that communicate with
38     *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the
39     *  license terms of these independent modules, and to copy and distribute
40     *  the resulting combined work under terms of your choice, provided that
41     *  every copy of the combined work is accompanied by a complete copy of
42     *  the source code of XviD (the version of XviD used to produce the
43     *  combined work), being distributed under the terms of the GNU General
44     *  Public License plus this exception.  An independent module is a module
45     *  which is not derived from or based on XviD.
46   *   *
47   *      14.04.2002      added user_to_yuv_c()   *  Note that people who make modified versions of XviD are not obligated
48   *      30.02.2002      out_yuv dst_stride2 fix   *  to grant this special exception for their modified versions; it is
49   *      26.02.2002      rgb555, rgb565   *  their choice whether to do so.  The GNU General Public License gives
50   *      24.11.2001      accuracy improvement to yuyv/vyuy conversion   *  permission to release a modified version without this exception; this
51   *      28.10.2001      total rewrite <pross@cs.rmit.edu.au>   *  exception also makes it possible to release a modified version which
52     *  carries forward this exception.
53   *   *
54   **************************************************************************/   * $Id$
55     *
56     ****************************************************************************/
57    
58  #include <string.h>                             // memcpy  #include <string.h>                             // memcpy
59    
# Line 39  Line 63 
63  // function pointers  // function pointers
64    
65  /* input */  /* input */
66  packedFuncPtr rgb555_to_yv12;  color_inputFuncPtr rgb555_to_yv12;
67  packedFuncPtr rgb565_to_yv12;  color_inputFuncPtr rgb565_to_yv12;
68  packedFuncPtr bgr_to_yv12;  color_inputFuncPtr rgb24_to_yv12;
69  packedFuncPtr bgra_to_yv12;  color_inputFuncPtr rgb32_to_yv12;
70  packedFuncPtr abgr_to_yv12;  color_inputFuncPtr yuv_to_yv12;
71  packedFuncPtr rgba_to_yv12;  color_inputFuncPtr yuyv_to_yv12;
72  packedFuncPtr yuv_to_yv12;  color_inputFuncPtr uyvy_to_yv12;
 packedFuncPtr yuyv_to_yv12;  
 packedFuncPtr uyvy_to_yv12;  
   
 packedFuncPtr rgb555i_to_yv12;  
 packedFuncPtr rgb565i_to_yv12;  
 packedFuncPtr bgri_to_yv12;  
 packedFuncPtr bgrai_to_yv12;  
 packedFuncPtr abgri_to_yv12;  
 packedFuncPtr rgbai_to_yv12;  
 packedFuncPtr yuyvi_to_yv12;  
 packedFuncPtr uyvyi_to_yv12;  
73    
74  /* output */  /* output */
75  packedFuncPtr yv12_to_rgb555;  color_outputFuncPtr yv12_to_rgb555;
76  packedFuncPtr yv12_to_rgb565;  color_outputFuncPtr yv12_to_rgb565;
77  packedFuncPtr yv12_to_bgr;  color_outputFuncPtr yv12_to_rgb24;
78  packedFuncPtr yv12_to_bgra;  color_outputFuncPtr yv12_to_rgb32;
79  packedFuncPtr yv12_to_abgr;  color_outputFuncPtr yv12_to_yuv;
80  packedFuncPtr yv12_to_rgba;  color_outputFuncPtr yv12_to_yuyv;
81  packedFuncPtr yv12_to_yuv;  color_outputFuncPtr yv12_to_uyvy;
 packedFuncPtr yv12_to_yuyv;  
 packedFuncPtr yv12_to_uyvy;  
   
 packedFuncPtr yv12_to_rgb555i;  
 packedFuncPtr yv12_to_rgb565i;  
 packedFuncPtr yv12_to_bgri;  
 packedFuncPtr yv12_to_bgrai;  
 packedFuncPtr yv12_to_abgri;  
 packedFuncPtr yv12_to_rgbai;  
 packedFuncPtr yv12_to_yuyvi;  
 packedFuncPtr yv12_to_uyvyi;  
   
 planarFuncPtr yv12_to_yv12;  
   
   
 int32_t RGB_Y_tab[256];  
 int32_t B_U_tab[256];  
 int32_t G_U_tab[256];  
 int32_t G_V_tab[256];  
 int32_t R_V_tab[256];  
   
82    
83  #define MIN(A,B)        ((A)<(B)?(A):(B))  #define MIN(A,B)        ((A)<(B)?(A):(B))
84  #define MAX(A,B)        ((A)>(B)?(A):(B))  #define MAX(A,B)        ((A)>(B)?(A):(B))
85    
   
 /********** generic colorspace macro **********/  
   
   
 #define MAKE_COLORSPACE(NAME,SIZE,PIXELS,VPIXELS,FUNC,C1,C2,C3,C4) \  
 void    \  
 NAME(uint8_t * x_ptr, int x_stride,     \  
                                  uint8_t * y_ptr, uint8_t * u_ptr, uint8_t * v_ptr,     \  
                                  int y_stride, int uv_stride,   \  
                                  int width, int height, int vflip)      \  
 {       \  
         int fixed_width = (width + 1) & ~1;                             \  
         int x_dif = x_stride - (SIZE)*fixed_width;              \  
         int y_dif = y_stride - fixed_width;                             \  
         int uv_dif = uv_stride - (fixed_width / 2);             \  
         int x, y;                                                                               \  
         if (vflip) {                                                            \  
                 x_ptr += (height - 1) * x_stride;                       \  
                 x_dif = -(SIZE)*fixed_width - x_stride;         \  
                 x_stride = -x_stride;                                           \  
         }                                                                                               \  
         for (y = 0; y < height; y+=(VPIXELS)) {                 \  
                 FUNC##_ROW(SIZE,C1,C2,C3,C4);                           \  
                 for (x = 0; x < fixed_width; x+=(PIXELS)) {     \  
                         FUNC(SIZE,C1,C2,C3,C4);                         \  
                         x_ptr += (PIXELS)*(SIZE);                               \  
                         y_ptr += (PIXELS);                                              \  
                         u_ptr += (PIXELS)/2;                                    \  
                         v_ptr += (PIXELS)/2;                                    \  
                 }                                                                                       \  
                 x_ptr += x_dif + (VPIXELS-1)*x_stride;          \  
                 y_ptr += y_dif + (VPIXELS-1)*y_stride;          \  
                 u_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride;    \  
                 v_ptr += uv_dif + ((VPIXELS/2)-1)*uv_stride;    \  
         }                                                                                               \  
 }  
   
   
   
 /********** colorspace input (xxx_to_yv12) functions **********/  
   
86  /*      rgb -> yuv def's  /*      rgb -> yuv def's
87    
88          this following constants are "official spec"          this following constants are "official spec"
# Line 161  Line 112 
112  #define FIX_IN(x)               ((uint16_t) ((x) * (1L<<SCALEBITS_IN) + 0.5))  #define FIX_IN(x)               ((uint16_t) ((x) * (1L<<SCALEBITS_IN) + 0.5))
113    
114    
115  /* rgb16/rgb16i input */  int32_t RGB_Y_tab[256];
116    int32_t B_U_tab[256];
117    int32_t G_U_tab[256];
118    int32_t G_V_tab[256];
119    int32_t R_V_tab[256];
120    
121    
122    /* rgb555 -> yuv 4:2:0 planar */
123    void
124    rgb555_to_yv12_c(uint8_t * y_out,
125                                     uint8_t * u_out,
126                                     uint8_t * v_out,
127                                     uint8_t * src,
128                                     int width,
129                                     int height,
130                                     int y_stride)
131    {
132            int32_t src_stride = width * 2;
133            uint32_t y_dif = y_stride - width;
134            uint32_t uv_dif = (y_stride - width) / 2;
135            uint32_t x, y;
136    
137            if (height < 0) {
138                    height = -height;
139                    src += (height - 1) * src_stride;
140                    src_stride = -src_stride;
141            }
142    
143    
144            for (y = height / 2; y; y--) {
145                    // process one 2x2 block per iteration
146                    for (x = 0; x < (uint32_t) width; x += 2) {
147                            int rgb, r, g, b, r4, g4, b4;
148    
149                            rgb = *(uint16_t *) (src + x * 2);
150                            b4 = b = (rgb << 3) & 0xf8;
151                            g4 = g = (rgb >> 2) & 0xf8;
152                            r4 = r = (rgb >> 7) & 0xf8;
153                            y_out[0] =
154                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
155                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
156    
157                            rgb = *(uint16_t *) (src + x * 2 + src_stride);
158                            b4 += b = (rgb << 3) & 0xf8;
159                            g4 += g = (rgb >> 2) & 0xf8;
160                            r4 += r = (rgb >> 7) & 0xf8;
161                            y_out[y_stride] =
162                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
163                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
164    
165                            rgb = *(uint16_t *) (src + x * 2 + 2);
166                            b4 += b = (rgb << 3) & 0xf8;
167                            g4 += g = (rgb >> 2) & 0xf8;
168                            r4 += r = (rgb >> 7) & 0xf8;
169                            y_out[1] =
170                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
171                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
172    
173                            rgb = *(uint16_t *) (src + x * 2 + src_stride + 2);
174                            b4 += b = (rgb << 3) & 0xf8;
175                            g4 += g = (rgb >> 2) & 0xf8;
176                            r4 += r = (rgb >> 7) & 0xf8;
177                            y_out[y_stride + 1] =
178                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
179                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
180    
181                            *u_out++ =
182                                    (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 +
183                                                            FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
184                                    U_ADD_IN;
185    
186    
187                            *v_out++ =
188                                    (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 -
189                                                            FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
190                                    V_ADD_IN;
191    
192                            y_out += 2;
193                    }
194                    src += src_stride * 2;
195                    y_out += y_dif + y_stride;
196                    u_out += uv_dif;
197                    v_out += uv_dif;
198            }
199    }
200    
201    
202    
203    /* rgb565_to_yuv_c
204            NOTE:   identical to rgb555 except for shift/mask
205                            not tested */
206    
207    void
208    rgb565_to_yv12_c(uint8_t * y_out,
209                                     uint8_t * u_out,
210                                     uint8_t * v_out,
211                                     uint8_t * src,
212                                     int width,
213                                     int height,
214                                     int y_stride)
215    {
216            int32_t src_stride = width * 2;
217    
218            uint32_t y_dif = y_stride - width;
219            uint32_t uv_dif = (y_stride - width) / 2;
220            uint32_t x, y;
221    
222            if (height < 0) {
223                    height = -height;
224                    src += (height - 1) * src_stride;
225                    src_stride = -src_stride;
226            }
227    
228    
229            for (y = height / 2; y; y--) {
230                    // process one 2x2 block per iteration
231                    for (x = 0; x < (uint32_t) width; x += 2) {
232                            int rgb, r, g, b, r4, g4, b4;
233    
234                            rgb = *(uint16_t *) (src + x * 2);
235                            b4 = b = (rgb << 3) & 0xf8;
236                            g4 = g = (rgb >> 3) & 0xfc;
237                            r4 = r = (rgb >> 8) & 0xf8;
238                            y_out[0] =
239                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
240                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
241    
242                            rgb = *(uint16_t *) (src + x * 2 + src_stride);
243                            b4 += b = (rgb << 3) & 0xf8;
244                            g4 += g = (rgb >> 3) & 0xfc;
245                            r4 += r = (rgb >> 8) & 0xf8;
246                            y_out[y_stride] =
247                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
248                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
249    
250                            rgb = *(uint16_t *) (src + x * 2 + 2);
251                            b4 += b = (rgb << 3) & 0xf8;
252                            g4 += g = (rgb >> 3) & 0xfc;
253                            r4 += r = (rgb >> 8) & 0xf8;
254                            y_out[1] =
255                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
256                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
257    
258                            rgb = *(uint16_t *) (src + x * 2 + src_stride + 2);
259                            b4 += b = (rgb << 3) & 0xf8;
260                            g4 += g = (rgb >> 3) & 0xfc;
261                            r4 += r = (rgb >> 8) & 0xf8;
262                            y_out[y_stride + 1] =
263                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
264                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
265    
266                            *u_out++ =
267                                    (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 +
268                                                            FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
269                                    U_ADD_IN;
270    
271    
272                            *v_out++ =
273                                    (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 -
274                                                            FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
275                                    V_ADD_IN;
276    
277                            y_out += 2;
278                    }
279                    src += src_stride * 2;
280                    y_out += y_dif + y_stride;
281                    u_out += uv_dif;
282                    v_out += uv_dif;
283            }
284    }
285    
286    
287    
288    
289    /*      rgb24 -> yuv 4:2:0 planar
290    
291            NOTE: always flips.
292    */
293    
294    void
295    rgb24_to_yv12_c(uint8_t * y_out,
296                                    uint8_t * u_out,
297                                    uint8_t * v_out,
298                                    uint8_t * src,
299                                    int width,
300                                    int height,
301                                    int stride)
302    {
303            uint32_t width3 = (width << 1) + width; /* width * 3 */
304            uint32_t src_dif = (width << 3) + width;        /* width3 * 3 */
305            uint32_t y_dif = (stride << 1) - width;
306            uint32_t uv_dif = (stride - width) >> 1;
307            uint32_t x, y;
308    
309            src += (height - 2) * width3;
310    
311    
312            for (y = height >> 1; y; y--) {
313                    for (x = width >> 1; x; x--) {
314                            uint32_t r, g, b, r4, g4, b4;
315    
316                            b4 = b = src[0];
317                            g4 = g = src[1];
318                            r4 = r = src[2];
319                            y_out[stride + 0] =
320                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
321                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
322    
323                            b4 += (b = src[3]);
324                            g4 += (g = src[4]);
325                            r4 += (r = src[5]);
326                            y_out[stride + 1] =
327                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
328                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
329    
330                            b4 += (b = src[width3 + 0]);
331                            g4 += (g = src[width3 + 1]);
332                            r4 += (r = src[width3 + 2]);
333                            y_out[0] =
334                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
335                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
336    
337                            b4 += (b = src[width3 + 3]);
338                            g4 += (g = src[width3 + 4]);
339                            r4 += (r = src[width3 + 5]);
340                            y_out[1] =
341                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
342                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
343    
344                            *u_out++ =
345                                    (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 +
346                                                            FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
347                                    U_ADD_IN;
348    
349    
350                            *v_out++ =
351                                    (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 -
352                                                            FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
353                                    V_ADD_IN;
354    
355    
356                            src += 6;
357                            y_out += 2;
358                    }
359                    src -= src_dif;
360                    y_out += y_dif;
361                    u_out += uv_dif;
362                    v_out += uv_dif;
363            }
364    }
365    
366    
367    /*      rgb32 -> yuv 4:2:0 planar
368    
369            NOTE: always flips
370    */
371    
372    void
373    rgb32_to_yv12_c(uint8_t * y_out,
374                                    uint8_t * u_out,
375                                    uint8_t * v_out,
376                                    uint8_t * src,
377                                    int width,
378                                    int height,
379                                    int stride)
380    {
381            uint32_t width4 = (width << 2); /* width * 4 */
382            uint32_t src_dif = 3 * width4;
383            uint32_t y_dif = (stride << 1) - width;
384            uint32_t uv_dif = (stride - width) >> 1;
385            uint32_t x, y;
386    
387            src += (height - 2) * width4;
388    
389            for (y = height >> 1; y; y--) {
390                    for (x = width >> 1; x; x--) {
391                            uint32_t r, g, b, r4, g4, b4;
392    
393                            b4 = b = src[0];
394                            g4 = g = src[1];
395                            r4 = r = src[2];
396                            y_out[stride + 0] =
397                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
398                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
399    
400                            b4 += (b = src[4]);
401                            g4 += (g = src[5]);
402                            r4 += (r = src[6]);
403                            y_out[stride + 1] =
404                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
405                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
406    
407                            b4 += (b = src[width4 + 0]);
408                            g4 += (g = src[width4 + 1]);
409                            r4 += (r = src[width4 + 2]);
410    
411                            y_out[0] =
412                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
413                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
414    
415                            b4 += (b = src[width4 + 4]);
416                            g4 += (g = src[width4 + 5]);
417                            r4 += (r = src[width4 + 6]);
418                            y_out[1] =
419                                    (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +
420                                                            FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;
421    
422                            *u_out++ =
423                                    (uint8_t) ((-FIX_IN(U_R_IN) * r4 - FIX_IN(U_G_IN) * g4 +
424                                                            FIX_IN(U_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
425                                    U_ADD_IN;
426    
427                            *v_out++ =
428                                    (uint8_t) ((FIX_IN(V_R_IN) * r4 - FIX_IN(V_G_IN) * g4 -
429                                                            FIX_IN(V_B_IN) * b4) >> (SCALEBITS_IN + 2)) +
430                                    V_ADD_IN;
431    
432                            src += 8;
433                            y_out += 2;
434                    }
435                    src -= src_dif;
436                    y_out += y_dif;
437                    u_out += uv_dif;
438                    v_out += uv_dif;
439            }
440    }
441    
442    /*      yuv planar -> yuv 4:2:0 planar
443    
444            NOTE: does not flip */
445    
446    void
447    yuv_to_yv12_c(uint8_t * y_out,
448                              uint8_t * u_out,
449                              uint8_t * v_out,
450                              uint8_t * src,
451                              int width,
452                              int height,
453                              int stride)
454    {
455            uint32_t stride2 = stride >> 1;
456            uint32_t width2 = width >> 1;
457            uint32_t y;
458    
459            for (y = height; y; y--) {
460                    memcpy(y_out, src, width);
461                    src += width;
462                    y_out += stride;
463            }
464    
465            for (y = height >> 1; y; y--) {
466                    memcpy(u_out, src, width2);
467                    src += width2;
468                    u_out += stride2;
469            }
470    
471            for (y = height >> 1; y; y--) {
472                    memcpy(v_out, src, width2);
473                    src += width2;
474                    v_out += stride2;
475            }
476    }
477    
478    
479    
480    /* yuyv (yuv2) packed -> yuv 4:2:0 planar
481    
482       NOTE: does not flip */
483    
484    void
485    yuyv_to_yv12_c(uint8_t * y_out,
486                               uint8_t * u_out,
487                               uint8_t * v_out,
488                               uint8_t * src,
489                               int width,
490                               int height,
491                               int stride)
492    {
493            uint32_t width2 = width + width;
494            uint32_t y_dif = stride - width;
495            uint32_t uv_dif = y_dif >> 1;
496            uint32_t x, y;
497    
498            for (y = height >> 1; y; y--) {
499    
500                    for (x = width >> 1; x; x--) {
501                            *y_out++ = *src++;
502                            //*u_out++ = *src++;
503                            *u_out++ = (*(src + width2) + *src) >> 1;
504                            src++;
505                            *y_out++ = *src++;
506                            //*v_out++ = *src++;
507                            *v_out++ = (*(src + width2) + *src) >> 1;
508                            src++;
509    
510                    }
511    
512                    y_out += y_dif;
513                    u_out += uv_dif;
514                    v_out += uv_dif;
515    
516                    for (x = width >> 1; x; x--) {
517                            *y_out++ = *src++;
518                            src++;
519                            *y_out++ = *src++;
520                            src++;
521                    }
522    
523                    y_out += y_dif;
524    
525            }
526    
527    }
528    
529    
530    
531    /* uyvy packed -> yuv 4:2:0 planar
532    
533       NOTE: does not flip */
534    
535    
536  #define MK_RGB555_B(RGB)  ((RGB) << 3) & 0xf8  void
537  #define MK_RGB555_G(RGB)  ((RGB) >> 2) & 0xf8  uyvy_to_yv12_c(uint8_t * y_out,
538  #define MK_RGB555_R(RGB)  ((RGB) >> 7) & 0xf8                             uint8_t * u_out,
539                               uint8_t * v_out,
540  #define MK_RGB565_B(RGB)  ((RGB) << 3) & 0xf8                             uint8_t * src,
541  #define MK_RGB565_G(RGB)  ((RGB) >> 3) & 0xfc                             int width,
542  #define MK_RGB565_R(RGB)  ((RGB) >> 8) & 0xf8                             int height,
543                               int stride)
544    {
545  #define READ_RGB16_Y(ROW, UVID, C1,C2,C3,C4)    \          uint32_t width2 = width + width;
546          rgb = *(uint16_t *) (x_ptr + ((ROW)*x_stride) + 0);     \          uint32_t y_dif = stride - width;
547          b##UVID += b = C1##_B(rgb);                             \          uint32_t uv_dif = y_dif >> 1;
548          g##UVID += g = C1##_G(rgb);                             \          uint32_t x, y;
549          r##UVID += r = C1##_R(rgb);                             \  
550          y_ptr[(ROW)*y_stride+0] =                               \          for (y = height >> 1; y; y--) {
551                  (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +   \  
552                                          FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;        \                  for (x = width >> 1; x; x--) {
553          rgb = *(uint16_t *) (x_ptr + ((ROW)*x_stride) + 2);     \                          *u_out++ = *src++;
554          b##UVID += b = C1##_B(rgb);                             \                          // *u_out++ = (*(src+width2) + *src++) >> 1;
555          g##UVID += g = C1##_G(rgb);                             \                          *y_out++ = *src++;
556          r##UVID += r = C1##_R(rgb);                             \                          //*v_out++ = *src++;
557          y_ptr[(ROW)*y_stride+1] =                               \                          *v_out++ = (*(src + width2) + *src) >> 1;
558                  (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +                   \                          src++;
559                                          FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;                          *y_out++ = *src++;
560                    }
 #define READ_RGB16_UV(UV_ROW,UVID)      \  
         u_ptr[(UV_ROW)*uv_stride] =                                                                                                             \  
                 (uint8_t) ((-FIX_IN(U_R_IN) * r##UVID - FIX_IN(U_G_IN) * g##UVID +                      \  
                                         FIX_IN(U_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + U_ADD_IN;    \  
         v_ptr[(UV_ROW)*uv_stride] =                                                                                                             \  
                 (uint8_t) ((FIX_IN(V_R_IN) * r##UVID - FIX_IN(V_G_IN) * g##UVID -                       \  
                                         FIX_IN(V_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + V_ADD_IN;  
   
 #define RGB16_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define RGB16_TO_YV12(SIZE,C1,C2,C3,C4) \  
         uint32_t rgb, r, g, b, r0, g0, b0;      \  
         r0 = g0 = b0 = 0;                                       \  
         READ_RGB16_Y (0, 0, C1,C2,C3,C4)        \  
         READ_RGB16_Y (1, 0, C1,C2,C3,C4)        \  
         READ_RGB16_UV(0, 0)  
   
   
 #define RGB16I_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define RGB16I_TO_YV12(SIZE,C1,C2,C3,C4)        \  
         uint32_t rgb, r, g, b, r0, g0, b0, r1, g1, b1;  \  
         r0 = g0 = b0 = r1 = g1 = b1 = 0;        \  
         READ_RGB16_Y (0, 0, C1,C2,C3,C4)        \  
         READ_RGB16_Y (1, 1, C1,C2,C3,C4)        \  
         READ_RGB16_Y (2, 0, C1,C2,C3,C4)        \  
         READ_RGB16_Y (3, 1, C1,C2,C3,C4)        \  
         READ_RGB16_UV(0, 0)                                     \  
         READ_RGB16_UV(1, 1)  
   
   
 /* rgb/rgbi input */  
   
 #define READ_RGB_Y(SIZE, ROW, UVID, C1,C2,C3,C4)        \  
         r##UVID += r = x_ptr[(ROW)*x_stride+(C1)];                                              \  
         g##UVID += g = x_ptr[(ROW)*x_stride+(C2)];                                              \  
         b##UVID += b = x_ptr[(ROW)*x_stride+(C3)];                                              \  
         y_ptr[(ROW)*y_stride+0] =                                                                       \  
                 (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +   \  
                                         FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;        \  
         r##UVID += r = x_ptr[(ROW)*x_stride+(SIZE)+(C1)];                               \  
         g##UVID += g = x_ptr[(ROW)*x_stride+(SIZE)+(C2)];                               \  
         b##UVID += b = x_ptr[(ROW)*x_stride+(SIZE)+(C3)];                               \  
         y_ptr[(ROW)*y_stride+1] =                                                                       \  
                 (uint8_t) ((FIX_IN(Y_R_IN) * r + FIX_IN(Y_G_IN) * g +   \  
                                         FIX_IN(Y_B_IN) * b) >> SCALEBITS_IN) + Y_ADD_IN;  
   
 #define READ_RGB_UV(UV_ROW,UVID)        \  
         u_ptr[(UV_ROW)*uv_stride] =                                                                                                             \  
                 (uint8_t) ((-FIX_IN(U_R_IN) * r##UVID - FIX_IN(U_G_IN) * g##UVID +                      \  
                                         FIX_IN(U_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + U_ADD_IN;    \  
         v_ptr[(UV_ROW)*uv_stride] =                                                                                                             \  
                 (uint8_t) ((FIX_IN(V_R_IN) * r##UVID - FIX_IN(V_G_IN) * g##UVID -                       \  
                                         FIX_IN(V_B_IN) * b##UVID) >> (SCALEBITS_IN + 2)) + V_ADD_IN;  
   
   
 #define RGB_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define RGB_TO_YV12(SIZE,C1,C2,C3,C4)   \  
         uint32_t r, g, b, r0, g0, b0;           \  
         r0 = g0 = b0 = 0;                                       \  
         READ_RGB_Y(SIZE, 0, 0, C1,C2,C3,C4)     \  
         READ_RGB_Y(SIZE, 1, 0, C1,C2,C3,C4)     \  
         READ_RGB_UV(     0, 0)  
   
 #define RGBI_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define RGBI_TO_YV12(SIZE,C1,C2,C3,C4)  \  
         uint32_t r, g, b, r0, g0, b0, r1, g1, b1;       \  
         r0 = g0 = b0 = r1 = g1 = b1 = 0;        \  
         READ_RGB_Y(SIZE, 0, 0, C1,C2,C3,C4)     \  
         READ_RGB_Y(SIZE, 1, 1, C1,C2,C3,C4)     \  
         READ_RGB_Y(SIZE, 2, 0, C1,C2,C3,C4)     \  
         READ_RGB_Y(SIZE, 3, 1, C1,C2,C3,C4)     \  
         READ_RGB_UV(     0, 0)                          \  
         READ_RGB_UV(     1, 1)  
   
   
 /* yuyv/yuyvi input */  
   
 #define READ_YUYV_Y(ROW,C1,C2,C3,C4)    \  
         y_ptr[(ROW)*y_stride+0] = x_ptr[(ROW)*x_stride+(C1)];   \  
         y_ptr[(ROW)*y_stride+1] = x_ptr[(ROW)*x_stride+(C3)];  
 #define READ_YUYV_UV(UV_ROW,ROW1,ROW2,C1,C2,C3,C4) \  
         u_ptr[(UV_ROW)*uv_stride] = (x_ptr[(ROW1)*x_stride+(C2)] + x_ptr[(ROW2)*x_stride+(C2)] + 1) / 2;        \  
         v_ptr[(UV_ROW)*uv_stride] = (x_ptr[(ROW1)*x_stride+(C4)] + x_ptr[(ROW2)*x_stride+(C4)] + 1) / 2;  
   
 #define YUYV_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define YUYV_TO_YV12(SIZE,C1,C2,C3,C4)  \  
         READ_YUYV_Y (0,      C1,C2,C3,C4)       \  
         READ_YUYV_Y (1,      C1,C2,C3,C4)       \  
         READ_YUYV_UV(0, 0,1, C1,C2,C3,C4)  
   
 #define YUYVI_TO_YV12_ROW(SIZE,C1,C2,C3,C4) \  
         /* nothing */  
 #define YUYVI_TO_YV12(SIZE,C1,C2,C3,C4) \  
         READ_YUYV_Y (0, C1,C2,C3,C4)    \  
         READ_YUYV_Y (1, C1,C2,C3,C4)    \  
         READ_YUYV_Y (2, C1,C2,C3,C4)    \  
         READ_YUYV_Y (3, C1,C2,C3,C4)    \  
         READ_YUYV_UV(0, 0,2, C1,C2,C3,C4)       \  
         READ_YUYV_UV(1, 1,3, C1,C2,C3,C4)  
   
   
 MAKE_COLORSPACE(rgb555_to_yv12_c,  2,2,2, RGB16_TO_YV12,  MK_RGB555, 0,0,0)  
 MAKE_COLORSPACE(rgb565_to_yv12_c,  2,2,2, RGB16_TO_YV12,  MK_RGB565, 0,0,0)  
 MAKE_COLORSPACE(bgr_to_yv12_c,     3,2,2, RGB_TO_YV12,    2,1,0, 0)  
 MAKE_COLORSPACE(bgra_to_yv12_c,    4,2,2, RGB_TO_YV12,    2,1,0, 0)  
 MAKE_COLORSPACE(abgr_to_yv12_c,    4,2,2, RGB_TO_YV12,    3,2,1, 0)  
 MAKE_COLORSPACE(rgba_to_yv12_c,    4,2,2, RGB_TO_YV12,    0,1,2, 0)  
 MAKE_COLORSPACE(yuyv_to_yv12_c,    2,2,2, YUYV_TO_YV12,   0,1,2,3)  
 MAKE_COLORSPACE(uyvy_to_yv12_c,    2,2,2, YUYV_TO_YV12,   1,0,3,2)  
   
 MAKE_COLORSPACE(rgb555i_to_yv12_c, 2,2,4, RGB16I_TO_YV12, MK_RGB555, 0,0,0)  
 MAKE_COLORSPACE(rgb565i_to_yv12_c, 2,2,4, RGB16I_TO_YV12, MK_RGB565, 0,0,0)  
 MAKE_COLORSPACE(bgri_to_yv12_c,    3,2,4, RGBI_TO_YV12,   2,1,0, 0)  
 MAKE_COLORSPACE(bgrai_to_yv12_c,   4,2,4, RGBI_TO_YV12,   2,1,0, 0)  
 MAKE_COLORSPACE(abgri_to_yv12_c,   4,2,4, RGBI_TO_YV12,   3,2,1, 0)  
 MAKE_COLORSPACE(rgbai_to_yv12_c,   4,2,4, RGBI_TO_YV12,   0,1,2, 0)  
 MAKE_COLORSPACE(yuyvi_to_yv12_c,   2,2,4, YUYVI_TO_YV12,  0,1,2,3)  
 MAKE_COLORSPACE(uyvyi_to_yv12_c,   2,2,4, YUYVI_TO_YV12,  1,0,3,2)  
561    
562                    y_out += y_dif;
563                    u_out += uv_dif;;
564                    v_out += uv_dif;;
565    
566                    for (x = width >> 1; x; x--) {
567                            src++;
568                            *y_out++ = *src++;
569                            src++;
570                            *y_out++ = *src++;
571                    }
572    
573                    y_out += y_dif;
574            }
575    }
576    
 /********** colorspace output (yv12_to_xxx) functions **********/  
577    
578  /* yuv -> rgb def's */  /* yuv -> rgb def's */
579    
# Line 327  Line 588 
588  #define R_V_OUT                 1.596  #define R_V_OUT                 1.596
589  #define V_ADD_OUT               128  #define V_ADD_OUT               128
590    
591    
592  #define SCALEBITS_OUT   13  #define SCALEBITS_OUT   13
593  #define FIX_OUT(x)              ((uint16_t) ((x) * (1L<<SCALEBITS_OUT) + 0.5))  #define FIX_OUT(x)              ((uint16_t) ((x) * (1L<<SCALEBITS_OUT) + 0.5))
594    
595    
596  /* rgb16/rgb16i output */  /* initialize rgb lookup tables */
597    
598    void
599    colorspace_init(void)
600    {
601            int32_t i;
602    
603            for (i = 0; i < 256; i++) {
604                    RGB_Y_tab[i] = FIX_OUT(RGB_Y_OUT) * (i - Y_ADD_OUT);
605                    B_U_tab[i] = FIX_OUT(B_U_OUT) * (i - U_ADD_OUT);
606                    G_U_tab[i] = FIX_OUT(G_U_OUT) * (i - U_ADD_OUT);
607                    G_V_tab[i] = FIX_OUT(G_V_OUT) * (i - V_ADD_OUT);
608                    R_V_tab[i] = FIX_OUT(R_V_OUT) * (i - V_ADD_OUT);
609            }
610    }
611    
612    /* yuv 4:2:0 planar -> rgb555 + very simple error diffusion
613    */
614    
615  #define MK_RGB555(R,G,B)        \  #define MK_RGB555(R,G,B)        ((MAX(0,MIN(255, R)) << 7) & 0x7c00) | \
         ((MAX(0,MIN(255, R)) << 7) & 0x7c00) | \  
616          ((MAX(0,MIN(255, G)) << 2) & 0x03e0) | \          ((MAX(0,MIN(255, G)) << 2) & 0x03e0) | \
617          ((MAX(0,MIN(255, B)) >> 3) & 0x001f)          ((MAX(0,MIN(255, B)) >> 3) & 0x001f)
618    
619  #define MK_RGB565(R,G,B)        \  
620          ((MAX(0,MIN(255, R)) << 8) & 0xf800) | \  void
621    yv12_to_rgb555_c(uint8_t * dst,
622                                     int dst_stride,
623                                     uint8_t * y_src,
624                                     uint8_t * u_src,
625                                     uint8_t * v_src,
626                                     int y_stride,
627                                     int uv_stride,
628                                     int width,
629                                     int height)
630    {
631            const uint32_t dst_dif = 4 * dst_stride - 2 * width;
632            int32_t y_dif = 2 * y_stride - width;
633    
634            uint8_t *dst2 = dst + 2 * dst_stride;
635            uint8_t *y_src2 = y_src + y_stride;
636            uint32_t x, y;
637    
638            if (height < 0) {
639                    height = -height;
640                    y_src += (height - 1) * y_stride;
641                    y_src2 = y_src - y_stride;
642                    u_src += (height / 2 - 1) * uv_stride;
643                    v_src += (height / 2 - 1) * uv_stride;
644                    y_dif = -width - 2 * y_stride;
645                    uv_stride = -uv_stride;
646            }
647    
648            for (y = height / 2; y; y--) {
649                    int r, g, b;
650                    int r2, g2, b2;
651    
652                    r = g = b = 0;
653                    r2 = g2 = b2 = 0;
654    
655                    // process one 2x2 block per iteration
656                    for (x = 0; x < (uint32_t) width / 2; x++) {
657                            int u, v;
658                            int b_u, g_uv, r_v, rgb_y;
659    
660                            u = u_src[x];
661                            v = v_src[x];
662    
663                            b_u = B_U_tab[u];
664                            g_uv = G_U_tab[u] + G_V_tab[v];
665                            r_v = R_V_tab[v];
666    
667                            rgb_y = RGB_Y_tab[*y_src];
668                            b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
669                            g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
670                            r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
671                            *(uint16_t *) dst = MK_RGB555(r, g, b);
672    
673                            y_src++;
674                            rgb_y = RGB_Y_tab[*y_src];
675                            b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
676                            g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
677                            r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
678                            *(uint16_t *) (dst + 2) = MK_RGB555(r, g, b);
679                            y_src++;
680    
681                            rgb_y = RGB_Y_tab[*y_src2];
682                            b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
683                            g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
684                            r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
685                            *(uint16_t *) (dst2) = MK_RGB555(r2, g2, b2);
686                            y_src2++;
687    
688                            rgb_y = RGB_Y_tab[*y_src2];
689                            b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
690                            g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
691                            r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
692                            *(uint16_t *) (dst2 + 2) = MK_RGB555(r2, g2, b2);
693                            y_src2++;
694    
695                            dst += 4;
696                            dst2 += 4;
697                    }
698    
699                    dst += dst_dif;
700                    dst2 += dst_dif;
701    
702                    y_src += y_dif;
703                    y_src2 += y_dif;
704    
705                    u_src += uv_stride;
706                    v_src += uv_stride;
707            }
708    }
709    
710    
711    /* yuv 4:2:0 planar -> rgb565 + very simple error diffusion
712            NOTE:   identical to rgb555 except for shift/mask  */
713    
714    
715    #define MK_RGB565(R,G,B)        ((MAX(0,MIN(255, R)) << 8) & 0xf800) | \
716          ((MAX(0,MIN(255, G)) << 3) & 0x07e0) | \          ((MAX(0,MIN(255, G)) << 3) & 0x07e0) | \
717          ((MAX(0,MIN(255, B)) >> 3) & 0x001f)          ((MAX(0,MIN(255, B)) >> 3) & 0x001f)
718    
719  #define WRITE_RGB16(ROW,UV_ROW,C1)      \  void
720          rgb_y = RGB_Y_tab[ y_ptr[y_stride + 0] ];                       \  yv12_to_rgb565_c(uint8_t * dst,
721          b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT);     \                                   int dst_stride,
722          g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT);    \                                   uint8_t * y_src,
723          r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT);             \                                   uint8_t * u_src,
724          *(uint16_t *) (x_ptr+((ROW)*x_stride)+0) = C1(r[ROW], g[ROW], b[ROW]);  \                                   uint8_t * v_src,
725          rgb_y = RGB_Y_tab[ y_ptr[y_stride + 1] ];                               \                                   int y_stride,
726          b[ROW] = (b[ROW] & 0x7) + ((rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT);             \                                   int uv_stride,
727          g[ROW] = (g[ROW] & 0x7) + ((rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT);    \                                   int width,
728          r[ROW] = (r[ROW] & 0x7) + ((rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT);             \                                   int height)
729          *(uint16_t *) (x_ptr+((ROW)*x_stride)+2) = C1(r[ROW], g[ROW], b[ROW]);  {
730            const uint32_t dst_dif = 4 * dst_stride - 2 * width;
731  #define YV12_TO_RGB16_ROW(SIZE,C1,C2,C3,C4) \          int32_t y_dif = 2 * y_stride - width;
732          int r[2], g[2], b[2];                                   \  
733          r[0] = r[1] = g[0] = g[1] = b[0] = b[1] = 0;          uint8_t *dst2 = dst + 2 * dst_stride;
734  #define YV12_TO_RGB16(SIZE,C1,C2,C3,C4)         \          uint8_t *y_src2 = y_src + y_stride;
735          int rgb_y;                                                                                              \          uint32_t x, y;
736          int b_u0 = B_U_tab[ u_ptr[0] ];                                                         \  
737          int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ];          \          if (height < 0) {                       // flip image?
738          int r_v0 = R_V_tab[ v_ptr[0] ];                                                         \                  height = -height;
739          WRITE_RGB16(0, 0, C1)                                                                           \                  y_src += (height - 1) * y_stride;
740          WRITE_RGB16(1, 0, C1)                  y_src2 = y_src - y_stride;
741                    u_src += (height / 2 - 1) * uv_stride;
742  #define YV12_TO_RGB16I_ROW(SIZE,C1,C2,C3,C4) \                  v_src += (height / 2 - 1) * uv_stride;
743          int r[4], g[4], b[4];                                   \                  y_dif = -width - 2 * y_stride;
744          r[0] = r[1] = r[2] = r[3] = 0;                  \                  uv_stride = -uv_stride;
745          g[0] = g[1] = g[2] = g[3] = 0;                  \          }
746          b[0] = b[1] = b[2] = b[3] = 0;  
747  #define YV12_TO_RGB16I(SIZE,C1,C2,C3,C4)                \          for (y = height / 2; y; y--) {
748          int rgb_y;                                                                                                      \                  int r, g, b;
749          int b_u0 = B_U_tab[ u_ptr[0] ];                                                         \                  int r2, g2, b2;
750          int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ];          \  
751          int r_v0 = R_V_tab[ v_ptr[0] ];                                                         \                  r = g = b = 0;
752      int b_u1 = B_U_tab[ u_ptr[uv_stride] ];                                             \                  r2 = g2 = b2 = 0;
753          int g_uv1 = G_U_tab[ u_ptr[uv_stride] ] + G_V_tab[ v_ptr[uv_stride] ];  \  
754          int r_v1 = R_V_tab[ v_ptr[uv_stride] ];                                         \                  // process one 2x2 block per iteration
755      WRITE_RGB16(0, 0, C1)                                                                               \                  for (x = 0; x < (uint32_t) width / 2; x++) {
756          WRITE_RGB16(1, 1, C1)                                                                           \                          int u, v;
757      WRITE_RGB16(2, 0, C1)                                                                               \                          int b_u, g_uv, r_v, rgb_y;
758          WRITE_RGB16(3, 1, C1)                                                                           \  
759                            u = u_src[x];
760                            v = v_src[x];
761  /* rgb/rgbi output */  
762                            b_u = B_U_tab[u];
763  #define WRITE_RGB(SIZE,ROW,UV_ROW,C1,C2,C3,C4)  \                          g_uv = G_U_tab[u] + G_V_tab[v];
764          rgb_y = RGB_Y_tab[ y_ptr[(ROW)*y_stride + 0] ];                                         \                          r_v = R_V_tab[v];
765          x_ptr[(ROW)*x_stride+(C3)] = MAX(0, MIN(255, (rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT));  \  
766          x_ptr[(ROW)*x_stride+(C2)] = MAX(0, MIN(255, (rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT)); \                          rgb_y = RGB_Y_tab[*y_src];
767          x_ptr[(ROW)*x_stride+(C1)] = MAX(0, MIN(255, (rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT));  \                          b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
768          if ((SIZE)>3) x_ptr[(ROW)*x_stride+(C4)] = 0;                                                                   \                          g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
769          rgb_y = RGB_Y_tab[ y_ptr[(ROW)*y_stride + 1] ];                                                                 \                          r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
770          x_ptr[(ROW)*x_stride+(SIZE)+(C3)] = MAX(0, MIN(255, (rgb_y + b_u##UV_ROW) >> SCALEBITS_OUT));   \                          *(uint16_t *) dst = MK_RGB565(r, g, b);
771          x_ptr[(ROW)*x_stride+(SIZE)+(C2)] = MAX(0, MIN(255, (rgb_y - g_uv##UV_ROW) >> SCALEBITS_OUT));  \  
772          x_ptr[(ROW)*x_stride+(SIZE)+(C1)] = MAX(0, MIN(255, (rgb_y + r_v##UV_ROW) >> SCALEBITS_OUT));   \                          y_src++;
773          if ((SIZE)>3) x_ptr[(ROW)*x_stride+(SIZE)+(C4)] = 0;                          rgb_y = RGB_Y_tab[*y_src];
774                            b = (b & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
775                            g = (g & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
776  #define YV12_TO_RGB_ROW(SIZE,C1,C2,C3,C4)       /* nothing */                          r = (r & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
777  #define YV12_TO_RGB(SIZE,C1,C2,C3,C4)                           \                          *(uint16_t *) (dst + 2) = MK_RGB565(r, g, b);
778          int rgb_y;                                                                                              \                          y_src++;
779          int b_u0 = B_U_tab[ u_ptr[0] ];                                                 \  
780          int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ];  \                          rgb_y = RGB_Y_tab[*y_src2];
781          int r_v0 = R_V_tab[ v_ptr[0] ];                                                 \                          b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
782          WRITE_RGB(SIZE, 0, 0, C1,C2,C3,C4)                                              \                          g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
783          WRITE_RGB(SIZE, 1, 0, C1,C2,C3,C4)                          r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
784                            *(uint16_t *) (dst2) = MK_RGB565(r2, g2, b2);
785  #define YV12_TO_RGBI_ROW(SIZE,C1,C2,C3,C4)      /* nothing */                          y_src2++;
786  #define YV12_TO_RGBI(SIZE,C1,C2,C3,C4)                          \  
787          int rgb_y;                                                                                              \                          rgb_y = RGB_Y_tab[*y_src2];
788          int b_u0 = B_U_tab[ u_ptr[0] ];                                                 \                          b2 = (b2 & 0x7) + ((rgb_y + b_u) >> SCALEBITS_OUT);
789          int g_uv0 = G_U_tab[ u_ptr[0] ] + G_V_tab[ v_ptr[0] ];  \                          g2 = (g2 & 0x7) + ((rgb_y - g_uv) >> SCALEBITS_OUT);
790          int r_v0 = R_V_tab[ v_ptr[0] ];                                                 \                          r2 = (r2 & 0x7) + ((rgb_y + r_v) >> SCALEBITS_OUT);
791      int b_u1 = B_U_tab[ u_ptr[uv_stride] ];                                     \                          *(uint16_t *) (dst2 + 2) = MK_RGB565(r2, g2, b2);
792          int g_uv1 = G_U_tab[ u_ptr[uv_stride] ] + G_V_tab[ v_ptr[uv_stride] ];  \                          y_src2++;
793          int r_v1 = R_V_tab[ v_ptr[uv_stride] ];                                 \  
794          WRITE_RGB(SIZE, 0, 0, C1,C2,C3,C4)              \                          dst += 4;
795          WRITE_RGB(SIZE, 1, 1, C1,C2,C3,C4)              \                          dst2 += 4;
796          WRITE_RGB(SIZE, 2, 0, C1,C2,C3,C4)              \                  }
797          WRITE_RGB(SIZE, 3, 1, C1,C2,C3,C4)  
798                    dst += dst_dif;
799                    dst2 += dst_dif;
800  /* yuyv/yuyvi output */  
801                    y_src += y_dif;
802  #define WRITE_YUYV(ROW,UV_ROW,C1,C2,C3,C4)      \                  y_src2 += y_dif;
803          x_ptr[(ROW)*x_stride+(C1)] = y_ptr[   (ROW)*y_stride +0];       \  
804          x_ptr[(ROW)*x_stride+(C2)] = u_ptr[(UV_ROW)*uv_stride+0];       \                  u_src += uv_stride;
805          x_ptr[(ROW)*x_stride+(C3)] = y_ptr[   (ROW)*y_stride +1];       \                  v_src += uv_stride;
806          x_ptr[(ROW)*x_stride+(C4)] = v_ptr[(UV_ROW)*uv_stride+0];       \          }
807    }
808  #define YV12_TO_YUYV_ROW(SIZE,C1,C2,C3,C4)      /* nothing */  
809  #define YV12_TO_YUYV(SIZE,C1,C2,C3,C4)  \  
810          WRITE_YUYV(0, 0, C1,C2,C3,C4)           \  
811          WRITE_YUYV(1, 0, C1,C2,C3,C4)  /* yuv 4:2:0 planar -> rgb24 */
812    
813  #define YV12_TO_YUYVI_ROW(SIZE,C1,C2,C3,C4) /* nothing */  void
814  #define YV12_TO_YUYVI(SIZE,C1,C2,C3,C4) \  yv12_to_rgb24_c(uint8_t * dst,
815          WRITE_YUYV(0, 0, C1,C2,C3,C4)           \                                  int dst_stride,
816          WRITE_YUYV(1, 1, C1,C2,C3,C4)           \                                  uint8_t * y_src,
817          WRITE_YUYV(2, 0, C1,C2,C3,C4)           \                                  uint8_t * u_src,
818          WRITE_YUYV(3, 1, C1,C2,C3,C4)                                  uint8_t * v_src,
819                                    int y_stride,
820                                    int uv_stride,
821  MAKE_COLORSPACE(yv12_to_rgb555_c,  2,2,2, YV12_TO_RGB16,  MK_RGB555, 0,0,0)                                  int width,
822  MAKE_COLORSPACE(yv12_to_rgb565_c,  2,2,2, YV12_TO_RGB16,  MK_RGB565, 0,0,0)                                  int height)
823  MAKE_COLORSPACE(yv12_to_bgr_c,     3,2,2, YV12_TO_RGB,    2,1,0, 0)  {
824  MAKE_COLORSPACE(yv12_to_bgra_c,    4,2,2, YV12_TO_RGB,    2,1,0,3)          const uint32_t dst_dif = 6 * dst_stride - 3 * width;
825  MAKE_COLORSPACE(yv12_to_abgr_c,    4,2,2, YV12_TO_RGB,    3,2,1,0)          int32_t y_dif = 2 * y_stride - width;
826  MAKE_COLORSPACE(yv12_to_rgba_c,    4,2,2, YV12_TO_RGB,    0,1,2,3)  
827  MAKE_COLORSPACE(yv12_to_yuyv_c,    2,2,2, YV12_TO_YUYV,   0,1,2,3)          uint8_t *dst2 = dst + 3 * dst_stride;
828  MAKE_COLORSPACE(yv12_to_uyvy_c,    2,2,2, YV12_TO_YUYV,   1,0,3,2)          uint8_t *y_src2 = y_src + y_stride;
829            uint32_t x, y;
830  MAKE_COLORSPACE(yv12_to_rgb555i_c, 2,2,4, YV12_TO_RGB16I, MK_RGB555, 0,0,0)  
831  MAKE_COLORSPACE(yv12_to_rgb565i_c, 2,2,4, YV12_TO_RGB16I, MK_RGB565, 0,0,0)          if (height < 0) {                       // flip image?
832  MAKE_COLORSPACE(yv12_to_bgri_c,    3,2,4, YV12_TO_RGBI,   2,1,0, 0)                  height = -height;
833  MAKE_COLORSPACE(yv12_to_bgrai_c,   4,2,4, YV12_TO_RGBI,   2,1,0,3)                  y_src += (height - 1) * y_stride;
834  MAKE_COLORSPACE(yv12_to_abgri_c,   4,2,4, YV12_TO_RGBI,   3,2,1,0)                  y_src2 = y_src - y_stride;
835  MAKE_COLORSPACE(yv12_to_rgbai_c,   4,2,4, YV12_TO_RGBI,   0,1,2,3)                  u_src += (height / 2 - 1) * uv_stride;
836  MAKE_COLORSPACE(yv12_to_yuyvi_c,   2,2,4, YV12_TO_YUYVI,  0,1,2,3)                  v_src += (height / 2 - 1) * uv_stride;
837  MAKE_COLORSPACE(yv12_to_uyvyi_c,   2,2,4, YV12_TO_YUYVI,  1,0,3,2)                  y_dif = -width - 2 * y_stride;
838                    uv_stride = -uv_stride;
839            }
840    
841  /* yv12 to yv12 copy function */          for (y = height / 2; y; y--) {
842                    // process one 2x2 block per iteration
843  void                  for (x = 0; x < (uint32_t) width / 2; x++) {
844  yv12_to_yv12_c(uint8_t * y_dst, uint8_t * u_dst, uint8_t * v_dst,                          int u, v;
845                                  int y_dst_stride, int uv_dst_stride,                          int b_u, g_uv, r_v, rgb_y;
846                                  uint8_t * y_src, uint8_t * u_src, uint8_t * v_src,                          int r, g, b;
847                                  int y_src_stride, int uv_src_stride,  
848                                  int width, int height, int vflip)                          u = u_src[x];
849  {                          v = v_src[x];
850          int width2 = width / 2;  
851          int height2 = height / 2;                          b_u = B_U_tab[u];
852          int y;                          g_uv = G_U_tab[u] + G_V_tab[v];
853                            r_v = R_V_tab[v];
854          if (vflip) {  
855                  y_src += (height - 1) * y_src_stride;                          rgb_y = RGB_Y_tab[*y_src];
856                  u_src += (height2 - 1) * uv_src_stride;                          b = (rgb_y + b_u) >> SCALEBITS_OUT;
857                  v_src += (height2 - 1) * uv_src_stride;                          g = (rgb_y - g_uv) >> SCALEBITS_OUT;
858                  y_src_stride = -y_src_stride;                          r = (rgb_y + r_v) >> SCALEBITS_OUT;
859                  uv_src_stride = -uv_src_stride;                          dst[0] = MAX(0, MIN(255, b));
860                            dst[1] = MAX(0, MIN(255, g));
861                            dst[2] = MAX(0, MIN(255, r));
862    
863                            y_src++;
864                            rgb_y = RGB_Y_tab[*y_src];
865                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
866                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
867                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
868                            dst[3] = MAX(0, MIN(255, b));
869                            dst[4] = MAX(0, MIN(255, g));
870                            dst[5] = MAX(0, MIN(255, r));
871                            y_src++;
872    
873                            rgb_y = RGB_Y_tab[*y_src2];
874                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
875                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
876                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
877                            dst2[0] = MAX(0, MIN(255, b));
878                            dst2[1] = MAX(0, MIN(255, g));
879                            dst2[2] = MAX(0, MIN(255, r));
880                            y_src2++;
881    
882                            rgb_y = RGB_Y_tab[*y_src2];
883                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
884                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
885                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
886                            dst2[3] = MAX(0, MIN(255, b));
887                            dst2[4] = MAX(0, MIN(255, g));
888                            dst2[5] = MAX(0, MIN(255, r));
889                            y_src2++;
890    
891                            dst += 6;
892                            dst2 += 6;
893                    }
894    
895                    dst += dst_dif;
896                    dst2 += dst_dif;
897    
898                    y_src += y_dif;
899                    y_src2 += y_dif;
900    
901                    u_src += uv_stride;
902                    v_src += uv_stride;
903            }
904    }
905    
906    
907    
908    /* yuv 4:2:0 planar -> rgb32 */
909    
910    void
911    yv12_to_rgb32_c(uint8_t * dst,
912                                    int dst_stride,
913                                    uint8_t * y_src,
914                                    uint8_t * v_src,
915                                    uint8_t * u_src,
916                                    int y_stride,
917                                    int uv_stride,
918                                    int width,
919                                    int height)
920    {
921            const uint32_t dst_dif = 8 * dst_stride - 4 * width;
922            int32_t y_dif = 2 * y_stride - width;
923    
924            uint8_t *dst2 = dst + 4 * dst_stride;
925            uint8_t *y_src2 = y_src + y_stride;
926            uint32_t x, y;
927    
928            if (height < 0) {                       // flip image?
929                    height = -height;
930                    y_src += (height - 1) * y_stride;
931                    y_src2 = y_src - y_stride;
932                    u_src += (height / 2 - 1) * uv_stride;
933                    v_src += (height / 2 - 1) * uv_stride;
934                    y_dif = -width - 2 * y_stride;
935                    uv_stride = -uv_stride;
936            }
937    
938            for (y = height / 2; y; y--) {
939                    // process one 2x2 block per iteration
940                    for (x = 0; x < (uint32_t) width / 2; x++) {
941                            int u, v;
942                            int b_u, g_uv, r_v, rgb_y;
943                            int r, g, b;
944    
945                            u = u_src[x];
946                            v = v_src[x];
947    
948                            b_u = B_U_tab[u];
949                            g_uv = G_U_tab[u] + G_V_tab[v];
950                            r_v = R_V_tab[v];
951    
952                            rgb_y = RGB_Y_tab[*y_src];
953                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
954                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
955                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
956                            dst[0] = MAX(0, MIN(255, r));
957                            dst[1] = MAX(0, MIN(255, g));
958                            dst[2] = MAX(0, MIN(255, b));
959                            dst[3] = 0;
960    
961                            y_src++;
962                            rgb_y = RGB_Y_tab[*y_src];
963                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
964                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
965                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
966                            dst[4] = MAX(0, MIN(255, r));
967                            dst[5] = MAX(0, MIN(255, g));
968                            dst[6] = MAX(0, MIN(255, b));
969                            dst[7] = 0;
970                            y_src++;
971    
972                            rgb_y = RGB_Y_tab[*y_src2];
973                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
974                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
975                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
976                            dst2[0] = MAX(0, MIN(255, r));
977                            dst2[1] = MAX(0, MIN(255, g));
978                            dst2[2] = MAX(0, MIN(255, b));
979                            dst2[3] = 0;
980                            y_src2++;
981    
982                            rgb_y = RGB_Y_tab[*y_src2];
983                            b = (rgb_y + b_u) >> SCALEBITS_OUT;
984                            g = (rgb_y - g_uv) >> SCALEBITS_OUT;
985                            r = (rgb_y + r_v) >> SCALEBITS_OUT;
986                            dst2[4] = MAX(0, MIN(255, r));
987                            dst2[5] = MAX(0, MIN(255, g));
988                            dst2[6] = MAX(0, MIN(255, b));
989                            dst2[7] = 0;
990                            y_src2++;
991    
992                            dst += 8;
993                            dst2 += 8;
994                    }
995    
996                    dst += dst_dif;
997                    dst2 += dst_dif;
998    
999                    y_src += y_dif;
1000                    y_src2 += y_dif;
1001    
1002                    u_src += uv_stride;
1003                    v_src += uv_stride;
1004            }
1005    }
1006    
1007    
1008    
1009    /*      yuv 4:2:0 planar -> yuv planar */
1010    
1011    void
1012    yv12_to_yuv_c(uint8_t * dst,
1013                              int dst_stride,
1014                              uint8_t * y_src,
1015                              uint8_t * u_src,
1016                              uint8_t * v_src,
1017                              int y_stride,
1018                              int uv_stride,
1019                              int width,
1020                              int height)
1021    {
1022            uint32_t dst_stride2 = dst_stride >> 1;
1023            uint32_t width2 = width >> 1;
1024            uint32_t y;
1025    
1026            if (height < 0) {
1027                    height = -height;
1028                    y_src += (height - 1) * y_stride;
1029                    u_src += (height / 2 - 1) * uv_stride;
1030                    v_src += (height / 2 - 1) * uv_stride;
1031                    y_stride = -y_stride;
1032                    uv_stride = -uv_stride;
1033          }          }
1034    
1035          for (y = height; y; y--) {          for (y = height; y; y--) {
1036                  memcpy(y_dst, y_src, width);                  memcpy(dst, y_src, width);
1037                  y_src += y_src_stride;                  dst += dst_stride;
1038                  y_dst += y_dst_stride;                  y_src += y_stride;
1039          }          }
1040    
1041          for (y = height2; y; y--) {          for (y = height >> 1; y; y--) {
1042                  memcpy(u_dst, u_src, width2);                  memcpy(dst, u_src, width2);
1043                  u_src += uv_src_stride;                  dst += dst_stride2;
1044                  u_dst += uv_dst_stride;                  u_src += uv_stride;
1045          }          }
1046    
1047          for (y = height2; y; y--) {          for (y = height >> 1; y; y--) {
1048                  memcpy(v_dst, v_src, width2);                  memcpy(dst, v_src, width2);
1049                  v_src += uv_src_stride;                  dst += dst_stride2;
1050                  v_dst += uv_dst_stride;                  v_src += uv_stride;
1051          }          }
1052  }  }
1053    
1054    
1055    
1056  /* initialize rgb lookup tables */  
1057    /* yuv 4:2:0 planar -> yuyv (yuv2) packed */
1058    
1059  void  void
1060  colorspace_init(void)  yv12_to_yuyv_c(uint8_t * dst,
1061                               int dst_stride,
1062                               uint8_t * y_src,
1063                               uint8_t * u_src,
1064                               uint8_t * v_src,
1065                               int y_stride,
1066                               int uv_stride,
1067                               int width,
1068                               int height)
1069  {  {
1070          int32_t i;          const uint32_t dst_dif = 2 * (dst_stride - width);
1071            uint32_t x, y;
1072    
1073          for (i = 0; i < 256; i++) {          if (height < 0) {
1074                  RGB_Y_tab[i] = FIX_OUT(RGB_Y_OUT) * (i - Y_ADD_OUT);                  height = -height;
1075                  B_U_tab[i] = FIX_OUT(B_U_OUT) * (i - U_ADD_OUT);                  y_src += (height - 1) * y_stride;
1076                  G_U_tab[i] = FIX_OUT(G_U_OUT) * (i - U_ADD_OUT);                  u_src += (height / 2 - 1) * uv_stride;
1077                  G_V_tab[i] = FIX_OUT(G_V_OUT) * (i - V_ADD_OUT);                  v_src += (height / 2 - 1) * uv_stride;
1078                  R_V_tab[i] = FIX_OUT(R_V_OUT) * (i - V_ADD_OUT);                  y_stride = -y_stride;
1079                    uv_stride = -uv_stride;
1080            }
1081    
1082            for (y = 0; y < (uint32_t) height; y++) {
1083                    for (x = 0; x < (uint32_t) width / 2; x++) {
1084                            dst[0] = y_src[2 * x];
1085                            dst[1] = u_src[x];
1086                            dst[2] = y_src[2 * x + 1];
1087                            dst[3] = v_src[x];
1088                            dst += 4;
1089                    }
1090                    dst += dst_dif;
1091                    y_src += y_stride;
1092                    if (y & 1) {
1093                            u_src += uv_stride;
1094                            v_src += uv_stride;
1095                    }
1096            }
1097    }
1098    
1099    
1100    
1101    /* yuv 4:2:0 planar -> uyvy packed */
1102    
1103    void
1104    yv12_to_uyvy_c(uint8_t * dst,
1105                               int dst_stride,
1106                               uint8_t * y_src,
1107                               uint8_t * u_src,
1108                               uint8_t * v_src,
1109                               int y_stride,
1110                               int uv_stride,
1111                               int width,
1112                               int height)
1113    {
1114            const uint32_t dst_dif = 2 * (dst_stride - width);
1115            uint32_t x, y;
1116    
1117            if (height < 0) {
1118                    height = -height;
1119                    y_src += (height - 1) * y_stride;
1120                    u_src += (height / 2 - 1) * uv_stride;
1121                    v_src += (height / 2 - 1) * uv_stride;
1122                    y_stride = -y_stride;
1123                    uv_stride = -uv_stride;
1124            }
1125    
1126            for (y = 0; y < (uint32_t) height; y++) {
1127                    for (x = 0; x < (uint32_t) width / 2; x++) {
1128                            dst[0] = u_src[x];
1129                            dst[1] = y_src[2 * x];
1130                            dst[2] = v_src[x];
1131                            dst[3] = y_src[2 * x + 1];
1132                            dst += 4;
1133                    }
1134                    dst += dst_dif;
1135                    y_src += y_stride;
1136                    if (y & 1) {
1137                            u_src += uv_stride;
1138                            v_src += uv_stride;
1139                    }
1140            }
1141    }
1142    
1143    
1144    /*      user yuv planar -> yuv 4:2:0 planar
1145    
1146            NOTE: does not flip */
1147    
1148    void
1149    user_to_yuv_c(uint8_t * y_out,
1150                              uint8_t * u_out,
1151                              uint8_t * v_out,
1152                              int stride,
1153                              DEC_PICTURE * picture,
1154                              int width,
1155                              int height)
1156    {
1157            uint32_t stride2 = stride >> 1;
1158            uint32_t width2 = width >> 1;
1159            uint32_t y;
1160            uint8_t *src;
1161    
1162            src = picture->y;
1163            for (y = height; y; y--) {
1164                    memcpy(y_out, src, width);
1165                    src += picture->stride_y;
1166                    y_out += stride;
1167            }
1168    
1169            src = picture->u;
1170            for (y = height >> 1; y; y--) {
1171                    memcpy(u_out, src, width2);
1172                    src += picture->stride_uv;
1173                    u_out += stride2;
1174            }
1175    
1176            src = picture->v;
1177            for (y = height >> 1; y; y--) {
1178                    memcpy(v_out, src, width2);
1179                    src += picture->stride_uv;
1180                    v_out += stride2;
1181          }          }
1182  }  }

Legend:
Removed from v.1.3.2.2  
changed lines
  Added in v.1.6

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4