2 * TinyPTC x11 v0.7.3 Pixelformat converters
3 * Copyright (C) 2000-2002 Alessandro Gatti <a.gatti@tiscali.it>
4 * Copyright (C) 2000-2001 Glenn Fiedler <gaffer@gaffer.org>
6 * http://www.sourceforge.net/projects/tinyptc/
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifdef __PTC_CONVERTER_32_TO_32_RGB888
30 ptc_convert_32_to_32_rgb888 (void *src, void *dst, int pixels)
33 mmx_memcpy (dst, src, pixels * 4);
36 memcpy (dst, src, pixels * 4);
38 int32 *p = (int32 *) src;
39 int32 *q = (int32 *) dst;
44 #endif /* __PTC_MEMCPY__ */
45 #endif /* __PTC_MMX__ */
47 #endif /* __PTC_CONVERTER_32_TO_32_RGB888 */
49 #ifdef __PTC_CONVERTER_32_TO_32_BGR888
51 ptc_convert_32_to_32_bgr888 (void *src, void *dst, int pixels)
53 int32 *p = (int32 *) src;
54 int32 *q = (int32 *) dst;
57 #ifdef __PTC_LITTLE_ENDIAN__
58 int32 r = (int32) ((*p & 0x00FF0000) << 8);
59 int32 g = (int32) ((*p & 0x0000FF00) << 8);
60 int32 b = (int32) ((*p & 0x000000FF) << 8);
62 int32 r = (int32) ((*p & 0x00FF0000) >> 16);
63 int32 g = (int32) ((*p & 0x0000FF00));
64 int32 b = (int32) ((*p & 0x000000FF) << 16);
65 #endif /* __PTC_LITTLE_ENDIAN__ */
70 #endif /* __PTC_CONVERTER_32_TO_32_BGR888 */
72 #ifdef __PTC_CONVERTER_32_TO_24_RGB888
74 ptc_convert_32_to_24_rgb888 (void *src, void *dst, int pixels)
77 mmx_convert_32_to_24_rgb888 (dst, src, pixels);
79 char8 *p = (char8 *) src;
80 char8 *q = (char8 *) dst;
83 #ifdef __PTC_LITTLE_ENDIAN__
91 #endif /* __PTC_LITTLE_ENDIAN__ */
95 #endif /* __PTC_MMX__ */
97 #endif /* __PTC_CONVERTER_32_TO_24_RGB888 */
99 #ifdef __PTC_CONVERTER_32_TO_24_BGR888
101 ptc_convert_32_to_24_bgr888 (void *src, void *dst, int pixels)
104 mmx_convert_32_to_24_bgr888 (dst, src, pixels);
106 char8 *p = (char8 *) src;
107 char8 *q = (char8 *) dst;
110 #ifdef __PTC_LITTLE_ENDIAN__
118 #endif /* __PTC_LITTLE_ENDIAN__ */
122 #endif /* __PTC_MMX__ */
124 #endif /* __PTC_CONVERTER_32_TO_24_BGR888 */
126 #ifdef __PTC_CONVERTER_32_TO_16_RGB565
128 ptc_convert_32_to_16_rgb565 (void *src, void *dst, int pixels)
131 mmx_convert_32_to_16_rgb565 (dst, src, pixels);
133 int32 *p = (int32 *) src;
134 short16 *q = (short16 *) dst;
137 short16 r = (short16) ((*p & 0x00F80000) >> 8);
138 short16 g = (short16) ((*p & 0x0000FC00) >> 5);
139 short16 b = (short16) ((*p & 0x000000F8) >> 3);
144 #endif /* __PTC_MMX__ */
146 #endif /* __PTC_CONVERTER_32_TO_16_RGB565 */
148 #ifdef __PTC_CONVERTER_32_TO_16_BGR565
150 ptc_convert_32_to_16_bgr565 (void *src, void *dst, int pixels)
153 mmx_convert_32_to_16_bgr565 (dst, src, pixels);
155 int32 *p = (int32 *) src;
156 short16 *q = (short16 *) dst;
159 short16 r = (short16) ((*p & 0x00F80000) >> 19);
160 short16 g = (short16) ((*p & 0x0000FC00) >> 5);
161 short16 b = (short16) ((*p & 0x000000F8) << 8);
166 #endif /* __PTC_MMX__ */
168 #endif /* __PTC_CONVERTER_32_TO_16_RGB565 */
170 #ifdef __PTC_CONVERTER_32_TO_16_RGB555
172 ptc_convert_32_to_16_rgb555 (void *src, void *dst, int pixels)
175 mmx_convert_32_to_16_rgb555 (dst, src, pixels);
177 int32 *p = (int32 *) src;
178 short16 *q = (short16 *) dst;
181 short16 r = (short16) ((*p & 0x00F80000) >> 9);
182 short16 g = (short16) ((*p & 0x0000F800) >> 6);
183 short16 b = (short16) ((*p & 0x000000F8) >> 3);
188 #endif /* __PTC_MMX__ */
190 #endif /* __PTC_CONVERTER_32_TO_16_RGB555 */
192 #ifdef __PTC_CONVERTER_32_TO_16_BGR555
194 ptc_convert_32_to_16_bgr555 (void *src, void *dst, int pixels)
197 mmx_convert_32_to_16_bgr555 (dst, src, pixels);
199 int32 *p = (int32 *) src;
200 short16 *q = (short16 *) dst;
203 short16 r = (short16) ((*p & 0x00F80000) >> 20);
204 short16 g = (short16) ((*p & 0x0000F800) >> 6);
205 short16 b = (short16) ((*p & 0x000000F8) << 8);
210 #endif /* __PTC_MMX__ */
212 #endif /* __PTC_CONVERTER_32_TO_16_BGR555 */
215 ptc_request_converter (int bits, int32 r, int32 g, int32 b)
217 /* 32bit RGB888 -> 32bit RGB888 */
218 #ifdef __PTC_CONVERTER_32_TO_32_RGB888
219 if (bits == 32 && r == 0x00FF0000 && g == 0x0000FF00 && b == 0x000000FF)
220 return &ptc_convert_32_to_32_rgb888;
223 /* 32bit RGB888 -> 32bit BGR888 */
224 #ifdef __PTC_CONVERTER_32_TO_32_BGR888
225 if (bits == 32 && r == 0x000000FF && g == 0x0000FF00 && b == 0x00FF0000)
226 return &ptc_convert_32_to_32_bgr888;
229 /* 32bit RGB888 -> 24bit RGB888 */
230 #ifdef __PTC_CONVERTER_32_TO_24_RGB888
231 if (bits == 24 && r == 0x00FF0000 && g == 0x0000FF00 && b == 0x000000FF)
232 return &ptc_convert_32_to_24_rgb888;
235 /* 32bit RGB888 -> 24bit BGR888 */
236 #ifdef __PTC_CONVERTER_32_TO_24_BGR888
237 if (bits == 24 && r == 0x000000FF && g == 0x0000FF00 && b == 0x00FF0000)
238 return &ptc_convert_32_to_24_bgr888;
241 /* 32bit RGB888 -> 16bit RGB565 */
242 #ifdef __PTC_CONVERTER_32_TO_16_RGB565
243 if (bits == 16 && r == 0xF800 && g == 0x07E0 && b == 0x001F)
244 return &ptc_convert_32_to_16_rgb565;
247 /* 32bit RGB888 -> 16bit BGR565 */
248 #ifdef __PTC_CONVERTER_32_TO_16_BGR565
249 if (bits == 16 && r == 0x001F && g == 0x07E0 && b == 0xF800)
250 return &ptc_convert_32_to_16_bgr565;
253 /* 32bit RGB888 -> 16bit RGB555 */
254 #ifdef __PTC_CONVERTER_32_TO_16_RGB555
255 if (bits == 16 && r == 0x7C00 && g == 0x03E0 && b == 0x001F)
256 return &ptc_convert_32_to_16_rgb555;
259 /* 32bit RGB888 -> 16bit BGR555 */
260 #ifdef __PTC_CONVERTER_32_TO_16_BGR555
261 if (bits == 16 && r == 0x001F && g == 0x03E0 && b == 0x7C00)
262 return &ptc_convert_32_to_16_bgr555;