cosmetics: Replace manual tab indentation by \n\t as in the rest of the file.
[libav.git] / libswscale / rgb2rgb.c
CommitLineData
fcfbc150 1/*
a3aece93
NK
2 *
3 * rgb2rgb.c, Software RGB to RGB convertor
6611aa83
NK
4 * pluralize by Software PAL8 to RGB convertor
5 * Software YUV to YUV convertor
6 * Software YUV to RGB convertor
a3aece93 7 * Written by Nick Kurshev.
4fadc2b4
DB
8 * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at)
9 *
d026b45e
DB
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or modify
4fadc2b4
DB
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
d026b45e 17 * FFmpeg is distributed in the hope that it will be useful,
4fadc2b4
DB
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
d026b45e 23 * along with FFmpeg; if not, write to the Free Software
4fadc2b4 24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6a4970ab 25 *
807e0c66
LA
26 * the C code (not assembly, mmx, ...) of this file can be used
27 * under the LGPL license too
a3aece93 28 */
b234ae81 29#include <inttypes.h>
b2d374c9 30#include "config.h"
b234ae81 31#include "rgb2rgb.h"
700490a4 32#include "swscale.h"
94c4def2
LA
33#include "swscale_internal.h"
34#include "x86_cpu.h"
b2d374c9 35#include "bswap.h"
94c4def2 36#ifdef USE_FASTMEMCPY
b2d374c9 37#include "libvo/fastmemcpy.h"
94c4def2 38#endif
a3aece93 39
21316f3c
MN
40#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
41
7f526efd
RD
42void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size);
43void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size);
44void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size);
45void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size);
46void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size);
47void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size);
48void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size);
49void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size);
50void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size);
51void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size);
52void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size);
53void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size);
54//void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
55void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
56void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
57void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
58void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size);
59//void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size);
60void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size);
61void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size);
700490a4
MN
62
63void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
7f526efd
RD
64 long width, long height,
65 long lumStride, long chromStride, long dstStride);
caeaabe7 66void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
7f526efd
RD
67 long width, long height,
68 long lumStride, long chromStride, long dstStride);
700490a4 69void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
7f526efd
RD
70 long width, long height,
71 long lumStride, long chromStride, long dstStride);
700490a4 72void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
7f526efd
RD
73 long width, long height,
74 long lumStride, long chromStride, long srcStride);
700490a4 75void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
7f526efd
RD
76 long width, long height,
77 long lumStride, long chromStride, long srcStride);
78void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height,
79 long srcStride, long dstStride);
700490a4 80void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst,
7f526efd
RD
81 long width, long height, long src1Stride,
82 long src2Stride, long dstStride);
700490a4
MN
83void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
84 uint8_t *dst1, uint8_t *dst2,
7f526efd
RD
85 long width, long height,
86 long srcStride1, long srcStride2,
87 long dstStride1, long dstStride2);
700490a4
MN
88void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
89 uint8_t *dst,
7f526efd
RD
90 long width, long height,
91 long srcStride1, long srcStride2,
92 long srcStride3, long dstStride);
700490a4 93
9bde778e 94#if defined(ARCH_X86) && defined(CONFIG_GPL)
0d9f3d85
A
95static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL;
96static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
db7a2e0d
MC
97static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
98static const uint64_t mask32g attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
99static const uint64_t mask32r attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
a3aece93 100static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
aeae5d53
MN
101static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL;
102static const uint64_t mask3216g __attribute__((aligned(8)))=0x0000FC000000FC00ULL;
103static const uint64_t mask3215g __attribute__((aligned(8)))=0x0000F8000000F800ULL;
104static const uint64_t mul3216 __attribute__((aligned(8))) = 0x2000000420000004ULL;
105static const uint64_t mul3215 __attribute__((aligned(8))) = 0x2000000820000008ULL;
db7a2e0d
MC
106static const uint64_t mask24b attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
107static const uint64_t mask24g attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
108static const uint64_t mask24r attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
a3aece93
NK
109static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
110static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
2b3eef22
NK
111static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL;
112static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL;
113static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
a3aece93
NK
114static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */
115static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */
9b2c28e6 116static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
0d9f3d85
A
117static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
118static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
119#define mask16b mask15b
120static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
121static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
53445e83
NK
122static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
123static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
124static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
19b202f9
IP
125static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c0000007c00ULL;
126static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000003e0ULL;
53445e83 127static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
21316f3c
MN
128
129#ifdef FAST_BGR2YV12
db7a2e0d
MC
130static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
131static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
132static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
21316f3c 133#else
db7a2e0d
MC
134static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
135static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
136static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
21316f3c 137#endif
db7a2e0d
MC
138static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
139static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL;
140static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
21316f3c 141
99969243
MN
142#if 0
143static volatile uint64_t __attribute__((aligned(8))) b5Dither;
144static volatile uint64_t __attribute__((aligned(8))) g5Dither;
145static volatile uint64_t __attribute__((aligned(8))) g6Dither;
146static volatile uint64_t __attribute__((aligned(8))) r5Dither;
147
148static uint64_t __attribute__((aligned(8))) dither4[2]={
149 0x0103010301030103LL,
150 0x0200020002000200LL,};
151
152static uint64_t __attribute__((aligned(8))) dither8[2]={
153 0x0602060206020602LL,
154 0x0004000400040004LL,};
155#endif
3d6a30d9 156#endif /* defined(ARCH_X86) */
79811694 157
1de97d84
MN
158#define RGB2YUV_SHIFT 8
159#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
160#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
161#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
162#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
163#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
164#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
165#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
166#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
167#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
168
169//Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
170//Plain C versions
171#undef HAVE_MMX
172#undef HAVE_MMX2
173#undef HAVE_3DNOW
52075cde 174#undef HAVE_SSE2
1de97d84
MN
175#define RENAME(a) a ## _C
176#include "rgb2rgb_template.c"
177
9bde778e 178#if defined(ARCH_X86) && defined(CONFIG_GPL)
1de97d84
MN
179
180//MMX versions
181#undef RENAME
182#define HAVE_MMX
183#undef HAVE_MMX2
184#undef HAVE_3DNOW
52075cde 185#undef HAVE_SSE2
1de97d84
MN
186#define RENAME(a) a ## _MMX
187#include "rgb2rgb_template.c"
188
189//MMX2 versions
190#undef RENAME
191#define HAVE_MMX
192#define HAVE_MMX2
193#undef HAVE_3DNOW
52075cde 194#undef HAVE_SSE2
1de97d84
MN
195#define RENAME(a) a ## _MMX2
196#include "rgb2rgb_template.c"
197
198//3DNOW versions
199#undef RENAME
200#define HAVE_MMX
201#undef HAVE_MMX2
202#define HAVE_3DNOW
52075cde 203#undef HAVE_SSE2
abdcd337 204#define RENAME(a) a ## _3DNOW
1de97d84
MN
205#include "rgb2rgb_template.c"
206
6e1c66bc 207#endif //ARCH_X86 || ARCH_X86_64
b238eb2e 208
a3aece93 209/*
700490a4 210 rgb15->rgb16 Original by Strepto/Astral
a3aece93 211 ported to gcc & bugfixed : A'rpi
51da31f1 212 MMX2, 3DNOW optimization by Nick Kurshev
9b2c28e6 213 32bit c version, and and&add trick by Michael Niedermayer
a3aece93 214*/
fcfbc150 215
700490a4 216void sws_rgb2rgb_init(int flags){
9bde778e 217#if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL)
ea708173 218 if(flags & SWS_CPU_CAPS_MMX2)
df170b81 219 rgb2rgb_init_MMX2();
ea708173 220 else if(flags & SWS_CPU_CAPS_3DNOW)
df170b81 221 rgb2rgb_init_3DNOW();
ea708173 222 else if(flags & SWS_CPU_CAPS_MMX)
df170b81 223 rgb2rgb_init_MMX();
ea708173 224 else
dbdae6ec 225#endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
df170b81 226 rgb2rgb_init_C();
ac4d0aea 227}
700490a4 228
fcfbc150 229/**
10ef990d 230 * Palette is assumed to contain BGR32.
fcfbc150 231 */
7f526efd 232void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
fcfbc150 233{
7f526efd 234 long i;
9780c7ff
AB
235
236/*
4060205b 237 for(i=0; i<num_pixels; i++)
996e1a7c 238 ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
9780c7ff 239*/
fcfbc150 240
6c1baeb0
AB
241 for(i=0; i<num_pixels; i++)
242 {
f8c1d62d 243 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
244 dst[3]= palette[ src[i]*4+2 ];
245 dst[2]= palette[ src[i]*4+1 ];
246 dst[1]= palette[ src[i]*4+0 ];
f8c1d62d 247 #else
6c1baeb0 248 //FIXME slow?
c9fa86df
DB
249 dst[0]= palette[ src[i]*4+2 ];
250 dst[1]= palette[ src[i]*4+1 ];
251 dst[2]= palette[ src[i]*4+0 ];
252 //dst[3]= 0; /* do we need this cleansing? */
f8c1d62d 253 #endif
6c1baeb0
AB
254 dst+= 4;
255 }
256}
9780c7ff 257
7f526efd 258void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
6c1baeb0 259{
7f526efd 260 long i;
6c1baeb0 261 for(i=0; i<num_pixels; i++)
9780c7ff 262 {
f8c1d62d 263 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
264 dst[3]= palette[ src[i]*4+0 ];
265 dst[2]= palette[ src[i]*4+1 ];
266 dst[1]= palette[ src[i]*4+2 ];
f8c1d62d 267 #else
c9fa86df
DB
268 //FIXME slow?
269 dst[0]= palette[ src[i]*4+0 ];
270 dst[1]= palette[ src[i]*4+1 ];
271 dst[2]= palette[ src[i]*4+2 ];
272 //dst[3]= 0; /* do we need this cleansing? */
f8c1d62d 273 #endif
6a4970ab 274
9780c7ff
AB
275 dst+= 4;
276 }
6c1baeb0 277}
6c1baeb0 278
9ce6584e 279/**
10ef990d 280 * Palette is assumed to contain BGR32.
9ce6584e 281 */
7f526efd 282void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
9ce6584e 283{
7f526efd 284 long i;
9ce6584e
MN
285/*
286 writes 1 byte o much and might cause alignment issues on some architectures?
4060205b 287 for(i=0; i<num_pixels; i++)
996e1a7c 288 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
9ce6584e 289*/
4060205b 290 for(i=0; i<num_pixels; i++)
9ce6584e
MN
291 {
292 //FIXME slow?
9780c7ff 293 dst[0]= palette[ src[i]*4+2 ];
9ce6584e 294 dst[1]= palette[ src[i]*4+1 ];
9780c7ff 295 dst[2]= palette[ src[i]*4+0 ];
9ce6584e
MN
296 dst+= 3;
297 }
298}
299
7f526efd 300void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
6c1baeb0 301{
7f526efd 302 long i;
6c1baeb0
AB
303/*
304 writes 1 byte o much and might cause alignment issues on some architectures?
305 for(i=0; i<num_pixels; i++)
306 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
307*/
308 for(i=0; i<num_pixels; i++)
309 {
310 //FIXME slow?
9780c7ff
AB
311 dst[0]= palette[ src[i]*4+0 ];
312 dst[1]= palette[ src[i]*4+1 ];
313 dst[2]= palette[ src[i]*4+2 ];
6c1baeb0
AB
314 dst+= 3;
315 }
316}
317
fcfbc150
MN
318/**
319 * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette
320 */
7f526efd 321void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
fcfbc150 322{
7f526efd 323 long i;
4060205b 324 for(i=0; i<num_pixels; i++)
fcfbc150
MN
325 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
326}
7f526efd 327void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
6c1baeb0 328{
7f526efd 329 long i;
6c1baeb0
AB
330 for(i=0; i<num_pixels; i++)
331 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
332}
fcfbc150
MN
333
334/**
10ef990d 335 * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette.
fcfbc150 336 */
7f526efd 337void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
fcfbc150 338{
7f526efd 339 long i;
4060205b 340 for(i=0; i<num_pixels; i++)
fcfbc150 341 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
9ce6584e 342}
7f526efd 343void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette)
6c1baeb0 344{
7f526efd 345 long i;
6c1baeb0
AB
346 for(i=0; i<num_pixels; i++)
347 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
348}
99969243 349
7f526efd 350void rgb32tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 351{
7f526efd
RD
352 long i;
353 long num_pixels = src_size >> 2;
ac4d0aea
MN
354 for(i=0; i<num_pixels; i++)
355 {
f688668c 356 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
357 /* RGB32 (= A,B,G,R) -> BGR24 (= B,G,R) */
358 dst[3*i + 0] = src[4*i + 1];
359 dst[3*i + 1] = src[4*i + 2];
360 dst[3*i + 2] = src[4*i + 3];
f688668c 361 #else
c9fa86df
DB
362 dst[3*i + 0] = src[4*i + 2];
363 dst[3*i + 1] = src[4*i + 1];
364 dst[3*i + 2] = src[4*i + 0];
f688668c 365 #endif
ac4d0aea
MN
366 }
367}
368
7f526efd 369void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 370{
7f526efd 371 long i;
a1ce46cf 372 for(i=0; 3*i<src_size; i++)
ac4d0aea 373 {
f688668c 374 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
375 /* RGB24 (= R,G,B) -> BGR32 (= A,R,G,B) */
376 dst[4*i + 0] = 0;
377 dst[4*i + 1] = src[3*i + 0];
378 dst[4*i + 2] = src[3*i + 1];
379 dst[4*i + 3] = src[3*i + 2];
f688668c 380 #else
c9fa86df
DB
381 dst[4*i + 0] = src[3*i + 2];
382 dst[4*i + 1] = src[3*i + 1];
383 dst[4*i + 2] = src[3*i + 0];
384 dst[4*i + 3] = 0;
f688668c 385 #endif
ac4d0aea
MN
386 }
387}
388
7f526efd 389void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea
MN
390{
391 const uint16_t *end;
392 uint8_t *d = (uint8_t *)dst;
393 const uint16_t *s = (uint16_t *)src;
394 end = s + src_size/2;
395 while(s < end)
396 {
397 register uint16_t bgr;
398 bgr = *s++;
f688668c 399 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
400 *d++ = 0;
401 *d++ = (bgr&0x1F)<<3;
402 *d++ = (bgr&0x7E0)>>3;
403 *d++ = (bgr&0xF800)>>8;
f688668c 404 #else
c9fa86df
DB
405 *d++ = (bgr&0xF800)>>8;
406 *d++ = (bgr&0x7E0)>>3;
407 *d++ = (bgr&0x1F)<<3;
408 *d++ = 0;
f688668c 409 #endif
ac4d0aea
MN
410 }
411}
412
7f526efd 413void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea
MN
414{
415 const uint16_t *end;
416 uint8_t *d = (uint8_t *)dst;
417 const uint16_t *s = (const uint16_t *)src;
418 end = s + src_size/2;
419 while(s < end)
420 {
421 register uint16_t bgr;
422 bgr = *s++;
423 *d++ = (bgr&0xF800)>>8;
424 *d++ = (bgr&0x7E0)>>3;
425 *d++ = (bgr&0x1F)<<3;
426 }
427}
428
7f526efd 429void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 430{
7f526efd
RD
431 long i;
432 long num_pixels = src_size >> 1;
6a4970ab 433
ac4d0aea
MN
434 for(i=0; i<num_pixels; i++)
435 {
436 unsigned b,g,r;
437 register uint16_t rgb;
438 rgb = src[2*i];
439 r = rgb&0x1F;
440 g = (rgb&0x7E0)>>5;
441 b = (rgb&0xF800)>>11;
442 dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
443 }
444}
445
7f526efd 446void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 447{
7f526efd
RD
448 long i;
449 long num_pixels = src_size >> 1;
6a4970ab 450
ac4d0aea
MN
451 for(i=0; i<num_pixels; i++)
452 {
453 unsigned b,g,r;
454 register uint16_t rgb;
455 rgb = src[2*i];
456 r = rgb&0x1F;
457 g = (rgb&0x7E0)>>5;
458 b = (rgb&0xF800)>>11;
459 dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
460 }
461}
462
7f526efd 463void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea
MN
464{
465 const uint16_t *end;
466 uint8_t *d = (uint8_t *)dst;
467 const uint16_t *s = (const uint16_t *)src;
468 end = s + src_size/2;
469 while(s < end)
470 {
471 register uint16_t bgr;
472 bgr = *s++;
f688668c 473 #ifdef WORDS_BIGENDIAN
c9fa86df
DB
474 *d++ = 0;
475 *d++ = (bgr&0x1F)<<3;
476 *d++ = (bgr&0x3E0)>>2;
477 *d++ = (bgr&0x7C00)>>7;
f688668c 478 #else
c9fa86df
DB
479 *d++ = (bgr&0x7C00)>>7;
480 *d++ = (bgr&0x3E0)>>2;
481 *d++ = (bgr&0x1F)<<3;
482 *d++ = 0;
f688668c 483 #endif
ac4d0aea
MN
484 }
485}
486
7f526efd 487void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea
MN
488{
489 const uint16_t *end;
490 uint8_t *d = (uint8_t *)dst;
491 const uint16_t *s = (uint16_t *)src;
492 end = s + src_size/2;
493 while(s < end)
494 {
495 register uint16_t bgr;
496 bgr = *s++;
497 *d++ = (bgr&0x7C00)>>7;
498 *d++ = (bgr&0x3E0)>>2;
499 *d++ = (bgr&0x1F)<<3;
500 }
501}
502
7f526efd 503void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 504{
7f526efd
RD
505 long i;
506 long num_pixels = src_size >> 1;
6a4970ab 507
ac4d0aea
MN
508 for(i=0; i<num_pixels; i++)
509 {
510 unsigned b,g,r;
511 register uint16_t rgb;
512 rgb = src[2*i];
513 r = rgb&0x1F;
514 g = (rgb&0x3E0)>>5;
515 b = (rgb&0x7C00)>>10;
516 dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
517 }
518}
519
7f526efd 520void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 521{
7f526efd
RD
522 long i;
523 long num_pixels = src_size >> 1;
6a4970ab 524
ac4d0aea
MN
525 for(i=0; i<num_pixels; i++)
526 {
527 unsigned b,g,r;
528 register uint16_t rgb;
529 rgb = src[2*i];
530 r = rgb&0x1F;
531 g = (rgb&0x3E0)>>5;
532 b = (rgb&0x7C00)>>10;
533 dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
534 }
535}
536
7f526efd 537void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size)
ac4d0aea 538{
7f526efd
RD
539 long i;
540 long num_pixels = src_size;
ac4d0aea
MN
541 for(i=0; i<num_pixels; i++)
542 {
543 unsigned b,g,r;
544 register uint8_t rgb;
545 rgb = src[i];
546 r = (rgb&0x07);
547 g = (rgb&0x38)>>3;
548 b = (rgb&0xC0)>>6;
549 dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
550 }
551}