Mercurial > mplayer.hg
annotate libswscale/rgb2rgb.c @ 23066:9fa58c749c03
include inttypes.h in the check for dvdnav
author | nicodvb |
---|---|
date | Sun, 22 Apr 2007 20:03:09 +0000 |
parents | ec0ead587e2f |
children | 9528d1ebe68f |
rev | line source |
---|---|
18861 | 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. | |
19703
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
8 * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at) |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
9 * |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19703
diff
changeset
|
10 * This file is part of FFmpeg. |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19703
diff
changeset
|
11 * |
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19703
diff
changeset
|
12 * FFmpeg is free software; you can redistribute it and/or modify |
19703
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
13 * it under the terms of the GNU General Public License as published by |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
14 * the Free Software Foundation; either version 2 of the License, or |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
15 * (at your option) any later version. |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
16 * |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19703
diff
changeset
|
17 * FFmpeg is distributed in the hope that it will be useful, |
19703
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
20 * GNU General Public License for more details. |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
21 * |
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
22 * You should have received a copy of the GNU General Public License |
20094
aca9e9783f67
Change license headers to say 'FFmpeg' instead of 'this program'.
diego
parents:
19703
diff
changeset
|
23 * along with FFmpeg; if not, write to the Free Software |
19703
ad7f49a1ba95
Add official GPL header to make license explicit as discussed on ffmpeg-devel.
diego
parents:
19361
diff
changeset
|
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21029
1f2ba24b4e47
Clarify that some of the non-SIMD code is now LGPLed.
lucabe
parents:
20576
diff
changeset
|
25 * |
1f2ba24b4e47
Clarify that some of the non-SIMD code is now LGPLed.
lucabe
parents:
20576
diff
changeset
|
26 * the C code (not assembly, mmx, ...) of this file can be used |
1f2ba24b4e47
Clarify that some of the non-SIMD code is now LGPLed.
lucabe
parents:
20576
diff
changeset
|
27 * under the LGPL license too |
18861 | 28 */ |
29 #include <inttypes.h> | |
30 #include "config.h" | |
31 #include "rgb2rgb.h" | |
32 #include "swscale.h" | |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
33 #include "swscale_internal.h" |
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
34 #include "x86_cpu.h" |
18861 | 35 #include "bswap.h" |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
36 #ifdef USE_FASTMEMCPY |
18861 | 37 #include "libvo/fastmemcpy.h" |
19143
c4dac777b44c
Use libavutil in libswscale, and allow it to be built out of the mplayer tree
lucabe
parents:
18861
diff
changeset
|
38 #endif |
18861 | 39 |
40 #define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit | |
41 | |
42 void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size); | |
43 void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size); | |
44 void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size); | |
45 void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size); | |
46 void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size); | |
47 void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size); | |
48 void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size); | |
49 void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size); | |
50 void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size); | |
51 void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size); | |
52 void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size); | |
53 void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size); | |
54 //void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); | |
55 void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); | |
56 void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); | |
57 void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); | |
58 void (*rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); | |
59 //void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); | |
60 void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); | |
61 void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); | |
62 | |
63 void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, | |
64 long width, long height, | |
65 long lumStride, long chromStride, long dstStride); | |
66 void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, | |
67 long width, long height, | |
68 long lumStride, long chromStride, long dstStride); | |
69 void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, | |
70 long width, long height, | |
71 long lumStride, long chromStride, long dstStride); | |
72 void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, | |
73 long width, long height, | |
74 long lumStride, long chromStride, long srcStride); | |
75 void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, | |
76 long width, long height, | |
77 long lumStride, long chromStride, long srcStride); | |
78 void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, | |
79 long srcStride, long dstStride); | |
80 void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, | |
81 long width, long height, long src1Stride, | |
82 long src2Stride, long dstStride); | |
83 void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, | |
84 uint8_t *dst1, uint8_t *dst2, | |
85 long width, long height, | |
86 long srcStride1, long srcStride2, | |
87 long dstStride1, long dstStride2); | |
88 void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, | |
89 uint8_t *dst, | |
90 long width, long height, | |
91 long srcStride1, long srcStride2, | |
92 long srcStride3, long dstStride); | |
93 | |
21683
befebdb3ebaa
Allow to compile swscale's non-SIMD code under the LGPL license.
lucabe
parents:
21029
diff
changeset
|
94 #if defined(ARCH_X86) && defined(CONFIG_GPL) |
18861 | 95 static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL; |
96 static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL; | |
97 static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL; | |
98 static const uint64_t mask32g attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL; | |
99 static const uint64_t mask32r attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL; | |
100 static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL; | |
101 static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL; | |
102 static const uint64_t mask3216g __attribute__((aligned(8)))=0x0000FC000000FC00ULL; | |
103 static const uint64_t mask3215g __attribute__((aligned(8)))=0x0000F8000000F800ULL; | |
104 static const uint64_t mul3216 __attribute__((aligned(8))) = 0x2000000420000004ULL; | |
105 static const uint64_t mul3215 __attribute__((aligned(8))) = 0x2000000820000008ULL; | |
106 static const uint64_t mask24b attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL; | |
107 static const uint64_t mask24g attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL; | |
108 static const uint64_t mask24r attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL; | |
109 static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL; | |
110 static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL; | |
111 static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL; | |
112 static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL; | |
113 static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL; | |
114 static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ | |
115 static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ | |
116 static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL; | |
117 static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL; | |
118 static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL; | |
119 #define mask16b mask15b | |
120 static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL; | |
121 static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL; | |
122 static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL; | |
123 static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL; | |
124 static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL; | |
23003
ec0ead587e2f
fix red_15mask and green_15mask. the previous values were wrong and caused
ivo
parents:
22961
diff
changeset
|
125 static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c0000007c00ULL; |
ec0ead587e2f
fix red_15mask and green_15mask. the previous values were wrong and caused
ivo
parents:
22961
diff
changeset
|
126 static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000003e0ULL; |
18861 | 127 static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL; |
128 | |
129 #ifdef FAST_BGR2YV12 | |
130 static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL; | |
131 static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL; | |
132 static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL; | |
133 #else | |
134 static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL; | |
135 static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL; | |
136 static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL; | |
137 #endif | |
138 static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL; | |
139 static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL; | |
140 static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL; | |
141 | |
142 #if 0 | |
143 static volatile uint64_t __attribute__((aligned(8))) b5Dither; | |
144 static volatile uint64_t __attribute__((aligned(8))) g5Dither; | |
145 static volatile uint64_t __attribute__((aligned(8))) g6Dither; | |
146 static volatile uint64_t __attribute__((aligned(8))) r5Dither; | |
147 | |
148 static uint64_t __attribute__((aligned(8))) dither4[2]={ | |
149 0x0103010301030103LL, | |
150 0x0200020002000200LL,}; | |
151 | |
152 static uint64_t __attribute__((aligned(8))) dither8[2]={ | |
153 0x0602060206020602LL, | |
154 0x0004000400040004LL,}; | |
155 #endif | |
20576 | 156 #endif /* defined(ARCH_X86) */ |
18861 | 157 |
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 | |
174 #undef HAVE_SSE2 | |
175 #define RENAME(a) a ## _C | |
176 #include "rgb2rgb_template.c" | |
177 | |
21683
befebdb3ebaa
Allow to compile swscale's non-SIMD code under the LGPL license.
lucabe
parents:
21029
diff
changeset
|
178 #if defined(ARCH_X86) && defined(CONFIG_GPL) |
18861 | 179 |
180 //MMX versions | |
181 #undef RENAME | |
182 #define HAVE_MMX | |
183 #undef HAVE_MMX2 | |
184 #undef HAVE_3DNOW | |
185 #undef HAVE_SSE2 | |
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 | |
194 #undef HAVE_SSE2 | |
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 | |
203 #undef HAVE_SSE2 | |
204 #define RENAME(a) a ## _3DNOW | |
205 #include "rgb2rgb_template.c" | |
206 | |
207 #endif //ARCH_X86 || ARCH_X86_64 | |
208 | |
209 /* | |
210 rgb15->rgb16 Original by Strepto/Astral | |
211 ported to gcc & bugfixed : A'rpi | |
212 MMX2, 3DNOW optimization by Nick Kurshev | |
213 32bit c version, and and&add trick by Michael Niedermayer | |
214 */ | |
215 | |
216 void sws_rgb2rgb_init(int flags){ | |
21683
befebdb3ebaa
Allow to compile swscale's non-SIMD code under the LGPL license.
lucabe
parents:
21029
diff
changeset
|
217 #if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL) |
22961
08c5276ddf1d
cosmetics after last commit; remove superfluous braces
ivo
parents:
22960
diff
changeset
|
218 if(flags & SWS_CPU_CAPS_MMX2) |
22960 | 219 rgb2rgb_init_MMX2(); |
22961
08c5276ddf1d
cosmetics after last commit; remove superfluous braces
ivo
parents:
22960
diff
changeset
|
220 else if(flags & SWS_CPU_CAPS_3DNOW) |
22960 | 221 rgb2rgb_init_3DNOW(); |
22961
08c5276ddf1d
cosmetics after last commit; remove superfluous braces
ivo
parents:
22960
diff
changeset
|
222 else if(flags & SWS_CPU_CAPS_MMX) |
22960 | 223 rgb2rgb_init_MMX(); |
22961
08c5276ddf1d
cosmetics after last commit; remove superfluous braces
ivo
parents:
22960
diff
changeset
|
224 else |
19333
4f5e2e0529b1
Do not assemble MMX, MMX2 or 3DNOW code unconditionally on X86 and X86_64.
diego
parents:
19206
diff
changeset
|
225 #endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */ |
22960 | 226 rgb2rgb_init_C(); |
18861 | 227 } |
228 | |
229 /** | |
21874 | 230 * Palette is assumed to contain BGR32. |
18861 | 231 */ |
232 void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
233 { | |
234 long i; | |
235 | |
236 /* | |
237 for(i=0; i<num_pixels; i++) | |
238 ((unsigned *)dst)[i] = ((unsigned *)palette)[ src[i] ]; | |
239 */ | |
240 | |
241 for(i=0; i<num_pixels; i++) | |
242 { | |
243 #ifdef WORDS_BIGENDIAN | |
244 dst[3]= palette[ src[i]*4+2 ]; | |
245 dst[2]= palette[ src[i]*4+1 ]; | |
246 dst[1]= palette[ src[i]*4+0 ]; | |
247 #else | |
248 //FIXME slow? | |
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? */ | |
253 #endif | |
254 dst+= 4; | |
255 } | |
256 } | |
257 | |
258 void palette8tobgr32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
259 { | |
260 long i; | |
261 for(i=0; i<num_pixels; i++) | |
262 { | |
263 #ifdef WORDS_BIGENDIAN | |
264 dst[3]= palette[ src[i]*4+0 ]; | |
265 dst[2]= palette[ src[i]*4+1 ]; | |
266 dst[1]= palette[ src[i]*4+2 ]; | |
267 #else | |
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? */ | |
273 #endif | |
274 | |
275 dst+= 4; | |
276 } | |
277 } | |
278 | |
279 /** | |
21874 | 280 * Palette is assumed to contain BGR32. |
18861 | 281 */ |
282 void palette8torgb24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
283 { | |
284 long i; | |
285 /* | |
286 writes 1 byte o much and might cause alignment issues on some architectures? | |
287 for(i=0; i<num_pixels; i++) | |
288 ((unsigned *)(&dst[i*3])) = ((unsigned *)palette)[ src[i] ]; | |
289 */ | |
290 for(i=0; i<num_pixels; i++) | |
291 { | |
292 //FIXME slow? | |
293 dst[0]= palette[ src[i]*4+2 ]; | |
294 dst[1]= palette[ src[i]*4+1 ]; | |
295 dst[2]= palette[ src[i]*4+0 ]; | |
296 dst+= 3; | |
297 } | |
298 } | |
299 | |
300 void palette8tobgr24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
301 { | |
302 long i; | |
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? | |
311 dst[0]= palette[ src[i]*4+0 ]; | |
312 dst[1]= palette[ src[i]*4+1 ]; | |
313 dst[2]= palette[ src[i]*4+2 ]; | |
314 dst+= 3; | |
315 } | |
316 } | |
317 | |
318 /** | |
319 * Palette is assumed to contain bgr16, see rgb32to16 to convert the palette | |
320 */ | |
321 void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
322 { | |
323 long i; | |
324 for(i=0; i<num_pixels; i++) | |
325 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ]; | |
326 } | |
327 void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
328 { | |
329 long i; | |
330 for(i=0; i<num_pixels; i++) | |
331 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]); | |
332 } | |
333 | |
334 /** | |
21874 | 335 * Palette is assumed to contain BGR15, see rgb32to15 to convert the palette. |
18861 | 336 */ |
337 void palette8torgb15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
338 { | |
339 long i; | |
340 for(i=0; i<num_pixels; i++) | |
341 ((uint16_t *)dst)[i] = ((uint16_t *)palette)[ src[i] ]; | |
342 } | |
343 void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) | |
344 { | |
345 long i; | |
346 for(i=0; i<num_pixels; i++) | |
347 ((uint16_t *)dst)[i] = bswap_16(((uint16_t *)palette)[ src[i] ]); | |
348 } | |
349 | |
350 void rgb32tobgr24(const uint8_t *src, uint8_t *dst, long src_size) | |
351 { | |
352 long i; | |
353 long num_pixels = src_size >> 2; | |
354 for(i=0; i<num_pixels; i++) | |
355 { | |
356 #ifdef WORDS_BIGENDIAN | |
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]; | |
361 #else | |
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]; | |
365 #endif | |
366 } | |
367 } | |
368 | |
369 void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size) | |
370 { | |
371 long i; | |
372 for(i=0; 3*i<src_size; i++) | |
373 { | |
374 #ifdef WORDS_BIGENDIAN | |
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]; | |
380 #else | |
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; | |
385 #endif | |
386 } | |
387 } | |
388 | |
389 void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) | |
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++; | |
399 #ifdef WORDS_BIGENDIAN | |
400 *d++ = 0; | |
401 *d++ = (bgr&0x1F)<<3; | |
402 *d++ = (bgr&0x7E0)>>3; | |
403 *d++ = (bgr&0xF800)>>8; | |
404 #else | |
405 *d++ = (bgr&0xF800)>>8; | |
406 *d++ = (bgr&0x7E0)>>3; | |
407 *d++ = (bgr&0x1F)<<3; | |
408 *d++ = 0; | |
409 #endif | |
410 } | |
411 } | |
412 | |
413 void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size) | |
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 | |
429 void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size) | |
430 { | |
431 long i; | |
432 long num_pixels = src_size >> 1; | |
433 | |
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 | |
446 void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size) | |
447 { | |
448 long i; | |
449 long num_pixels = src_size >> 1; | |
450 | |
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 | |
463 void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size) | |
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++; | |
473 #ifdef WORDS_BIGENDIAN | |
474 *d++ = 0; | |
475 *d++ = (bgr&0x1F)<<3; | |
476 *d++ = (bgr&0x3E0)>>2; | |
477 *d++ = (bgr&0x7C00)>>7; | |
478 #else | |
479 *d++ = (bgr&0x7C00)>>7; | |
480 *d++ = (bgr&0x3E0)>>2; | |
481 *d++ = (bgr&0x1F)<<3; | |
482 *d++ = 0; | |
483 #endif | |
484 } | |
485 } | |
486 | |
487 void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size) | |
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 | |
503 void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size) | |
504 { | |
505 long i; | |
506 long num_pixels = src_size >> 1; | |
507 | |
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 | |
520 void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size) | |
521 { | |
522 long i; | |
523 long num_pixels = src_size >> 1; | |
524 | |
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 | |
537 void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size) | |
538 { | |
539 long i; | |
540 long num_pixels = src_size; | |
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 } |