2 * DIB conversion routines for cases where the source
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
30 #define FLIP_WORD(x) \
31 ( *(x) = ( (*(x) & 0xff) << 8) | \
32 ( (*(x) & 0xff00) >> 8) )
34 #define FLIP_TWO_WORDS(x) \
35 ( *(x) = ( (*(x) & 0x00ff00ff) << 8) | \
36 ( (*(x) & 0xff00ff00) >> 8) )
38 #define FLIP_DWORD(x) \
39 ( *(x) = ( (*(x) & 0xff) << 24) | \
40 ( (*(x) & 0xff00) << 8) | \
41 ( (*(x) & 0xff0000) >> 8) | \
42 ( (*(x) & 0xff000000) >> 24) )
50 static void convert_5x5_asis_src_byteswap(int width, int height,
51 const void* srcbits, int srclinebytes,
52 void* dstbits, int dstlinebytes)
55 const DWORD *srcpixel;
58 for (y=0; y<height; y++) {
61 for(x = 0; x < width/2; x++) {
62 /* Do 2 pixels at a time */
63 DWORD srcval = *srcpixel++;
64 *dstpixel++=((srcval << 8) & 0xff00ff00) |
65 ((srcval >> 8) & 0x00ff00ff);
68 /* And the odd pixel */
69 WORD srcval = *(const WORD*)srcpixel;
70 *(WORD*)dstpixel = ((srcval << 8) & 0xff00) |
71 ((srcval >> 8) & 0x00ff);
73 srcbits = (const char*)srcbits + srclinebytes;
74 dstbits = (char*)dstbits + dstlinebytes;
78 static void convert_555_reverse_src_byteswap(int width, int height,
79 const void* srcbits, int srclinebytes,
80 void* dstbits, int dstlinebytes)
82 const DWORD* srcpixel;
86 for (y=0; y<height; y++) {
89 for (x=0; x<width/2; x++) {
90 /* Do 2 pixels at a time */
93 *dstpixel++=((srcval >> 2) & 0x001f001f) | /* h */
94 ((srcval << 8) & 0x03000300) | /* g - 2 bits */
95 ((srcval >> 8) & 0x00e000e0) | /* g - 3 bits */
96 ((srcval << 2) & 0x7c007c00); /* l */
99 /* And then the odd pixel */
101 srcval=*((const WORD*)srcpixel);
102 *((WORD*)dstpixel)=((srcval >> 2) & 0x001f) | /* h */
103 ((srcval << 8) & 0x0300) | /* g - 2 bits */
104 ((srcval >> 8) & 0x00e0) | /* g - 3 bits */
105 ((srcval << 2) & 0x7c00); /* l */
107 srcbits = (const char*)srcbits + srclinebytes;
108 dstbits = (char*)dstbits + dstlinebytes;
112 static void convert_555_to_565_asis_src_byteswap(int width, int height,
113 const void* srcbits, int srclinebytes,
114 void* dstbits, int dstlinebytes)
116 const DWORD* srcpixel;
120 for (y=0; y<height; y++) {
123 for (x=0; x<width/2; x++) {
124 /* Do 2 pixels at a time */
127 *dstpixel++=((srcval << 9) & 0xfe00fe00) | /* h, g - 2 bits*/
128 ((srcval >> 7) & 0x01c001c0) | /* g - 3 bits */
129 ((srcval << 4) & 0x00200020) | /* g - 1 bit */
130 ((srcval >> 8) & 0x001f001f); /* l */
133 /* And then the odd pixel */
135 srcval=*((const WORD*)srcpixel);
136 *((WORD*)dstpixel)=((srcval << 9) & 0xfe00) | /* h, g - 2bits*/
137 ((srcval >> 7) & 0x01c0) | /* g - 3 bits */
138 ((srcval << 4) & 0x0020) | /* g - 1 bit */
139 ((srcval >> 8) & 0x001f); /* l */
141 srcbits = (const char*)srcbits + srclinebytes;
142 dstbits = (char*)dstbits + dstlinebytes;
146 static void convert_555_to_565_reverse_src_byteswap(int width, int height,
147 const void* srcbits, int srclinebytes,
148 void* dstbits, int dstlinebytes)
150 const DWORD* srcpixel;
154 for (y=0; y<height; y++) {
157 for (x=0; x<width/2; x++) {
158 /* Do 2 pixels at a time */
161 *dstpixel++=((srcval >> 2) & 0x001f001f) | /* h */
162 ((srcval << 9) & 0x06000600) | /* g - 2 bits*/
163 ((srcval >> 7) & 0x01c001c0) | /* g - 3 bits */
164 ((srcval << 4) & 0x00200020) | /* g - 1 bits */
165 ((srcval << 3) & 0xf800f800); /* l */
168 /* And then the odd pixel */
170 srcval=*((const WORD*)srcpixel);
171 *((WORD*)dstpixel)=((srcval >> 2) & 0x001f) | /* h */
172 ((srcval << 9) & 0x0600) | /* g - 2 bits */
173 ((srcval >> 7) & 0x01c0) | /* g - 3 bits */
174 ((srcval << 4) & 0x0020) | /* g - 1 bit */
175 ((srcval << 3) & 0xf800); /* l */
177 srcbits = (const char*)srcbits + srclinebytes;
178 dstbits = (char*)dstbits + dstlinebytes;
182 static void convert_555_to_888_asis_src_byteswap(int width, int height,
183 const void* srcbits, int srclinebytes,
184 void* dstbits, int dstlinebytes)
186 const WORD* srcpixel;
190 for (y=0; y<height; y++) {
193 for (x=0; x<width; x++) {
196 dstpixel[0]=((srcval >> 5) & 0xf8) | /* l */
197 ((srcval >> 10) & 0x07); /* l - 3 bits */
198 dstpixel[1]=((srcval << 6) & 0xc0) | /* g - 2 bits */
199 ((srcval >> 10) & 0x38) | /* g - 3 bits */
200 ((srcval << 1) & 0x06) | /* g - 2 bits */
201 ((srcval >> 15) & 0x01); /* g - 1 bit */
202 dstpixel[2]=((srcval << 1) & 0xf8) | /* h */
203 ((srcval >> 4) & 0x07); /* h - 3 bits */
206 srcbits = (const char*)srcbits + srclinebytes;
207 dstbits = (char*)dstbits + dstlinebytes;
211 static void convert_555_to_888_reverse_src_byteswap(int width, int height,
212 const void* srcbits, int srclinebytes,
213 void* dstbits, int dstlinebytes)
215 const WORD* srcpixel;
219 for (y=0; y<height; y++) {
222 for (x=0; x<width; x++) {
225 dstpixel[0]=((srcval << 1) & 0xf8) | /* h */
226 ((srcval >> 4) & 0x07); /* h - 3 bits */
227 dstpixel[1]=((srcval << 6) & 0xc0) | /* g - 2 bits */
228 ((srcval >> 10) & 0x38) | /* g - 3 bits */
229 ((srcval << 1) & 0x06) | /* g - 2 bits */
230 ((srcval >> 15) & 0x01); /* g - 1 bits */
231 dstpixel[2]=((srcval >> 5) & 0xf8) | /* l */
232 ((srcval >> 10) & 0x07); /* l - 3 bits */
235 srcbits = (const char*)srcbits + srclinebytes;
236 dstbits = (char*)dstbits + dstlinebytes;
240 static void convert_555_to_0888_asis_src_byteswap(int width, int height,
241 const void* srcbits, int srclinebytes,
242 void* dstbits, int dstlinebytes)
244 const WORD* srcpixel;
248 for (y=0; y<height; y++) {
251 for (x=0; x<width; x++) {
254 *dstpixel++=((srcval << 17) & 0xf80000) | /* h */
255 ((srcval << 12) & 0x070000) | /* h - 3 bits */
256 ((srcval << 14) & 0x00c000) | /* g - 2 bits */
257 ((srcval >> 2) & 0x003800) | /* g - 3 bits */
258 ((srcval << 9) & 0x000600) | /* g - 2 bits */
259 ((srcval >> 7) & 0x000100) | /* g - 1 bit */
260 ((srcval >> 5) & 0x0000f8) | /* l */
261 ((srcval >> 10) & 0x000007); /* l - 3 bits */
263 srcbits = (const char*)srcbits + srclinebytes;
264 dstbits = (char*)dstbits + dstlinebytes;
268 static void convert_555_to_0888_reverse_src_byteswap(int width, int height,
269 const void* srcbits, int srclinebytes,
270 void* dstbits, int dstlinebytes)
272 const WORD* srcpixel;
276 for (y=0; y<height; y++) {
279 for (x=0; x<width; x++) {
282 *dstpixel++=((srcval << 1) & 0x0000f8) | /* h */
283 ((srcval >> 4) & 0x000007) | /* h - 3 bits */
284 ((srcval << 14) & 0x00c000) | /* g - 2 bits */
285 ((srcval >> 2) & 0x003800) | /* g - 3 bits */
286 ((srcval << 9) & 0x000600) | /* g - 2 bits */
287 ((srcval >> 7) & 0x000100) | /* g - 1 bit */
288 ((srcval << 11) & 0xf80000) | /* l */
289 ((srcval << 6) & 0x070000); /* l - 3 bits */
291 srcbits = (const char*)srcbits + srclinebytes;
292 dstbits = (char*)dstbits + dstlinebytes;
296 static void convert_5x5_to_any0888_src_byteswap(int width, int height,
297 const void* srcbits, int srclinebytes,
298 WORD rsrc, WORD gsrc, WORD bsrc,
299 void* dstbits, int dstlinebytes,
300 DWORD rdst, DWORD gdst, DWORD bdst)
302 int rRightShift1,gRightShift1,bRightShift1;
303 int rRightShift2,gRightShift2,bRightShift2;
305 int rLeftShift,gLeftShift,bLeftShift;
306 const WORD* srcpixel;
310 /* Note, the source pixel value is shifted left by 16 bits so that
311 * we know we will always have to shift right to extract the components.
313 rRightShift1=16+X11DRV_DIB_MaskToShift(rsrc)-3;
314 gRightShift1=16+X11DRV_DIB_MaskToShift(gsrc)-3;
315 bRightShift1=16+X11DRV_DIB_MaskToShift(bsrc)-3;
316 rRightShift2=rRightShift1+5;
317 gRightShift2=gRightShift1+5;
318 bRightShift2=bRightShift1+5;
320 /* Green has 5 bits, like the others */
324 /* Green has 6 bits, not 5. Compensate. */
331 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
332 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
333 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
335 for (y=0; y<height; y++) {
338 for (x=0; x<width; x++) {
341 srcval=*srcpixel++ << 16;
342 FLIP_TWO_WORDS(&srcval);
344 red= ((srcval >> rRightShift1) & 0xf8) |
345 ((srcval >> rRightShift2) & 0x07);
346 green=((srcval >> gRightShift1) & gMask1) |
347 ((srcval >> gRightShift2) & gMask2);
348 blue= ((srcval >> bRightShift1) & 0xf8) |
349 ((srcval >> bRightShift2) & 0x07);
350 *dstpixel++=(red << rLeftShift) |
351 (green << gLeftShift) |
352 (blue << bLeftShift);
354 srcbits = (const char*)srcbits + srclinebytes;
355 dstbits = (char*)dstbits + dstlinebytes;
360 * 16 bits conversions
363 static void convert_565_reverse_src_byteswap(int width, int height,
364 const void* srcbits, int srclinebytes,
365 void* dstbits, int dstlinebytes)
367 const DWORD* srcpixel;
371 for (y=0; y<height; y++) {
374 for (x=0; x<width/2; x++) {
375 /* Do 2 pixels at a time */
378 *dstpixel++=((srcval << 3) & 0xf800f800) | /* l */
379 ((srcval << 8) & 0x07000700) | /* g - 3 bits */
380 ((srcval >> 8) & 0x00e000e0) | /* g - 3 bits */
381 ((srcval >> 3) & 0x001f001f); /* h */
384 /* And then the odd pixel */
386 srcval=*((const WORD*)srcpixel);
387 *((WORD*)dstpixel)=((srcval << 3) & 0xf800) | /* l */
388 ((srcval << 8) & 0x0700) | /* g - 3 bits */
389 ((srcval >> 8) & 0x00e0) | /* g - 3 bits */
390 ((srcval >> 3) & 0x001f); /* h */
392 srcbits = (const char*)srcbits + srclinebytes;
393 dstbits = (char*)dstbits + dstlinebytes;
397 static void convert_565_to_555_asis_src_byteswap(int width, int height,
398 const void* srcbits, int srclinebytes,
399 void* dstbits, int dstlinebytes)
401 const DWORD* srcpixel;
405 for (y=0; y<height; y++) {
408 for (x=0; x<width/2; x++) {
409 /* Do 2 pixels at a time */
412 *dstpixel++=((srcval << 7) & 0x7f807f80) | /* h, g - 3 bits */
413 ((srcval >> 9) & 0x00600060) | /* g - 2 bits */
414 ((srcval >> 8) & 0x001f001f); /* l */
417 /* And then the odd pixel */
419 srcval=*((const WORD*)srcpixel);
420 *((WORD*)dstpixel)=((srcval << 7) & 0x7f80) | /* h, g - 3 bits */
421 ((srcval >> 9) & 0x0060) | /* g - 2 bits */
422 ((srcval >> 8) & 0x001f); /* l */
424 srcbits = (const char*)srcbits + srclinebytes;
425 dstbits = (char*)dstbits + dstlinebytes;
429 static void convert_565_to_555_reverse_src_byteswap(int width, int height,
430 const void* srcbits, int srclinebytes,
431 void* dstbits, int dstlinebytes)
433 const DWORD* srcpixel;
437 for (y=0; y<height; y++) {
440 for (x=0; x<width/2; x++) {
441 /* Do 2 pixels at a time */
444 *dstpixel++=((srcval >> 3) & 0x001f001f) | /* h */
445 ((srcval >> 9) & 0x00600060) | /* g - 2 bits */
446 ((srcval << 7) & 0x03800380) | /* g - 3 bits */
447 ((srcval << 2) & 0x7c007c00); /* l */
450 /* And then the odd pixel */
452 srcval=*((const WORD*)srcpixel);
453 *((WORD*)dstpixel)=((srcval >> 3) & 0x001f) | /* h */
454 ((srcval >> 9) & 0x0060) | /* g - 2 bits */
455 ((srcval << 7) & 0x0380) | /* g - 3 bits */
456 ((srcval << 2) & 0x7c00); /* l */
458 srcbits = (const char*)srcbits + srclinebytes;
459 dstbits = (char*)dstbits + dstlinebytes;
463 static void convert_565_to_888_asis_src_byteswap(int width, int height,
464 const void* srcbits, int srclinebytes,
465 void* dstbits, int dstlinebytes)
467 const WORD* srcpixel;
471 for (y=0; y<height; y++) {
474 for (x=0; x<width; x++) {
477 dstpixel[0]=((srcval >> 5) & 0xf8) | /* l */
478 ((srcval >> 10) & 0x07); /* l - 3 bits */
479 dstpixel[1]=((srcval << 5) & 0xe0) | /* g - 3 bits */
480 ((srcval >> 11) & 0x1c) | /* g - 3 bits */
481 ((srcval >> 1) & 0x03); /* g - 2 bits */
482 dstpixel[2]=((srcval >> 0) & 0xf8) | /* h */
483 ((srcval >> 5) & 0x07); /* h - 3 bits */
486 srcbits = (const char*)srcbits + srclinebytes;
487 dstbits = (char*)dstbits + dstlinebytes;
491 static void convert_565_to_888_reverse_src_byteswap(int width, int height,
492 const void* srcbits, int srclinebytes,
493 void* dstbits, int dstlinebytes)
495 const WORD* srcpixel;
499 for (y=0; y<height; y++) {
502 for (x=0; x<width; x++) {
505 dstpixel[0]=((srcval >> 0) & 0xf8) | /* h */
506 ((srcval >> 5) & 0x07); /* h - 3 bits */
507 dstpixel[1]=((srcval << 5) & 0xe0) | /* g - 3 bits */
508 ((srcval >> 11) & 0x1c) | /* g - 3 bits */
509 ((srcval >> 1) & 0x03); /* g - 2 bits */
510 dstpixel[2]=((srcval >> 5) & 0xf8) | /* l */
511 ((srcval >> 10) & 0x07); /* l - 3 bits */
514 srcbits = (const char*)srcbits + srclinebytes;
515 dstbits = (char*)dstbits + dstlinebytes;
519 static void convert_565_to_0888_asis_src_byteswap(int width, int height,
520 const void* srcbits, int srclinebytes,
521 void* dstbits, int dstlinebytes)
523 const WORD* srcpixel;
527 for (y=0; y<height; y++) {
530 for (x=0; x<width; x++) {
533 *dstpixel++=((srcval << 16) & 0xf80000) | /* h */
534 ((srcval << 11) & 0x070000) | /* h - 3 bits */
535 ((srcval << 13) & 0x00e000) | /* g - 3 bits */
536 ((srcval >> 3) & 0x001c00) | /* g - 3 bits */
537 ((srcval << 7) & 0x000300) | /* g - 2 bits */
538 ((srcval >> 5) & 0x0000f8) | /* l */
539 ((srcval >> 10) & 0x000007); /* l - 3 bits */
541 srcbits = (const char*)srcbits + srclinebytes;
542 dstbits = (char*)dstbits + dstlinebytes;
546 static void convert_565_to_0888_reverse_src_byteswap(int width, int height,
547 const void* srcbits, int srclinebytes,
548 void* dstbits, int dstlinebytes)
550 const WORD* srcpixel;
554 for (y=0; y<height; y++) {
557 for (x=0; x<width; x++) {
560 *dstpixel++=((srcval >> 0) & 0x0000f8) | /* h */
561 ((srcval >> 5) & 0x000007) | /* h - 3 bits */
562 ((srcval << 13) & 0x00e000) | /* g - 3 bits */
563 ((srcval >> 3) & 0x001c00) | /* g - 3 bits */
564 ((srcval << 7) & 0x000300) | /* g - 2 bits */
565 ((srcval << 11) & 0xf80000) | /* l */
566 ((srcval << 6) & 0x070000); /* l - 3 bits */
568 srcbits = (const char*)srcbits + srclinebytes;
569 dstbits = (char*)dstbits + dstlinebytes;
577 static void convert_888_asis_src_byteswap(int width, int height,
578 const void* srcbits, int srclinebytes,
579 void* dstbits, int dstlinebytes)
583 for (y=0; y<height; y++) {
584 for(x = 0; x < ((width+1)*3/4); x++) {
585 DWORD srcval = *((const DWORD*)srcbits + x);
586 *((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
587 ((srcval << 8) & 0x00ff0000) |
588 ((srcval >> 8) & 0x0000ff00) |
589 ((srcval >> 24) & 0x000000ff);
591 srcbits = (const char*)srcbits + srclinebytes;
592 dstbits = (char*)dstbits + dstlinebytes;
596 static void convert_888_reverse_src_byteswap(int width, int height,
597 const void* srcbits, int srclinebytes,
598 void* dstbits, int dstlinebytes)
600 const DWORD* srcpixel;
604 int oddwidth = width & 3;
608 for (y=0; y<height; y++) {
611 for (x=0; x<width; x++) {
612 /* Do 4 pixels at a time: 3 dwords in and 3 dwords out */
613 *dstpixel++= ((srcpixel[0] >> 8) & 0x00ffffff) | /* l1, g1, h1 */
614 ((srcpixel[1] << 8) & 0xff000000); /* h2 */
615 *dstpixel++= ((srcpixel[1] >> 24) & 0x000000ff) | /* g2 */
616 ((srcpixel[0] << 8) & 0x0000ff00) | /* l2 */
617 ((srcpixel[2] >> 8) & 0x00ff0000) | /* h3 */
618 ((srcpixel[1] << 24) & 0xff000000); /* g3 */
619 *dstpixel++= ((srcpixel[1] >> 8) & 0x000000ff) | /* l3 */
620 ((srcpixel[2] << 8) & 0xffffff00); /* l4, g4, h4 */
623 /* And now up to 3 odd pixels */
625 BYTE *dstbyte, *srcbyte;
626 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
627 dstbyte = (LPBYTE)dstpixel;
628 srcbyte = (LPBYTE)srcarray;
629 for (x=0; x<oddwidth; x++) {
630 FLIP_DWORD(srcarray+x);
631 dstbyte[0] = srcbyte[2];
632 dstbyte[1] = srcbyte[1];
633 dstbyte[2] = srcbyte[0];
639 srcbits = (const char*)srcbits + srclinebytes;
640 dstbits = (char*)dstbits + dstlinebytes;
644 static void convert_888_to_555_asis_src_byteswap(int width, int height,
645 const void* srcbits, int srclinebytes,
646 void* dstbits, int dstlinebytes)
648 const DWORD* srcpixel;
657 for (y=0; y<height; y++) {
660 for (x=0; x<width; x++) {
661 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
662 DWORD srcval1,srcval2;
664 FLIP_DWORD(&srcval1);
665 dstpixel[0]=((srcval1 >> 3) & 0x001f) | /* l1 */
666 ((srcval1 >> 6) & 0x03e0) | /* g1 */
667 ((srcval1 >> 9) & 0x7c00); /* h1 */
669 FLIP_DWORD(&srcval2);
670 dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */
671 ((srcval2 << 2) & 0x03e0) | /* g2 */
672 ((srcval2 >> 1) & 0x7c00); /* h2 */
674 FLIP_DWORD(&srcval1);
675 dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */
676 ((srcval2 >> 22) & 0x03e0) | /* g3 */
677 ((srcval1 << 7) & 0x7c00); /* h3 */
678 dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */
679 ((srcval1 >> 14) & 0x03e0) | /* g4 */
680 ((srcval1 >> 17) & 0x7c00); /* h4 */
684 /* And now up to 3 odd pixels */
686 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
687 srcbyte = (LPBYTE)srcarray;
688 for (x=0; x<oddwidth; x++) {
690 FLIP_DWORD(srcarray+x);
692 dstval =((srcbyte[0] >> 3) & 0x001f); /* l */
693 dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */
694 dstval|=((srcbyte[2] << 7) & 0x7c00); /* h */
699 srcbits = (const char*)srcbits + srclinebytes;
700 dstbits = (char*)dstbits + dstlinebytes;
704 static void convert_888_to_555_reverse_src_byteswap(int width, int height,
705 const void* srcbits, int srclinebytes,
706 void* dstbits, int dstlinebytes)
708 const DWORD* srcpixel;
717 for (y=0; y<height; y++) {
720 for (x=0; x<width; x++) {
721 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
722 DWORD srcval1,srcval2;
724 FLIP_DWORD(&srcval1);
725 dstpixel[0]=((srcval1 << 7) & 0x7c00) | /* l1 */
726 ((srcval1 >> 6) & 0x03e0) | /* g1 */
727 ((srcval1 >> 19) & 0x001f); /* h1 */
729 FLIP_DWORD(&srcval2);
730 dstpixel[1]=((srcval1 >> 17) & 0x7c00) | /* l2 */
731 ((srcval2 << 2) & 0x03e0) | /* g2 */
732 ((srcval2 >> 11) & 0x001f); /* h2 */
734 FLIP_DWORD(&srcval1);
735 dstpixel[2]=((srcval2 >> 9) & 0x7c00) | /* l3 */
736 ((srcval2 >> 22) & 0x03e0) | /* g3 */
737 ((srcval1 >> 3) & 0x001f); /* h3 */
738 dstpixel[3]=((srcval1 >> 1) & 0x7c00) | /* l4 */
739 ((srcval1 >> 14) & 0x03e0) | /* g4 */
740 ((srcval1 >> 27) & 0x001f); /* h4 */
744 /* And now up to 3 odd pixels */
746 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
747 srcbyte = (LPBYTE)srcarray;
748 for (x=0; x<oddwidth; x++) {
750 FLIP_DWORD(srcarray+x);
751 dstval =((srcbyte[0] << 7) & 0x7c00); /* l */
752 dstval|=((srcbyte[1] << 2) & 0x03e0); /* g */
753 dstval|=((srcbyte[2] >> 3) & 0x001f); /* h */
758 srcbits = (const char*)srcbits + srclinebytes;
759 dstbits = (char*)dstbits + dstlinebytes;
763 static void convert_888_to_565_asis_src_byteswap(int width, int height,
764 const void* srcbits, int srclinebytes,
765 void* dstbits, int dstlinebytes)
767 const DWORD* srcpixel;
776 for (y=0; y<height; y++) {
779 for (x=0; x<width; x++) {
780 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
781 DWORD srcval1,srcval2;
783 FLIP_DWORD(&srcval1);
784 dstpixel[0]=((srcval1 >> 3) & 0x001f) | /* l1 */
785 ((srcval1 >> 5) & 0x07e0) | /* g1 */
786 ((srcval1 >> 8) & 0xf800); /* h1 */
788 FLIP_DWORD(&srcval2);
789 dstpixel[1]=((srcval1 >> 27) & 0x001f) | /* l2 */
790 ((srcval2 << 3) & 0x07e0) | /* g2 */
791 ( srcval2 & 0xf800); /* h2 */
793 FLIP_DWORD(&srcval1);
794 dstpixel[2]=((srcval2 >> 19) & 0x001f) | /* l3 */
795 ((srcval2 >> 21) & 0x07e0) | /* g3 */
796 ((srcval1 << 8) & 0xf800); /* h3 */
797 dstpixel[3]=((srcval1 >> 11) & 0x001f) | /* l4 */
798 ((srcval1 >> 13) & 0x07e0) | /* g4 */
799 ((srcval1 >> 16) & 0xf800); /* h4 */
803 /* And now up to 3 odd pixels */
805 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
806 srcbyte = (LPBYTE)srcarray;
807 for (x=0; x<oddwidth; x++) {
809 FLIP_DWORD(srcarray+x);
810 dstval =((srcbyte[0] >> 3) & 0x001f); /* l */
811 dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */
812 dstval|=((srcbyte[2] << 8) & 0xf800); /* h */
817 srcbits = (const char*)srcbits + srclinebytes;
818 dstbits = (char*)dstbits + dstlinebytes;
822 static void convert_888_to_565_reverse_src_byteswap(int width, int height,
823 const void* srcbits, int srclinebytes,
824 void* dstbits, int dstlinebytes)
826 const DWORD* srcpixel;
835 for (y=0; y<height; y++) {
838 for (x=0; x<width; x++) {
839 /* Do 4 pixels at a time: 3 dwords in and 4 words out */
840 DWORD srcval1,srcval2;
842 FLIP_DWORD(&srcval1);
843 dstpixel[0]=((srcval1 << 8) & 0xf800) | /* l1 */
844 ((srcval1 >> 5) & 0x07e0) | /* g1 */
845 ((srcval1 >> 19) & 0x001f); /* h1 */
847 FLIP_DWORD(&srcval2);
848 dstpixel[1]=((srcval1 >> 16) & 0xf800) | /* l2 */
849 ((srcval2 << 3) & 0x07e0) | /* g2 */
850 ((srcval2 >> 11) & 0x001f); /* h2 */
852 FLIP_DWORD(&srcval1);
853 dstpixel[2]=((srcval2 >> 8) & 0xf800) | /* l3 */
854 ((srcval2 >> 21) & 0x07e0) | /* g3 */
855 ((srcval1 >> 3) & 0x001f); /* h3 */
856 dstpixel[3]=(srcval1 & 0xf800) | /* l4 */
857 ((srcval1 >> 13) & 0x07e0) | /* g4 */
858 ((srcval1 >> 27) & 0x001f); /* h4 */
862 /* And now up to 3 odd pixels */
864 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
865 srcbyte = (LPBYTE)srcarray;
866 for (x=0; x<oddwidth; x++) {
868 FLIP_DWORD(srcarray+x);
869 dstval =((srcbyte[0] << 8) & 0xf800); /* l */
870 dstval|=((srcbyte[1] << 3) & 0x07e0); /* g */
871 dstval|=((srcbyte[2] >> 3) & 0x001f); /* h */
876 srcbits = (const char*)srcbits + srclinebytes;
877 dstbits = (char*)dstbits + dstlinebytes;
881 static void convert_888_to_0888_asis_src_byteswap(int width, int height,
882 const void* srcbits, int srclinebytes,
883 void* dstbits, int dstlinebytes)
885 const DWORD* srcpixel;
893 for (y=0; y<height; y++) {
896 for (x=0; x<width; x++) {
897 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
898 DWORD srcval1,srcval2;
900 FLIP_DWORD(&srcval1);
901 dstpixel[0]=( srcval1 & 0x00ffffff); /* h1, g1, l1 */
903 FLIP_DWORD(&srcval2);
904 dstpixel[1]=( srcval1 >> 24) | /* l2 */
905 ((srcval2 << 8) & 0x00ffff00); /* h2, g2 */
907 FLIP_DWORD(&srcval1);
908 dstpixel[2]=( srcval2 >> 16) | /* g3, l3 */
909 ((srcval1 << 16) & 0x00ff0000); /* h3 */
910 dstpixel[3]=( srcval1 >> 8); /* h4, g4, l4 */
914 /* And now up to 3 odd pixels */
916 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
918 for (x=0; x<oddwidth; x++) {
920 FLIP_DWORD(srcarray+x);
922 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
923 *dstpixel++=( srcval & 0x00ffffff); /* h, g, l */
926 srcbits = (const char*)srcbits + srclinebytes;
927 dstbits = (char*)dstbits + dstlinebytes;
931 static void convert_888_to_0888_reverse_src_byteswap(int width, int height,
932 const void* srcbits, int srclinebytes,
933 void* dstbits, int dstlinebytes)
935 const DWORD* srcpixel;
943 for (y=0; y<height; y++) {
946 for (x=0; x<width; x++) {
947 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
948 DWORD srcval1,srcval2;
951 FLIP_DWORD(&srcval1);
952 dstpixel[0]=((srcval1 >> 16) & 0x0000ff) | /* h1 */
953 ( srcval1 & 0x00ff00) | /* g1 */
954 ((srcval1 << 16) & 0xff0000); /* l1 */
956 FLIP_DWORD(&srcval2);
957 dstpixel[1]=((srcval1 >> 8) & 0xff0000) | /* l2 */
958 ((srcval2 << 8) & 0x00ff00) | /* g2 */
959 ((srcval2 >> 8) & 0x0000ff); /* h2 */
961 FLIP_DWORD(&srcval1);
962 dstpixel[2]=( srcval2 & 0xff0000) | /* l3 */
963 ((srcval2 >> 16) & 0x00ff00) | /* g3 */
964 ( srcval1 & 0x0000ff); /* h3 */
965 dstpixel[3]=((srcval1 >> 24) & 0x0000ff) | /* h4 */
966 ((srcval1 >> 8) & 0x00ff00) | /* g4 */
967 ((srcval1 << 8) & 0xff0000); /* l4 */
971 /* And now up to 3 odd pixels */
973 memcpy(srcarray,srcpixel,oddwidth*sizeof(DWORD));
975 for (x=0; x<oddwidth; x++) {
977 FLIP_DWORD(srcarray+x);
979 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
980 *dstpixel++=((srcval >> 16) & 0x0000ff) | /* h */
981 ( srcval & 0x00ff00) | /* g */
982 ((srcval << 16) & 0xff0000); /* l */
985 srcbits = (const char*)srcbits + srclinebytes;
986 dstbits = (char*)dstbits + dstlinebytes;
990 static void convert_rgb888_to_any0888_src_byteswap(int width, int height,
991 const void* srcbits, int srclinebytes,
992 void* dstbits, int dstlinebytes,
993 DWORD rdst, DWORD gdst, DWORD bdst)
995 int rLeftShift,gLeftShift,bLeftShift;
996 const DWORD* srcpixel;
1001 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1002 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1003 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1004 for (y=0; y<height; y++) {
1007 for (x=0; x<width/4; x++) {
1008 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
1009 DWORD srcval1, srcval2;
1010 srcval1=*srcpixel++;
1011 *dstpixel++=(((srcval1 >> 24) & 0xff) << bLeftShift) | /* b1 */
1012 (((srcval1 >> 16) & 0xff) << gLeftShift) | /* g1 */
1013 (((srcval1 >> 8) & 0xff) << rLeftShift); /* r1 */
1014 srcval2=*srcpixel++;
1015 *dstpixel++=(((srcval1 >> 0) & 0xff) << bLeftShift) | /* b2 */
1016 (((srcval2 >> 24) & 0xff) << gLeftShift) | /* g2 */
1017 (((srcval2 >> 16) & 0xff) << rLeftShift); /* r2 */
1018 srcval1=*srcpixel++;
1019 *dstpixel++=(((srcval2 >> 8) & 0xff) << bLeftShift) | /* b3 */
1020 (((srcval2 >> 0) & 0xff) << gLeftShift) | /* g3 */
1021 (((srcval1 >> 24) & 0xff) << rLeftShift); /* r3 */
1022 *dstpixel++=(((srcval1 >> 16) & 0xff) << bLeftShift) | /* b4 */
1023 (((srcval1 >> 8) & 0xff) << gLeftShift) | /* g4 */
1024 (((srcval1 >> 0) & 0xff) << rLeftShift); /* r4 */
1026 /* And now up to 3 odd pixels */
1028 memcpy(srcarray,srcpixel,width&3*sizeof(DWORD));
1029 srcpixel = srcarray;
1030 for (x=0; x < (width&3); x++) {
1032 FLIP_DWORD(srcarray+x);
1034 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
1035 *dstpixel++=(((srcval >> 0) & 0xff) << bLeftShift) | /* b */
1036 (((srcval >> 8) & 0xff) << gLeftShift) | /* g */
1037 (((srcval >> 16) & 0xff) << rLeftShift); /* r */
1040 srcbits = (const char*)srcbits + srclinebytes;
1041 dstbits = (char*)dstbits + dstlinebytes;
1045 static void convert_bgr888_to_any0888_src_byteswap(int width, int height,
1046 const void* srcbits, int srclinebytes,
1047 void* dstbits, int dstlinebytes,
1048 DWORD rdst, DWORD gdst, DWORD bdst)
1050 int rLeftShift,gLeftShift,bLeftShift;
1051 const DWORD* srcpixel;
1056 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1057 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1058 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1059 for (y=0; y<height; y++) {
1062 for (x=0; x<width/4; x++) {
1063 /* Do 4 pixels at a time: 3 dwords in and 4 dwords out */
1064 DWORD srcval1, srcval2;
1065 srcval1=*srcpixel++;
1066 *dstpixel++=(((srcval1 >> 24) & 0xff) << rLeftShift) | /* r1 */
1067 (((srcval1 >> 16) & 0xff) << gLeftShift) | /* g1 */
1068 (((srcval1 >> 8) & 0xff) << bLeftShift); /* b1 */
1069 srcval2=*srcpixel++;
1070 *dstpixel++=(((srcval1 >> 0) & 0xff) << rLeftShift) | /* r2 */
1071 (((srcval2 >> 24) & 0xff) << gLeftShift) | /* g2 */
1072 (((srcval2 >> 16) & 0xff) << bLeftShift); /* b2 */
1073 srcval1=*srcpixel++;
1074 *dstpixel++=(((srcval2 >> 8) & 0xff) << rLeftShift) | /* r3 */
1075 (((srcval2 >> 0) & 0xff) << gLeftShift) | /* g3 */
1076 (((srcval1 >> 24) & 0xff) << bLeftShift); /* b3 */
1077 *dstpixel++=(((srcval1 >> 16) & 0xff) << rLeftShift) | /* r4 */
1078 (((srcval1 >> 8) & 0xff) << gLeftShift) | /* g4 */
1079 (((srcval1 >> 0) & 0xff) << bLeftShift); /* b4 */
1081 /* And now up to 3 odd pixels */
1083 memcpy(srcarray,srcpixel,width&3*sizeof(DWORD));
1084 srcpixel = srcarray;
1085 for (x=0; x < (width&3); x++) {
1087 FLIP_DWORD(srcarray+x);
1089 srcpixel=(const DWORD*)(((const char*)srcpixel)+3);
1090 *dstpixel++=(((srcval >> 0) & 0xff) << rLeftShift) | /* r */
1091 (((srcval >> 8) & 0xff) << gLeftShift) | /* g */
1092 (((srcval >> 16) & 0xff) << bLeftShift); /* b */
1095 srcbits = (const char*)srcbits + srclinebytes;
1096 dstbits = (char*)dstbits + dstlinebytes;
1102 * 32 bit conversions
1105 static void convert_0888_asis_src_byteswap(int width, int height,
1106 const void* srcbits, int srclinebytes,
1107 void* dstbits, int dstlinebytes)
1111 for (y=0; y<height; y++) {
1112 for(x = 0; x < width; x++) {
1113 DWORD srcval = *((const DWORD*)srcbits + x);
1114 *((DWORD*)dstbits + x) = ((srcval << 24) & 0xff000000) |
1115 ((srcval << 8) & 0x00ff0000) |
1116 ((srcval >> 8) & 0x0000ff00) |
1117 ((srcval >> 24) & 0x000000ff);
1119 srcbits = (const char*)srcbits + srclinebytes;
1120 dstbits = (char*)dstbits + dstlinebytes;
1124 static void convert_0888_reverse_src_byteswap(int width, int height,
1125 const void* srcbits, int srclinebytes,
1126 void* dstbits, int dstlinebytes)
1128 const DWORD* srcpixel;
1132 for (y=0; y<height; y++) {
1135 for (x=0; x<width; x++) {
1138 *dstpixel++=((srcval >> 8) & 0x00ffffff);
1140 srcbits = (const char*)srcbits + srclinebytes;
1141 dstbits = (char*)dstbits + dstlinebytes;
1145 static void convert_0888_any_src_byteswap(int width, int height,
1146 const void* srcbits, int srclinebytes,
1147 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1148 void* dstbits, int dstlinebytes,
1149 DWORD rdst, DWORD gdst, DWORD bdst)
1151 int rRightShift,gRightShift,bRightShift;
1152 int rLeftShift,gLeftShift,bLeftShift;
1153 const DWORD* srcpixel;
1157 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1158 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1159 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1160 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1161 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1162 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1163 for (y=0; y<height; y++) {
1166 for (x=0; x<width; x++) {
1169 FLIP_DWORD(&srcval);
1170 *dstpixel++=(((srcval >> rRightShift) & 0xff) << rLeftShift) |
1171 (((srcval >> gRightShift) & 0xff) << gLeftShift) |
1172 (((srcval >> bRightShift) & 0xff) << bLeftShift);
1174 srcbits = (const char*)srcbits + srclinebytes;
1175 dstbits = (char*)dstbits + dstlinebytes;
1179 static void convert_0888_to_555_asis_src_byteswap(int width, int height,
1180 const void* srcbits, int srclinebytes,
1181 void* dstbits, int dstlinebytes)
1183 const DWORD* srcpixel;
1187 for (y=0; y<height; y++) {
1190 for (x=0; x<width; x++) {
1193 *dstpixel++=((srcval >> 1) & 0x7c00) | /* h */
1194 ((srcval >> 14) & 0x03e0) | /* g */
1195 ((srcval >> 27) & 0x001f); /* l */
1197 srcbits = (const char*)srcbits + srclinebytes;
1198 dstbits = (char*)dstbits + dstlinebytes;
1202 static void convert_0888_to_555_reverse_src_byteswap(int width, int height,
1203 const void* srcbits, int srclinebytes,
1204 void* dstbits, int dstlinebytes)
1206 const DWORD* srcpixel;
1210 for (y=0; y<height; y++) {
1213 for (x=0; x<width; x++) {
1216 *dstpixel++=((srcval >> 11) & 0x001f) | /* h */
1217 ((srcval >> 14) & 0x03e0) | /* g */
1218 ((srcval >> 17) & 0x7c00); /* l */
1220 srcbits = (const char*)srcbits + srclinebytes;
1221 dstbits = (char*)dstbits + dstlinebytes;
1225 static void convert_0888_to_565_asis_src_byteswap(int width, int height,
1226 const void* srcbits, int srclinebytes,
1227 void* dstbits, int dstlinebytes)
1229 const DWORD* srcpixel;
1233 for (y=0; y<height; y++) {
1236 for (x=0; x<width; x++) {
1239 *dstpixel++=((srcval >> 0) & 0xf800) | /* h */
1240 ((srcval >> 13) & 0x07e0) | /* g */
1241 ((srcval >> 27) & 0x001f); /* l */
1243 srcbits = (const char*)srcbits + srclinebytes;
1244 dstbits = (char*)dstbits + dstlinebytes;
1248 static void convert_0888_to_565_reverse_src_byteswap(int width, int height,
1249 const void* srcbits, int srclinebytes,
1250 void* dstbits, int dstlinebytes)
1252 const DWORD* srcpixel;
1256 for (y=0; y<height; y++) {
1259 for (x=0; x<width; x++) {
1262 *dstpixel++=((srcval >> 11) & 0x001f) | /* h */
1263 ((srcval >> 13) & 0x07e0) | /* g */
1264 ((srcval >> 16) & 0xf800); /* l */
1266 srcbits = (const char*)srcbits + srclinebytes;
1267 dstbits = (char*)dstbits + dstlinebytes;
1271 static void convert_any0888_to_5x5_src_byteswap(int width, int height,
1272 const void* srcbits, int srclinebytes,
1273 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1274 void* dstbits, int dstlinebytes,
1275 WORD rdst, WORD gdst, WORD bdst)
1277 int rRightShift,gRightShift,bRightShift;
1278 int rLeftShift,gLeftShift,bLeftShift;
1279 const DWORD* srcpixel;
1283 /* Here is how we proceed. Assume we have rsrc=0x0000ff00 and our pixel
1284 * contains 0x11223344.
1285 * - first we shift 0x11223344 right by rRightShift to bring the most
1286 * significant bits of the red components in the bottom 5 (or 6) bits
1288 * - then we remove non red bits by anding with the modified rdst (0x1f)
1290 * - finally shift these bits left by rLeftShift so that they end up in
1294 rRightShift=X11DRV_DIB_MaskToShift(rsrc)+3;
1295 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1296 gRightShift+=(gdst==0x07e0?2:3);
1297 bRightShift=X11DRV_DIB_MaskToShift(bsrc)+3;
1299 rLeftShift=X11DRV_DIB_MaskToShift(rdst);
1300 rdst=rdst >> rLeftShift;
1301 gLeftShift=X11DRV_DIB_MaskToShift(gdst);
1302 gdst=gdst >> gLeftShift;
1303 bLeftShift=X11DRV_DIB_MaskToShift(bdst);
1304 bdst=bdst >> bLeftShift;
1306 for (y=0; y<height; y++) {
1309 for (x=0; x<width; x++) {
1312 FLIP_DWORD(&srcval);
1313 *dstpixel++=(((srcval >> rRightShift) & rdst) << rLeftShift) |
1314 (((srcval >> gRightShift) & gdst) << gLeftShift) |
1315 (((srcval >> bRightShift) & bdst) << bLeftShift);
1317 srcbits = (const char*)srcbits + srclinebytes;
1318 dstbits = (char*)dstbits + dstlinebytes;
1322 static void convert_0888_to_888_asis_src_byteswap(int width, int height,
1323 const void* srcbits, int srclinebytes,
1324 void* dstbits, int dstlinebytes)
1326 const DWORD* srcpixel;
1334 for (y=0; y<height; y++) {
1337 for (x=0; x<width; x++) {
1338 /* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
1339 DWORD srcval1, srcval2;
1340 srcval1 = *srcpixel++;
1341 srcval2 = *srcpixel++;
1342 *dstpixel++= ((srcval1 >> 24) & 0x000000ff) | /* l1 */
1343 ((srcval1 >> 8) & 0x0000ff00) | /* g1 */
1344 ((srcval1 << 8) & 0x00ff0000) | /* h1 */
1345 ( srcval2 & 0xff000000); /* l2 */
1346 srcval1 = *srcpixel++;
1347 *dstpixel++= ((srcval2 >> 16) & 0x000000ff) | /* g2 */
1348 ( srcval2 & 0x0000ff00) | /* h2 */
1349 ((srcval1 >> 8) & 0x00ff0000) | /* l3 */
1350 ((srcval1 << 8) & 0xff000000); /* g3 */
1351 srcval2 = *srcpixel++;
1352 *dstpixel++= ((srcval1 >> 8) & 0x000000ff) | /* h3 */
1353 ((srcval2 >> 16) & 0x0000ff00) | /* l4 */
1354 ( srcval2 & 0x00ff0000) | /* g4 */
1355 ((srcval2 << 16) & 0xff000000); /* h4 */
1357 /* And now up to 3 odd pixels */
1358 dstbyte=(BYTE*)dstpixel;
1359 for (x=0; x<oddwidth; x++) {
1362 FLIP_DWORD(&srcval);
1363 *((WORD*)dstbyte)=srcval; /* h, g */
1364 dstbyte+=sizeof(WORD);
1365 *dstbyte++=srcval >> 16; /* l */
1367 srcbits = (const char*)srcbits + srclinebytes;
1368 dstbits = (char*)dstbits + dstlinebytes;
1372 static void convert_0888_to_888_reverse_src_byteswap(int width, int height,
1373 const void* srcbits, int srclinebytes,
1374 void* dstbits, int dstlinebytes)
1376 const DWORD* srcpixel;
1384 for (y=0; y<height; y++) {
1387 for (x=0; x<width; x++) {
1388 /* Do 4 pixels at a time: 4 dwords in and 3 dwords out */
1389 DWORD srcval1,srcval2;
1390 srcval1=*srcpixel++;
1391 srcval2= ((srcval1 >> 8 ) & 0x00ffffff); /* l1, g1, h1 */
1392 srcval1=*srcpixel++;
1393 *dstpixel++=srcval2 |
1394 ((srcval1 << 16) & 0xff000000); /* h2 */
1395 srcval2= ((srcval1 >> 16) & 0x0000ffff); /* l2, g2 */
1396 srcval1=*srcpixel++;
1397 *dstpixel++=srcval2 |
1398 ((srcval1 << 8) & 0xffff0000); /* g3, h3 */
1399 srcval2= ((srcval1 >> 24) & 0x000000ff); /* l3 */
1400 srcval1=*srcpixel++;
1401 *dstpixel++=srcval2 |
1402 srcval1; /* l4, g4, h4 */
1404 /* And now up to 3 odd pixels */
1405 dstbyte=(BYTE*)dstpixel;
1406 for (x=0; x<oddwidth; x++) {
1409 *((WORD*)dstbyte)=((srcval >> 8) & 0xffff); /* g, h */
1410 dstbyte+=sizeof(WORD);
1411 *dstbyte++= srcval >> 24; /* l */
1413 srcbits = (const char*)srcbits + srclinebytes;
1414 dstbits = (char*)dstbits + dstlinebytes;
1418 static void convert_any0888_to_rgb888_src_byteswap(int width, int height,
1419 const void* srcbits, int srclinebytes,
1420 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1421 void* dstbits, int dstlinebytes)
1423 int rRightShift,gRightShift,bRightShift;
1424 const DWORD* srcpixel;
1428 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1429 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1430 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1431 for (y=0; y<height; y++) {
1434 for (x=0; x<width; x++) {
1437 FLIP_DWORD(&srcval);
1438 dstpixel[0]=(srcval >> bRightShift); /* b */
1439 dstpixel[1]=(srcval >> gRightShift); /* g */
1440 dstpixel[2]=(srcval >> rRightShift); /* r */
1443 srcbits = (const char*)srcbits + srclinebytes;
1444 dstbits = (char*)dstbits + dstlinebytes;
1448 static void convert_any0888_to_bgr888_src_byteswap(int width, int height,
1449 const void* srcbits, int srclinebytes,
1450 DWORD rsrc, DWORD gsrc, DWORD bsrc,
1451 void* dstbits, int dstlinebytes)
1453 int rRightShift,gRightShift,bRightShift;
1454 const DWORD* srcpixel;
1458 rRightShift=X11DRV_DIB_MaskToShift(rsrc);
1459 gRightShift=X11DRV_DIB_MaskToShift(gsrc);
1460 bRightShift=X11DRV_DIB_MaskToShift(bsrc);
1461 for (y=0; y<height; y++) {
1464 for (x=0; x<width; x++) {
1467 FLIP_DWORD(&srcval);
1468 dstpixel[0]=(srcval >> rRightShift); /* r */
1469 dstpixel[1]=(srcval >> gRightShift); /* g */
1470 dstpixel[2]=(srcval >> bRightShift); /* b */
1473 srcbits = (const char*)srcbits + srclinebytes;
1474 dstbits = (char*)dstbits + dstlinebytes;
1479 const dib_conversions dib_src_byteswap = {
1480 convert_5x5_asis_src_byteswap,
1481 convert_555_reverse_src_byteswap,
1482 convert_555_to_565_asis_src_byteswap,
1483 convert_555_to_565_reverse_src_byteswap,
1484 convert_555_to_888_asis_src_byteswap,
1485 convert_555_to_888_reverse_src_byteswap,
1486 convert_555_to_0888_asis_src_byteswap,
1487 convert_555_to_0888_reverse_src_byteswap,
1488 convert_5x5_to_any0888_src_byteswap,
1489 convert_565_reverse_src_byteswap,
1490 convert_565_to_555_asis_src_byteswap,
1491 convert_565_to_555_reverse_src_byteswap,
1492 convert_565_to_888_asis_src_byteswap,
1493 convert_565_to_888_reverse_src_byteswap,
1494 convert_565_to_0888_asis_src_byteswap,
1495 convert_565_to_0888_reverse_src_byteswap,
1496 convert_888_asis_src_byteswap,
1497 convert_888_reverse_src_byteswap,
1498 convert_888_to_555_asis_src_byteswap,
1499 convert_888_to_555_reverse_src_byteswap,
1500 convert_888_to_565_asis_src_byteswap,
1501 convert_888_to_565_reverse_src_byteswap,
1502 convert_888_to_0888_asis_src_byteswap,
1503 convert_888_to_0888_reverse_src_byteswap,
1504 convert_rgb888_to_any0888_src_byteswap,
1505 convert_bgr888_to_any0888_src_byteswap,
1506 convert_0888_asis_src_byteswap,
1507 convert_0888_reverse_src_byteswap,
1508 convert_0888_any_src_byteswap,
1509 convert_0888_to_555_asis_src_byteswap,
1510 convert_0888_to_555_reverse_src_byteswap,
1511 convert_0888_to_565_asis_src_byteswap,
1512 convert_0888_to_565_reverse_src_byteswap,
1513 convert_any0888_to_5x5_src_byteswap,
1514 convert_0888_to_888_asis_src_byteswap,
1515 convert_0888_to_888_reverse_src_byteswap,
1516 convert_any0888_to_rgb888_src_byteswap,
1517 convert_any0888_to_bgr888_src_byteswap