00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <inttypes.h>
00026 #include "config.h"
00027 #include "libavutil/bswap.h"
00028 #include "rgb2rgb.h"
00029 #include "swscale.h"
00030 #include "swscale_internal.h"
00031
00032 void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size);
00033 void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
00034 void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
00035 void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
00036 void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size);
00037 void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size);
00038 void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size);
00039 void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
00040 void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size);
00041 void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size);
00042 void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
00043 void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size);
00044 void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size);
00045 void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size);
00046 void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size);
00047 void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size);
00048 void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size);
00049 void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size);
00050
00051 void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00052 int width, int height,
00053 int lumStride, int chromStride, int dstStride);
00054 void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00055 int width, int height,
00056 int lumStride, int chromStride, int dstStride);
00057 void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00058 int width, int height,
00059 int lumStride, int chromStride, int dstStride);
00060 void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
00061 int width, int height,
00062 int lumStride, int chromStride, int dstStride);
00063 void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
00064 int width, int height,
00065 int lumStride, int chromStride, int srcStride);
00066 void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
00067 int width, int height,
00068 int lumStride, int chromStride, int srcStride);
00069 void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height,
00070 int srcStride, int dstStride);
00071 void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst,
00072 int width, int height, int src1Stride,
00073 int src2Stride, int dstStride);
00074 void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
00075 uint8_t *dst1, uint8_t *dst2,
00076 int width, int height,
00077 int srcStride1, int srcStride2,
00078 int dstStride1, int dstStride2);
00079 void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
00080 uint8_t *dst,
00081 int width, int height,
00082 int srcStride1, int srcStride2,
00083 int srcStride3, int dstStride);
00084 void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
00085 int width, int height,
00086 int lumStride, int chromStride, int srcStride);
00087 void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
00088 int width, int height,
00089 int lumStride, int chromStride, int srcStride);
00090 void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
00091 int width, int height,
00092 int lumStride, int chromStride, int srcStride);
00093 void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src,
00094 int width, int height,
00095 int lumStride, int chromStride, int srcStride);
00096
00097 #define RGB2YUV_SHIFT 8
00098 #define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
00099 #define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
00100 #define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
00101 #define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
00102 #define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
00103 #define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
00104 #define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
00105 #define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
00106 #define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
00107
00108
00109 #include "rgb2rgb_template.c"
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 void sws_rgb2rgb_init(void)
00120 {
00121 rgb2rgb_init_c();
00122 if (HAVE_MMX)
00123 rgb2rgb_init_x86();
00124 }
00125
00126 #if LIBSWSCALE_VERSION_MAJOR < 1
00127 void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
00128 {
00129 sws_convertPalette8ToPacked32(src, dst, num_pixels, palette);
00130 }
00131
00132 void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
00133 {
00134 sws_convertPalette8ToPacked24(src, dst, num_pixels, palette);
00135 }
00136
00140 void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
00141 {
00142 long i;
00143 for (i=0; i<num_pixels; i++)
00144 ((uint16_t *)dst)[i] = ((const uint16_t *)palette)[src[i]];
00145 }
00146 void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
00147 {
00148 long i;
00149 for (i=0; i<num_pixels; i++)
00150 ((uint16_t *)dst)[i] = av_bswap16(((const uint16_t *)palette)[src[i]]);
00151 }
00152 #endif
00153
00154 void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
00155 {
00156 int i;
00157 int num_pixels = src_size >> 2;
00158 for (i=0; i<num_pixels; i++) {
00159 #if HAVE_BIGENDIAN
00160
00161 dst[3*i + 0] = src[4*i + 1];
00162 dst[3*i + 1] = src[4*i + 2];
00163 dst[3*i + 2] = src[4*i + 3];
00164 #else
00165 dst[3*i + 0] = src[4*i + 2];
00166 dst[3*i + 1] = src[4*i + 1];
00167 dst[3*i + 2] = src[4*i + 0];
00168 #endif
00169 }
00170 }
00171
00172 void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
00173 {
00174 int i;
00175 for (i=0; 3*i<src_size; i++) {
00176 #if HAVE_BIGENDIAN
00177
00178 dst[4*i + 0] = 255;
00179 dst[4*i + 1] = src[3*i + 0];
00180 dst[4*i + 2] = src[3*i + 1];
00181 dst[4*i + 3] = src[3*i + 2];
00182 #else
00183 dst[4*i + 0] = src[3*i + 2];
00184 dst[4*i + 1] = src[3*i + 1];
00185 dst[4*i + 2] = src[3*i + 0];
00186 dst[4*i + 3] = 255;
00187 #endif
00188 }
00189 }
00190
00191 void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
00192 {
00193 const uint16_t *end;
00194 uint8_t *d = dst;
00195 const uint16_t *s = (const uint16_t *)src;
00196 end = s + src_size/2;
00197 while (s < end) {
00198 register uint16_t bgr;
00199 bgr = *s++;
00200 #if HAVE_BIGENDIAN
00201 *d++ = 255;
00202 *d++ = (bgr&0x1F)<<3;
00203 *d++ = (bgr&0x7E0)>>3;
00204 *d++ = (bgr&0xF800)>>8;
00205 #else
00206 *d++ = (bgr&0xF800)>>8;
00207 *d++ = (bgr&0x7E0)>>3;
00208 *d++ = (bgr&0x1F)<<3;
00209 *d++ = 255;
00210 #endif
00211 }
00212 }
00213
00214 void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
00215 {
00216 const uint16_t *end;
00217 uint8_t *d = dst;
00218 const uint16_t *s = (const uint16_t *)src;
00219 end = s + src_size/2;
00220 while (s < end) {
00221 register uint16_t bgr;
00222 bgr = *s++;
00223 *d++ = (bgr&0xF800)>>8;
00224 *d++ = (bgr&0x7E0)>>3;
00225 *d++ = (bgr&0x1F)<<3;
00226 }
00227 }
00228
00229 void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
00230 {
00231 int i;
00232 int num_pixels = src_size >> 1;
00233
00234 for (i=0; i<num_pixels; i++) {
00235 unsigned rgb = ((const uint16_t*)src)[i];
00236 ((uint16_t*)dst)[i] = (rgb>>11) | (rgb&0x7E0) | (rgb<<11);
00237 }
00238 }
00239
00240 void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
00241 {
00242 int i;
00243 int num_pixels = src_size >> 1;
00244
00245 for (i=0; i<num_pixels; i++) {
00246 unsigned rgb = ((const uint16_t*)src)[i];
00247 ((uint16_t*)dst)[i] = (rgb>>11) | ((rgb&0x7C0)>>1) | ((rgb&0x1F)<<10);
00248 }
00249 }
00250
00251 void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
00252 {
00253 const uint16_t *end;
00254 uint8_t *d = dst;
00255 const uint16_t *s = (const uint16_t *)src;
00256 end = s + src_size/2;
00257 while (s < end) {
00258 register uint16_t bgr;
00259 bgr = *s++;
00260 #if HAVE_BIGENDIAN
00261 *d++ = 255;
00262 *d++ = (bgr&0x1F)<<3;
00263 *d++ = (bgr&0x3E0)>>2;
00264 *d++ = (bgr&0x7C00)>>7;
00265 #else
00266 *d++ = (bgr&0x7C00)>>7;
00267 *d++ = (bgr&0x3E0)>>2;
00268 *d++ = (bgr&0x1F)<<3;
00269 *d++ = 255;
00270 #endif
00271 }
00272 }
00273
00274 void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
00275 {
00276 const uint16_t *end;
00277 uint8_t *d = dst;
00278 const uint16_t *s = (const uint16_t *)src;
00279 end = s + src_size/2;
00280 while (s < end) {
00281 register uint16_t bgr;
00282 bgr = *s++;
00283 *d++ = (bgr&0x7C00)>>7;
00284 *d++ = (bgr&0x3E0)>>2;
00285 *d++ = (bgr&0x1F)<<3;
00286 }
00287 }
00288
00289 void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
00290 {
00291 int i;
00292 int num_pixels = src_size >> 1;
00293
00294 for (i=0; i<num_pixels; i++) {
00295 unsigned rgb = ((const uint16_t*)src)[i];
00296 ((uint16_t*)dst)[i] = ((rgb&0x7C00)>>10) | ((rgb&0x3E0)<<1) | (rgb<<11);
00297 }
00298 }
00299
00300 void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
00301 {
00302 int i;
00303 int num_pixels = src_size >> 1;
00304
00305 for (i=0; i<num_pixels; i++) {
00306 unsigned br;
00307 unsigned rgb = ((const uint16_t*)src)[i];
00308 br = rgb&0x7c1F;
00309 ((uint16_t*)dst)[i] = (br>>10) | (rgb&0x3E0) | (br<<10);
00310 }
00311 }
00312
00313 void bgr8torgb8(const uint8_t *src, uint8_t *dst, int src_size)
00314 {
00315 int i;
00316 int num_pixels = src_size;
00317 for (i=0; i<num_pixels; i++) {
00318 unsigned b,g,r;
00319 register uint8_t rgb;
00320 rgb = src[i];
00321 r = (rgb&0x07);
00322 g = (rgb&0x38)>>3;
00323 b = (rgb&0xC0)>>6;
00324 dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
00325 }
00326 }
00327
00328 #define DEFINE_SHUFFLE_BYTES(a, b, c, d) \
00329 void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \
00330 { \
00331 int i; \
00332 \
00333 for (i = 0; i < src_size; i+=4) { \
00334 dst[i + 0] = src[i + a]; \
00335 dst[i + 1] = src[i + b]; \
00336 dst[i + 2] = src[i + c]; \
00337 dst[i + 3] = src[i + d]; \
00338 } \
00339 }
00340
00341 DEFINE_SHUFFLE_BYTES(0, 3, 2, 1);
00342 DEFINE_SHUFFLE_BYTES(1, 2, 3, 0);
00343 DEFINE_SHUFFLE_BYTES(3, 0, 1, 2);
00344 DEFINE_SHUFFLE_BYTES(3, 2, 1, 0);
00345