Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

rgb2rgb.c

00001 /*
00002  *
00003  *  rgb2rgb.c, Software RGB to RGB convertor
00004  *  pluralize by Software PAL8 to RGB convertor
00005  *               Software YUV to YUV convertor
00006  *               Software YUV to RGB convertor
00007  *  Written by Nick Kurshev.
00008  *  palette & yuv & runtime cpu stuff by Michael ([email protected]) (under GPL)
00009  */
00010 #include <inttypes.h>
00011 #include "config.h"
00012 #include "rgb2rgb.h"
00013 #include "swscale.h"
00014 #include "common.h"
00015 
00016 #define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
00017 
00018 void (*rgb24to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00019 void (*rgb24to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00020 void (*rgb24to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00021 void (*rgb32to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00022 void (*rgb32to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00023 void (*rgb32to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00024 void (*rgb15to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00025 void (*rgb15to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00026 void (*rgb15to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00027 void (*rgb16to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00028 void (*rgb16to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00029 void (*rgb16to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
00030 //void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00031 void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00032 void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00033 void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00034 void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00035 //void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00036 void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00037 void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size);
00038 
00039 void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00040         unsigned int width, unsigned int height,
00041         int lumStride, int chromStride, int dstStride);
00042 void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00043         unsigned int width, unsigned int height,
00044         int lumStride, int chromStride, int dstStride);
00045 void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00046         unsigned int width, unsigned int height,
00047         int lumStride, int chromStride, int dstStride);
00048 void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
00049         unsigned int width, unsigned int height,
00050         int lumStride, int chromStride, int srcStride);
00051 void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
00052         unsigned int width, unsigned int height,
00053         int lumStride, int chromStride, int srcStride);
00054 void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride);
00055 void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst,
00056                             unsigned width, unsigned height, int src1Stride,
00057                             int src2Stride, int dstStride);
00058 void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
00059                         uint8_t *dst1, uint8_t *dst2,
00060                         unsigned width, unsigned height,
00061                         int srcStride1, int srcStride2,
00062                         int dstStride1, int dstStride2);
00063 void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
00064                         uint8_t *dst,
00065                         unsigned width, unsigned height,
00066                         int srcStride1, int srcStride2,
00067                         int srcStride3, int dstStride);
00068 
00069 #ifdef ARCH_X86
00070 static const uint64_t mmx_null  __attribute__((aligned(8))) = 0x0000000000000000ULL;
00071 static const uint64_t mmx_one   __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
00072 static const uint64_t mask32b  attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
00073 static const uint64_t mask32g  attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
00074 static const uint64_t mask32r  attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
00075 static const uint64_t mask32   __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
00076 static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL;
00077 static const uint64_t mask3216g  __attribute__((aligned(8)))=0x0000FC000000FC00ULL;
00078 static const uint64_t mask3215g  __attribute__((aligned(8)))=0x0000F8000000F800ULL;
00079 static const uint64_t mul3216  __attribute__((aligned(8))) = 0x2000000420000004ULL;
00080 static const uint64_t mul3215  __attribute__((aligned(8))) = 0x2000000820000008ULL;
00081 static const uint64_t mask24b  attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
00082 static const uint64_t mask24g  attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
00083 static const uint64_t mask24r  attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
00084 static const uint64_t mask24l  __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
00085 static const uint64_t mask24h  __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
00086 static const uint64_t mask24hh  __attribute__((aligned(8))) = 0xffff000000000000ULL;
00087 static const uint64_t mask24hhh  __attribute__((aligned(8))) = 0xffffffff00000000ULL;
00088 static const uint64_t mask24hhhh  __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
00089 static const uint64_t mask15b  __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111  xxB */
00090 static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000  RGx */
00091 static const uint64_t mask15s  __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
00092 static const uint64_t mask15g  __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
00093 static const uint64_t mask15r  __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
00094 #define mask16b mask15b
00095 static const uint64_t mask16g  __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
00096 static const uint64_t mask16r  __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
00097 static const uint64_t red_16mask  __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
00098 static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
00099 static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
00100 static const uint64_t red_15mask  __attribute__((aligned(8))) = 0x00007c000000f800ULL;
00101 static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000007e0ULL;
00102 static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
00103 
00104 #ifdef FAST_BGR2YV12
00105 static const uint64_t bgr2YCoeff  attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
00106 static const uint64_t bgr2UCoeff  attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
00107 static const uint64_t bgr2VCoeff  attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
00108 #else
00109 static const uint64_t bgr2YCoeff  attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
00110 static const uint64_t bgr2UCoeff  attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
00111 static const uint64_t bgr2VCoeff  attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
00112 #endif
00113 static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
00114 static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL;
00115 static const uint64_t w1111       attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
00116 
00117 #if 0
00118 static volatile uint64_t __attribute__((aligned(8))) b5Dither;
00119 static volatile uint64_t __attribute__((aligned(8))) g5Dither;
00120 static volatile uint64_t __attribute__((aligned(8))) g6Dither;
00121 static volatile uint64_t __attribute__((aligned(8))) r5Dither;
00122 
00123 static uint64_t __attribute__((aligned(8))) dither4[2]={
00124         0x0103010301030103LL,
00125         0x0200020002000200LL,};
00126 
00127 static uint64_t __attribute__((aligned(8))) dither8[2]={
00128         0x0602060206020602LL,
00129         0x0004000400040004LL,};
00130 #endif
00131 #endif
00132 
00133 #define RGB2YUV_SHIFT 8
00134 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
00135 #define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
00136 #define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
00137 #define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
00138 #define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
00139 #define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
00140 #define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
00141 #define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
00142 #define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
00143 
00144 //Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
00145 //Plain C versions
00146 #undef HAVE_MMX
00147 #undef HAVE_MMX2
00148 #undef HAVE_3DNOW
00149 #undef HAVE_SSE2
00150 #define RENAME(a) a ## _C
00151 #include "rgb2rgb_template.c"
00152 
00153 #ifdef ARCH_X86
00154 
00155 //MMX versions
00156 #undef RENAME
00157 #define HAVE_MMX
00158 #undef HAVE_MMX2
00159 #undef HAVE_3DNOW
00160 #undef HAVE_SSE2
00161 #define RENAME(a) a ## _MMX
00162 #include "rgb2rgb_template.c"
00163 
00164 //MMX2 versions
00165 #undef RENAME
00166 #define HAVE_MMX
00167 #define HAVE_MMX2
00168 #undef HAVE_3DNOW
00169 #undef HAVE_SSE2
00170 #define RENAME(a) a ## _MMX2
00171 #include "rgb2rgb_template.c"
00172 
00173 //3DNOW versions
00174 #undef RENAME
00175 #define HAVE_MMX
00176 #undef HAVE_MMX2
00177 #define HAVE_3DNOW
00178 #undef HAVE_SSE2
00179 #define RENAME(a) a ## _3DNOW
00180 #include "rgb2rgb_template.c"
00181 
00182 #endif //ARCH_X86
00183 
00184 /*
00185  rgb15->rgb16 Original by Strepto/Astral
00186  ported to gcc & bugfixed : A'rpi
00187  MMX2, 3DNOW optimization by Nick Kurshev
00188  32bit c version, and and&add trick by Michael Niedermayer
00189 */
00190 
00191 void sws_rgb2rgb_init(int flags){
00192 #ifdef ARCH_X86
00193         if(flags & SWS_CPU_CAPS_MMX2){
00194                 rgb15to16= rgb15to16_MMX2;
00195                 rgb15to24= rgb15to24_MMX2;
00196                 rgb15to32= rgb15to32_MMX2;
00197                 rgb16to24= rgb16to24_MMX2;
00198                 rgb16to32= rgb16to32_MMX2;
00199                 rgb16to15= rgb16to15_MMX2;
00200                 rgb24to16= rgb24to16_MMX2;
00201                 rgb24to15= rgb24to15_MMX2;
00202                 rgb24to32= rgb24to32_MMX2;
00203                 rgb32to16= rgb32to16_MMX2;
00204                 rgb32to15= rgb32to15_MMX2;
00205                 rgb32to24= rgb32to24_MMX2;
00206                 rgb24tobgr15= rgb24tobgr15_MMX2;
00207                 rgb24tobgr16= rgb24tobgr16_MMX2;
00208                 rgb24tobgr24= rgb24tobgr24_MMX2;
00209                 rgb32tobgr32= rgb32tobgr32_MMX2;
00210                 rgb32tobgr16= rgb32tobgr16_MMX2;
00211                 rgb32tobgr15= rgb32tobgr15_MMX2;
00212                 yv12toyuy2= yv12toyuy2_MMX2;
00213                 yv12touyvy= yv12touyvy_MMX2;
00214                 yuv422ptoyuy2= yuv422ptoyuy2_MMX2;
00215                 yuy2toyv12= yuy2toyv12_MMX2;
00216 //              uyvytoyv12= uyvytoyv12_MMX2;
00217 //              yvu9toyv12= yvu9toyv12_MMX2;
00218                 planar2x= planar2x_MMX2;
00219                 rgb24toyv12= rgb24toyv12_MMX2;
00220                 interleaveBytes= interleaveBytes_MMX2;
00221                 vu9_to_vu12= vu9_to_vu12_MMX2;
00222                 yvu9_to_yuy2= yvu9_to_yuy2_MMX2;
00223         }else if(flags & SWS_CPU_CAPS_3DNOW){
00224                 rgb15to16= rgb15to16_3DNOW;
00225                 rgb15to24= rgb15to24_3DNOW;
00226                 rgb15to32= rgb15to32_3DNOW;
00227                 rgb16to24= rgb16to24_3DNOW;
00228                 rgb16to32= rgb16to32_3DNOW;
00229                 rgb16to15= rgb16to15_3DNOW;
00230                 rgb24to16= rgb24to16_3DNOW;
00231                 rgb24to15= rgb24to15_3DNOW;
00232                 rgb24to32= rgb24to32_3DNOW;
00233                 rgb32to16= rgb32to16_3DNOW;
00234                 rgb32to15= rgb32to15_3DNOW;
00235                 rgb32to24= rgb32to24_3DNOW;
00236                 rgb24tobgr15= rgb24tobgr15_3DNOW;
00237                 rgb24tobgr16= rgb24tobgr16_3DNOW;
00238                 rgb24tobgr24= rgb24tobgr24_3DNOW;
00239                 rgb32tobgr32= rgb32tobgr32_3DNOW;
00240                 rgb32tobgr16= rgb32tobgr16_3DNOW;
00241                 rgb32tobgr15= rgb32tobgr15_3DNOW;
00242                 yv12toyuy2= yv12toyuy2_3DNOW;
00243                 yv12touyvy= yv12touyvy_3DNOW;
00244                 yuv422ptoyuy2= yuv422ptoyuy2_3DNOW;
00245                 yuy2toyv12= yuy2toyv12_3DNOW;
00246 //              uyvytoyv12= uyvytoyv12_3DNOW;
00247 //              yvu9toyv12= yvu9toyv12_3DNOW;
00248                 planar2x= planar2x_3DNOW;
00249                 rgb24toyv12= rgb24toyv12_3DNOW;
00250                 interleaveBytes= interleaveBytes_3DNOW;
00251                 vu9_to_vu12= vu9_to_vu12_3DNOW;
00252                 yvu9_to_yuy2= yvu9_to_yuy2_3DNOW;
00253         }else if(flags & SWS_CPU_CAPS_MMX){
00254                 rgb15to16= rgb15to16_MMX;
00255                 rgb15to24= rgb15to24_MMX;
00256                 rgb15to32= rgb15to32_MMX;
00257                 rgb16to24= rgb16to24_MMX;
00258                 rgb16to32= rgb16to32_MMX;
00259                 rgb16to15= rgb16to15_MMX;
00260                 rgb24to16= rgb24to16_MMX;
00261                 rgb24to15= rgb24to15_MMX;
00262                 rgb24to32= rgb24to32_MMX;
00263                 rgb32to16= rgb32to16_MMX;
00264                 rgb32to15= rgb32to15_MMX;
00265                 rgb32to24= rgb32to24_MMX;
00266                 rgb24tobgr15= rgb24tobgr15_MMX;
00267                 rgb24tobgr16= rgb24tobgr16_MMX;
00268                 rgb24tobgr24= rgb24tobgr24_MMX;
00269                 rgb32tobgr32= rgb32tobgr32_MMX;
00270                 rgb32tobgr16= rgb32tobgr16_MMX;
00271                 rgb32tobgr15= rgb32tobgr15_MMX;
00272                 yv12toyuy2= yv12toyuy2_MMX;
00273                 yv12touyvy= yv12touyvy_MMX;
00274                 yuv422ptoyuy2= yuv422ptoyuy2_MMX;
00275                 yuy2toyv12= yuy2toyv12_MMX;
00276 //              uyvytoyv12= uyvytoyv12_MMX;
00277 //              yvu9toyv12= yvu9toyv12_MMX;
00278                 planar2x= planar2x_MMX;
00279                 rgb24toyv12= rgb24toyv12_MMX;
00280                 interleaveBytes= interleaveBytes_MMX;
00281                 vu9_to_vu12= vu9_to_vu12_MMX;
00282                 yvu9_to_yuy2= yvu9_to_yuy2_MMX;
00283         }else
00284 #endif
00285         {
00286                 rgb15to16= rgb15to16_C;
00287                 rgb15to24= rgb15to24_C;
00288                 rgb15to32= rgb15to32_C;
00289                 rgb16to24= rgb16to24_C;
00290                 rgb16to32= rgb16to32_C;
00291                 rgb16to15= rgb16to15_C;
00292                 rgb24to16= rgb24to16_C;
00293                 rgb24to15= rgb24to15_C;
00294                 rgb24to32= rgb24to32_C;
00295                 rgb32to16= rgb32to16_C;
00296                 rgb32to15= rgb32to15_C;
00297                 rgb32to24= rgb32to24_C;
00298                 rgb24tobgr15= rgb24tobgr15_C;
00299                 rgb24tobgr16= rgb24tobgr16_C;
00300                 rgb24tobgr24= rgb24tobgr24_C;
00301                 rgb32tobgr32= rgb32tobgr32_C;
00302                 rgb32tobgr16= rgb32tobgr16_C;
00303                 rgb32tobgr15= rgb32tobgr15_C;
00304                 yv12toyuy2= yv12toyuy2_C;
00305                 yv12touyvy= yv12touyvy_C;
00306                 yuv422ptoyuy2= yuv422ptoyuy2_C;
00307                 yuy2toyv12= yuy2toyv12_C;
00308 //              uyvytoyv12= uyvytoyv12_C;
00309 //              yvu9toyv12= yvu9toyv12_C;
00310                 planar2x= planar2x_C;
00311                 rgb24toyv12= rgb24toyv12_C;
00312                 interleaveBytes= interleaveBytes_C;
00313                 vu9_to_vu12= vu9_to_vu12_C;
00314                 yvu9_to_yuy2= yvu9_to_yuy2_C;
00315         }
00316 }
00317 
00321 void palette8torgb32(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00322 {
00323         unsigned i;
00324 
00325 /*
00326         for(i=0; i<num_pixels; i++)
00327                 ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
00328 */
00329 
00330         for(i=0; i<num_pixels; i++)
00331         {
00332                 //FIXME slow?
00333                 dst[0]= palette[ src[i]*4+2 ];
00334                 dst[1]= palette[ src[i]*4+1 ];
00335                 dst[2]= palette[ src[i]*4+0 ];
00336 //              dst[3]= 0; /* do we need this cleansing? */
00337                 dst+= 4;
00338         }
00339 }
00340 
00341 void palette8tobgr32(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00342 {
00343         unsigned i;
00344         for(i=0; i<num_pixels; i++)
00345         {
00346                 //FIXME slow?
00347                 dst[0]= palette[ src[i]*4+0 ];
00348                 dst[1]= palette[ src[i]*4+1 ];
00349                 dst[2]= palette[ src[i]*4+2 ];
00350 //              dst[3]= 0; /* do we need this cleansing? */
00351                 dst+= 4;
00352         }
00353 }
00354 
00358 void palette8torgb24(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00359 {
00360         unsigned i;
00361 /*
00362         writes 1 byte o much and might cause alignment issues on some architectures?
00363         for(i=0; i<num_pixels; i++)
00364                 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
00365 */
00366         for(i=0; i<num_pixels; i++)
00367         {
00368                 //FIXME slow?
00369                 dst[0]= palette[ src[i]*4+2 ];
00370                 dst[1]= palette[ src[i]*4+1 ];
00371                 dst[2]= palette[ src[i]*4+0 ];
00372                 dst+= 3;
00373         }
00374 }
00375 
00376 void palette8tobgr24(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00377 {
00378         unsigned i;
00379 /*
00380         writes 1 byte o much and might cause alignment issues on some architectures?
00381         for(i=0; i<num_pixels; i++)
00382                 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
00383 */
00384         for(i=0; i<num_pixels; i++)
00385         {
00386                 //FIXME slow?
00387                 dst[0]= palette[ src[i]*4+0 ];
00388                 dst[1]= palette[ src[i]*4+1 ];
00389                 dst[2]= palette[ src[i]*4+2 ];
00390                 dst+= 3;
00391         }
00392 }
00393 
00397 void palette8torgb16(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00398 {
00399         unsigned i;
00400         for(i=0; i<num_pixels; i++)
00401                 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
00402 }
00403 void palette8tobgr16(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00404 {
00405         unsigned i;
00406         for(i=0; i<num_pixels; i++)
00407                 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
00408 }
00409 
00413 void palette8torgb15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00414 {
00415         unsigned i;
00416         for(i=0; i<num_pixels; i++)
00417                 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
00418 }
00419 void palette8tobgr15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
00420 {
00421         unsigned i;
00422         for(i=0; i<num_pixels; i++)
00423                 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
00424 }
00425 
00426 void rgb32tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00427 {
00428         unsigned i;
00429         unsigned num_pixels = src_size >> 2;
00430         for(i=0; i<num_pixels; i++)
00431         {
00432                 dst[3*i + 0] = src[4*i + 2];
00433                 dst[3*i + 1] = src[4*i + 1];
00434                 dst[3*i + 2] = src[4*i + 0];
00435         }
00436 }
00437 
00438 void rgb24tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00439 {
00440         unsigned i;
00441         for(i=0; 3*i<src_size; i++)
00442         {
00443                 dst[4*i + 0] = src[3*i + 2];
00444                 dst[4*i + 1] = src[3*i + 1];
00445                 dst[4*i + 2] = src[3*i + 0];
00446                 dst[4*i + 3] = 0;
00447         }
00448 }
00449 
00450 void rgb16tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00451 {
00452         const uint16_t *end;
00453         uint8_t *d = (uint8_t *)dst;
00454         const uint16_t *s = (uint16_t *)src;
00455         end = s + src_size/2;
00456         while(s < end)
00457         {
00458                 register uint16_t bgr;
00459                 bgr = *s++;
00460                 *d++ = (bgr&0xF800)>>8;
00461                 *d++ = (bgr&0x7E0)>>3;
00462                 *d++ = (bgr&0x1F)<<3;
00463                 *d++ = 0;
00464         }
00465 }
00466 
00467 void rgb16tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00468 {
00469         const uint16_t *end;
00470         uint8_t *d = (uint8_t *)dst;
00471         const uint16_t *s = (const uint16_t *)src;
00472         end = s + src_size/2;
00473         while(s < end)
00474         {
00475                 register uint16_t bgr;
00476                 bgr = *s++;
00477                 *d++ = (bgr&0xF800)>>8;
00478                 *d++ = (bgr&0x7E0)>>3;
00479                 *d++ = (bgr&0x1F)<<3;
00480         }
00481 }
00482 
00483 void rgb16tobgr16(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00484 {
00485         unsigned i;
00486         unsigned num_pixels = src_size >> 1;
00487         
00488         for(i=0; i<num_pixels; i++)
00489         {
00490             unsigned b,g,r;
00491             register uint16_t rgb;
00492             rgb = src[2*i];
00493             r = rgb&0x1F;
00494             g = (rgb&0x7E0)>>5;
00495             b = (rgb&0xF800)>>11;
00496             dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
00497         }
00498 }
00499 
00500 void rgb16tobgr15(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00501 {
00502         unsigned i;
00503         unsigned num_pixels = src_size >> 1;
00504         
00505         for(i=0; i<num_pixels; i++)
00506         {
00507             unsigned b,g,r;
00508             register uint16_t rgb;
00509             rgb = src[2*i];
00510             r = rgb&0x1F;
00511             g = (rgb&0x7E0)>>5;
00512             b = (rgb&0xF800)>>11;
00513             dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
00514         }
00515 }
00516 
00517 void rgb15tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00518 {
00519         const uint16_t *end;
00520         uint8_t *d = (uint8_t *)dst;
00521         const uint16_t *s = (const uint16_t *)src;
00522         end = s + src_size/2;
00523         while(s < end)
00524         {
00525                 register uint16_t bgr;
00526                 bgr = *s++;
00527                 *d++ = (bgr&0x7C00)>>7;
00528                 *d++ = (bgr&0x3E0)>>2;
00529                 *d++ = (bgr&0x1F)<<3;
00530                 *d++ = 0;
00531         }
00532 }
00533 
00534 void rgb15tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00535 {
00536         const uint16_t *end;
00537         uint8_t *d = (uint8_t *)dst;
00538         const uint16_t *s = (uint16_t *)src;
00539         end = s + src_size/2;
00540         while(s < end)
00541         {
00542                 register uint16_t bgr;
00543                 bgr = *s++;
00544                 *d++ = (bgr&0x7C00)>>7;
00545                 *d++ = (bgr&0x3E0)>>2;
00546                 *d++ = (bgr&0x1F)<<3;
00547         }
00548 }
00549 
00550 void rgb15tobgr16(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00551 {
00552         unsigned i;
00553         unsigned num_pixels = src_size >> 1;
00554         
00555         for(i=0; i<num_pixels; i++)
00556         {
00557             unsigned b,g,r;
00558             register uint16_t rgb;
00559             rgb = src[2*i];
00560             r = rgb&0x1F;
00561             g = (rgb&0x3E0)>>5;
00562             b = (rgb&0x7C00)>>10;
00563             dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
00564         }
00565 }
00566 
00567 void rgb15tobgr15(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00568 {
00569         unsigned i;
00570         unsigned num_pixels = src_size >> 1;
00571         
00572         for(i=0; i<num_pixels; i++)
00573         {
00574             unsigned b,g,r;
00575             register uint16_t rgb;
00576             rgb = src[2*i];
00577             r = rgb&0x1F;
00578             g = (rgb&0x3E0)>>5;
00579             b = (rgb&0x7C00)>>10;
00580             dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
00581         }
00582 }
00583 
00584 void rgb8tobgr8(const uint8_t *src, uint8_t *dst, unsigned int src_size)
00585 {
00586         unsigned i;
00587         unsigned num_pixels = src_size;
00588         for(i=0; i<num_pixels; i++)
00589         {
00590             unsigned b,g,r;
00591             register uint8_t rgb;
00592             rgb = src[i];
00593             r = (rgb&0x07);
00594             g = (rgb&0x38)>>3;
00595             b = (rgb&0xC0)>>6;
00596             dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
00597         }
00598 }

Generated on Tue Dec 20 10:14:54 2005 for vlc-0.8.4a by  doxygen 1.4.2