msvcrt: New implementation of fcvt.
[wine/multimedia.git] / dlls / winex11.drv / dib_dst_swap.c
blob9a66bf427fa1aef69221c8909ddd3b85cdf1dbd8
1 /*
2 * DIB conversion routinues for cases where the destination
3 * has non-native byte order.
5 * Copyright (C) 2003 Huw Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdlib.h>
26 #include "windef.h"
27 #include "x11drv.h"
29 #define FLIP_WORD(x) \
30 ( *(x) = ( (*(x) & 0xff) << 8) | \
31 ( (*(x) & 0xff00) >> 8) )
33 #define FLIP_TWO_WORDS(x) \
34 ( *(x) = ( (*(x) & 0x00ff00ff) << 8) | \
35 ( (*(x) & 0xff00ff00) >> 8) )
37 #define FLIP_DWORD(x) \
38 ( *(x) = ( (*(x) & 0xff) << 24) | \
39 ( (*(x) & 0xff00) << 8) | \
40 ( (*(x) & 0xff0000) >> 8) | \
41 ( (*(x) & 0xff000000) >> 24) )
45 * 15 bit conversions
48 static void convert_5x5_asis_dst_byteswap(int width, int height,
49 const void* srcbits, int srclinebytes,
50 void* dstbits, int dstlinebytes)
52 int x, y;
53 const DWORD *srcpixel;
54 DWORD *dstpixel;
56 for (y=0; y<height; y++) {
57 srcpixel=srcbits;
58 dstpixel=dstbits;
59 for(x = 0; x < width/2; x++) {
60 /* Do 2 pixels at a time */
61 DWORD srcval = *srcpixel++;
62 *dstpixel++=((srcval << 8) & 0xff00ff00) |
63 ((srcval >> 8) & 0x00ff00ff);
65 if(width&1) {
66 /* And the odd pixel */
67 WORD srcval = *(const WORD*)srcpixel;
68 *(WORD*)dstpixel = ((srcval << 8) & 0xff00) |
69 ((srcval >> 8) & 0x00ff);
71 srcbits = (const char*)srcbits + srclinebytes;
72 dstbits = (char*)dstbits + dstlinebytes;
76 static void convert_555_reverse_dst_byteswap(int width, int height,
77 const void* srcbits, int srclinebytes,
78 void* dstbits, int dstlinebytes)
80 const DWORD* srcpixel;
81 DWORD* dstpixel;
82 int x,y;
84 for (y=0; y<height; y++) {
85 srcpixel=srcbits;
86 dstpixel=dstbits;
87 for (x=0; x<width/2; x++) {
88 /* Do 2 pixels at a time */
89 DWORD srcval;
90 srcval=*srcpixel++;
91 *dstpixel++=((srcval >> 2) & 0x1f001f00) | /* h */
92 ((srcval >> 8) & 0x00030003) | /* g - 2 bits */
93 ((srcval << 8) & 0xe000e000) | /* g - 3 bits */
94 ((srcval << 2) & 0x007c007c); /* l */
96 if (width&1) {
97 /* And the the odd pixel */
98 WORD srcval;
99 srcval=*((const WORD*)srcpixel);
100 *((WORD*)dstpixel)=((srcval >> 2) & 0x1f00) | /* h */
101 ((srcval >> 8) & 0x0003) | /* g - 2 bits */
102 ((srcval << 8) & 0xe000) | /* g - 3 bits */
103 ((srcval << 2) & 0x007c); /* l */
105 srcbits = (const char*)srcbits + srclinebytes;
106 dstbits = (char*)dstbits + dstlinebytes;
110 static void convert_555_to_565_asis_dst_byteswap(int width, int height,
111 const void* srcbits, int srclinebytes,
112 void* dstbits, int dstlinebytes)
114 const DWORD* srcpixel;
115 DWORD* dstpixel;
116 int x,y;
118 for (y=0; y<height; y++) {
119 srcpixel=srcbits;
120 dstpixel=dstbits;
121 for (x=0; x<width/2; x++) {
122 /* Do 2 pixels at a time */
123 DWORD srcval;
124 srcval=*srcpixel++;
125 *dstpixel++=((srcval >> 7) & 0x00ff00ff) | /* h, g - 3 bits */
126 ((srcval << 9) & 0xc000c000) | /* g - 2 bits */
127 ((srcval << 4) & 0x20002000) | /* g - 1 bits */
128 ((srcval << 8) & 0x1f001f00); /* l */
130 if (width&1) {
131 /* And the the odd pixel */
132 WORD srcval;
133 srcval=*((const WORD*)srcpixel);
134 *((WORD*)dstpixel)=((srcval >> 7) & 0x00ff) | /* h, g - 3 bits */
135 ((srcval << 9) & 0xc000) | /* g - 2 bits */
136 ((srcval << 4) & 0x2000) | /* g - 1 bit */
137 ((srcval << 8) & 0x1f00); /* l */
139 srcbits = (const char*)srcbits + srclinebytes;
140 dstbits = (char*)dstbits + dstlinebytes;
144 static void convert_555_to_565_reverse_dst_byteswap(int width, int height,
145 const void* srcbits, int srclinebytes,
146 void* dstbits, int dstlinebytes)
148 const DWORD* srcpixel;
149 DWORD* dstpixel;
150 int x,y;
152 for (y=0; y<height; y++) {
153 srcpixel=srcbits;
154 dstpixel=dstbits;
155 for (x=0; x<width/2; x++) {
156 /* Do 2 pixels at a time */
157 DWORD srcval;
158 srcval=*srcpixel++;
159 *dstpixel++=((srcval >> 2) & 0x1f001f00) | /* h */
160 ((srcval >> 7) & 0x00070007) | /* g - 3 bits */
161 ((srcval << 9) & 0xc000c000) | /* g - 2 bits */
162 ((srcval << 4) & 0x20002000) | /* g - 1 bit */
163 ((srcval << 3) & 0x00f800f8); /* l */
165 if (width&1) {
166 /* And the the odd pixel */
167 WORD srcval;
168 srcval=*((const WORD*)srcpixel);
169 *((WORD*)dstpixel)=((srcval >> 2) & 0x1f00) | /* h */
170 ((srcval >> 7) & 0x0007) | /* g - 3 bits */
171 ((srcval << 9) & 0xc000) | /* g - 2 bits */
172 ((srcval << 4) & 0x2000) | /* g - 1 bit */
173 ((srcval << 3) & 0x00f8); /* l */
175 srcbits = (const char*)srcbits + srclinebytes;
176 dstbits = (char*)dstbits + dstlinebytes;
180 static void convert_555_to_888_asis_dst_byteswap(int width, int height,
181 const void* srcbits, int srclinebytes,
182 void* dstbits, int dstlinebytes)
184 const WORD* srcpixel;
185 DWORD* dstpixel;
186 int x,y;
188 for (y=0; y<height; y++) {
189 srcpixel=srcbits;
190 dstpixel=dstbits;
191 for (x=0; x<width/4; x++) {
192 /* Do 4 pixels at a time. 4 words in 3 dwords out */
193 DWORD srcval1, srcval2;
194 srcval1=(DWORD)*srcpixel++;
195 srcval2=(DWORD)*srcpixel++;
196 *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l1 */
197 ((srcval1 << 22) & 0x07000000) | /* l1 - 3 bits */
198 ((srcval1 << 14) & 0x00f80000) | /* g1 */
199 ((srcval1 << 9) & 0x00070000) | /* g1 - 3 bits */
200 ((srcval1 << 1) & 0x0000f800) | /* h1 */
201 ((srcval1 >> 4) & 0x00070000) | /* h1 - 3 bits */
202 ((srcval2 << 3) & 0x000000f8) | /* l2 */
203 ((srcval2 >> 2) & 0x00000007); /* l2 - 3 bits */
204 srcval1=(DWORD)*srcpixel++;
205 *dstpixel++= ((srcval2 << 22) & 0xf8000000) | /* g2 */
206 ((srcval2 << 17) & 0x07000000) | /* g2 - 3 bits */
207 ((srcval2 << 9) & 0x00f80000) | /* h2 */
208 ((srcval2 << 4) & 0x00070000) | /* h2 - 3 bits */
209 ((srcval1 << 11) & 0x0000f800) | /* l3 */
210 ((srcval1 << 6) & 0x00000700) | /* l3 - 3 bits */
211 ((srcval1 >> 2) & 0x000000f8) | /* g3 */
212 ((srcval1 >> 7) & 0x00000007); /* g3 - 3 bits */
213 srcval2=(DWORD)*srcpixel++;
214 *dstpixel++= ((srcval1 << 17) & 0xf8000000) | /* h3 */
215 ((srcval1 << 12) & 0x07000000) | /* h3 - 3 bits */
216 ((srcval2 << 19) & 0x00f80000) | /* l4 */
217 ((srcval2 << 14) & 0x00070000) | /* l4 - 3 bits */
218 ((srcval2 << 6) & 0x0000f800) | /* g4 */
219 ((srcval2 << 1) & 0x00000700) | /* g4 - 3 bits */
220 ((srcval2 >> 7) & 0x000000f8) | /* h4 */
221 ((srcval2 >> 12) & 0x00000007); /* h4 - 3 bits */
223 if(width&3) {
224 BYTE *dstbyte = (BYTE*)dstpixel;
225 DWORD srcval;
226 for(x = 0; x < (width&3); x++) {
227 srcval = *srcpixel++;
228 dstbyte[0] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07);
229 dstbyte[1] = ((srcval >> 2) & 0xf8) | ((srcval >> 7) & 0x07);
230 dstbyte[2] = ((srcval >> 7) & 0xf8) | ((srcval >> 12) & 0x07);
231 dstbyte+=3;
232 if(x > 0)
233 FLIP_DWORD(dstpixel + x - 1);
235 FLIP_DWORD(dstpixel + x - 1);
237 srcbits = (const char*)srcbits + srclinebytes;
238 dstbits = (char*)dstbits + dstlinebytes;
242 static void convert_555_to_888_reverse_dst_byteswap(int width, int height,
243 const void* srcbits, int srclinebytes,
244 void* dstbits, int dstlinebytes)
246 const WORD* srcpixel;
247 DWORD* dstpixel;
248 int x,y;
250 for (y=0; y<height; y++) {
251 srcpixel=srcbits;
252 dstpixel=dstbits;
253 for (x=0; x<width/4; x++) {
254 /* Do 4 pixels at a time. 4 words in 3 dwords out */
255 DWORD srcval1, srcval2;
256 srcval1=(DWORD)*srcpixel++;
257 srcval2=(DWORD)*srcpixel++;
258 *dstpixel++= ((srcval1 << 17) & 0xf8000000) | /* h1 */
259 ((srcval1 << 12) & 0x07000000) | /* h1 - 3 bits */
260 ((srcval1 << 14) & 0x00f80000) | /* g1 */
261 ((srcval1 << 9) & 0x00070000) | /* g1 - 3 bits */
262 ((srcval1 << 11) & 0x0000f800) | /* l1 */
263 ((srcval1 << 6) & 0x00070000) | /* l1 - 3 bits */
264 ((srcval2 >> 7) & 0x000000f8) | /* h2 */
265 ((srcval2 >> 12) & 0x00000007); /* h2 - 3 bits */
266 srcval1=(DWORD)*srcpixel++;
267 *dstpixel++= ((srcval2 << 22) & 0xf8000000) | /* g2 */
268 ((srcval2 << 17) & 0x07000000) | /* g2 - 3 bits */
269 ((srcval2 << 19) & 0x00f80000) | /* l2 */
270 ((srcval2 << 14) & 0x00070000) | /* l2 - 3 bits */
271 ((srcval1 << 1) & 0x0000f800) | /* h3 */
272 ((srcval1 >> 4) & 0x00000700) | /* h3 - 3 bits */
273 ((srcval1 >> 2) & 0x000000f8) | /* g3 */
274 ((srcval1 >> 7) & 0x00000007); /* g3 - 3 bits */
275 srcval2=(DWORD)*srcpixel++;
276 *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l3 */
277 ((srcval1 << 22) & 0x07000000) | /* l3 - 3 bits */
278 ((srcval2 << 9) & 0x00f80000) | /* h4 */
279 ((srcval2 << 4) & 0x00070000) | /* h4 - 3 bits */
280 ((srcval2 << 6) & 0x0000f800) | /* g4 */
281 ((srcval2 << 1) & 0x00000700) | /* g4 - 3 bits */
282 ((srcval2 << 3) & 0x000000f8) | /* l4 */
283 ((srcval2 >> 2) & 0x00000007); /* l4 - 3 bits */
285 if(width&3) {
286 BYTE *dstbyte = (BYTE*)dstpixel;
287 DWORD srcval;
288 for(x = 0; x < (width&3); x++) {
289 srcval = *srcpixel++;
290 dstbyte[2] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07);
291 dstbyte[1] = ((srcval >> 2) & 0xf8) | ((srcval >> 7) & 0x07);
292 dstbyte[0] = ((srcval >> 7) & 0xf8) | ((srcval >> 12) & 0x07);
293 dstbyte+=3;
294 if(x > 0)
295 FLIP_DWORD(dstpixel + x - 1);
297 FLIP_DWORD(dstpixel + x - 1);
299 srcbits = (const char*)srcbits + srclinebytes;
300 dstbits = (char*)dstbits + dstlinebytes;
304 static void convert_555_to_0888_asis_dst_byteswap(int width, int height,
305 const void* srcbits, int srclinebytes,
306 void* dstbits, int dstlinebytes)
308 const WORD* srcpixel;
309 DWORD* dstpixel;
310 int x,y;
312 for (y=0; y<height; y++) {
313 srcpixel=srcbits;
314 dstpixel=dstbits;
315 for (x=0; x<width; x++) {
316 WORD srcval;
317 srcval=*srcpixel++;
318 *dstpixel++=((srcval << 1) & 0x0000f800) | /* h */
319 ((srcval >> 4) & 0x00000700) | /* h - 3 bits */
320 ((srcval << 14) & 0x00f80000) | /* g */
321 ((srcval << 9) & 0x00070000) | /* g - 3 bits */
322 ((srcval << 27) & 0xf8000000) | /* l */
323 ((srcval << 22) & 0x07000000); /* l - 3 bits */
325 srcbits = (const char*)srcbits + srclinebytes;
326 dstbits = (char*)dstbits + dstlinebytes;
330 static void convert_555_to_0888_reverse_dst_byteswap(int width, int height,
331 const void* srcbits, int srclinebytes,
332 void* dstbits, int dstlinebytes)
334 const WORD* srcpixel;
335 DWORD* dstpixel;
336 int x,y;
338 for (y=0; y<height; y++) {
339 srcpixel=srcbits;
340 dstpixel=dstbits;
341 for (x=0; x<width; x++) {
342 WORD srcval;
343 srcval=*srcpixel++;
344 *dstpixel++=((srcval << 17) & 0xf8000000) | /* h */
345 ((srcval << 12) & 0x07000000) | /* h - 3 bits */
346 ((srcval << 14) & 0x00f80000) | /* g */
347 ((srcval << 9) & 0x00070000) | /* g - 3 bits */
348 ((srcval << 11) & 0x0000f800) | /* l */
349 ((srcval << 6) & 0x00000700); /* l - 3 bits */
351 srcbits = (const char*)srcbits + srclinebytes;
352 dstbits = (char*)dstbits + dstlinebytes;
356 static void convert_5x5_to_any0888_dst_byteswap(int width, int height,
357 const void* srcbits, int srclinebytes,
358 WORD rsrc, WORD gsrc, WORD bsrc,
359 void* dstbits, int dstlinebytes,
360 DWORD rdst, DWORD gdst, DWORD bdst)
362 int rRightShift1,gRightShift1,bRightShift1;
363 int rRightShift2,gRightShift2,bRightShift2;
364 BYTE gMask1,gMask2;
365 int rLeftShift,gLeftShift,bLeftShift;
366 const WORD* srcpixel;
367 DWORD* dstpixel;
368 int x,y;
370 /* Note, the source pixel value is shifted left by 16 bits so that
371 * we know we will always have to shift right to extract the components.
373 rRightShift1=16+X11DRV_DIB_MaskToShift(rsrc)-3;
374 gRightShift1=16+X11DRV_DIB_MaskToShift(gsrc)-3;
375 bRightShift1=16+X11DRV_DIB_MaskToShift(bsrc)-3;
376 rRightShift2=rRightShift1+5;
377 gRightShift2=gRightShift1+5;
378 bRightShift2=bRightShift1+5;
379 if (gsrc==0x03e0) {
380 /* Green has 5 bits, like the others */
381 gMask1=0xf8;
382 gMask2=0x07;
383 } else {
384 /* Green has 6 bits, not 5. Compensate. */
385 gRightShift1++;
386 gRightShift2+=2;
387 gMask1=0xfc;
388 gMask2=0x03;
391 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
392 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
393 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
395 for (y=0; y<height; y++) {
396 srcpixel=srcbits;
397 dstpixel=dstbits;
398 for (x=0; x<width; x++) {
399 DWORD srcval;
400 BYTE red,green,blue;
401 srcval=*srcpixel++ << 16;
402 red= ((srcval >> rRightShift1) & 0xf8) |
403 ((srcval >> rRightShift2) & 0x07);
404 green=((srcval >> gRightShift1) & gMask1) |
405 ((srcval >> gRightShift2) & gMask2);
406 blue= ((srcval >> bRightShift1) & 0xf8) |
407 ((srcval >> bRightShift2) & 0x07);
408 *dstpixel =(red << rLeftShift) |
409 (green << gLeftShift) |
410 (blue << bLeftShift);
411 FLIP_DWORD(dstpixel);
412 dstpixel++;
414 srcbits = (const char*)srcbits + srclinebytes;
415 dstbits = (char*)dstbits + dstlinebytes;
420 * 16 bits conversions
423 static void convert_565_reverse_dst_byteswap(int width, int height,
424 const void* srcbits, int srclinebytes,
425 void* dstbits, int dstlinebytes)
427 const DWORD* srcpixel;
428 DWORD* dstpixel;
429 int x,y;
431 for (y=0; y<height; y++) {
432 srcpixel=srcbits;
433 dstpixel=dstbits;
434 for (x=0; x<width/2; x++) {
435 /* Do 2 pixels at a time */
436 DWORD srcval;
437 srcval=*srcpixel++;
438 *dstpixel++=((srcval >> 3) & 0x1f001f00) | /* h */
439 ((srcval >> 8) & 0x00070007) | /* g - 3 bits */
440 ((srcval << 8) & 0xe000e000) | /* g - 3 bits */
441 ((srcval << 3) & 0x00f800f8); /* l */
443 if (width&1) {
444 /* And the the odd pixel */
445 WORD srcval;
446 srcval=*((const WORD*)srcpixel);
447 *((WORD*)dstpixel)=((srcval >> 3) & 0x1f00) | /* h */
448 ((srcval >> 8) & 0x0007) | /* g - 3 bits */
449 ((srcval << 8) & 0xe000) | /* g - 3 bits */
450 ((srcval << 3) & 0x00f8); /* l */
452 srcbits = (const char*)srcbits + srclinebytes;
453 dstbits = (char*)dstbits + dstlinebytes;
457 static void convert_565_to_555_asis_dst_byteswap(int width, int height,
458 const void* srcbits, int srclinebytes,
459 void* dstbits, int dstlinebytes)
461 const DWORD* srcpixel;
462 DWORD* dstpixel;
463 int x,y;
465 for (y=0; y<height; y++) {
466 srcpixel=srcbits;
467 dstpixel=dstbits;
468 for (x=0; x<width/2; x++) {
469 /* Do 2 pixels at a time */
470 DWORD srcval;
471 srcval=*srcpixel++;
472 *dstpixel++=((srcval << 7) & 0xe000e000) | /* g - 3 bits */
473 ((srcval << 8) & 0x1f001f00) | /* l */
474 ((srcval >> 9) & 0x007f007f); /* h, g - 2 bits */
476 if (width&1) {
477 /* And the the odd pixel */
478 WORD srcval;
479 srcval=*((const WORD*)srcpixel);
480 *((WORD*)dstpixel)=((srcval << 7) & 0xe000) | /* g - 3 bits*/
481 ((srcval << 8) & 0x1f00) | /* l */
482 ((srcval >> 9) & 0x007f); /* h, g - 2 bits */
484 srcbits = (const char*)srcbits + srclinebytes;
485 dstbits = (char*)dstbits + dstlinebytes;
489 static void convert_565_to_555_reverse_dst_byteswap(int width, int height,
490 const void* srcbits, int srclinebytes,
491 void* dstbits, int dstlinebytes)
493 const DWORD* srcpixel;
494 DWORD* dstpixel;
495 int x,y;
497 for (y=0; y<height; y++) {
498 srcpixel=srcbits;
499 dstpixel=dstbits;
500 for (x=0; x<width/2; x++) {
501 /* Do 2 pixels at a time */
502 DWORD srcval;
503 srcval=*srcpixel++;
504 *dstpixel++=((srcval << 7) & 0xe000e000) | /* g - 3 bits */
505 ((srcval >> 3) & 0x1f001f00) | /* l */
506 ((srcval << 2) & 0x007c007c) | /* h */
507 ((srcval >> 9) & 0x00030003); /* g - 2 bits */
509 if (width&1) {
510 /* And the the odd pixel */
511 WORD srcval;
512 srcval=*((const WORD*)srcpixel);
513 *((WORD*)dstpixel)=((srcval << 7) & 0xe000) | /* g - 3 bits */
514 ((srcval >> 3) & 0x1f00) | /* l */
515 ((srcval << 2) & 0x007c) | /* h */
516 ((srcval >> 9) & 0x0003); /* g - 2 bits */
518 srcbits = (const char*)srcbits + srclinebytes;
519 dstbits = (char*)dstbits + dstlinebytes;
523 static void convert_565_to_888_asis_dst_byteswap(int width, int height,
524 const void* srcbits, int srclinebytes,
525 void* dstbits, int dstlinebytes)
527 const WORD* srcpixel;
528 DWORD* dstpixel;
529 int x,y;
531 for (y=0; y<height; y++) {
532 srcpixel=srcbits;
533 dstpixel=dstbits;
534 for (x=0; x<width/4; x++) {
535 /* Do 4 pixels at a time. 4 words in 3 dwords out */
536 DWORD srcval1, srcval2;
537 srcval1=(DWORD)*srcpixel++;
538 srcval2=(DWORD)*srcpixel++;
539 *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l1 */
540 ((srcval1 << 22) & 0x07000000) | /* l1 - 3 bits */
541 ((srcval1 << 13) & 0x00fc0000) | /* g1 */
542 ((srcval1 << 7) & 0x00030000) | /* g1 - 2 bits */
543 ((srcval1 << 0) & 0x0000f800) | /* h1 */
544 ((srcval1 >> 5) & 0x00070000) | /* h1 - 3 bits */
545 ((srcval2 << 3) & 0x000000f8) | /* l2 */
546 ((srcval2 >> 2) & 0x00000007); /* l2 - 3 bits */
547 srcval1=(DWORD)*srcpixel++;
548 *dstpixel++= ((srcval2 << 21) & 0xfc000000) | /* g2 */
549 ((srcval2 << 15) & 0x03000000) | /* g2 - 2 bits */
550 ((srcval2 << 8) & 0x00f80000) | /* h2 */
551 ((srcval2 << 3) & 0x00070000) | /* h2 - 3 bits */
552 ((srcval1 << 11) & 0x0000f800) | /* l3 */
553 ((srcval1 << 6) & 0x00000700) | /* l3 - 3 bits */
554 ((srcval1 >> 3) & 0x000000fc) | /* g3 */
555 ((srcval1 >> 9) & 0x00000003); /* g3 - 2 bits */
556 srcval2=(DWORD)*srcpixel++;
557 *dstpixel++= ((srcval1 << 16) & 0xf8000000) | /* h3 */
558 ((srcval1 << 11) & 0x07000000) | /* h3 - 3 bits */
559 ((srcval2 << 19) & 0x00f80000) | /* l4 */
560 ((srcval2 << 14) & 0x00070000) | /* l4 - 3 bits */
561 ((srcval2 << 5) & 0x0000fc00) | /* g4 */
562 ((srcval2 >> 1) & 0x00000300) | /* g4 - 2 bits */
563 ((srcval2 >> 8) & 0x000000f8) | /* h4 */
564 ((srcval2 >> 13) & 0x00000007); /* h4 - 3 bits */
566 if(width&3) {
567 BYTE *dstbyte = (BYTE*)dstpixel;
568 DWORD srcval;
569 for(x = 0; x < (width&3); x++) {
570 srcval = *srcpixel++;
571 dstbyte[0] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07);
572 dstbyte[1] = ((srcval >> 3) & 0xfc) | ((srcval >> 9) & 0x03);
573 dstbyte[2] = ((srcval >> 8) & 0xf8) | ((srcval >> 13) & 0x07);
574 dstbyte+=3;
575 if(x > 0)
576 FLIP_DWORD(dstpixel + x - 1);
578 FLIP_DWORD(dstpixel + x - 1);
581 srcbits = (const char*)srcbits + srclinebytes;
582 dstbits = (char*)dstbits + dstlinebytes;
586 static void convert_565_to_888_reverse_dst_byteswap(int width, int height,
587 const void* srcbits, int srclinebytes,
588 void* dstbits, int dstlinebytes)
590 const WORD* srcpixel;
591 DWORD* dstpixel;
592 int x,y;
594 for (y=0; y<height; y++) {
595 srcpixel=srcbits;
596 dstpixel=dstbits;
597 for (x=0; x<width/4; x++) {
598 /* Do 4 pixels at a time. 4 words in 3 dwords out */
599 DWORD srcval1, srcval2;
600 srcval1=(DWORD)*srcpixel++;
601 srcval2=(DWORD)*srcpixel++;
602 *dstpixel++= ((srcval1 << 16) & 0xf8000000) | /* h1 */
603 ((srcval1 << 11) & 0x07000000) | /* h1 - 3 bits */
604 ((srcval1 << 13) & 0x00fc0000) | /* g1 */
605 ((srcval1 << 7) & 0x00030000) | /* g1 - 2 bits */
606 ((srcval1 << 11) & 0x0000f800) | /* l1 */
607 ((srcval1 << 6) & 0x00070000) | /* l1 - 3 bits */
608 ((srcval2 >> 8) & 0x000000f8) | /* h2 */
609 ((srcval2 >> 13) & 0x00000007); /* h2 - 3 bits */
610 srcval1=(DWORD)*srcpixel++;
611 *dstpixel++= ((srcval2 << 21) & 0xfc000000) | /* g2 */
612 ((srcval2 << 15) & 0x03000000) | /* g2 - 2 bits */
613 ((srcval2 << 19) & 0x00f80000) | /* l2 */
614 ((srcval2 << 14) & 0x00070000) | /* l2 - 3 bits */
615 ((srcval1 << 0) & 0x0000f800) | /* h3 */
616 ((srcval1 >> 5) & 0x00000700) | /* h3 - 3 bits */
617 ((srcval1 >> 3) & 0x000000fc) | /* g3 */
618 ((srcval1 >> 9) & 0x00000003); /* g3 - 2 bits */
619 srcval2=(DWORD)*srcpixel++;
620 *dstpixel++= ((srcval1 << 27) & 0xf8000000) | /* l3 */
621 ((srcval1 << 22) & 0x07000000) | /* l3 - 3 bits */
622 ((srcval2 << 8) & 0x00f80000) | /* h4 */
623 ((srcval2 << 3) & 0x00070000) | /* h4 - 3 bits */
624 ((srcval2 << 5) & 0x0000fc00) | /* g4 */
625 ((srcval2 >> 1) & 0x00000700) | /* g4 - 2 bits */
626 ((srcval2 << 3) & 0x000000f8) | /* l4 */
627 ((srcval2 >> 2) & 0x00000007); /* l4 - 3 bits */
629 if(width&3) {
630 BYTE *dstbyte = (BYTE*)dstpixel;
631 DWORD srcval;
632 for(x = 0; x < (width&3); x++) {
633 srcval = *srcpixel++;
634 dstbyte[2] = ((srcval << 3) & 0xf8) | ((srcval >> 2) & 0x07);
635 dstbyte[1] = ((srcval >> 3) & 0xfc) | ((srcval >> 9) & 0x03);
636 dstbyte[0] = ((srcval >> 8) & 0xf8) | ((srcval >> 13) & 0x07);
637 dstbyte+=3;
638 if(x > 0)
639 FLIP_DWORD(dstpixel + x - 1);
641 FLIP_DWORD(dstpixel + x - 1);
643 srcbits = (const char*)srcbits + srclinebytes;
644 dstbits = (char*)dstbits + dstlinebytes;
648 static void convert_565_to_0888_asis_dst_byteswap(int width, int height,
649 const void* srcbits, int srclinebytes,
650 void* dstbits, int dstlinebytes)
652 const WORD* srcpixel;
653 DWORD* dstpixel;
654 int x,y;
656 for (y=0; y<height; y++) {
657 srcpixel=srcbits;
658 dstpixel=dstbits;
659 for (x=0; x<width; x++) {
660 WORD srcval;
661 srcval=*srcpixel++;
662 *dstpixel++=((srcval << 0) & 0x0000f800) | /* h */
663 ((srcval >> 5) & 0x00000700) | /* h - 3 bits */
664 ((srcval << 13) & 0x00fc0000) | /* g */
665 ((srcval << 7) & 0x00030000) | /* g - 2 bits */
666 ((srcval << 27) & 0xf8000000) | /* l */
667 ((srcval << 22) & 0x07000000); /* l - 3 bits */
669 srcbits = (const char*)srcbits + srclinebytes;
670 dstbits = (char*)dstbits + dstlinebytes;
674 static void convert_565_to_0888_reverse_dst_byteswap(int width, int height,
675 const void* srcbits, int srclinebytes,
676 void* dstbits, int dstlinebytes)
678 const WORD* srcpixel;
679 DWORD* dstpixel;
680 int x,y;
682 for (y=0; y<height; y++) {
683 srcpixel=srcbits;
684 dstpixel=dstbits;
685 for (x=0; x<width; x++) {
686 WORD srcval;
687 srcval=*srcpixel++;
688 *dstpixel++=((srcval << 16) & 0xf8000000) | /* h */
689 ((srcval << 11) & 0x07000000) | /* h - 3 bits */
690 ((srcval << 13) & 0x00fc0000) | /* g */
691 ((srcval << 7) & 0x00030000) | /* g - 2 bits */
692 ((srcval << 11) & 0x0000f800) | /* l */
693 ((srcval << 6) & 0x00000700); /* l - 3 bits */
695 srcbits = (const char*)srcbits + srclinebytes;
696 dstbits = (char*)dstbits + dstlinebytes;
701 * 24 bit conversions
704 static void convert_888_asis_dst_byteswap(int width, int height,
705 const void* srcbits, int srclinebytes,
706 void* dstbits, int dstlinebytes)
708 int x, y;
710 for (y=0; y<height; y++) {
711 for(x = 0; x < ((width+1)*3/4); x++) {
712 DWORD srcval = *((const DWORD*)srcbits + x);
713 *((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
714 ((srcval << 8) & 0x00ff0000) |
715 ((srcval >> 8) & 0x0000ff00) |
716 ((srcval >> 24) & 0x000000ff);
718 srcbits = (const char*)srcbits + srclinebytes;
719 dstbits = (char*)dstbits + dstlinebytes;
723 static void convert_888_reverse_dst_byteswap(int width, int height,
724 const void* srcbits, int srclinebytes,
725 void* dstbits, int dstlinebytes)
727 const DWORD* srcpixel;
728 DWORD* dstpixel;
729 int x,y;
731 for (y=0; y<height; y++) {
732 srcpixel=srcbits;
733 dstpixel=dstbits;
734 for (x=0; x<width/4; x++) {
735 /* Do 4 pixels at a time. 3 dwords in 3 dwords out */
736 *dstpixel++=((srcpixel[0] << 8) & 0xffffff00) | /* h1, g1, l1 */
737 ((srcpixel[1] >> 8) & 0x000000ff); /* h2 */
738 *dstpixel++=((srcpixel[1] << 24) & 0xff000000) | /* g2 */
739 ((srcpixel[0] >> 8) & 0x00ff0000) | /* l2 */
740 ((srcpixel[2] << 8) & 0x0000ff00) | /* h3 */
741 ((srcpixel[0] >> 24) & 0x000000ff); /* g3 */
742 *dstpixel++=((srcpixel[1] << 8) & 0xff000000) | /* l3 */
743 ((srcpixel[2] >> 8) & 0x00ffffff); /* h4, g4, l4 */
744 srcpixel+=3;
746 if(width&3) {
747 BYTE *dstbyte = (BYTE*)dstpixel;
748 const BYTE *srcbyte = (const BYTE*)srcpixel;
749 for(x = 0; x < (width&3); x++) {
750 dstbyte[2] = srcbyte[0];
751 dstbyte[1] = srcbyte[1];
752 dstbyte[0] = srcbyte[2];
753 dstbyte+=3;
754 srcbyte+=3;
755 if(x > 0)
756 FLIP_DWORD(dstpixel + x - 1);
758 FLIP_DWORD(dstpixel + x - 1);
760 srcbits = (const char*)srcbits + srclinebytes;
761 dstbits = (char*)dstbits + dstlinebytes;
765 static void convert_888_to_555_asis_dst_byteswap(int width, int height,
766 const void* srcbits, int srclinebytes,
767 void* dstbits, int dstlinebytes)
769 const DWORD* srcpixel;
770 const BYTE* srcbyte;
771 WORD* dstpixel;
772 int x,y;
773 int oddwidth;
775 oddwidth=width & 3;
776 width=width/4;
777 for (y=0; y<height; y++) {
778 srcpixel=srcbits;
779 dstpixel=dstbits;
780 for (x=0; x<width; x++) {
781 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
782 DWORD srcval1,srcval2;
783 srcval1=srcpixel[0];
784 dstpixel[0]=((srcval1 << 5) & 0x1f00) | /* l1 */
785 ((srcval1 >> 14) & 0x0003) | /* g1 - 2 bits */
786 ((srcval1 << 2) & 0xe000) | /* g1 - 3 bits */
787 ((srcval1 >> 17) & 0x007c); /* h1 */
788 srcval2=srcpixel[1];
789 dstpixel[1]=((srcval1 >> 19) & 0x1f00) | /* l2 */
790 ((srcval2 >> 6) & 0x0003) | /* g2 - 2 bits */
791 ((srcval2 << 10) & 0xe000) | /* g2 - 3 bits */
792 ((srcval2 >> 9) & 0x007c); /* h2 */
793 srcval1=srcpixel[2];
794 dstpixel[2]=((srcval2 >> 11) & 0x1f00) | /* l3 */
795 ((srcval2 >> 30) & 0x0003) | /* g3 - 2 bits */
796 ((srcval2 >> 14) & 0xe000) | /* g3 - 3 bits */
797 ((srcval1 >> 1) & 0x007c); /* h3 */
798 dstpixel[3]=((srcval1 >> 3) & 0x1f00) | /* l4 */
799 ((srcval1 >> 22) & 0x0003) | /* g4 - 2 bits */
800 ((srcval1 >> 6) & 0xe000) | /* g4 - 3 bits */
801 ((srcval1 >> 17) & 0x007c); /* h4 */
802 srcpixel+=3;
803 dstpixel+=4;
805 /* And now up to 3 odd pixels */
806 srcbyte=(const BYTE*)srcpixel;
807 for (x=0; x<oddwidth; x++) {
808 WORD dstval;
809 dstval =((srcbyte[0] << 5) & 0x1f00); /* l */
810 dstval|=((srcbyte[1] >> 6) & 0x0003); /* g - 2 bits */
811 dstval|=((srcbyte[1] << 10) & 0xe000); /* g - 3 bits */
812 dstval|=((srcbyte[2] >> 1) & 0x007c); /* h */
813 *dstpixel++=dstval;
814 srcbyte+=3;
816 srcbits = (const char*)srcbits + srclinebytes;
817 dstbits = (char*)dstbits + dstlinebytes;
821 static void convert_888_to_555_reverse_dst_byteswap(int width, int height,
822 const void* srcbits, int srclinebytes,
823 void* dstbits, int dstlinebytes)
825 const DWORD* srcpixel;
826 const BYTE* srcbyte;
827 WORD* dstpixel;
828 int x,y;
829 int oddwidth;
831 oddwidth=width & 3;
832 width=width/4;
833 for (y=0; y<height; y++) {
834 srcpixel=srcbits;
835 dstpixel=dstbits;
836 for (x=0; x<width; x++) {
837 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
838 DWORD srcval1,srcval2;
839 srcval1=srcpixel[0];
840 dstpixel[0]=((srcval1 >> 1) & 0x007c) | /* l1 */
841 ((srcval1 >> 14) & 0x0003) | /* g1 - 2 bits */
842 ((srcval1 << 2) & 0xe000) | /* g1 - 3 bits */
843 ((srcval1 >> 11) & 0x1f00); /* h1 */
844 srcval2=srcpixel[1];
845 dstpixel[1]=((srcval1 >> 25) & 0x007c) | /* l2 */
846 ((srcval2 >> 6) & 0x0003) | /* g2 - 2 bits */
847 ((srcval2 << 10) & 0xe000) | /* g2 - 3 bits */
848 ((srcval2 >> 3) & 0x1f00); /* h2 */
849 srcval1=srcpixel[2];
850 dstpixel[2]=((srcval2 >> 17) & 0x007c) | /* l3 */
851 ((srcval2 >> 30) & 0x0003) | /* g3 - 2 bits */
852 ((srcval2 >> 14) & 0xe000) | /* g3 - 3 bits */
853 ((srcval1 << 5) & 0x1f00); /* h3 */
854 dstpixel[3]=((srcval1 >> 9) & 0x007c) | /* l4 */
855 ((srcval1 >> 22) & 0x0003) | /* g4 - 2 bits */
856 ((srcval1 >> 6) & 0xe000) | /* g4 - 3 bits */
857 ((srcval1 >> 19) & 0x1f00); /* h4 */
858 srcpixel+=3;
859 dstpixel+=4;
861 /* And now up to 3 odd pixels */
862 srcbyte=(const BYTE*)srcpixel;
863 for (x=0; x<oddwidth; x++) {
864 WORD dstval;
865 dstval =((srcbyte[0] >> 1) & 0x007c); /* l */
866 dstval|=((srcbyte[1] >> 6) & 0x0003); /* g - 2 bits */
867 dstval|=((srcbyte[1] << 10) & 0xe000); /* g - 3 bits */
868 dstval|=((srcbyte[2] << 5) & 0x1f00); /* h */
869 FLIP_WORD(&dstval);
870 *dstpixel++=dstval;
871 srcbyte+=3;
873 srcbits = (const char*)srcbits + srclinebytes;
874 dstbits = (char*)dstbits + dstlinebytes;
878 static void convert_888_to_565_asis_dst_byteswap(int width, int height,
879 const void* srcbits, int srclinebytes,
880 void* dstbits, int dstlinebytes)
882 const DWORD* srcpixel;
883 const BYTE* srcbyte;
884 WORD* dstpixel;
885 int x,y;
886 int oddwidth;
888 oddwidth=width & 3;
889 width=width/4;
890 for (y=0; y<height; y++) {
891 srcpixel=srcbits;
892 dstpixel=dstbits;
893 for (x=0; x<width; x++) {
894 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
895 DWORD srcval1,srcval2;
896 srcval1=srcpixel[0];
897 dstpixel[0]=((srcval1 << 5) & 0x1f00) | /* l1 */
898 ((srcval1 >> 13) & 0x0007) | /* g1 - 3 bits */
899 ((srcval1 << 3) & 0xe000) | /* g1 - 3 bits */
900 ((srcval1 >> 16) & 0x00f8); /* h1 */
901 srcval2=srcpixel[1];
902 dstpixel[1]=((srcval1 >> 19) & 0x1f00) | /* l2 */
903 ((srcval2 >> 5) & 0x0007) | /* g2 - 3 bits */
904 ((srcval2 << 11) & 0xe000) | /* g2 - 3 bits */
905 ((srcval2 >> 8) & 0x00f8); /* h2 */
906 srcval1=srcpixel[2];
907 dstpixel[2]=((srcval2 >> 11) & 0x1f00) | /* l3 */
908 ((srcval2 >> 29) & 0x0007) | /* g3 - 3 bits */
909 ((srcval2 >> 13) & 0xe000) | /* g3 - 3 bits */
910 ((srcval1 << 0) & 0x00f8); /* h3 */
911 dstpixel[3]=((srcval1 >> 3) & 0x1f00) | /* l4 */
912 ((srcval1 >> 21) & 0x0007) | /* g4 - 3 bits */
913 ((srcval1 >> 5) & 0xe000) | /* g4 - 3 bits */
914 ((srcval1 >> 24) & 0x00f8); /* h4 */
915 srcpixel+=3;
916 dstpixel+=4;
918 /* And now up to 3 odd pixels */
919 srcbyte=(const BYTE*)srcpixel;
920 for (x=0; x<oddwidth; x++) {
921 WORD dstval;
922 dstval =((srcbyte[0] << 5) & 0x1f00); /* l */
923 dstval|=((srcbyte[1] >> 5) & 0x0007); /* g - 3 bits */
924 dstval|=((srcbyte[1] << 11) & 0xe000); /* g - 3 bits */
925 dstval|=((srcbyte[2] << 0) & 0x00f8); /* h */
926 *dstpixel++=dstval;
927 srcbyte+=3;
929 srcbits = (const char*)srcbits + srclinebytes;
930 dstbits = (char*)dstbits + dstlinebytes;
934 static void convert_888_to_565_reverse_dst_byteswap(int width, int height,
935 const void* srcbits, int srclinebytes,
936 void* dstbits, int dstlinebytes)
938 const DWORD* srcpixel;
939 const BYTE* srcbyte;
940 WORD* dstpixel;
941 int x,y;
942 int oddwidth;
944 oddwidth=width & 3;
945 width=width/4;
946 for (y=0; y<height; y++) {
947 srcpixel=srcbits;
948 dstpixel=dstbits;
949 for (x=0; x<width; x++) {
950 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
951 DWORD srcval1,srcval2;
952 srcval1=srcpixel[0];
953 dstpixel[0]=((srcval1 >> 0) & 0x00f8) | /* l1 */
954 ((srcval1 >> 13) & 0x0007) | /* g1 - 3 bits */
955 ((srcval1 << 3) & 0xe000) | /* g1 - 3 bits */
956 ((srcval1 >> 11) & 0x1f00); /* h1 */
957 srcval2=srcpixel[1];
958 dstpixel[1]=((srcval1 >> 24) & 0x00f8) | /* l2 */
959 ((srcval2 >> 5) & 0x0007) | /* g2 - 3 bits */
960 ((srcval2 << 11) & 0xe000) | /* g2 - 3 bits */
961 ((srcval2 >> 3) & 0x1f00); /* h2 */
962 srcval1=srcpixel[2];
963 dstpixel[2]=((srcval2 >> 16) & 0x00f8) | /* l3 */
964 ((srcval2 >> 29) & 0x0007) | /* g3 - 3 bits */
965 ((srcval2 >> 13) & 0xe000) | /* g3 - 3 bits */
966 ((srcval1 << 5) & 0x1f00); /* h3 */
967 dstpixel[3]=((srcval1 >> 8) & 0x00f8) | /* l4 */
968 ((srcval1 >> 21) & 0x0007) | /* g4 - 3 bits */
969 ((srcval1 >> 5) & 0xe000) | /* g4 - 3 bits */
970 ((srcval1 >> 19) & 0x1f00); /* h4 */
971 srcpixel+=3;
972 dstpixel+=4;
974 /* And now up to 3 odd pixels */
975 srcbyte=(const BYTE*)srcpixel;
976 for (x=0; x<oddwidth; x++) {
977 WORD dstval;
978 dstval =((srcbyte[0] << 0) & 0x00f8); /* l */
979 dstval|=((srcbyte[1] >> 5) & 0x0007); /* g - 3 bits */
980 dstval|=((srcbyte[1] << 11) & 0xe000); /* g - 3 bits */
981 dstval|=((srcbyte[2] << 5) & 0x1f00); /* h */
982 *dstpixel++=dstval;
983 srcbyte+=3;
985 srcbits = (const char*)srcbits + srclinebytes;
986 dstbits = (char*)dstbits + dstlinebytes;
990 static void convert_888_to_0888_asis_dst_byteswap(int width, int height,
991 const void* srcbits, int srclinebytes,
992 void* dstbits, int dstlinebytes)
994 const DWORD* srcpixel;
995 DWORD* dstpixel;
996 int x,y;
997 int oddwidth;
999 oddwidth=width & 3;
1000 width=width/4;
1001 for (y=0; y<height; y++) {
1002 srcpixel=srcbits;
1003 dstpixel=dstbits;
1004 for (x=0; x<width; x++) {
1005 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
1006 DWORD srcval1,srcval2;
1007 srcval1=*srcpixel++;
1008 *dstpixel++=((srcval1 << 24) & 0xff000000) | /* l1 */
1009 ((srcval1 << 8) & 0x00ff0000) | /* g1 */
1010 ((srcval1 >> 8) & 0x0000ff00); /* h1 */
1011 srcval2=*srcpixel++;
1012 *dstpixel++=((srcval1 << 0) & 0xff000000) | /* l2 */
1013 ((srcval2 << 16) & 0x00ff0000) | /* g2 */
1014 ((srcval2 << 0) & 0x0000ff00); /* h2 */
1015 srcval1=*srcpixel++;
1016 *dstpixel++=((srcval2 << 8) & 0xff000000) | /* l3 */
1017 ((srcval2 >> 8) & 0x00ff0000) | /* g3 */
1018 ((srcval1 << 8) & 0x0000ff00); /* h3 */
1019 *dstpixel++=((srcval1 << 16) & 0xff000000) | /* l4 */
1020 ((srcval1 << 0) & 0x00ff0000) | /* g4 */
1021 ((srcval1 >> 16) & 0x0000ff00); /* h4 */
1023 /* And now up to 3 odd pixels */
1024 for (x=0; x<oddwidth; x++) {
1025 DWORD srcval;
1026 srcval=*srcpixel;
1027 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
1028 *dstpixel++=((srcval << 24) & 0xff000000) | /* l */
1029 ((srcval << 8) & 0x00ff0000) | /* g */
1030 ((srcval >> 8) & 0x0000ff00); /* h */
1032 srcbits = (const char*)srcbits + srclinebytes;
1033 dstbits = (char*)dstbits + dstlinebytes;
1037 static void convert_888_to_0888_reverse_dst_byteswap(int width, int height,
1038 const void* srcbits, int srclinebytes,
1039 void* dstbits, int dstlinebytes)
1041 const DWORD* srcpixel;
1042 DWORD* dstpixel;
1043 int x,y;
1044 int oddwidth;
1046 oddwidth=width & 3;
1047 width=width/4;
1048 for (y=0; y<height; y++) {
1049 srcpixel=srcbits;
1050 dstpixel=dstbits;
1051 for (x=0; x<width; x++) {
1052 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
1053 DWORD srcval1,srcval2;
1055 srcval1=*srcpixel++;
1056 *dstpixel++=((srcval1 << 8) & 0xffffff00); /* h1, g1, l1 */
1057 srcval2=*srcpixel++;
1058 *dstpixel++=((srcval2 << 16) & 0xffff0000) | /* h2, g2 */
1059 ((srcval1 >> 16) & 0x0000ff00); /* l2 */
1060 srcval1=*srcpixel++;
1061 *dstpixel++=((srcval1 << 24) & 0xff000000) | /* h3 */
1062 ((srcval2 >> 8) & 0x00ffff00); /* g3, l3 */
1063 *dstpixel++=((srcval1 >> 0) & 0xffffff00); /* h4, g4, l4 */
1065 /* And now up to 3 odd pixels */
1066 for (x=0; x<oddwidth; x++) {
1067 DWORD srcval;
1068 srcval=*srcpixel;
1069 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
1070 *dstpixel++=((srcval << 8) & 0xffffff00);
1072 srcbits = (const char*)srcbits + srclinebytes;
1073 dstbits = (char*)dstbits + dstlinebytes;
1077 static void convert_rgb888_to_any0888_dst_byteswap(int width, int height,
1078 const void* srcbits, int srclinebytes,
1079 void* dstbits, int dstlinebytes,
1080 DWORD rdst, DWORD gdst, DWORD bdst)
1082 int rLeftShift,gLeftShift,bLeftShift;
1083 const BYTE* srcpixel;
1084 DWORD* dstpixel;
1085 int x,y;
1087 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1088 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1089 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1090 for (y=0; y<height; y++) {
1091 srcpixel=srcbits;
1092 dstpixel=dstbits;
1093 for (x=0; x<width; x++) {
1094 *dstpixel =(srcpixel[0] << bLeftShift) | /* b */
1095 (srcpixel[1] << gLeftShift) | /* g */
1096 (srcpixel[2] << rLeftShift); /* r */
1097 FLIP_DWORD(dstpixel);
1098 dstpixel++;
1099 srcpixel+=3;
1101 srcbits = (const char*)srcbits + srclinebytes;
1102 dstbits = (char*)dstbits + dstlinebytes;
1106 static void convert_bgr888_to_any0888_dst_byteswap(int width, int height,
1107 const void* srcbits, int srclinebytes,
1108 void* dstbits, int dstlinebytes,
1109 DWORD rdst, DWORD gdst, DWORD bdst)
1111 int rLeftShift,gLeftShift,bLeftShift;
1112 const BYTE* srcpixel;
1113 DWORD* dstpixel;
1114 int x,y;
1116 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1117 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1118 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1119 for (y=0; y<height; y++) {
1120 srcpixel=srcbits;
1121 dstpixel=dstbits;
1122 for (x=0; x<width; x++) {
1123 *dstpixel =(srcpixel[0] << rLeftShift) | /* r */
1124 (srcpixel[1] << gLeftShift) | /* g */
1125 (srcpixel[2] << bLeftShift); /* b */
1126 FLIP_DWORD(dstpixel);
1127 dstpixel++;
1128 srcpixel+=3;
1130 srcbits = (const char*)srcbits + srclinebytes;
1131 dstbits = (char*)dstbits + dstlinebytes;
1136 * 32 bit conversions
1139 static void convert_0888_asis_dst_byteswap(int width, int height,
1140 const void* srcbits, int srclinebytes,
1141 void* dstbits, int dstlinebytes)
1143 int x, y;
1145 for (y=0; y<height; y++) {
1146 for(x = 0; x < width; x++) {
1147 DWORD srcval = *((const DWORD*)srcbits + x);
1148 *((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
1149 ((srcval << 8) & 0x00ff0000) |
1150 ((srcval >> 8) & 0x0000ff00) |
1151 ((srcval >> 24) & 0x000000ff);
1153 srcbits = (const char*)srcbits + srclinebytes;
1154 dstbits = (char*)dstbits + dstlinebytes;
1159 static void convert_0888_reverse_dst_byteswap(int width, int height,
1160 const void* srcbits, int srclinebytes,
1161 void* dstbits, int dstlinebytes)
1163 const DWORD* srcpixel;
1164 DWORD* dstpixel;
1165 int x,y;
1167 for (y=0; y<height; y++) {
1168 srcpixel=srcbits;
1169 dstpixel=dstbits;
1170 for (x=0; x<width; x++) {
1171 DWORD srcval;
1172 srcval=*srcpixel++;
1173 *dstpixel++=((srcval << 8) & 0xffffff00);
1175 srcbits = (const char*)srcbits + srclinebytes;
1176 dstbits = (char*)dstbits + dstlinebytes;
1180 static void convert_0888_any_dst_byteswap(int width, int height,
1181 const void* srcbits, int srclinebytes,
1182 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1183 void* dstbits, int dstlinebytes,
1184 DWORD rdst, DWORD gdst, DWORD bdst)
1186 int rRightShift,gRightShift,bRightShift;
1187 int rLeftShift,gLeftShift,bLeftShift;
1188 const DWORD* srcpixel;
1189 DWORD* dstpixel;
1190 int x,y;
1192 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1193 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1194 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1195 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1196 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1197 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1198 for (y=0; y<height; y++) {
1199 srcpixel=srcbits;
1200 dstpixel=dstbits;
1201 for (x=0; x<width; x++) {
1202 DWORD srcval;
1203 srcval=*srcpixel++;
1204 *dstpixel =(((srcval >> rRightShift) & 0xff) << rLeftShift) |
1205 (((srcval >> gRightShift) & 0xff) << gLeftShift) |
1206 (((srcval >> bRightShift) & 0xff) << bLeftShift);
1207 FLIP_DWORD(dstpixel);
1208 dstpixel++;
1210 srcbits = (const char*)srcbits + srclinebytes;
1211 dstbits = (char*)dstbits + dstlinebytes;
1215 static void convert_0888_to_555_asis_dst_byteswap(int width, int height,
1216 const void* srcbits, int srclinebytes,
1217 void* dstbits, int dstlinebytes)
1219 const DWORD* srcpixel;
1220 WORD* dstpixel;
1221 int x,y;
1223 for (y=0; y<height; y++) {
1224 srcpixel=srcbits;
1225 dstpixel=dstbits;
1226 for (x=0; x<width; x++) {
1227 DWORD srcval;
1228 srcval=*srcpixel++;
1229 *dstpixel =((srcval >> 17) & 0x007c) | /* h */
1230 ((srcval >> 14) & 0x0003) | /* g - 2 bits */
1231 ((srcval << 2) & 0xe000) | /* g - 3 bits */
1232 ((srcval << 5) & 0x1f00); /* l */
1233 dstpixel++;
1235 srcbits = (const char*)srcbits + srclinebytes;
1236 dstbits = (char*)dstbits + dstlinebytes;
1240 static void convert_0888_to_555_reverse_dst_byteswap(int width, int height,
1241 const void* srcbits, int srclinebytes,
1242 void* dstbits, int dstlinebytes)
1244 const DWORD* srcpixel;
1245 WORD* dstpixel;
1246 int x,y;
1248 for (y=0; y<height; y++) {
1249 srcpixel=srcbits;
1250 dstpixel=dstbits;
1251 for (x=0; x<width; x++) {
1252 DWORD srcval;
1253 srcval=*srcpixel++;
1254 *dstpixel =((srcval >> 11) & 0x1f00) | /* h */
1255 ((srcval >> 6) & 0x0003) | /* g - 2 bits */
1256 ((srcval << 2) & 0xe000) | /* g - 3 bits */
1257 ((srcval >> 1) & 0x7c00); /* l */
1258 dstpixel++;
1260 srcbits = (const char*)srcbits + srclinebytes;
1261 dstbits = (char*)dstbits + dstlinebytes;
1265 static void convert_0888_to_565_asis_dst_byteswap(int width, int height,
1266 const void* srcbits, int srclinebytes,
1267 void* dstbits, int dstlinebytes)
1269 const DWORD* srcpixel;
1270 WORD* dstpixel;
1271 int x,y;
1273 for (y=0; y<height; y++) {
1274 srcpixel=srcbits;
1275 dstpixel=dstbits;
1276 for (x=0; x<width; x++) {
1277 DWORD srcval;
1278 srcval=*srcpixel++;
1279 *dstpixel++=((srcval >> 16) & 0x00f8) | /* h */
1280 ((srcval >> 13) & 0x0007) | /* g - 3 bits */
1281 ((srcval << 3) & 0xe000) | /* g - 3 bits */
1282 ((srcval << 5) & 0x1f00); /* l */
1284 srcbits = (const char*)srcbits + srclinebytes;
1285 dstbits = (char*)dstbits + dstlinebytes;
1289 static void convert_0888_to_565_reverse_dst_byteswap(int width, int height,
1290 const void* srcbits, int srclinebytes,
1291 void* dstbits, int dstlinebytes)
1293 const DWORD* srcpixel;
1294 WORD* dstpixel;
1295 int x,y;
1297 for (y=0; y<height; y++) {
1298 srcpixel=srcbits;
1299 dstpixel=dstbits;
1300 for (x=0; x<width; x++) {
1301 DWORD srcval;
1302 srcval=*srcpixel++;
1303 *dstpixel++=((srcval >> 11) & 0x1f00) | /* h */
1304 ((srcval >> 13) & 0x0007) | /* g - 3 bits */
1305 ((srcval << 3) & 0xe000) | /* g - 3 bits */
1306 ((srcval << 0) & 0x00f8); /* l */
1308 srcbits = (const char*)srcbits + srclinebytes;
1309 dstbits = (char*)dstbits + dstlinebytes;
1313 static void convert_any0888_to_5x5_dst_byteswap(int width, int height,
1314 const void* srcbits, int srclinebytes,
1315 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1316 void* dstbits, int dstlinebytes,
1317 WORD rdst, WORD gdst, WORD bdst)
1319 int rRightShift,gRightShift,bRightShift;
1320 int rLeftShift,gLeftShift,bLeftShift;
1321 const DWORD* srcpixel;
1322 WORD* dstpixel;
1323 int x,y;
1325 /* Here is how we proceed. Assume we have rsrc=0x0000ff00 and our pixel
1326 * contains 0x11223344.
1327 * - first we shift 0x11223344 right by rRightShift to bring the most
1328 * significant bits of the red components in the bottom 5 (or 6) bits
1329 * -> 0x4488c
1330 * - then we remove non red bits by anding with the modified rdst (0x1f)
1331 * -> 0x0c
1332 * - finally shift these bits left by rLeftShift so that they end up in
1333 * the right place
1334 * -> 0x3000
1336 rRightShift=X11DRV_DIB_MaskToShift(rsrc)+3;
1337 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1338 gRightShift+=(gdst==0x07e0?2:3);
1339 bRightShift=X11DRV_DIB_MaskToShift(bsrc)+3;
1341 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1342 rdst=rdst >> rLeftShift;
1343 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1344 gdst=gdst >> gLeftShift;
1345 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1346 bdst=bdst >> bLeftShift;
1348 for (y=0; y<height; y++) {
1349 srcpixel=srcbits;
1350 dstpixel=dstbits;
1351 for (x=0; x<width; x++) {
1352 DWORD srcval;
1353 srcval=*srcpixel++;
1354 *dstpixel =(((srcval >> rRightShift) & rdst) << rLeftShift) |
1355 (((srcval >> gRightShift) & gdst) << gLeftShift) |
1356 (((srcval >> bRightShift) & bdst) << bLeftShift);
1357 FLIP_WORD(dstpixel);
1358 dstpixel++;
1360 srcbits = (const char*)srcbits + srclinebytes;
1361 dstbits = (char*)dstbits + dstlinebytes;
1365 static void convert_0888_to_888_asis_dst_byteswap(int width, int height,
1366 const void* srcbits, int srclinebytes,
1367 void* dstbits, int dstlinebytes)
1369 const DWORD* srcpixel;
1370 DWORD* dstpixel;
1371 int x,y;
1372 int oddwidth;
1374 oddwidth=width & 3;
1375 width=width/4;
1376 for (y=0; y<height; y++) {
1377 srcpixel=srcbits;
1378 dstpixel=dstbits;
1379 for (x=0; x<width; x++) {
1380 /* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
1381 DWORD srcval1, srcval2;
1382 srcval1=*srcpixel++;
1383 srcval2=*srcpixel++;
1384 *dstpixel++=((srcval1 << 24) & 0xff000000) | /* l1 */
1385 ((srcval1 << 8) & 0x00ff0000) | /* g1 */
1386 ((srcval1 >> 8) & 0x0000ff00) | /* h1 */
1387 ((srcval2 >> 0) & 0x000000ff); /* l2 */
1388 srcval1=*srcpixel++;
1389 *dstpixel++=((srcval2 << 16) & 0xff000000) | /* g2 */
1390 ((srcval2 << 0) & 0x00ff0000) | /* h2 */
1391 ((srcval1 << 8) & 0x0000ff00) | /* l3 */
1392 ((srcval1 >> 8) & 0x000000ff); /* g3 */
1393 srcval2=*srcpixel++;
1394 *dstpixel++=((srcval1 << 8) & 0xff000000) | /* h3 */
1395 ((srcval2 << 16) & 0x00ff0000) | /* l4 */
1396 ((srcval2 << 0) & 0x0000ff00) | /* g4 */
1397 ((srcval2 >> 16) & 0x000000ff); /* h4 */
1399 /* And now up to 3 odd pixels */
1400 if(width&3) {
1401 BYTE *dstbyte = (BYTE*)dstpixel;
1402 const BYTE *srcbyte = (const BYTE*)srcpixel;
1403 for(x = 0; x < (width&3); x++) {
1404 dstbyte[0] = srcbyte[0];
1405 dstbyte[1] = srcbyte[1];
1406 dstbyte[2] = srcbyte[2];
1407 dstbyte+=3;
1408 srcbyte+=4;
1409 if(x > 0)
1410 FLIP_DWORD(dstpixel + x - 1);
1412 FLIP_DWORD(dstpixel + x - 1);
1414 srcbits = (const char*)srcbits + srclinebytes;
1415 dstbits = (char*)dstbits + dstlinebytes;
1419 static void convert_0888_to_888_reverse_dst_byteswap(int width, int height,
1420 const void* srcbits, int srclinebytes,
1421 void* dstbits, int dstlinebytes)
1423 const DWORD* srcpixel;
1424 DWORD* dstpixel;
1425 int x,y;
1426 int oddwidth;
1428 oddwidth=width & 3;
1429 width=width/4;
1430 for (y=0; y<height; y++) {
1431 srcpixel=srcbits;
1432 dstpixel=dstbits;
1433 for (x=0; x<width; x++) {
1434 /* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
1435 DWORD srcval1,srcval2;
1436 srcval1=*srcpixel++;
1437 srcval2=*srcpixel++;
1438 *dstpixel++=((srcval1 << 8) & 0xffffff00) | /* h1, g1, l1 */
1439 ((srcval2 >> 16) & 0x000000ff); /* h2 */
1440 srcval1=*srcpixel++;
1441 *dstpixel++=((srcval2 << 16) & 0xffff0000) | /* g2, l2 */
1442 ((srcval1 >> 8) & 0x0000ffff); /* h3, g3 */
1443 srcval2=*srcpixel++;
1444 *dstpixel++=((srcval1 << 24) & 0xff000000) | /* l3 */
1445 ((srcval2 << 0) & 0x00ffffff); /* h4, g4, l4 */
1447 /* And now up to 3 odd pixels */
1448 if(width&3) {
1449 BYTE *dstbyte = (BYTE*)dstpixel;
1450 const BYTE *srcbyte = (const BYTE*)srcpixel;
1451 for(x = 0; x < (width&3); x++) {
1452 dstbyte[2] = srcbyte[0];
1453 dstbyte[1] = srcbyte[1];
1454 dstbyte[0] = srcbyte[2];
1455 dstbyte+=3;
1456 srcbyte+=4;
1457 if(x > 0)
1458 FLIP_DWORD(dstpixel + x - 1);
1460 FLIP_DWORD(dstpixel + x - 1);
1462 srcbits = (const char*)srcbits + srclinebytes;
1463 dstbits = (char*)dstbits + dstlinebytes;
1467 static void convert_any0888_to_rgb888_dst_byteswap(int width, int height,
1468 const void* srcbits, int srclinebytes,
1469 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1470 void* dstbits, int dstlinebytes)
1472 int rRightShift,gRightShift,bRightShift;
1473 const DWORD* srcpixel;
1474 BYTE* dstpixel;
1475 int x,y;
1477 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1478 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1479 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1480 for (y=0; y<height; y++) {
1481 srcpixel=srcbits;
1482 dstpixel=dstbits;
1483 for (x=0; x<width; x++) {
1484 DWORD srcval;
1485 srcval=*srcpixel++;
1486 dstpixel[0]=(srcval >> bRightShift); /* b */
1487 dstpixel[1]=(srcval >> gRightShift); /* g */
1488 dstpixel[2]=(srcval >> rRightShift); /* r */
1489 if(x&3)
1490 FLIP_DWORD((DWORD*)(dstpixel + x - 4));
1491 dstpixel+=3;
1493 if(x&3)
1494 FLIP_DWORD((DWORD*)(dstpixel + x - 4));
1496 srcbits = (const char*)srcbits + srclinebytes;
1497 dstbits = (char*)dstbits + dstlinebytes;
1501 static void convert_any0888_to_bgr888_dst_byteswap(int width, int height,
1502 const void* srcbits, int srclinebytes,
1503 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1504 void* dstbits, int dstlinebytes)
1506 int rRightShift,gRightShift,bRightShift;
1507 const DWORD* srcpixel;
1508 BYTE* dstpixel;
1509 int x,y;
1511 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1512 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1513 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1514 for (y=0; y<height; y++) {
1515 srcpixel=srcbits;
1516 dstpixel=dstbits;
1517 for (x=0; x<width; x++) {
1518 DWORD srcval;
1519 srcval=*srcpixel++;
1520 dstpixel[0]=(srcval >> rRightShift); /* r */
1521 dstpixel[1]=(srcval >> gRightShift); /* g */
1522 dstpixel[2]=(srcval >> bRightShift); /* b */
1523 if(x&3)
1524 FLIP_DWORD((DWORD*)(dstpixel + x - 4));
1525 dstpixel+=3;
1527 if(x&3)
1528 FLIP_DWORD((DWORD*)(dstpixel + x - 4));
1529 srcbits = (const char*)srcbits + srclinebytes;
1530 dstbits = (char*)dstbits + dstlinebytes;
1534 const dib_conversions dib_dst_byteswap = {
1535 convert_5x5_asis_dst_byteswap,
1536 convert_555_reverse_dst_byteswap,
1537 convert_555_to_565_asis_dst_byteswap,
1538 convert_555_to_565_reverse_dst_byteswap,
1539 convert_555_to_888_asis_dst_byteswap,
1540 convert_555_to_888_reverse_dst_byteswap,
1541 convert_555_to_0888_asis_dst_byteswap,
1542 convert_555_to_0888_reverse_dst_byteswap,
1543 convert_5x5_to_any0888_dst_byteswap,
1544 convert_565_reverse_dst_byteswap,
1545 convert_565_to_555_asis_dst_byteswap,
1546 convert_565_to_555_reverse_dst_byteswap,
1547 convert_565_to_888_asis_dst_byteswap,
1548 convert_565_to_888_reverse_dst_byteswap,
1549 convert_565_to_0888_asis_dst_byteswap,
1550 convert_565_to_0888_reverse_dst_byteswap,
1551 convert_888_asis_dst_byteswap,
1552 convert_888_reverse_dst_byteswap,
1553 convert_888_to_555_asis_dst_byteswap,
1554 convert_888_to_555_reverse_dst_byteswap,
1555 convert_888_to_565_asis_dst_byteswap,
1556 convert_888_to_565_reverse_dst_byteswap,
1557 convert_888_to_0888_asis_dst_byteswap,
1558 convert_888_to_0888_reverse_dst_byteswap,
1559 convert_rgb888_to_any0888_dst_byteswap,
1560 convert_bgr888_to_any0888_dst_byteswap,
1561 convert_0888_asis_dst_byteswap,
1562 convert_0888_reverse_dst_byteswap,
1563 convert_0888_any_dst_byteswap,
1564 convert_0888_to_555_asis_dst_byteswap,
1565 convert_0888_to_555_reverse_dst_byteswap,
1566 convert_0888_to_565_asis_dst_byteswap,
1567 convert_0888_to_565_reverse_dst_byteswap,
1568 convert_any0888_to_5x5_dst_byteswap,
1569 convert_0888_to_888_asis_dst_byteswap,
1570 convert_0888_to_888_reverse_dst_byteswap,
1571 convert_any0888_to_rgb888_dst_byteswap,
1572 convert_any0888_to_bgr888_dst_byteswap