~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libswscale/rgb2rgb.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

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