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 void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
00127 {
00128 int i;
00129 int num_pixels = src_size >> 2;
00130 for (i=0; i<num_pixels; i++) {
00131 #if HAVE_BIGENDIAN
00132
00133 dst[3*i + 0] = src[4*i + 1];
00134 dst[3*i + 1] = src[4*i + 2];
00135 dst[3*i + 2] = src[4*i + 3];
00136 #else
00137 dst[3*i + 0] = src[4*i + 2];
00138 dst[3*i + 1] = src[4*i + 1];
00139 dst[3*i + 2] = src[4*i + 0];
00140 #endif
00141 }
00142 }
00143
00144 void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
00145 {
00146 int i;
00147 for (i=0; 3*i<src_size; i++) {
00148 #if HAVE_BIGENDIAN
00149
00150 dst[4*i + 0] = 255;
00151 dst[4*i + 1] = src[3*i + 0];
00152 dst[4*i + 2] = src[3*i + 1];
00153 dst[4*i + 3] = src[3*i + 2];
00154 #else
00155 dst[4*i + 0] = src[3*i + 2];
00156 dst[4*i + 1] = src[3*i + 1];
00157 dst[4*i + 2] = src[3*i + 0];
00158 dst[4*i + 3] = 255;
00159 #endif
00160 }
00161 }
00162
00163 void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
00164 {
00165 const uint16_t *end;
00166 uint8_t *d = dst;
00167 const uint16_t *s = (const uint16_t *)src;
00168 end = s + src_size/2;
00169 while (s < end) {
00170 register uint16_t bgr;
00171 bgr = *s++;
00172 #if HAVE_BIGENDIAN
00173 *d++ = 255;
00174 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00175 *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
00176 *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
00177 #else
00178 *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
00179 *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
00180 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00181 *d++ = 255;
00182 #endif
00183 }
00184 }
00185
00186 void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
00187 {
00188 const uint16_t *end;
00189 uint16_t *d = (uint16_t *)dst;
00190 const uint16_t *s = (const uint16_t *)src;
00191 uint16_t rgb, r, g, b;
00192 end = s + src_size / 2;
00193 while (s < end) {
00194 rgb = *s++;
00195 r = rgb & 0xF00;
00196 g = rgb & 0x0F0;
00197 b = rgb & 0x00F;
00198 r = (r << 3) | ((r & 0x800) >> 1);
00199 g = (g << 2) | ((g & 0x080) >> 2);
00200 b = (b << 1) | ( b >> 3);
00201 *d++ = r | g | b;
00202 }
00203 }
00204
00205 void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
00206 {
00207 const uint16_t *end;
00208 uint8_t *d = dst;
00209 const uint16_t *s = (const uint16_t *)src;
00210 end = s + src_size/2;
00211 while (s < end) {
00212 register uint16_t bgr;
00213 bgr = *s++;
00214 *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13);
00215 *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9);
00216 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00217 }
00218 }
00219
00220 void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
00221 {
00222 int i;
00223 int num_pixels = src_size >> 1;
00224
00225 for (i=0; i<num_pixels; i++) {
00226 unsigned rgb = ((const uint16_t*)src)[i];
00227 ((uint16_t*)dst)[i] = (rgb>>11) | (rgb&0x7E0) | (rgb<<11);
00228 }
00229 }
00230
00231 void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
00232 {
00233 int i;
00234 int num_pixels = src_size >> 1;
00235
00236 for (i=0; i<num_pixels; i++) {
00237 unsigned rgb = ((const uint16_t*)src)[i];
00238 ((uint16_t*)dst)[i] = (rgb>>11) | ((rgb&0x7C0)>>1) | ((rgb&0x1F)<<10);
00239 }
00240 }
00241
00242 void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
00243 {
00244 const uint16_t *end;
00245 uint8_t *d = dst;
00246 const uint16_t *s = (const uint16_t *)src;
00247 end = s + src_size/2;
00248 while (s < end) {
00249 register uint16_t bgr;
00250 bgr = *s++;
00251 #if HAVE_BIGENDIAN
00252 *d++ = 255;
00253 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00254 *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
00255 *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
00256 #else
00257 *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
00258 *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
00259 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00260 *d++ = 255;
00261 #endif
00262 }
00263 }
00264
00265 void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
00266 {
00267 const uint16_t *end;
00268 uint8_t *d = dst;
00269 const uint16_t *s = (const uint16_t *)src;
00270 end = s + src_size/2;
00271 while (s < end) {
00272 register uint16_t bgr;
00273 bgr = *s++;
00274 *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12);
00275 *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7);
00276 *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2);
00277 }
00278 }
00279
00280 void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
00281 {
00282 int i;
00283 int num_pixels = src_size >> 1;
00284
00285 for (i=0; i<num_pixels; i++) {
00286 unsigned rgb = ((const uint16_t*)src)[i];
00287 ((uint16_t*)dst)[i] = ((rgb&0x7C00)>>10) | ((rgb&0x3E0)<<1) | (rgb<<11);
00288 }
00289 }
00290
00291 void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
00292 {
00293 int i;
00294 int num_pixels = src_size >> 1;
00295
00296 for (i=0; i<num_pixels; i++) {
00297 unsigned br;
00298 unsigned rgb = ((const uint16_t*)src)[i];
00299 br = rgb&0x7c1F;
00300 ((uint16_t*)dst)[i] = (br>>10) | (rgb&0x3E0) | (br<<10);
00301 }
00302 }
00303
00304 void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
00305 {
00306 uint16_t *d = (uint16_t*)dst;
00307 uint16_t *s = (uint16_t*)src;
00308 int i;
00309 int num_pixels = src_size >> 1;
00310
00311 for (i = 0; i < num_pixels; i++) {
00312 unsigned rgb = s[i];
00313 d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF;
00314 }
00315 }
00316
00317 #define DEFINE_SHUFFLE_BYTES(a, b, c, d) \
00318 void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \
00319 { \
00320 int i; \
00321 \
00322 for (i = 0; i < src_size; i+=4) { \
00323 dst[i + 0] = src[i + a]; \
00324 dst[i + 1] = src[i + b]; \
00325 dst[i + 2] = src[i + c]; \
00326 dst[i + 3] = src[i + d]; \
00327 } \
00328 }
00329
00330 DEFINE_SHUFFLE_BYTES(0, 3, 2, 1)
00331 DEFINE_SHUFFLE_BYTES(1, 2, 3, 0)
00332 DEFINE_SHUFFLE_BYTES(3, 0, 1, 2)
00333 DEFINE_SHUFFLE_BYTES(3, 2, 1, 0)
00334