i420_rgb.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * i420_rgb.h : YUV to bitmap RGB conversion module for vlc
00003  *****************************************************************************
00004  * Copyright (C) 2000, 2004 the VideoLAN team
00005  * $Id: 66171fbeee5ad0e40355391250d0c691739100b9 $
00006  *
00007  * Authors: Samuel Hocevar <sam@zoy.org>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00022  *****************************************************************************/
00023 
00024 /** Number of entries in RGB palette/colormap */
00025 #define CMAP_RGB2_SIZE 256
00026 
00027 /**
00028  * filter_sys_t: chroma method descriptor
00029 
00030  * This structure is part of the chroma transformation descriptor, it
00031  * describes the yuv2rgb specific properties.
00032  */
00033 struct filter_sys_t
00034 {
00035     uint8_t  *p_buffer;
00036     int *p_offset;
00037 
00038 #ifdef MODULE_NAME_IS_i420_rgb
00039     /**< Pre-calculated conversion tables */
00040     void *p_base;                      /**< base for all conversion tables */
00041     uint8_t   *p_rgb8;                 /**< RGB 8 bits table */
00042     uint16_t  *p_rgb16;                /**< RGB 16 bits table */
00043     uint32_t  *p_rgb32;                /**< RGB 32 bits table */
00044 
00045     /**< To get RGB value for palette entry i, use (p_rgb_r[i], p_rgb_g[i],
00046        p_rgb_b[i]). Note these are 16 bits per pixel. For 8bpp entries,
00047        shift right 8 bits.
00048     */
00049     uint16_t  p_rgb_r[CMAP_RGB2_SIZE];  /**< Red values of palette */
00050     uint16_t  p_rgb_g[CMAP_RGB2_SIZE];  /**< Green values of palette */
00051     uint16_t  p_rgb_b[CMAP_RGB2_SIZE];  /**< Blue values of palette */
00052 #endif
00053 };
00054 
00055 /*****************************************************************************
00056  * Prototypes
00057  *****************************************************************************/
00058 #ifdef MODULE_NAME_IS_i420_rgb
00059 void I420_RGB8         ( filter_t *, picture_t *, picture_t * );
00060 void I420_RGB16_dither ( filter_t *, picture_t *, picture_t * );
00061 void I420_RGB16        ( filter_t *, picture_t *, picture_t * );
00062 void I420_RGB32        ( filter_t *, picture_t *, picture_t * );
00063 #else // if defined(MODULE_NAME_IS_i420_rgb_mmx)
00064 void I420_R5G5B5       ( filter_t *, picture_t *, picture_t * );
00065 void I420_R5G6B5       ( filter_t *, picture_t *, picture_t * );
00066 void I420_A8R8G8B8     ( filter_t *, picture_t *, picture_t * );
00067 void I420_R8G8B8A8     ( filter_t *, picture_t *, picture_t * );
00068 void I420_B8G8R8A8     ( filter_t *, picture_t *, picture_t * );
00069 void I420_A8B8G8R8     ( filter_t *, picture_t *, picture_t * );
00070 #endif
00071 
00072 /*****************************************************************************
00073  * CONVERT_*_PIXEL: pixel conversion macros
00074  *****************************************************************************
00075  * These conversion routines are used by YUV conversion functions.
00076  * conversion are made from p_y, p_u, p_v, which are modified, to p_buffer,
00077  * which is also modified. CONVERT_4YUV_PIXEL is used for 8bpp dithering,
00078  * CONVERT_4YUV_PIXEL_SCALE does the same but also scales the output.
00079  *****************************************************************************/
00080 #define CONVERT_Y_PIXEL( BPP )                                                \
00081     /* Only Y sample is present */                                            \
00082     p_ybase = p_yuv + *p_y++;                                                 \
00083     *p_buffer++ = p_ybase[RED_OFFSET-((V_RED_COEF*128)>>SHIFT) + i_red] |     \
00084         p_ybase[GREEN_OFFSET-(((U_GREEN_COEF+V_GREEN_COEF)*128)>>SHIFT)       \
00085         + i_green ] | p_ybase[BLUE_OFFSET-((U_BLUE_COEF*128)>>SHIFT) + i_blue];
00086 
00087 #define CONVERT_YUV_PIXEL( BPP )                                              \
00088     /* Y, U and V samples are present */                                      \
00089     i_uval =    *p_u++;                                                       \
00090     i_vval =    *p_v++;                                                       \
00091     i_red =     (V_RED_COEF * i_vval) >> SHIFT;                               \
00092     i_green =   (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;     \
00093     i_blue =    (U_BLUE_COEF * i_uval) >> SHIFT;                              \
00094     CONVERT_Y_PIXEL( BPP )                                                    \
00095 
00096 #define CONVERT_Y_PIXEL_DITHER( BPP )                                         \
00097     /* Only Y sample is present */                                            \
00098     p_ybase = p_yuv + *p_y++;                                                 \
00099     *p_buffer++ = p_ybase[RED_OFFSET-((V_RED_COEF*128+p_dither[i_real_y])>>SHIFT) + i_red] |     \
00100         p_ybase[GREEN_OFFSET-(((U_GREEN_COEF+V_GREEN_COEF)*128+p_dither[i_real_y])>>SHIFT)       \
00101         + i_green ] | p_ybase[BLUE_OFFSET-((U_BLUE_COEF*128+p_dither[i_real_y])>>SHIFT) + i_blue];
00102 
00103 #define CONVERT_YUV_PIXEL_DITHER( BPP )                                       \
00104     /* Y, U and V samples are present */                                      \
00105     i_uval =    *p_u++;                                                       \
00106     i_vval =    *p_v++;                                                       \
00107     i_red =     (V_RED_COEF * i_vval) >> SHIFT;                               \
00108     i_green =   (U_GREEN_COEF * i_uval + V_GREEN_COEF * i_vval) >> SHIFT;     \
00109     i_blue =    (U_BLUE_COEF * i_uval) >> SHIFT;                              \
00110     CONVERT_Y_PIXEL_DITHER( BPP )                                             \
00111 
00112 #define CONVERT_4YUV_PIXEL( CHROMA )                                          \
00113     *p_pic++ = p_lookup[                                                      \
00114         (((*p_y++ + dither10[i_real_y]) >> 4) << 7)                           \
00115       + ((*p_u + dither20[i_real_y]) >> 5) * 9                                \
00116       + ((*p_v + dither20[i_real_y]) >> 5) ];                                 \
00117     *p_pic++ = p_lookup[                                                      \
00118         (((*p_y++ + dither11[i_real_y]) >> 4) << 7)                           \
00119       + ((*p_u++ + dither21[i_real_y]) >> 5) * 9                              \
00120       + ((*p_v++ + dither21[i_real_y]) >> 5) ];                               \
00121     *p_pic++ = p_lookup[                                                      \
00122         (((*p_y++ + dither12[i_real_y]) >> 4) << 7)                           \
00123       + ((*p_u + dither22[i_real_y]) >> 5) * 9                                \
00124       + ((*p_v + dither22[i_real_y]) >> 5) ];                                 \
00125     *p_pic++ = p_lookup[                                                      \
00126         (((*p_y++ + dither13[i_real_y]) >> 4) << 7)                           \
00127       + ((*p_u++ + dither23[i_real_y]) >> 5) * 9                              \
00128       + ((*p_v++ + dither23[i_real_y]) >> 5) ];                               \
00129 
00130 #define CONVERT_4YUV_PIXEL_SCALE( CHROMA )                                    \
00131     *p_pic++ = p_lookup[                                                      \
00132         ( ((*p_y + dither10[i_real_y]) >> 4) << 7)                            \
00133         + ((*p_u + dither20[i_real_y]) >> 5) * 9                              \
00134         + ((*p_v + dither20[i_real_y]) >> 5) ];                               \
00135     p_y += *p_offset++;                                                       \
00136     p_u += *p_offset;                                                         \
00137     p_v += *p_offset++;                                                       \
00138     *p_pic++ = p_lookup[                                                      \
00139         ( ((*p_y + dither11[i_real_y]) >> 4) << 7)                            \
00140         + ((*p_u + dither21[i_real_y]) >> 5) * 9                              \
00141         + ((*p_v + dither21[i_real_y]) >> 5) ];                               \
00142     p_y += *p_offset++;                                                       \
00143     p_u += *p_offset;                                                         \
00144     p_v += *p_offset++;                                                       \
00145     *p_pic++ = p_lookup[                                                      \
00146         ( ((*p_y + dither12[i_real_y]) >> 4) << 7)                            \
00147         + ((*p_u + dither22[i_real_y]) >> 5) * 9                              \
00148         + ((*p_v + dither22[i_real_y]) >> 5) ];                               \
00149     p_y += *p_offset++;                                                       \
00150     p_u += *p_offset;                                                         \
00151     p_v += *p_offset++;                                                       \
00152     *p_pic++ = p_lookup[                                                      \
00153         ( ((*p_y + dither13[i_real_y]) >> 4) << 7)                            \
00154         + ((*p_u + dither23[i_real_y]) >> 5) * 9                              \
00155         + ((*p_v + dither23[i_real_y]) >> 5) ];                               \
00156     p_y += *p_offset++;                                                       \
00157     p_u += *p_offset;                                                         \
00158     p_v += *p_offset++;                                                       \
00159 
00160 /*****************************************************************************
00161  * SCALE_WIDTH: scale a line horizontally
00162  *****************************************************************************
00163  * This macro scales a line using rendering buffer and offset array. It works
00164  * for 1, 2 and 4 Bpp.
00165  *****************************************************************************/
00166 #define SCALE_WIDTH                                                           \
00167     if( b_hscale )                                                            \
00168     {                                                                         \
00169         /* Horizontal scaling, conversion has been done to buffer.            \
00170          * Rewind buffer and offset, then copy and scale line */              \
00171         p_buffer = p_buffer_start;                                            \
00172         p_offset = p_offset_start;                                            \
00173         for( i_x = p_filter->fmt_out.video.i_width / 16; i_x--; )             \
00174         {                                                                     \
00175             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00176             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00177             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00178             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00179             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00180             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00181             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00182             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00183             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00184             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00185             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00186             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00187             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00188             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00189             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00190             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00191         }                                                                     \
00192         for( i_x = p_filter->fmt_out.video.i_width & 15; i_x--; )             \
00193         {                                                                     \
00194             *p_pic++ = *p_buffer;   p_buffer += *p_offset++;                  \
00195         }                                                                     \
00196         p_pic = (void*)((uint8_t*)p_pic + i_right_margin );                   \
00197     }                                                                         \
00198     else                                                                      \
00199     {                                                                         \
00200         /* No scaling, conversion has been done directly in picture memory.   \
00201          * Increment of picture pointer to end of line is still needed */     \
00202         p_pic = (void*)((uint8_t*)p_pic + p_dest->p->i_pitch );               \
00203     }                                                                         \
00204 
00205 /*****************************************************************************
00206  * SCALE_WIDTH_DITHER: scale a line horizontally for dithered 8 bpp
00207  *****************************************************************************
00208  * This macro scales a line using an offset array.
00209  *****************************************************************************/
00210 #define SCALE_WIDTH_DITHER( CHROMA )                                          \
00211     if( b_hscale )                                                            \
00212     {                                                                         \
00213         /* Horizontal scaling - we can't use a buffer due to dithering */     \
00214         p_offset = p_offset_start;                                            \
00215         for( i_x = p_filter->fmt_out.video.i_width / 16; i_x--; )             \
00216         {                                                                     \
00217             CONVERT_4YUV_PIXEL_SCALE( CHROMA )                                \
00218             CONVERT_4YUV_PIXEL_SCALE( CHROMA )                                \
00219             CONVERT_4YUV_PIXEL_SCALE( CHROMA )                                \
00220             CONVERT_4YUV_PIXEL_SCALE( CHROMA )                                \
00221         }                                                                     \
00222     }                                                                         \
00223     else                                                                      \
00224     {                                                                         \
00225         for( i_x = p_filter->fmt_in.video.i_width / 16; i_x--;  )             \
00226         {                                                                     \
00227             CONVERT_4YUV_PIXEL( CHROMA )                                      \
00228             CONVERT_4YUV_PIXEL( CHROMA )                                      \
00229             CONVERT_4YUV_PIXEL( CHROMA )                                      \
00230             CONVERT_4YUV_PIXEL( CHROMA )                                      \
00231         }                                                                     \
00232     }                                                                         \
00233     /* Increment of picture pointer to end of line is still needed */         \
00234     p_pic = (void*)((uint8_t*)p_pic + i_right_margin );                       \
00235                                                                               \
00236     /* Increment the Y coordinate in the matrix, modulo 4 */                  \
00237     i_real_y = (i_real_y + 1) & 0x3;                                          \
00238 
00239 /*****************************************************************************
00240  * SCALE_HEIGHT: handle vertical scaling
00241  *****************************************************************************
00242  * This macro handle vertical scaling for a picture. CHROMA may be 420, 422 or
00243  * 444 for RGB conversion, or 400 for gray conversion. It works for 1, 2, 3
00244  * and 4 Bpp.
00245  *****************************************************************************/
00246 #define SCALE_HEIGHT( CHROMA, BPP )                                           \
00247     /* If line is odd, rewind 4:2:0 U and V samples */                        \
00248     if( ((CHROMA == 420) || (CHROMA == 422)) && !(i_y & 0x1) )                \
00249     {                                                                         \
00250         p_u -= i_chroma_width;                                                \
00251         p_v -= i_chroma_width;                                                \
00252     }                                                                         \
00253                                                                               \
00254     /*                                                                        \
00255      * Handle vertical scaling. The current line can be copied or next one    \
00256      * can be ignored.                                                        \
00257      */                                                                       \
00258     switch( i_vscale )                                                        \
00259     {                                                                         \
00260     case -1:                             /* vertical scaling factor is < 1 */ \
00261         while( (i_scale_count -= p_filter->fmt_out.video.i_height) > 0 )      \
00262         {                                                                     \
00263             /* Height reduction: skip next source line */                     \
00264             p_y += p_filter->fmt_in.video.i_width;                            \
00265             i_y++;                                                            \
00266             if( (CHROMA == 420) || (CHROMA == 422) )                          \
00267             {                                                                 \
00268                 if( i_y & 0x1 )                                               \
00269                 {                                                             \
00270                     p_u += i_chroma_width;                                    \
00271                     p_v += i_chroma_width;                                    \
00272                 }                                                             \
00273             }                                                                 \
00274             else if( CHROMA == 444 )                                          \
00275             {                                                                 \
00276                 p_u += p_filter->fmt_in.video.i_width;                        \
00277                 p_v += p_filter->fmt_in.video.i_width;                        \
00278             }                                                                 \
00279         }                                                                     \
00280         i_scale_count += p_filter->fmt_in.video.i_height;                     \
00281         break;                                                                \
00282     case 1:                              /* vertical scaling factor is > 1 */ \
00283         while( (i_scale_count -= p_filter->fmt_in.video.i_height) > 0 )       \
00284         {                                                                     \
00285             /* Height increment: copy previous picture line */                \
00286             vlc_memcpy( p_pic, p_pic_start, p_filter->fmt_out.video.i_width * BPP ); \
00287             p_pic = (void*)((uint8_t*)p_pic + p_dest->p->i_pitch );           \
00288         }                                                                     \
00289         i_scale_count += p_filter->fmt_out.video.i_height;                    \
00290         break;                                                                \
00291     }                                                                         \
00292 
00293 /*****************************************************************************
00294  * SCALE_HEIGHT_DITHER: handle vertical scaling for dithered 8 bpp
00295  *****************************************************************************
00296  * This macro handles vertical scaling for a picture. CHROMA may be 420,
00297  * 422 or 444 for RGB conversion, or 400 for gray conversion.
00298  *****************************************************************************/
00299 #define SCALE_HEIGHT_DITHER( CHROMA )                                         \
00300                                                                               \
00301     /* If line is odd, rewind 4:2:0 U and V samples */                        \
00302     if( ((CHROMA == 420) || (CHROMA == 422)) && !(i_y & 0x1) )                \
00303     {                                                                         \
00304         p_u -= i_chroma_width;                                                \
00305         p_v -= i_chroma_width;                                                \
00306     }                                                                         \
00307                                                                               \
00308     /*                                                                        \
00309      * Handle vertical scaling. The current line can be copied or next one    \
00310      * can be ignored.                                                        \
00311      */                                                                       \
00312                                                                               \
00313     switch( i_vscale )                                                        \
00314     {                                                                         \
00315     case -1:                             /* vertical scaling factor is < 1 */ \
00316         while( (i_scale_count -= p_filter->fmt_out.video.i_height) > 0 )      \
00317         {                                                                     \
00318             /* Height reduction: skip next source line */                     \
00319             p_y += p_filter->fmt_in.video.i_width;                            \
00320             i_y++;                                                            \
00321             if( (CHROMA == 420) || (CHROMA == 422) )                          \
00322             {                                                                 \
00323                 if( i_y & 0x1 )                                               \
00324                 {                                                             \
00325                     p_u += i_chroma_width;                                    \
00326                     p_v += i_chroma_width;                                    \
00327                 }                                                             \
00328             }                                                                 \
00329             else if( CHROMA == 444 )                                          \
00330             {                                                                 \
00331                 p_u += p_filter->fmt_in.video.i_width;                        \
00332                 p_v += p_filter->fmt_in.video.i_width;                        \
00333             }                                                                 \
00334         }                                                                     \
00335         i_scale_count += p_filter->fmt_in.video.i_height;                     \
00336         break;                                                                \
00337     case 1:                              /* vertical scaling factor is > 1 */ \
00338         while( (i_scale_count -= p_filter->fmt_in.video.i_height) > 0 )       \
00339         {                                                                     \
00340             p_y -= p_filter->fmt_in.video.i_width;                            \
00341             p_u -= i_chroma_width;                                            \
00342             p_v -= i_chroma_width;                                            \
00343             SCALE_WIDTH_DITHER( CHROMA );                                     \
00344         }                                                                     \
00345         i_scale_count += p_filter->fmt_out.video.i_height;                    \
00346         break;                                                                \
00347     }                                                                         \
00348 

Generated on Tue May 25 08:04:59 2010 for VLC by  doxygen 1.5.6