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
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) )
48 static void convert_5x5_asis_dst_byteswap(int width
, int height
,
49 const void* srcbits
, int srclinebytes
,
50 void* dstbits
, int dstlinebytes
)
53 const DWORD
*srcpixel
;
56 for (y
=0; y
<height
; y
++) {
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);
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
;
84 for (y
=0; y
<height
; y
++) {
87 for (x
=0; x
<width
/2; x
++) {
88 /* Do 2 pixels at a time */
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 */
97 /* And the the odd pixel */
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
;
118 for (y
=0; y
<height
; y
++) {
121 for (x
=0; x
<width
/2; x
++) {
122 /* Do 2 pixels at a time */
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 */
131 /* And the the odd pixel */
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
;
152 for (y
=0; y
<height
; y
++) {
155 for (x
=0; x
<width
/2; x
++) {
156 /* Do 2 pixels at a time */
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 */
166 /* And the the odd pixel */
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
;
188 for (y
=0; y
<height
; y
++) {
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 */
224 BYTE
*dstbyte
= (BYTE
*)dstpixel
;
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);
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
;
250 for (y
=0; y
<height
; y
++) {
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 */
286 BYTE
*dstbyte
= (BYTE
*)dstpixel
;
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);
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
;
312 for (y
=0; y
<height
; y
++) {
315 for (x
=0; x
<width
; x
++) {
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
;
338 for (y
=0; y
<height
; y
++) {
341 for (x
=0; x
<width
; x
++) {
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
;
365 int rLeftShift
,gLeftShift
,bLeftShift
;
366 const WORD
* srcpixel
;
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;
380 /* Green has 5 bits, like the others */
384 /* Green has 6 bits, not 5. Compensate. */
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
++) {
398 for (x
=0; x
<width
; x
++) {
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
);
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
;
431 for (y
=0; y
<height
; y
++) {
434 for (x
=0; x
<width
/2; x
++) {
435 /* Do 2 pixels at a time */
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 */
444 /* And the the odd pixel */
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
;
465 for (y
=0; y
<height
; y
++) {
468 for (x
=0; x
<width
/2; x
++) {
469 /* Do 2 pixels at a time */
472 *dstpixel
++=((srcval
<< 7) & 0xe000e000) | /* g - 3 bits */
473 ((srcval
<< 8) & 0x1f001f00) | /* l */
474 ((srcval
>> 9) & 0x007f007f); /* h, g - 2 bits */
477 /* And the the odd pixel */
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
;
497 for (y
=0; y
<height
; y
++) {
500 for (x
=0; x
<width
/2; x
++) {
501 /* Do 2 pixels at a time */
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 */
510 /* And the the odd pixel */
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
;
531 for (y
=0; y
<height
; y
++) {
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 */
567 BYTE
*dstbyte
= (BYTE
*)dstpixel
;
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);
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
;
594 for (y
=0; y
<height
; y
++) {
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 */
630 BYTE
*dstbyte
= (BYTE
*)dstpixel
;
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);
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
;
656 for (y
=0; y
<height
; y
++) {
659 for (x
=0; x
<width
; x
++) {
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
;
682 for (y
=0; y
<height
; y
++) {
685 for (x
=0; x
<width
; x
++) {
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
;
704 static void convert_888_asis_dst_byteswap(int width
, int height
,
705 const void* srcbits
, int srclinebytes
,
706 void* dstbits
, int dstlinebytes
)
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
;
731 for (y
=0; y
<height
; y
++) {
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 */
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];
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
;
777 for (y
=0; y
<height
; y
++) {
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
;
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 */
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 */
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 */
805 /* And now up to 3 odd pixels */
806 srcbyte
=(const BYTE
*)srcpixel
;
807 for (x
=0; x
<oddwidth
; x
++) {
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 */
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
;
833 for (y
=0; y
<height
; y
++) {
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
;
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 */
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 */
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 */
861 /* And now up to 3 odd pixels */
862 srcbyte
=(const BYTE
*)srcpixel
;
863 for (x
=0; x
<oddwidth
; x
++) {
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 */
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
;
890 for (y
=0; y
<height
; y
++) {
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
;
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 */
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 */
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 */
918 /* And now up to 3 odd pixels */
919 srcbyte
=(const BYTE
*)srcpixel
;
920 for (x
=0; x
<oddwidth
; x
++) {
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 */
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
;
946 for (y
=0; y
<height
; y
++) {
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
;
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 */
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 */
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 */
974 /* And now up to 3 odd pixels */
975 srcbyte
=(const BYTE
*)srcpixel
;
976 for (x
=0; x
<oddwidth
; x
++) {
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 */
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
;
1001 for (y
=0; y
<height
; y
++) {
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
++) {
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
;
1048 for (y
=0; y
<height
; y
++) {
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
++) {
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
;
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
++) {
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
);
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
;
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
++) {
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
);
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
)
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
;
1167 for (y
=0; y
<height
; y
++) {
1170 for (x
=0; x
<width
; x
++) {
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
;
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
++) {
1201 for (x
=0; x
<width
; x
++) {
1204 *dstpixel
=(((srcval
>> rRightShift
) & 0xff) << rLeftShift
) |
1205 (((srcval
>> gRightShift
) & 0xff) << gLeftShift
) |
1206 (((srcval
>> bRightShift
) & 0xff) << bLeftShift
);
1207 FLIP_DWORD(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
;
1223 for (y
=0; y
<height
; y
++) {
1226 for (x
=0; x
<width
; x
++) {
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 */
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
;
1248 for (y
=0; y
<height
; y
++) {
1251 for (x
=0; x
<width
; x
++) {
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 */
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
;
1273 for (y
=0; y
<height
; y
++) {
1276 for (x
=0; x
<width
; x
++) {
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
;
1297 for (y
=0; y
<height
; y
++) {
1300 for (x
=0; x
<width
; x
++) {
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
;
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
1330 * - then we remove non red bits by anding with the modified rdst (0x1f)
1332 * - finally shift these bits left by rLeftShift so that they end up in
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
++) {
1351 for (x
=0; x
<width
; x
++) {
1354 *dstpixel
=(((srcval
>> rRightShift
) & rdst
) << rLeftShift
) |
1355 (((srcval
>> gRightShift
) & gdst
) << gLeftShift
) |
1356 (((srcval
>> bRightShift
) & bdst
) << bLeftShift
);
1357 FLIP_WORD(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
;
1376 for (y
=0; y
<height
; y
++) {
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 */
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];
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
;
1430 for (y
=0; y
<height
; y
++) {
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 */
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];
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
;
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
++) {
1483 for (x
=0; x
<width
; x
++) {
1486 dstpixel
[0]=(srcval
>> bRightShift
); /* b */
1487 dstpixel
[1]=(srcval
>> gRightShift
); /* g */
1488 dstpixel
[2]=(srcval
>> rRightShift
); /* r */
1490 FLIP_DWORD((DWORD
*)(dstpixel
+ x
- 4));
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
;
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
++) {
1517 for (x
=0; x
<width
; x
++) {
1520 dstpixel
[0]=(srcval
>> rRightShift
); /* r */
1521 dstpixel
[1]=(srcval
>> gRightShift
); /* g */
1522 dstpixel
[2]=(srcval
>> bRightShift
); /* b */
1524 FLIP_DWORD((DWORD
*)(dstpixel
+ x
- 4));
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