]> git.sesse.net Git - ccbs/blob - bigscreen/tinyptc/convert.c
Fixed a misleading comment.
[ccbs] / bigscreen / tinyptc / convert.c
1 /*
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>
5  *
6  * http://www.sourceforge.net/projects/tinyptc/
7  *
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.
12  *
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.
17  *
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
21  * 
22  */
23
24 #include "convert.h"
25 #include "mmx.h"
26 #include <string.h>
27
28 #ifdef __PTC_CONVERTER_32_TO_32_RGB888
29 void
30 ptc_convert_32_to_32_rgb888 (void *src, void *dst, int pixels)
31 {
32 #ifdef __PTC_MMX__
33   mmx_memcpy (dst, src, pixels * 4);
34 #else
35 #ifdef __PTC_MEMCPY__
36   memcpy (dst, src, pixels * 4);
37 #else
38   int32 *p = (int32 *) src;
39   int32 *q = (int32 *) dst;
40   while (pixels--)
41     {
42       *(q++) = *(p++);
43     }
44 #endif /* __PTC_MEMCPY__ */
45 #endif /* __PTC_MMX__ */
46 }
47 #endif /* __PTC_CONVERTER_32_TO_32_RGB888 */
48
49 #ifdef __PTC_CONVERTER_32_TO_32_BGR888
50 void
51 ptc_convert_32_to_32_bgr888 (void *src, void *dst, int pixels)
52 {
53   int32 *p = (int32 *) src;
54   int32 *q = (int32 *) dst;
55   while (pixels--)
56     {
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);
61 #else
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__ */
66       *(q++) = r | g | b;
67       p++;
68     }
69 }
70 #endif /* __PTC_CONVERTER_32_TO_32_BGR888 */
71
72 #ifdef __PTC_CONVERTER_32_TO_24_RGB888
73 void
74 ptc_convert_32_to_24_rgb888 (void *src, void *dst, int pixels)
75 {
76 #ifdef __PTC_MMX__
77   mmx_convert_32_to_24_rgb888 (dst, src, pixels);
78 #else
79   char8 *p = (char8 *) src;
80   char8 *q = (char8 *) dst;
81   while (pixels--)
82     {
83 #ifdef __PTC_LITTLE_ENDIAN__
84       *q = *p;
85       *(q + 1) = *(p + 1);
86       *(q + 2) = *(p + 2);
87 #else
88       *(q + 2) = *p;
89       *(q + 1) = *(p + 1);
90       *q = *(p + 2);
91 #endif /* __PTC_LITTLE_ENDIAN__ */
92       p += 4;
93       q += 3;
94     }
95 #endif /* __PTC_MMX__ */
96 }
97 #endif /* __PTC_CONVERTER_32_TO_24_RGB888 */
98
99 #ifdef __PTC_CONVERTER_32_TO_24_BGR888
100 void
101 ptc_convert_32_to_24_bgr888 (void *src, void *dst, int pixels)
102 {
103 #ifdef __PTC_MMX__
104   mmx_convert_32_to_24_bgr888 (dst, src, pixels);
105 #else
106   char8 *p = (char8 *) src;
107   char8 *q = (char8 *) dst;
108   while (pixels--)
109     {
110 #ifdef __PTC_LITTLE_ENDIAN__
111       *(q + 2) = *p;
112       *(q + 1) = *(p + 1);
113       *q = *(p + 2);
114 #else
115       *q = *p;
116       *(q + 1) = *(p + 1);
117       *(q + 2) = *(p + 2);
118 #endif /* __PTC_LITTLE_ENDIAN__ */
119       p += 4;
120       q += 3;
121     }
122 #endif /* __PTC_MMX__ */
123 }
124 #endif /* __PTC_CONVERTER_32_TO_24_BGR888 */
125
126 #ifdef __PTC_CONVERTER_32_TO_16_RGB565
127 void
128 ptc_convert_32_to_16_rgb565 (void *src, void *dst, int pixels)
129 {
130 #ifdef __PTC_MMX__
131   mmx_convert_32_to_16_rgb565 (dst, src, pixels);
132 #else
133   int32 *p = (int32 *) src;
134   short16 *q = (short16 *) dst;
135   while (pixels--)
136     {
137       short16 r = (short16) ((*p & 0x00F80000) >> 8);
138       short16 g = (short16) ((*p & 0x0000FC00) >> 5);
139       short16 b = (short16) ((*p & 0x000000F8) >> 3);
140       *q = r | g | b;
141       p++;
142       q++;
143     }
144 #endif /* __PTC_MMX__ */
145 }
146 #endif /* __PTC_CONVERTER_32_TO_16_RGB565 */
147
148 #ifdef __PTC_CONVERTER_32_TO_16_BGR565
149 void
150 ptc_convert_32_to_16_bgr565 (void *src, void *dst, int pixels)
151 {
152 #ifdef __PTC_MMX__
153   mmx_convert_32_to_16_bgr565 (dst, src, pixels);
154 #else
155   int32 *p = (int32 *) src;
156   short16 *q = (short16 *) dst;
157   while (pixels--)
158     {
159       short16 r = (short16) ((*p & 0x00F80000) >> 19);
160       short16 g = (short16) ((*p & 0x0000FC00) >> 5);
161       short16 b = (short16) ((*p & 0x000000F8) << 8);
162       *q = r | g | b;
163       p++;
164       q++;
165     }
166 #endif /* __PTC_MMX__ */
167 }
168 #endif /* __PTC_CONVERTER_32_TO_16_RGB565 */
169
170 #ifdef __PTC_CONVERTER_32_TO_16_RGB555
171 void
172 ptc_convert_32_to_16_rgb555 (void *src, void *dst, int pixels)
173 {
174 #ifdef __PTC_MMX__
175   mmx_convert_32_to_16_rgb555 (dst, src, pixels);
176 #else
177   int32 *p = (int32 *) src;
178   short16 *q = (short16 *) dst;
179   while (pixels--)
180     {
181       short16 r = (short16) ((*p & 0x00F80000) >> 9);
182       short16 g = (short16) ((*p & 0x0000F800) >> 6);
183       short16 b = (short16) ((*p & 0x000000F8) >> 3);
184       *q = r | g | b;
185       p++;
186       q++;
187     }
188 #endif /* __PTC_MMX__ */
189 }
190 #endif /* __PTC_CONVERTER_32_TO_16_RGB555 */
191
192 #ifdef __PTC_CONVERTER_32_TO_16_BGR555
193 void
194 ptc_convert_32_to_16_bgr555 (void *src, void *dst, int pixels)
195 {
196 #ifdef __PTC_MMX__
197   mmx_convert_32_to_16_bgr555 (dst, src, pixels);
198 #else
199   int32 *p = (int32 *) src;
200   short16 *q = (short16 *) dst;
201   while (pixels--)
202     {
203       short16 r = (short16) ((*p & 0x00F80000) >> 20);
204       short16 g = (short16) ((*p & 0x0000F800) >> 6);
205       short16 b = (short16) ((*p & 0x000000F8) << 8);
206       *q = r | g | b;
207       p++;
208       q++;
209     }
210 #endif /* __PTC_MMX__ */
211 }
212 #endif /* __PTC_CONVERTER_32_TO_16_BGR555 */
213
214 PTC_CONVERTER
215 ptc_request_converter (int bits, int32 r, int32 g, int32 b)
216 {
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;
221 #endif
222
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;
227 #endif
228
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;
233 #endif
234
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;
239 #endif
240
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;
245 #endif
246
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;
251 #endif
252
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;
257 #endif
258
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;
263 #endif
264
265   /* failure */
266   return 0;
267 }