~ubuntu-branches/ubuntu/maverick/vlc/maverick

« back to all changes in this revision

Viewing changes to modules/video_filter/swscale/rgb2rgb.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-09-17 21:56:14 UTC
  • mfrom: (1.1.17 upstream)
  • Revision ID: james.westby@ubuntu.com-20080917215614-tj0vx8xzd57e52t8
Tags: 0.9.2-1ubuntu1
* New Upstream Release, exception granted by
    - dktrkranz, norsetto, Hobbsee (via irc). LP: #270404

Changes done in ubuntu:

* add libxul-dev to build-depends
* make sure that vlc is build against libxul in configure. This doesn't
  change anything in the package, but makes it more robust if building
  in an 'unclean' chroot or when modifying the package.
* debian/control: make Vcs-* fields point to the motumedia branch
* add libx264-dev and libass-dev to build-depends
  LP: #210354, #199870
* actually enable libass support by passing --enable-libass to configure
* enable libdca: add libdca-dev to build depends and --enable-libdca
* install the x264 plugin.

Changes already in the pkg-multimedia branch in debian:

* don't install usr/share/vlc/mozilla in debian/mozilla-plugin-vlc.install  
* new upstream .desktop file now registers flash video mimetype LP: #261567
* add Xb-Npp-Applications to mozilla-plugin-vlc
* remove duplicate entries in debian/vlc-nox.install

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *
3
 
 *  rgb2rgb.c, Software RGB to RGB convertor
4
 
 *  pluralize by Software PAL8 to RGB convertor
5
 
 *               Software YUV to YUV convertor
6
 
 *               Software YUV to RGB convertor
7
 
 *  Written by Nick Kurshev.
8
 
 *  palette & yuv & runtime cpu stuff by Michael (michaelni@gmx.at) (under GPL)
9
 
 */
10
 
#include <inttypes.h>
11
 
#include "config.h"
12
 
#include "rgb2rgb.h"
13
 
#include "swscale.h"
14
 
#include "common.h"
15
 
 
16
 
#define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit
17
 
 
18
 
void (*rgb24to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
19
 
void (*rgb24to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
20
 
void (*rgb24to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
21
 
void (*rgb32to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
22
 
void (*rgb32to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
23
 
void (*rgb32to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
24
 
void (*rgb15to16)(const uint8_t *src,uint8_t *dst,unsigned src_size);
25
 
void (*rgb15to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
26
 
void (*rgb15to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
27
 
void (*rgb16to15)(const uint8_t *src,uint8_t *dst,unsigned src_size);
28
 
void (*rgb16to24)(const uint8_t *src,uint8_t *dst,unsigned src_size);
29
 
void (*rgb16to32)(const uint8_t *src,uint8_t *dst,unsigned src_size);
30
 
//void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, unsigned src_size);
31
 
void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, unsigned src_size);
32
 
void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, unsigned src_size);
33
 
void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size);
34
 
void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, unsigned src_size);
35
 
//void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, unsigned src_size);
36
 
void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, unsigned src_size);
37
 
void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, unsigned src_size);
38
 
 
39
 
void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
40
 
        unsigned int width, unsigned int height,
41
 
        int lumStride, int chromStride, int dstStride);
42
 
void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
43
 
        unsigned int width, unsigned int height,
44
 
        int lumStride, int chromStride, int dstStride);
45
 
void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst,
46
 
        unsigned int width, unsigned int height,
47
 
        int lumStride, int chromStride, int dstStride);
48
 
void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
49
 
        unsigned int width, unsigned int height,
50
 
        int lumStride, int chromStride, int srcStride);
51
 
void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
52
 
        unsigned int width, unsigned int height,
53
 
        int lumStride, int chromStride, int srcStride);
54
 
void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride);
55
 
void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst,
56
 
                            unsigned width, unsigned height, int src1Stride,
57
 
                            int src2Stride, int dstStride);
58
 
void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2,
59
 
                        uint8_t *dst1, uint8_t *dst2,
60
 
                        unsigned width, unsigned height,
61
 
                        int srcStride1, int srcStride2,
62
 
                        int dstStride1, int dstStride2);
63
 
void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3,
64
 
                        uint8_t *dst,
65
 
                        unsigned width, unsigned height,
66
 
                        int srcStride1, int srcStride2,
67
 
                        int srcStride3, int dstStride);
68
 
 
69
 
#ifdef ARCH_X86
70
 
static const uint64_t mmx_null  __attribute__((aligned(8))) = 0x0000000000000000ULL;
71
 
static const uint64_t mmx_one   __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
72
 
static const uint64_t mask32b  attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
73
 
static const uint64_t mask32g  attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
74
 
static const uint64_t mask32r  attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
75
 
static const uint64_t mask32   __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL;
76
 
static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL;
77
 
static const uint64_t mask3216g  __attribute__((aligned(8)))=0x0000FC000000FC00ULL;
78
 
static const uint64_t mask3215g  __attribute__((aligned(8)))=0x0000F8000000F800ULL;
79
 
static const uint64_t mul3216  __attribute__((aligned(8))) = 0x2000000420000004ULL;
80
 
static const uint64_t mul3215  __attribute__((aligned(8))) = 0x2000000820000008ULL;
81
 
static const uint64_t mask24b  attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL;
82
 
static const uint64_t mask24g  attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL;
83
 
static const uint64_t mask24r  attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL;
84
 
static const uint64_t mask24l  __attribute__((aligned(8))) = 0x0000000000FFFFFFULL;
85
 
static const uint64_t mask24h  __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL;
86
 
static const uint64_t mask24hh  __attribute__((aligned(8))) = 0xffff000000000000ULL;
87
 
static const uint64_t mask24hhh  __attribute__((aligned(8))) = 0xffffffff00000000ULL;
88
 
static const uint64_t mask24hhhh  __attribute__((aligned(8))) = 0xffffffffffff0000ULL;
89
 
static const uint64_t mask15b  __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111  xxB */
90
 
static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000  RGx */
91
 
static const uint64_t mask15s  __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL;
92
 
static const uint64_t mask15g  __attribute__((aligned(8))) = 0x03E003E003E003E0ULL;
93
 
static const uint64_t mask15r  __attribute__((aligned(8))) = 0x7C007C007C007C00ULL;
94
 
#define mask16b mask15b
95
 
static const uint64_t mask16g  __attribute__((aligned(8))) = 0x07E007E007E007E0ULL;
96
 
static const uint64_t mask16r  __attribute__((aligned(8))) = 0xF800F800F800F800ULL;
97
 
static const uint64_t red_16mask  __attribute__((aligned(8))) = 0x0000f8000000f800ULL;
98
 
static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL;
99
 
static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
100
 
static const uint64_t red_15mask  __attribute__((aligned(8))) = 0x00007c000000f800ULL;
101
 
static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000007e0ULL;
102
 
static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL;
103
 
 
104
 
#ifdef FAST_BGR2YV12
105
 
static const uint64_t bgr2YCoeff  attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL;
106
 
static const uint64_t bgr2UCoeff  attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL;
107
 
static const uint64_t bgr2VCoeff  attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL;
108
 
#else
109
 
static const uint64_t bgr2YCoeff  attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL;
110
 
static const uint64_t bgr2UCoeff  attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL;
111
 
static const uint64_t bgr2VCoeff  attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL;
112
 
#endif
113
 
static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL;
114
 
static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL;
115
 
static const uint64_t w1111       attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL;
116
 
 
117
 
#if 0
118
 
static volatile uint64_t __attribute__((aligned(8))) b5Dither;
119
 
static volatile uint64_t __attribute__((aligned(8))) g5Dither;
120
 
static volatile uint64_t __attribute__((aligned(8))) g6Dither;
121
 
static volatile uint64_t __attribute__((aligned(8))) r5Dither;
122
 
 
123
 
static uint64_t __attribute__((aligned(8))) dither4[2]={
124
 
        0x0103010301030103LL,
125
 
        0x0200020002000200LL,};
126
 
 
127
 
static uint64_t __attribute__((aligned(8))) dither8[2]={
128
 
        0x0602060206020602LL,
129
 
        0x0004000400040004LL,};
130
 
#endif
131
 
#endif
132
 
 
133
 
#define RGB2YUV_SHIFT 8
134
 
#define BY ((int)( 0.098*(1<<RGB2YUV_SHIFT)+0.5))
135
 
#define BV ((int)(-0.071*(1<<RGB2YUV_SHIFT)+0.5))
136
 
#define BU ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
137
 
#define GY ((int)( 0.504*(1<<RGB2YUV_SHIFT)+0.5))
138
 
#define GV ((int)(-0.368*(1<<RGB2YUV_SHIFT)+0.5))
139
 
#define GU ((int)(-0.291*(1<<RGB2YUV_SHIFT)+0.5))
140
 
#define RY ((int)( 0.257*(1<<RGB2YUV_SHIFT)+0.5))
141
 
#define RV ((int)( 0.439*(1<<RGB2YUV_SHIFT)+0.5))
142
 
#define RU ((int)(-0.148*(1<<RGB2YUV_SHIFT)+0.5))
143
 
 
144
 
//Note: we have C, MMX, MMX2, 3DNOW version therse no 3DNOW+MMX2 one
145
 
//Plain C versions
146
 
#undef HAVE_MMX
147
 
#undef HAVE_MMX2
148
 
#undef HAVE_3DNOW
149
 
#undef HAVE_SSE2
150
 
#define RENAME(a) a ## _C
151
 
#include "rgb2rgb_template.c"
152
 
 
153
 
#ifdef ARCH_X86
154
 
 
155
 
//MMX versions
156
 
#undef RENAME
157
 
#define HAVE_MMX
158
 
#undef HAVE_MMX2
159
 
#undef HAVE_3DNOW
160
 
#undef HAVE_SSE2
161
 
#define RENAME(a) a ## _MMX
162
 
#include "rgb2rgb_template.c"
163
 
 
164
 
//MMX2 versions
165
 
#undef RENAME
166
 
#define HAVE_MMX
167
 
#define HAVE_MMX2
168
 
#undef HAVE_3DNOW
169
 
#undef HAVE_SSE2
170
 
#define RENAME(a) a ## _MMX2
171
 
#include "rgb2rgb_template.c"
172
 
 
173
 
//3DNOW versions
174
 
#undef RENAME
175
 
#define HAVE_MMX
176
 
#undef HAVE_MMX2
177
 
#define HAVE_3DNOW
178
 
#undef HAVE_SSE2
179
 
#define RENAME(a) a ## _3DNOW
180
 
#include "rgb2rgb_template.c"
181
 
 
182
 
#endif //ARCH_X86
183
 
 
184
 
/*
185
 
 rgb15->rgb16 Original by Strepto/Astral
186
 
 ported to gcc & bugfixed : A'rpi
187
 
 MMX2, 3DNOW optimization by Nick Kurshev
188
 
 32bit c version, and and&add trick by Michael Niedermayer
189
 
*/
190
 
 
191
 
void sws_rgb2rgb_init(int flags){
192
 
#ifdef ARCH_X86
193
 
        if(flags & SWS_CPU_CAPS_MMX2){
194
 
                rgb15to16= rgb15to16_MMX2;
195
 
                rgb15to24= rgb15to24_MMX2;
196
 
                rgb15to32= rgb15to32_MMX2;
197
 
                rgb16to24= rgb16to24_MMX2;
198
 
                rgb16to32= rgb16to32_MMX2;
199
 
                rgb16to15= rgb16to15_MMX2;
200
 
                rgb24to16= rgb24to16_MMX2;
201
 
                rgb24to15= rgb24to15_MMX2;
202
 
                rgb24to32= rgb24to32_MMX2;
203
 
                rgb32to16= rgb32to16_MMX2;
204
 
                rgb32to15= rgb32to15_MMX2;
205
 
                rgb32to24= rgb32to24_MMX2;
206
 
                rgb24tobgr15= rgb24tobgr15_MMX2;
207
 
                rgb24tobgr16= rgb24tobgr16_MMX2;
208
 
                rgb24tobgr24= rgb24tobgr24_MMX2;
209
 
                rgb32tobgr32= rgb32tobgr32_MMX2;
210
 
                rgb32tobgr16= rgb32tobgr16_MMX2;
211
 
                rgb32tobgr15= rgb32tobgr15_MMX2;
212
 
                yv12toyuy2= yv12toyuy2_MMX2;
213
 
                yv12touyvy= yv12touyvy_MMX2;
214
 
                yuv422ptoyuy2= yuv422ptoyuy2_MMX2;
215
 
                yuy2toyv12= yuy2toyv12_MMX2;
216
 
//              uyvytoyv12= uyvytoyv12_MMX2;
217
 
//              yvu9toyv12= yvu9toyv12_MMX2;
218
 
                planar2x= planar2x_MMX2;
219
 
                rgb24toyv12= rgb24toyv12_MMX2;
220
 
                interleaveBytes= interleaveBytes_MMX2;
221
 
                vu9_to_vu12= vu9_to_vu12_MMX2;
222
 
                yvu9_to_yuy2= yvu9_to_yuy2_MMX2;
223
 
        }else if(flags & SWS_CPU_CAPS_3DNOW){
224
 
                rgb15to16= rgb15to16_3DNOW;
225
 
                rgb15to24= rgb15to24_3DNOW;
226
 
                rgb15to32= rgb15to32_3DNOW;
227
 
                rgb16to24= rgb16to24_3DNOW;
228
 
                rgb16to32= rgb16to32_3DNOW;
229
 
                rgb16to15= rgb16to15_3DNOW;
230
 
                rgb24to16= rgb24to16_3DNOW;
231
 
                rgb24to15= rgb24to15_3DNOW;
232
 
                rgb24to32= rgb24to32_3DNOW;
233
 
                rgb32to16= rgb32to16_3DNOW;
234
 
                rgb32to15= rgb32to15_3DNOW;
235
 
                rgb32to24= rgb32to24_3DNOW;
236
 
                rgb24tobgr15= rgb24tobgr15_3DNOW;
237
 
                rgb24tobgr16= rgb24tobgr16_3DNOW;
238
 
                rgb24tobgr24= rgb24tobgr24_3DNOW;
239
 
                rgb32tobgr32= rgb32tobgr32_3DNOW;
240
 
                rgb32tobgr16= rgb32tobgr16_3DNOW;
241
 
                rgb32tobgr15= rgb32tobgr15_3DNOW;
242
 
                yv12toyuy2= yv12toyuy2_3DNOW;
243
 
                yv12touyvy= yv12touyvy_3DNOW;
244
 
                yuv422ptoyuy2= yuv422ptoyuy2_3DNOW;
245
 
                yuy2toyv12= yuy2toyv12_3DNOW;
246
 
//              uyvytoyv12= uyvytoyv12_3DNOW;
247
 
//              yvu9toyv12= yvu9toyv12_3DNOW;
248
 
                planar2x= planar2x_3DNOW;
249
 
                rgb24toyv12= rgb24toyv12_3DNOW;
250
 
                interleaveBytes= interleaveBytes_3DNOW;
251
 
                vu9_to_vu12= vu9_to_vu12_3DNOW;
252
 
                yvu9_to_yuy2= yvu9_to_yuy2_3DNOW;
253
 
        }else if(flags & SWS_CPU_CAPS_MMX){
254
 
                rgb15to16= rgb15to16_MMX;
255
 
                rgb15to24= rgb15to24_MMX;
256
 
                rgb15to32= rgb15to32_MMX;
257
 
                rgb16to24= rgb16to24_MMX;
258
 
                rgb16to32= rgb16to32_MMX;
259
 
                rgb16to15= rgb16to15_MMX;
260
 
                rgb24to16= rgb24to16_MMX;
261
 
                rgb24to15= rgb24to15_MMX;
262
 
                rgb24to32= rgb24to32_MMX;
263
 
                rgb32to16= rgb32to16_MMX;
264
 
                rgb32to15= rgb32to15_MMX;
265
 
                rgb32to24= rgb32to24_MMX;
266
 
                rgb24tobgr15= rgb24tobgr15_MMX;
267
 
                rgb24tobgr16= rgb24tobgr16_MMX;
268
 
                rgb24tobgr24= rgb24tobgr24_MMX;
269
 
                rgb32tobgr32= rgb32tobgr32_MMX;
270
 
                rgb32tobgr16= rgb32tobgr16_MMX;
271
 
                rgb32tobgr15= rgb32tobgr15_MMX;
272
 
                yv12toyuy2= yv12toyuy2_MMX;
273
 
                yv12touyvy= yv12touyvy_MMX;
274
 
                yuv422ptoyuy2= yuv422ptoyuy2_MMX;
275
 
                yuy2toyv12= yuy2toyv12_MMX;
276
 
//              uyvytoyv12= uyvytoyv12_MMX;
277
 
//              yvu9toyv12= yvu9toyv12_MMX;
278
 
                planar2x= planar2x_MMX;
279
 
                rgb24toyv12= rgb24toyv12_MMX;
280
 
                interleaveBytes= interleaveBytes_MMX;
281
 
                vu9_to_vu12= vu9_to_vu12_MMX;
282
 
                yvu9_to_yuy2= yvu9_to_yuy2_MMX;
283
 
        }else
284
 
#endif
285
 
        {
286
 
                rgb15to16= rgb15to16_C;
287
 
                rgb15to24= rgb15to24_C;
288
 
                rgb15to32= rgb15to32_C;
289
 
                rgb16to24= rgb16to24_C;
290
 
                rgb16to32= rgb16to32_C;
291
 
                rgb16to15= rgb16to15_C;
292
 
                rgb24to16= rgb24to16_C;
293
 
                rgb24to15= rgb24to15_C;
294
 
                rgb24to32= rgb24to32_C;
295
 
                rgb32to16= rgb32to16_C;
296
 
                rgb32to15= rgb32to15_C;
297
 
                rgb32to24= rgb32to24_C;
298
 
                rgb24tobgr15= rgb24tobgr15_C;
299
 
                rgb24tobgr16= rgb24tobgr16_C;
300
 
                rgb24tobgr24= rgb24tobgr24_C;
301
 
                rgb32tobgr32= rgb32tobgr32_C;
302
 
                rgb32tobgr16= rgb32tobgr16_C;
303
 
                rgb32tobgr15= rgb32tobgr15_C;
304
 
                yv12toyuy2= yv12toyuy2_C;
305
 
                yv12touyvy= yv12touyvy_C;
306
 
                yuv422ptoyuy2= yuv422ptoyuy2_C;
307
 
                yuy2toyv12= yuy2toyv12_C;
308
 
//              uyvytoyv12= uyvytoyv12_C;
309
 
//              yvu9toyv12= yvu9toyv12_C;
310
 
                planar2x= planar2x_C;
311
 
                rgb24toyv12= rgb24toyv12_C;
312
 
                interleaveBytes= interleaveBytes_C;
313
 
                vu9_to_vu12= vu9_to_vu12_C;
314
 
                yvu9_to_yuy2= yvu9_to_yuy2_C;
315
 
        }
316
 
}
317
 
 
318
 
/**
319
 
 * Pallete is assumed to contain bgr32
320
 
 */
321
 
void palette8torgb32(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
322
 
{
323
 
        unsigned i;
324
 
 
325
 
/*
326
 
        for(i=0; i<num_pixels; i++)
327
 
                ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ];
328
 
*/
329
 
 
330
 
        for(i=0; i<num_pixels; i++)
331
 
        {
332
 
                //FIXME slow?
333
 
                dst[0]= palette[ src[i]*4+2 ];
334
 
                dst[1]= palette[ src[i]*4+1 ];
335
 
                dst[2]= palette[ src[i]*4+0 ];
336
 
//              dst[3]= 0; /* do we need this cleansing? */
337
 
                dst+= 4;
338
 
        }
339
 
}
340
 
 
341
 
void palette8tobgr32(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
342
 
{
343
 
        unsigned i;
344
 
        for(i=0; i<num_pixels; i++)
345
 
        {
346
 
                //FIXME slow?
347
 
                dst[0]= palette[ src[i]*4+0 ];
348
 
                dst[1]= palette[ src[i]*4+1 ];
349
 
                dst[2]= palette[ src[i]*4+2 ];
350
 
//              dst[3]= 0; /* do we need this cleansing? */
351
 
                dst+= 4;
352
 
        }
353
 
}
354
 
 
355
 
/**
356
 
 * Pallete is assumed to contain bgr32
357
 
 */
358
 
void palette8torgb24(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
359
 
{
360
 
        unsigned i;
361
 
/*
362
 
        writes 1 byte o much and might cause alignment issues on some architectures?
363
 
        for(i=0; i<num_pixels; i++)
364
 
                ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
365
 
*/
366
 
        for(i=0; i<num_pixels; i++)
367
 
        {
368
 
                //FIXME slow?
369
 
                dst[0]= palette[ src[i]*4+2 ];
370
 
                dst[1]= palette[ src[i]*4+1 ];
371
 
                dst[2]= palette[ src[i]*4+0 ];
372
 
                dst+= 3;
373
 
        }
374
 
}
375
 
 
376
 
void palette8tobgr24(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
377
 
{
378
 
        unsigned i;
379
 
/*
380
 
        writes 1 byte o much and might cause alignment issues on some architectures?
381
 
        for(i=0; i<num_pixels; i++)
382
 
                ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ];
383
 
*/
384
 
        for(i=0; i<num_pixels; i++)
385
 
        {
386
 
                //FIXME slow?
387
 
                dst[0]= palette[ src[i]*4+0 ];
388
 
                dst[1]= palette[ src[i]*4+1 ];
389
 
                dst[2]= palette[ src[i]*4+2 ];
390
 
                dst+= 3;
391
 
        }
392
 
}
393
 
 
394
 
/**
395
 
 * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette
396
 
 */
397
 
void palette8torgb16(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
398
 
{
399
 
        unsigned i;
400
 
        for(i=0; i<num_pixels; i++)
401
 
                ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
402
 
}
403
 
void palette8tobgr16(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
404
 
{
405
 
        unsigned i;
406
 
        for(i=0; i<num_pixels; i++)
407
 
                ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
408
 
}
409
 
 
410
 
/**
411
 
 * Pallete is assumed to contain bgr15, see rgb32to15 to convert the palette
412
 
 */
413
 
void palette8torgb15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
414
 
{
415
 
        unsigned i;
416
 
        for(i=0; i<num_pixels; i++)
417
 
                ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ];
418
 
}
419
 
void palette8tobgr15(const uint8_t *src, uint8_t *dst, unsigned num_pixels, const uint8_t *palette)
420
 
{
421
 
        unsigned i;
422
 
        for(i=0; i<num_pixels; i++)
423
 
                ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]);
424
 
}
425
 
 
426
 
void rgb32tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
427
 
{
428
 
        unsigned i;
429
 
        unsigned num_pixels = src_size >> 2;
430
 
        for(i=0; i<num_pixels; i++)
431
 
        {
432
 
                dst[3*i + 0] = src[4*i + 2];
433
 
                dst[3*i + 1] = src[4*i + 1];
434
 
                dst[3*i + 2] = src[4*i + 0];
435
 
        }
436
 
}
437
 
 
438
 
void rgb24tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
439
 
{
440
 
        unsigned i;
441
 
        for(i=0; 3*i<src_size; i++)
442
 
        {
443
 
                dst[4*i + 0] = src[3*i + 2];
444
 
                dst[4*i + 1] = src[3*i + 1];
445
 
                dst[4*i + 2] = src[3*i + 0];
446
 
                dst[4*i + 3] = 0;
447
 
        }
448
 
}
449
 
 
450
 
void rgb16tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
451
 
{
452
 
        const uint16_t *end;
453
 
        uint8_t *d = (uint8_t *)dst;
454
 
        const uint16_t *s = (uint16_t *)src;
455
 
        end = s + src_size/2;
456
 
        while(s < end)
457
 
        {
458
 
                register uint16_t bgr;
459
 
                bgr = *s++;
460
 
                *d++ = (bgr&0xF800)>>8;
461
 
                *d++ = (bgr&0x7E0)>>3;
462
 
                *d++ = (bgr&0x1F)<<3;
463
 
                *d++ = 0;
464
 
        }
465
 
}
466
 
 
467
 
void rgb16tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
468
 
{
469
 
        const uint16_t *end;
470
 
        uint8_t *d = (uint8_t *)dst;
471
 
        const uint16_t *s = (const uint16_t *)src;
472
 
        end = s + src_size/2;
473
 
        while(s < end)
474
 
        {
475
 
                register uint16_t bgr;
476
 
                bgr = *s++;
477
 
                *d++ = (bgr&0xF800)>>8;
478
 
                *d++ = (bgr&0x7E0)>>3;
479
 
                *d++ = (bgr&0x1F)<<3;
480
 
        }
481
 
}
482
 
 
483
 
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, unsigned int src_size)
484
 
{
485
 
        unsigned i;
486
 
        unsigned num_pixels = src_size >> 1;
487
 
        
488
 
        for(i=0; i<num_pixels; i++)
489
 
        {
490
 
            unsigned b,g,r;
491
 
            register uint16_t rgb;
492
 
            rgb = src[2*i];
493
 
            r = rgb&0x1F;
494
 
            g = (rgb&0x7E0)>>5;
495
 
            b = (rgb&0xF800)>>11;
496
 
            dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
497
 
        }
498
 
}
499
 
 
500
 
void rgb16tobgr15(const uint8_t *src, uint8_t *dst, unsigned int src_size)
501
 
{
502
 
        unsigned i;
503
 
        unsigned num_pixels = src_size >> 1;
504
 
        
505
 
        for(i=0; i<num_pixels; i++)
506
 
        {
507
 
            unsigned b,g,r;
508
 
            register uint16_t rgb;
509
 
            rgb = src[2*i];
510
 
            r = rgb&0x1F;
511
 
            g = (rgb&0x7E0)>>5;
512
 
            b = (rgb&0xF800)>>11;
513
 
            dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
514
 
        }
515
 
}
516
 
 
517
 
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, unsigned int src_size)
518
 
{
519
 
        const uint16_t *end;
520
 
        uint8_t *d = (uint8_t *)dst;
521
 
        const uint16_t *s = (const uint16_t *)src;
522
 
        end = s + src_size/2;
523
 
        while(s < end)
524
 
        {
525
 
                register uint16_t bgr;
526
 
                bgr = *s++;
527
 
                *d++ = (bgr&0x7C00)>>7;
528
 
                *d++ = (bgr&0x3E0)>>2;
529
 
                *d++ = (bgr&0x1F)<<3;
530
 
                *d++ = 0;
531
 
        }
532
 
}
533
 
 
534
 
void rgb15tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size)
535
 
{
536
 
        const uint16_t *end;
537
 
        uint8_t *d = (uint8_t *)dst;
538
 
        const uint16_t *s = (uint16_t *)src;
539
 
        end = s + src_size/2;
540
 
        while(s < end)
541
 
        {
542
 
                register uint16_t bgr;
543
 
                bgr = *s++;
544
 
                *d++ = (bgr&0x7C00)>>7;
545
 
                *d++ = (bgr&0x3E0)>>2;
546
 
                *d++ = (bgr&0x1F)<<3;
547
 
        }
548
 
}
549
 
 
550
 
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, unsigned int src_size)
551
 
{
552
 
        unsigned i;
553
 
        unsigned num_pixels = src_size >> 1;
554
 
        
555
 
        for(i=0; i<num_pixels; i++)
556
 
        {
557
 
            unsigned b,g,r;
558
 
            register uint16_t rgb;
559
 
            rgb = src[2*i];
560
 
            r = rgb&0x1F;
561
 
            g = (rgb&0x3E0)>>5;
562
 
            b = (rgb&0x7C00)>>10;
563
 
            dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11);
564
 
        }
565
 
}
566
 
 
567
 
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, unsigned int src_size)
568
 
{
569
 
        unsigned i;
570
 
        unsigned num_pixels = src_size >> 1;
571
 
        
572
 
        for(i=0; i<num_pixels; i++)
573
 
        {
574
 
            unsigned b,g,r;
575
 
            register uint16_t rgb;
576
 
            rgb = src[2*i];
577
 
            r = rgb&0x1F;
578
 
            g = (rgb&0x3E0)>>5;
579
 
            b = (rgb&0x7C00)>>10;
580
 
            dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10);
581
 
        }
582
 
}
583
 
 
584
 
void rgb8tobgr8(const uint8_t *src, uint8_t *dst, unsigned int src_size)
585
 
{
586
 
        unsigned i;
587
 
        unsigned num_pixels = src_size;
588
 
        for(i=0; i<num_pixels; i++)
589
 
        {
590
 
            unsigned b,g,r;
591
 
            register uint8_t rgb;
592
 
            rgb = src[i];
593
 
            r = (rgb&0x07);
594
 
            g = (rgb&0x38)>>3;
595
 
            b = (rgb&0xC0)>>6;
596
 
            dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6);
597
 
        }
598
 
}