29b846c6096f0a5d953967e177a68932569a400a
[profile/ivi/pixman.git] / pixman / pixman-access.c
1 /*
2  *
3  * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4  *             2005 Lars Knoll & Zack Rusin, Trolltech
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of Keith Packard not be used in
11  * advertising or publicity pertaining to distribution of the software without
12  * specific, written prior permission.  Keith Packard makes no
13  * representations about the suitability of this software for any purpose.  It
14  * is provided "as is" without express or implied warranty.
15  *
16  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
22  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23  * SOFTWARE.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include <string.h>
31
32 #include "pixman-private.h"
33
34 #define Red(x) (((x) >> 16) & 0xff)
35 #define Green(x) (((x) >> 8) & 0xff)
36 #define Blue(x) ((x) & 0xff)
37
38 /*
39  * YV12 setup and access macros
40  */
41
42 #define YV12_SETUP(pict) \
43         uint32_t *bits = pict->bits; \
44         int stride = pict->rowstride; \
45         int offset0 = stride < 0 ? \
46                 ((-stride) >> 1) * ((pict->height - 1) >> 1) - stride : \
47                 stride * pict->height; \
48         int offset1 = stride < 0 ? \
49                 offset0 + ((-stride) >> 1) * ((pict->height) >> 1) : \
50                 offset0 + (offset0 >> 2)
51 /* Note n trailing semicolon on the above macro; if it's there, then
52  * the typical usage of YV12_SETUP(pict); will have an extra trailing ;
53  * that some compilers will interpret as a statement -- and then any further
54  * variable declarations will cause an error.
55  */
56
57 #define YV12_Y(line)            \
58     ((uint8_t *) ((bits) + (stride) * (line)))
59
60 #define YV12_U(line)          \
61     ((uint8_t *) ((bits) + offset1 + \
62                 ((stride) >> 1) * ((line) >> 1)))
63
64 #define YV12_V(line)          \
65     ((uint8_t *) ((bits) + offset0 + \
66                 ((stride) >> 1) * ((line) >> 1)))
67
68 /*********************************** Fetch ************************************/
69
70 static FASTCALL void
71 fbFetch_a8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
72 {
73     const uint32_t *bits = pict->bits + y*pict->rowstride;
74     MEMCPY_WRAPPED(pict,
75                    buffer, (const uint32_t *)bits + x,
76                    width*sizeof(uint32_t));
77 }
78
79 static FASTCALL void
80 fbFetch_x8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
81 {
82     const uint32_t *bits = pict->bits + y*pict->rowstride;
83     const uint32_t *pixel = (const uint32_t *)bits + x;
84     const uint32_t *end = pixel + width;
85     while (pixel < end) {
86         *buffer++ = READ(pict, pixel++) | 0xff000000;
87     }
88 }
89
90 static FASTCALL void
91 fbFetch_a8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
92 {
93     const uint32_t *bits = pict->bits + y*pict->rowstride;
94     const uint32_t *pixel = (uint32_t *)bits + x;
95     const uint32_t *end = pixel + width;
96     while (pixel < end) {
97         uint32_t p = READ(pict, pixel++);
98         *buffer++ = (p & 0xff00ff00) |
99                     ((p >> 16) & 0xff) |
100             ((p & 0xff) << 16);
101     }
102 }
103
104 static FASTCALL void
105 fbFetch_x8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
106 {
107     const uint32_t *bits = pict->bits + y*pict->rowstride;
108     const uint32_t *pixel = (uint32_t *)bits + x;
109     const uint32_t *end = pixel + width;
110     while (pixel < end) {
111         uint32_t p = READ(pict, pixel++);
112         *buffer++ = 0xff000000 |
113             (p & 0x0000ff00) |
114             ((p >> 16) & 0xff) |
115             ((p & 0xff) << 16);
116     }
117 }
118
119 static FASTCALL void
120 fbFetch_r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
121 {
122     const uint32_t *bits = pict->bits + y*pict->rowstride;
123     const uint8_t *pixel = (const uint8_t *)bits + 3*x;
124     const uint8_t *end = pixel + 3*width;
125     while (pixel < end) {
126         uint32_t b = Fetch24(pict, pixel) | 0xff000000;
127         pixel += 3;
128         *buffer++ = b;
129     }
130 }
131
132 static FASTCALL void
133 fbFetch_b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
134 {
135     const uint32_t *bits = pict->bits + y*pict->rowstride;
136     const uint8_t *pixel = (const uint8_t *)bits + 3*x;
137     const uint8_t *end = pixel + 3*width;
138     while (pixel < end) {
139         uint32_t b = 0xff000000;
140 #if IMAGE_BYTE_ORDER == MSBFirst
141         b |= (READ(pict, pixel++));
142         b |= (READ(pict, pixel++) << 8);
143         b |= (READ(pict, pixel++) << 16);
144 #else
145         b |= (READ(pict, pixel++) << 16);
146         b |= (READ(pict, pixel++) << 8);
147         b |= (READ(pict, pixel++));
148 #endif
149         *buffer++ = b;
150     }
151 }
152
153 static FASTCALL void
154 fbFetch_r5g6b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
155 {
156     const uint32_t *bits = pict->bits + y*pict->rowstride;
157     const uint16_t *pixel = (const uint16_t *)bits + x;
158     const uint16_t *end = pixel + width;
159     while (pixel < end) {
160         uint32_t p = READ(pict, pixel++);
161         uint32_t r = (((p) << 3) & 0xf8) |
162             (((p) << 5) & 0xfc00) |
163             (((p) << 8) & 0xf80000);
164         r |= (r >> 5) & 0x70007;
165         r |= (r >> 6) & 0x300;
166         *buffer++ = 0xff000000 | r;
167     }
168 }
169
170 static FASTCALL void
171 fbFetch_b5g6r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
172 {
173     uint32_t  r,g,b;
174     const uint32_t *bits = pict->bits + y*pict->rowstride;
175     const uint16_t *pixel = (const uint16_t *)bits + x;
176     const uint16_t *end = pixel + width;
177     while (pixel < end) {
178         uint32_t  p = READ(pict, pixel++);
179         b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
180         g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
181         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
182         *buffer++ = 0xff000000 | r | g | b;
183     }
184 }
185
186 static FASTCALL void
187 fbFetch_a1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
188 {
189     uint32_t  r,g,b, a;
190     const uint32_t *bits = pict->bits + y*pict->rowstride;
191     const uint16_t *pixel = (const uint16_t *)bits + x;
192     const uint16_t *end = pixel + width;
193     while (pixel < end) {
194         uint32_t  p = READ(pict, pixel++);
195
196         a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
197         r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
198         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
199         b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
200         *buffer++ = a | r | g | b;
201     }
202 }
203
204 static FASTCALL void
205 fbFetch_x1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
206 {
207     uint32_t  r,g,b;
208     const uint32_t *bits = pict->bits + y*pict->rowstride;
209     const uint16_t *pixel = (const uint16_t *)bits + x;
210     const uint16_t *end = pixel + width;
211     while (pixel < end) {
212         uint32_t  p = READ(pict, pixel++);
213
214         r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
215         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
216         b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
217         *buffer++ = 0xff000000 | r | g | b;
218     }
219 }
220
221 static FASTCALL void
222 fbFetch_a1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
223 {
224     uint32_t  r,g,b, a;
225     const uint32_t *bits = pict->bits + y*pict->rowstride;
226     const uint16_t *pixel = (const uint16_t *)bits + x;
227     const uint16_t *end = pixel + width;
228     while (pixel < end) {
229         uint32_t  p = READ(pict, pixel++);
230
231         a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
232         b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
233         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
234         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
235         *buffer++ = a | r | g | b;
236     }
237 }
238
239 static FASTCALL void
240 fbFetch_x1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
241 {
242     uint32_t  r,g,b;
243     const uint32_t *bits = pict->bits + y*pict->rowstride;
244     const uint16_t *pixel = (const uint16_t *)bits + x;
245     const uint16_t *end = pixel + width;
246     while (pixel < end) {
247         uint32_t  p = READ(pict, pixel++);
248
249         b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
250         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
251         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
252         *buffer++ = 0xff000000 | r | g | b;
253     }
254 }
255
256 static FASTCALL void
257 fbFetch_a4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
258 {
259     uint32_t  r,g,b, a;
260     const uint32_t *bits = pict->bits + y*pict->rowstride;
261     const uint16_t *pixel = (const uint16_t *)bits + x;
262     const uint16_t *end = pixel + width;
263     while (pixel < end) {
264         uint32_t  p = READ(pict, pixel++);
265
266         a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
267         r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
268         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
269         b = ((p & 0x000f) | ((p & 0x000f) << 4));
270         *buffer++ = a | r | g | b;
271     }
272 }
273
274 static FASTCALL void
275 fbFetch_x4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
276 {
277     uint32_t  r,g,b;
278     const uint32_t *bits = pict->bits + y*pict->rowstride;
279     const uint16_t *pixel = (const uint16_t *)bits + x;
280     const uint16_t *end = pixel + width;
281     while (pixel < end) {
282         uint32_t  p = READ(pict, pixel++);
283
284         r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
285         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
286         b = ((p & 0x000f) | ((p & 0x000f) << 4));
287         *buffer++ = 0xff000000 | r | g | b;
288     }
289 }
290
291 static FASTCALL void
292 fbFetch_a4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
293 {
294     uint32_t  r,g,b, a;
295     const uint32_t *bits = pict->bits + y*pict->rowstride;
296     const uint16_t *pixel = (const uint16_t *)bits + x;
297     const uint16_t *end = pixel + width;
298     while (pixel < end) {
299         uint32_t  p = READ(pict, pixel++);
300
301         a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
302         b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
303         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
304         r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
305         *buffer++ = a | r | g | b;
306     }
307 }
308
309 static FASTCALL void
310 fbFetch_x4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
311 {
312     uint32_t  r,g,b;
313     const uint32_t *bits = pict->bits + y*pict->rowstride;
314     const uint16_t *pixel = (const uint16_t *)bits + x;
315     const uint16_t *end = pixel + width;
316     while (pixel < end) {
317         uint32_t  p = READ(pict, pixel++);
318
319         b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
320         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
321         r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
322         *buffer++ = 0xff000000 | r | g | b;
323     }
324 }
325
326 static FASTCALL void
327 fbFetch_a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
328 {
329     const uint32_t *bits = pict->bits + y*pict->rowstride;
330     const uint8_t *pixel = (const uint8_t *)bits + x;
331     const uint8_t *end = pixel + width;
332     while (pixel < end) {
333         *buffer++ = READ(pict, pixel++) << 24;
334     }
335 }
336
337 static FASTCALL void
338 fbFetch_r3g3b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
339 {
340     uint32_t  r,g,b;
341     const uint32_t *bits = pict->bits + y*pict->rowstride;
342     const uint8_t *pixel = (const uint8_t *)bits + x;
343     const uint8_t *end = pixel + width;
344     while (pixel < end) {
345         uint32_t  p = READ(pict, pixel++);
346
347         r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
348         g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
349         b = (((p & 0x03)     ) |
350              ((p & 0x03) << 2) |
351              ((p & 0x03) << 4) |
352              ((p & 0x03) << 6));
353         *buffer++ = 0xff000000 | r | g | b;
354     }
355 }
356
357 static FASTCALL void
358 fbFetch_b2g3r3 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
359 {
360     uint32_t  r,g,b;
361     const uint32_t *bits = pict->bits + y*pict->rowstride;
362     const uint8_t *pixel = (const uint8_t *)bits + x;
363     const uint8_t *end = pixel + width;
364     while (pixel < end) {
365         uint32_t  p = READ(pict, pixel++);
366
367         b = (((p & 0xc0)     ) |
368              ((p & 0xc0) >> 2) |
369              ((p & 0xc0) >> 4) |
370              ((p & 0xc0) >> 6));
371         g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
372         r = (((p & 0x07)     ) |
373              ((p & 0x07) << 3) |
374              ((p & 0x06) << 6)) << 16;
375         *buffer++ = 0xff000000 | r | g | b;
376     }
377 }
378
379 static FASTCALL void
380 fbFetch_a2r2g2b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
381 {
382     uint32_t   a,r,g,b;
383     const uint32_t *bits = pict->bits + y*pict->rowstride;
384     const uint8_t *pixel = (const uint8_t *)bits + x;
385     const uint8_t *end = pixel + width;
386     while (pixel < end) {
387         uint32_t  p = READ(pict, pixel++);
388
389         a = ((p & 0xc0) * 0x55) << 18;
390         r = ((p & 0x30) * 0x55) << 12;
391         g = ((p & 0x0c) * 0x55) << 6;
392         b = ((p & 0x03) * 0x55);
393         *buffer++ = a|r|g|b;
394     }
395 }
396
397 static FASTCALL void
398 fbFetch_a2b2g2r2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
399 {
400     uint32_t   a,r,g,b;
401     const uint32_t *bits = pict->bits + y*pict->rowstride;
402     const uint8_t *pixel = (const uint8_t *)bits + x;
403     const uint8_t *end = pixel + width;
404     while (pixel < end) {
405         uint32_t  p = READ(pict, pixel++);
406
407         a = ((p & 0xc0) * 0x55) << 18;
408         b = ((p & 0x30) * 0x55) >> 6;
409         g = ((p & 0x0c) * 0x55) << 6;
410         r = ((p & 0x03) * 0x55) << 16;
411         *buffer++ = a|r|g|b;
412     }
413 }
414
415 static FASTCALL void
416 fbFetch_c8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
417 {
418     const uint32_t *bits = pict->bits + y*pict->rowstride;
419     const pixman_indexed_t * indexed = pict->indexed;
420     const uint8_t *pixel = (const uint8_t *)bits + x;
421     const uint8_t *end = pixel + width;
422     while (pixel < end) {
423         uint32_t  p = READ(pict, pixel++);
424         *buffer++ = indexed->rgba[p];
425     }
426 }
427
428 static FASTCALL void
429 fbFetch_x4a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
430 {
431     const uint32_t *bits = pict->bits + y*pict->rowstride;
432     const uint8_t *pixel = (const uint8_t *)bits + x;
433     const uint8_t *end = pixel + width;
434     while (pixel < end) {
435         uint8_t p = READ(pict, pixel++) & 0xf;
436         *buffer++ = (p | (p << 4)) << 24;
437     }
438 }
439
440 #define Fetch8(img,l,o)    (READ(img, (uint8_t *)(l) + ((o) >> 2)))
441 #if IMAGE_BYTE_ORDER == MSBFirst
442 #define Fetch4(img,l,o)    ((o) & 2 ? Fetch8(img,l,o) & 0xf : Fetch8(img,l,o) >> 4)
443 #else
444 #define Fetch4(img,l,o)    ((o) & 2 ? Fetch8(img,l,o) >> 4 : Fetch8(img,l,o) & 0xf)
445 #endif
446
447 static FASTCALL void
448 fbFetch_a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
449 {
450     const uint32_t *bits = pict->bits + y*pict->rowstride;
451     int i;
452     for (i = 0; i < width; ++i) {
453         uint32_t  p = Fetch4(pict, bits, i + x);
454
455         p |= p << 4;
456         *buffer++ = p << 24;
457     }
458 }
459
460 static FASTCALL void
461 fbFetch_r1g2b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
462 {
463     uint32_t  r,g,b;
464     const uint32_t *bits = pict->bits + y*pict->rowstride;
465     int i;
466     for (i = 0; i < width; ++i) {
467         uint32_t  p = Fetch4(pict, bits, i + x);
468
469         r = ((p & 0x8) * 0xff) << 13;
470         g = ((p & 0x6) * 0x55) << 7;
471         b = ((p & 0x1) * 0xff);
472         *buffer++ = 0xff000000|r|g|b;
473     }
474 }
475
476 static FASTCALL void
477 fbFetch_b1g2r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
478 {
479     uint32_t  r,g,b;
480     const uint32_t *bits = pict->bits + y*pict->rowstride;
481     int i;
482     for (i = 0; i < width; ++i) {
483         uint32_t  p = Fetch4(pict, bits, i + x);
484
485         b = ((p & 0x8) * 0xff) >> 3;
486         g = ((p & 0x6) * 0x55) << 7;
487         r = ((p & 0x1) * 0xff) << 16;
488         *buffer++ = 0xff000000|r|g|b;
489     }
490 }
491
492 static FASTCALL void
493 fbFetch_a1r1g1b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
494 {
495     uint32_t  a,r,g,b;
496     const uint32_t *bits = pict->bits + y*pict->rowstride;
497     int i;
498     for (i = 0; i < width; ++i) {
499         uint32_t  p = Fetch4(pict, bits, i + x);
500
501         a = ((p & 0x8) * 0xff) << 21;
502         r = ((p & 0x4) * 0xff) << 14;
503         g = ((p & 0x2) * 0xff) << 7;
504         b = ((p & 0x1) * 0xff);
505         *buffer++ = a|r|g|b;
506     }
507 }
508
509 static FASTCALL void
510 fbFetch_a1b1g1r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
511 {
512     uint32_t  a,r,g,b;
513     const uint32_t *bits = pict->bits + y*pict->rowstride;
514     int i;
515     for (i = 0; i < width; ++i) {
516         uint32_t  p = Fetch4(pict, bits, i + x);
517
518         a = ((p & 0x8) * 0xff) << 21;
519         r = ((p & 0x4) * 0xff) >> 3;
520         g = ((p & 0x2) * 0xff) << 7;
521         b = ((p & 0x1) * 0xff) << 16;
522         *buffer++ = a|r|g|b;
523     }
524 }
525
526 static FASTCALL void
527 fbFetch_c4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
528 {
529     const uint32_t *bits = pict->bits + y*pict->rowstride;
530     const pixman_indexed_t * indexed = pict->indexed;
531     int i;
532     for (i = 0; i < width; ++i) {
533         uint32_t  p = Fetch4(pict, bits, i + x);
534
535         *buffer++ = indexed->rgba[p];
536     }
537 }
538
539
540 static FASTCALL void
541 fbFetch_a1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
542 {
543     const uint32_t *bits = pict->bits + y*pict->rowstride;
544     int i;
545     for (i = 0; i < width; ++i) {
546         uint32_t  p = READ(pict, bits + ((i + x) >> 5));
547         uint32_t  a;
548 #if BITMAP_BIT_ORDER == MSBFirst
549         a = p >> (0x1f - ((i+x) & 0x1f));
550 #else
551         a = p >> ((i+x) & 0x1f);
552 #endif
553         a = a & 1;
554         a |= a << 1;
555         a |= a << 2;
556         a |= a << 4;
557         *buffer++ = a << 24;
558     }
559 }
560
561 static FASTCALL void
562 fbFetch_g1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
563 {
564     const uint32_t *bits = pict->bits + y*pict->rowstride;
565     const pixman_indexed_t * indexed = pict->indexed;
566     int i;
567     for (i = 0; i < width; ++i) {
568         uint32_t p = READ(pict, bits + ((i+x) >> 5));
569         uint32_t a;
570 #if BITMAP_BIT_ORDER == MSBFirst
571         a = p >> (0x1f - ((i+x) & 0x1f));
572 #else
573         a = p >> ((i+x) & 0x1f);
574 #endif
575         a = a & 1;
576         *buffer++ = indexed->rgba[a];
577     }
578 }
579
580 static FASTCALL void
581 fbFetch_yuy2 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
582 {
583     int16_t y, u, v;
584     int32_t r, g, b;
585     int   i;
586
587     const uint32_t *bits = pict->bits + pict->rowstride * line;
588
589     for (i = 0; i < width; i++)
590     {
591         y = ((uint8_t *) bits)[(x + i) << 1] - 16;
592         u = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 1] - 128;
593         v = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 3] - 128;
594
595         /* R = 1.164(Y - 16) + 1.596(V - 128) */
596         r = 0x012b27 * y + 0x019a2e * v;
597         /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
598         g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
599         /* B = 1.164(Y - 16) + 2.018(U - 128) */
600         b = 0x012b27 * y + 0x0206a2 * u;
601
602     WRITE(pict, buffer++, 0xff000000 |
603         (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
604         (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
605         (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
606     }
607 }
608
609 static FASTCALL void
610 fbFetch_yv12 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
611 {
612     YV12_SETUP(pict);
613     uint8_t *pY = YV12_Y (line);
614     uint8_t *pU = YV12_U (line);
615     uint8_t *pV = YV12_V (line);
616     int16_t y, u, v;
617     int32_t r, g, b;
618     int   i;
619
620     for (i = 0; i < width; i++)
621     {
622         y = pY[x + i] - 16;
623         u = pU[(x + i) >> 1] - 128;
624         v = pV[(x + i) >> 1] - 128;
625
626         /* R = 1.164(Y - 16) + 1.596(V - 128) */
627         r = 0x012b27 * y + 0x019a2e * v;
628         /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
629         g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
630         /* B = 1.164(Y - 16) + 2.018(U - 128) */
631         b = 0x012b27 * y + 0x0206a2 * u;
632
633         WRITE(pict, buffer++, 0xff000000 |
634             (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
635             (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
636             (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
637     }
638 }
639
640 fetchProc32 ACCESS(pixman_fetchProcForPicture32) (bits_image_t * pict)
641 {
642     switch(pict->format) {
643     case PIXMAN_a8r8g8b8: return fbFetch_a8r8g8b8;
644     case PIXMAN_x8r8g8b8: return fbFetch_x8r8g8b8;
645     case PIXMAN_a8b8g8r8: return fbFetch_a8b8g8r8;
646     case PIXMAN_x8b8g8r8: return fbFetch_x8b8g8r8;
647
648         /* 24bpp formats */
649     case PIXMAN_r8g8b8: return fbFetch_r8g8b8;
650     case PIXMAN_b8g8r8: return fbFetch_b8g8r8;
651
652         /* 16bpp formats */
653     case PIXMAN_r5g6b5: return fbFetch_r5g6b5;
654     case PIXMAN_b5g6r5: return fbFetch_b5g6r5;
655
656     case PIXMAN_a1r5g5b5: return fbFetch_a1r5g5b5;
657     case PIXMAN_x1r5g5b5: return fbFetch_x1r5g5b5;
658     case PIXMAN_a1b5g5r5: return fbFetch_a1b5g5r5;
659     case PIXMAN_x1b5g5r5: return fbFetch_x1b5g5r5;
660     case PIXMAN_a4r4g4b4: return fbFetch_a4r4g4b4;
661     case PIXMAN_x4r4g4b4: return fbFetch_x4r4g4b4;
662     case PIXMAN_a4b4g4r4: return fbFetch_a4b4g4r4;
663     case PIXMAN_x4b4g4r4: return fbFetch_x4b4g4r4;
664
665         /* 8bpp formats */
666     case PIXMAN_a8: return  fbFetch_a8;
667     case PIXMAN_r3g3b2: return fbFetch_r3g3b2;
668     case PIXMAN_b2g3r3: return fbFetch_b2g3r3;
669     case PIXMAN_a2r2g2b2: return fbFetch_a2r2g2b2;
670     case PIXMAN_a2b2g2r2: return fbFetch_a2b2g2r2;
671     case PIXMAN_c8: return  fbFetch_c8;
672     case PIXMAN_g8: return  fbFetch_c8;
673     case PIXMAN_x4a4: return fbFetch_x4a4;
674
675         /* 4bpp formats */
676     case PIXMAN_a4: return  fbFetch_a4;
677     case PIXMAN_r1g2b1: return fbFetch_r1g2b1;
678     case PIXMAN_b1g2r1: return fbFetch_b1g2r1;
679     case PIXMAN_a1r1g1b1: return fbFetch_a1r1g1b1;
680     case PIXMAN_a1b1g1r1: return fbFetch_a1b1g1r1;
681     case PIXMAN_c4: return  fbFetch_c4;
682     case PIXMAN_g4: return  fbFetch_c4;
683
684         /* 1bpp formats */
685     case PIXMAN_a1: return  fbFetch_a1;
686     case PIXMAN_g1: return  fbFetch_g1;
687
688         /* YUV formats */
689     case PIXMAN_yuy2: return fbFetch_yuy2;
690     case PIXMAN_yv12: return fbFetch_yv12;
691     }
692
693     return NULL;
694 }
695
696 /**************************** Pixel wise fetching *****************************/
697
698 static FASTCALL uint32_t
699 fbFetchPixel_a8r8g8b8 (bits_image_t *pict, int offset, int line)
700 {
701     uint32_t *bits = pict->bits + line*pict->rowstride;
702     return READ(pict, (uint32_t *)bits + offset);
703 }
704
705 static FASTCALL uint32_t
706 fbFetchPixel_x8r8g8b8 (bits_image_t *pict, int offset, int line)
707 {
708     uint32_t *bits = pict->bits + line*pict->rowstride;
709     return READ(pict, (uint32_t *)bits + offset) | 0xff000000;
710 }
711
712 static FASTCALL uint32_t
713 fbFetchPixel_a8b8g8r8 (bits_image_t *pict, int offset, int line)
714 {
715     uint32_t *bits = pict->bits + line*pict->rowstride;
716     uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
717
718     return ((pixel & 0xff000000) |
719             ((pixel >> 16) & 0xff) |
720             (pixel & 0x0000ff00) |
721             ((pixel & 0xff) << 16));
722 }
723
724 static FASTCALL uint32_t
725 fbFetchPixel_x8b8g8r8 (bits_image_t *pict, int offset, int line)
726 {
727     uint32_t *bits = pict->bits + line*pict->rowstride;
728     uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
729
730     return ((0xff000000) |
731             ((pixel >> 16) & 0xff) |
732             (pixel & 0x0000ff00) |
733             ((pixel & 0xff) << 16));
734 }
735
736 static FASTCALL uint32_t
737 fbFetchPixel_r8g8b8 (bits_image_t *pict, int offset, int line)
738 {
739     uint32_t *bits = pict->bits + line*pict->rowstride;
740     uint8_t   *pixel = ((uint8_t *) bits) + (offset*3);
741 #if IMAGE_BYTE_ORDER == MSBFirst
742     return (0xff000000 |
743             (READ(pict, pixel + 0) << 16) |
744             (READ(pict, pixel + 1) << 8) |
745             (READ(pict, pixel + 2)));
746 #else
747     return (0xff000000 |
748             (READ(pict, pixel + 2) << 16) |
749             (READ(pict, pixel + 1) << 8) |
750             (READ(pict, pixel + 0)));
751 #endif
752 }
753
754 static FASTCALL uint32_t
755 fbFetchPixel_b8g8r8 (bits_image_t *pict, int offset, int line)
756 {
757     uint32_t *bits = pict->bits + line*pict->rowstride;
758     uint8_t   *pixel = ((uint8_t *) bits) + (offset*3);
759 #if IMAGE_BYTE_ORDER == MSBFirst
760     return (0xff000000 |
761             (READ(pict, pixel + 2) << 16) |
762             (READ(pict, pixel + 1) << 8) |
763             (READ(pict, pixel + 0)));
764 #else
765     return (0xff000000 |
766             (READ(pict, pixel + 0) << 16) |
767             (READ(pict, pixel + 1) << 8) |
768             (READ(pict, pixel + 2)));
769 #endif
770 }
771
772 static FASTCALL uint32_t
773 fbFetchPixel_r5g6b5 (bits_image_t *pict, int offset, int line)
774 {
775     uint32_t  r,g,b;
776     uint32_t *bits = pict->bits + line*pict->rowstride;
777     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
778
779     r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
780     g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
781     b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
782     return (0xff000000 | r | g | b);
783 }
784
785 static FASTCALL uint32_t
786 fbFetchPixel_b5g6r5 (bits_image_t *pict, int offset, int line)
787 {
788     uint32_t  r,g,b;
789     uint32_t *bits = pict->bits + line*pict->rowstride;
790     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
791
792     b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
793     g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
794     r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
795     return (0xff000000 | r | g | b);
796 }
797
798 static FASTCALL uint32_t
799 fbFetchPixel_a1r5g5b5 (bits_image_t *pict, int offset, int line)
800 {
801     uint32_t  a,r,g,b;
802     uint32_t *bits = pict->bits + line*pict->rowstride;
803     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
804
805     a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
806     r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
807     g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
808     b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
809     return (a | r | g | b);
810 }
811
812 static FASTCALL uint32_t
813 fbFetchPixel_x1r5g5b5 (bits_image_t *pict, int offset, int line)
814 {
815     uint32_t  r,g,b;
816     uint32_t *bits = pict->bits + line*pict->rowstride;
817     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
818
819     r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
820     g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
821     b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
822     return (0xff000000 | r | g | b);
823 }
824
825 static FASTCALL uint32_t
826 fbFetchPixel_a1b5g5r5 (bits_image_t *pict, int offset, int line)
827 {
828     uint32_t  a,r,g,b;
829     uint32_t *bits = pict->bits + line*pict->rowstride;
830     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
831
832     a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
833     b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
834     g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
835     r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
836     return (a | r | g | b);
837 }
838
839 static FASTCALL uint32_t
840 fbFetchPixel_x1b5g5r5 (bits_image_t *pict, int offset, int line)
841 {
842     uint32_t  r,g,b;
843     uint32_t *bits = pict->bits + line*pict->rowstride;
844     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
845
846     b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
847     g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
848     r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
849     return (0xff000000 | r | g | b);
850 }
851
852 static FASTCALL uint32_t
853 fbFetchPixel_a4r4g4b4 (bits_image_t *pict, int offset, int line)
854 {
855     uint32_t  a,r,g,b;
856     uint32_t *bits = pict->bits + line*pict->rowstride;
857     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
858
859     a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
860     r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
861     g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
862     b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
863     return (a | r | g | b);
864 }
865
866 static FASTCALL uint32_t
867 fbFetchPixel_x4r4g4b4 (bits_image_t *pict, int offset, int line)
868 {
869     uint32_t  r,g,b;
870     uint32_t *bits = pict->bits + line*pict->rowstride;
871     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
872
873     r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
874     g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
875     b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
876     return (0xff000000 | r | g | b);
877 }
878
879 static FASTCALL uint32_t
880 fbFetchPixel_a4b4g4r4 (bits_image_t *pict, int offset, int line)
881 {
882     uint32_t  a,r,g,b;
883     uint32_t *bits = pict->bits + line*pict->rowstride;
884     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
885
886     a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
887     b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
888     g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
889     r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
890     return (a | r | g | b);
891 }
892
893 static FASTCALL uint32_t
894 fbFetchPixel_x4b4g4r4 (bits_image_t *pict, int offset, int line)
895 {
896     uint32_t  r,g,b;
897     uint32_t *bits = pict->bits + line*pict->rowstride;
898     uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
899
900     b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
901     g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
902     r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
903     return (0xff000000 | r | g | b);
904 }
905
906 static FASTCALL uint32_t
907 fbFetchPixel_a8 (bits_image_t *pict, int offset, int line)
908 {
909     uint32_t *bits = pict->bits + line*pict->rowstride;
910     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
911
912     return pixel << 24;
913 }
914
915 static FASTCALL uint32_t
916 fbFetchPixel_r3g3b2 (bits_image_t *pict, int offset, int line)
917 {
918     uint32_t  r,g,b;
919     uint32_t *bits = pict->bits + line*pict->rowstride;
920     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
921
922     r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16;
923     g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8;
924     b = (((pixel & 0x03)     ) |
925          ((pixel & 0x03) << 2) |
926          ((pixel & 0x03) << 4) |
927          ((pixel & 0x03) << 6));
928     return (0xff000000 | r | g | b);
929 }
930
931 static FASTCALL uint32_t
932 fbFetchPixel_b2g3r3 (bits_image_t *pict, int offset, int line)
933 {
934     uint32_t  r,g,b;
935     uint32_t *bits = pict->bits + line*pict->rowstride;
936     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
937
938     b = (((pixel & 0xc0)     ) |
939          ((pixel & 0xc0) >> 2) |
940          ((pixel & 0xc0) >> 4) |
941          ((pixel & 0xc0) >> 6));
942     g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8;
943     r = (((pixel & 0x07)     ) |
944          ((pixel & 0x07) << 3) |
945          ((pixel & 0x06) << 6)) << 16;
946     return (0xff000000 | r | g | b);
947 }
948
949 static FASTCALL uint32_t
950 fbFetchPixel_a2r2g2b2 (bits_image_t *pict, int offset, int line)
951 {
952     uint32_t   a,r,g,b;
953     uint32_t *bits = pict->bits + line*pict->rowstride;
954     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
955
956     a = ((pixel & 0xc0) * 0x55) << 18;
957     r = ((pixel & 0x30) * 0x55) << 12;
958     g = ((pixel & 0x0c) * 0x55) << 6;
959     b = ((pixel & 0x03) * 0x55);
960     return a|r|g|b;
961 }
962
963 static FASTCALL uint32_t
964 fbFetchPixel_a2b2g2r2 (bits_image_t *pict, int offset, int line)
965 {
966     uint32_t   a,r,g,b;
967     uint32_t *bits = pict->bits + line*pict->rowstride;
968     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
969
970     a = ((pixel & 0xc0) * 0x55) << 18;
971     b = ((pixel & 0x30) * 0x55) >> 6;
972     g = ((pixel & 0x0c) * 0x55) << 6;
973     r = ((pixel & 0x03) * 0x55) << 16;
974     return a|r|g|b;
975 }
976
977 static FASTCALL uint32_t
978 fbFetchPixel_c8 (bits_image_t *pict, int offset, int line)
979 {
980     uint32_t *bits = pict->bits + line*pict->rowstride;
981     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
982     const pixman_indexed_t * indexed = pict->indexed;
983     return indexed->rgba[pixel];
984 }
985
986 static FASTCALL uint32_t
987 fbFetchPixel_x4a4 (bits_image_t *pict, int offset, int line)
988 {
989     uint32_t *bits = pict->bits + line*pict->rowstride;
990     uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
991
992     return ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
993 }
994
995 static FASTCALL uint32_t
996 fbFetchPixel_a4 (bits_image_t *pict, int offset, int line)
997 {
998     uint32_t *bits = pict->bits + line*pict->rowstride;
999     uint32_t  pixel = Fetch4(pict, bits, offset);
1000
1001     pixel |= pixel << 4;
1002     return pixel << 24;
1003 }
1004
1005 static FASTCALL uint32_t
1006 fbFetchPixel_r1g2b1 (bits_image_t *pict, int offset, int line)
1007 {
1008     uint32_t  r,g,b;
1009     uint32_t *bits = pict->bits + line*pict->rowstride;
1010     uint32_t  pixel = Fetch4(pict, bits, offset);
1011
1012     r = ((pixel & 0x8) * 0xff) << 13;
1013     g = ((pixel & 0x6) * 0x55) << 7;
1014     b = ((pixel & 0x1) * 0xff);
1015     return 0xff000000|r|g|b;
1016 }
1017
1018 static FASTCALL uint32_t
1019 fbFetchPixel_b1g2r1 (bits_image_t *pict, int offset, int line)
1020 {
1021     uint32_t  r,g,b;
1022     uint32_t *bits = pict->bits + line*pict->rowstride;
1023     uint32_t  pixel = Fetch4(pict, bits, offset);
1024
1025     b = ((pixel & 0x8) * 0xff) >> 3;
1026     g = ((pixel & 0x6) * 0x55) << 7;
1027     r = ((pixel & 0x1) * 0xff) << 16;
1028     return 0xff000000|r|g|b;
1029 }
1030
1031 static FASTCALL uint32_t
1032 fbFetchPixel_a1r1g1b1 (bits_image_t *pict, int offset, int line)
1033 {
1034     uint32_t  a,r,g,b;
1035     uint32_t *bits = pict->bits + line*pict->rowstride;
1036     uint32_t  pixel = Fetch4(pict, bits, offset);
1037
1038     a = ((pixel & 0x8) * 0xff) << 21;
1039     r = ((pixel & 0x4) * 0xff) << 14;
1040     g = ((pixel & 0x2) * 0xff) << 7;
1041     b = ((pixel & 0x1) * 0xff);
1042     return a|r|g|b;
1043 }
1044
1045 static FASTCALL uint32_t
1046 fbFetchPixel_a1b1g1r1 (bits_image_t *pict, int offset, int line)
1047 {
1048     uint32_t  a,r,g,b;
1049     uint32_t *bits = pict->bits + line*pict->rowstride;
1050     uint32_t  pixel = Fetch4(pict, bits, offset);
1051
1052     a = ((pixel & 0x8) * 0xff) << 21;
1053     r = ((pixel & 0x4) * 0xff) >> 3;
1054     g = ((pixel & 0x2) * 0xff) << 7;
1055     b = ((pixel & 0x1) * 0xff) << 16;
1056     return a|r|g|b;
1057 }
1058
1059 static FASTCALL uint32_t
1060 fbFetchPixel_c4 (bits_image_t *pict, int offset, int line)
1061 {
1062     uint32_t *bits = pict->bits + line*pict->rowstride;
1063     uint32_t  pixel = Fetch4(pict, bits, offset);
1064     const pixman_indexed_t * indexed = pict->indexed;
1065
1066     return indexed->rgba[pixel];
1067 }
1068
1069
1070 static FASTCALL uint32_t
1071 fbFetchPixel_a1 (bits_image_t *pict, int offset, int line)
1072 {
1073     uint32_t *bits = pict->bits + line*pict->rowstride;
1074     uint32_t  pixel = READ(pict, bits + (offset >> 5));
1075     uint32_t  a;
1076 #if BITMAP_BIT_ORDER == MSBFirst
1077     a = pixel >> (0x1f - (offset & 0x1f));
1078 #else
1079     a = pixel >> (offset & 0x1f);
1080 #endif
1081     a = a & 1;
1082     a |= a << 1;
1083     a |= a << 2;
1084     a |= a << 4;
1085     return a << 24;
1086 }
1087
1088 static FASTCALL uint32_t
1089 fbFetchPixel_g1 (bits_image_t *pict, int offset, int line)
1090 {
1091     uint32_t *bits = pict->bits + line*pict->rowstride;
1092     uint32_t pixel = READ(pict, bits + (offset >> 5));
1093     const pixman_indexed_t * indexed = pict->indexed;
1094     uint32_t a;
1095 #if BITMAP_BIT_ORDER == MSBFirst
1096     a = pixel >> (0x1f - (offset & 0x1f));
1097 #else
1098     a = pixel >> (offset & 0x1f);
1099 #endif
1100     a = a & 1;
1101     return indexed->rgba[a];
1102 }
1103
1104 static FASTCALL uint32_t
1105 fbFetchPixel_yuy2 (bits_image_t *pict, int offset, int line)
1106 {
1107     int16_t y, u, v;
1108     int32_t r, g, b;
1109
1110     const uint32_t *bits = pict->bits + pict->rowstride * line;
1111
1112     y = ((uint8_t *) bits)[offset << 1] - 16;
1113     u = ((uint8_t *) bits)[((offset << 1) & -4) + 1] - 128;
1114     v = ((uint8_t *) bits)[((offset << 1) & -4) + 3] - 128;
1115
1116     /* R = 1.164(Y - 16) + 1.596(V - 128) */
1117     r = 0x012b27 * y + 0x019a2e * v;
1118     /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1119     g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1120     /* B = 1.164(Y - 16) + 2.018(U - 128) */
1121     b = 0x012b27 * y + 0x0206a2 * u;
1122
1123     return 0xff000000 |
1124         (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
1125         (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
1126         (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1127 }
1128
1129 static FASTCALL uint32_t
1130 fbFetchPixel_yv12 (bits_image_t *pict, int offset, int line)
1131 {
1132     YV12_SETUP(pict);
1133     int16_t y = YV12_Y (line)[offset] - 16;
1134     int16_t u = YV12_U (line)[offset >> 1] - 128;
1135     int16_t v = YV12_V (line)[offset >> 1] - 128;
1136     int32_t r, g, b;
1137
1138     /* R = 1.164(Y - 16) + 1.596(V - 128) */
1139     r = 0x012b27 * y + 0x019a2e * v;
1140     /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1141     g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1142     /* B = 1.164(Y - 16) + 2.018(U - 128) */
1143     b = 0x012b27 * y + 0x0206a2 * u;
1144
1145     return 0xff000000 |
1146         (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
1147         (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
1148         (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1149 }
1150
1151 fetchPixelProc32 ACCESS(pixman_fetchPixelProcForPicture32) (bits_image_t * pict)
1152 {
1153     switch(pict->format) {
1154     case PIXMAN_a8r8g8b8: return fbFetchPixel_a8r8g8b8;
1155     case PIXMAN_x8r8g8b8: return fbFetchPixel_x8r8g8b8;
1156     case PIXMAN_a8b8g8r8: return fbFetchPixel_a8b8g8r8;
1157     case PIXMAN_x8b8g8r8: return fbFetchPixel_x8b8g8r8;
1158
1159         /* 24bpp formats */
1160     case PIXMAN_r8g8b8: return fbFetchPixel_r8g8b8;
1161     case PIXMAN_b8g8r8: return fbFetchPixel_b8g8r8;
1162
1163         /* 16bpp formats */
1164     case PIXMAN_r5g6b5: return fbFetchPixel_r5g6b5;
1165     case PIXMAN_b5g6r5: return fbFetchPixel_b5g6r5;
1166
1167     case PIXMAN_a1r5g5b5: return fbFetchPixel_a1r5g5b5;
1168     case PIXMAN_x1r5g5b5: return fbFetchPixel_x1r5g5b5;
1169     case PIXMAN_a1b5g5r5: return fbFetchPixel_a1b5g5r5;
1170     case PIXMAN_x1b5g5r5: return fbFetchPixel_x1b5g5r5;
1171     case PIXMAN_a4r4g4b4: return fbFetchPixel_a4r4g4b4;
1172     case PIXMAN_x4r4g4b4: return fbFetchPixel_x4r4g4b4;
1173     case PIXMAN_a4b4g4r4: return fbFetchPixel_a4b4g4r4;
1174     case PIXMAN_x4b4g4r4: return fbFetchPixel_x4b4g4r4;
1175
1176         /* 8bpp formats */
1177     case PIXMAN_a8: return  fbFetchPixel_a8;
1178     case PIXMAN_r3g3b2: return fbFetchPixel_r3g3b2;
1179     case PIXMAN_b2g3r3: return fbFetchPixel_b2g3r3;
1180     case PIXMAN_a2r2g2b2: return fbFetchPixel_a2r2g2b2;
1181     case PIXMAN_a2b2g2r2: return fbFetchPixel_a2b2g2r2;
1182     case PIXMAN_c8: return  fbFetchPixel_c8;
1183     case PIXMAN_g8: return  fbFetchPixel_c8;
1184     case PIXMAN_x4a4: return fbFetchPixel_x4a4;
1185
1186         /* 4bpp formats */
1187     case PIXMAN_a4: return  fbFetchPixel_a4;
1188     case PIXMAN_r1g2b1: return fbFetchPixel_r1g2b1;
1189     case PIXMAN_b1g2r1: return fbFetchPixel_b1g2r1;
1190     case PIXMAN_a1r1g1b1: return fbFetchPixel_a1r1g1b1;
1191     case PIXMAN_a1b1g1r1: return fbFetchPixel_a1b1g1r1;
1192     case PIXMAN_c4: return  fbFetchPixel_c4;
1193     case PIXMAN_g4: return  fbFetchPixel_c4;
1194
1195         /* 1bpp formats */
1196     case PIXMAN_a1: return  fbFetchPixel_a1;
1197     case PIXMAN_g1: return  fbFetchPixel_g1;
1198
1199         /* YUV formats */
1200     case PIXMAN_yuy2: return fbFetchPixel_yuy2;
1201     case PIXMAN_yv12: return fbFetchPixel_yv12;
1202     }
1203
1204     return NULL;
1205 }
1206
1207 /*********************************** Store ************************************/
1208
1209 #define Splita(v)       uint32_t        a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1210 #define Split(v)        uint32_t        r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1211
1212 static FASTCALL void
1213 fbStore_a8r8g8b8 (pixman_image_t *image,
1214                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1215 {
1216     MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
1217 }
1218
1219 static FASTCALL void
1220 fbStore_x8r8g8b8 (pixman_image_t *image,
1221                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1222 {
1223     int i;
1224     uint32_t *pixel = (uint32_t *)bits + x;
1225     for (i = 0; i < width; ++i)
1226         WRITE(image, pixel++, values[i] & 0xffffff);
1227 }
1228
1229 static FASTCALL void
1230 fbStore_a8b8g8r8 (pixman_image_t *image,
1231                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1232 {
1233     int i;
1234     uint32_t *pixel = (uint32_t *)bits + x;
1235     for (i = 0; i < width; ++i)
1236         WRITE(image, pixel++, (values[i] & 0xff00ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1237 }
1238
1239 static FASTCALL void
1240 fbStore_x8b8g8r8 (pixman_image_t *image,
1241                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1242 {
1243     int i;
1244     uint32_t *pixel = (uint32_t *)bits + x;
1245     for (i = 0; i < width; ++i)
1246         WRITE(image, pixel++, (values[i] & 0x0000ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1247 }
1248
1249 static FASTCALL void
1250 fbStore_r8g8b8 (pixman_image_t *image,
1251                 uint32_t *bits, const uint32_t *values, int x, int width,
1252                 const pixman_indexed_t * indexed)
1253 {
1254     int i;
1255     uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1256     for (i = 0; i < width; ++i) {
1257         Store24(image, pixel, values[i]);
1258         pixel += 3;
1259     }
1260 }
1261
1262 static FASTCALL void
1263 fbStore_b8g8r8 (pixman_image_t *image,
1264                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1265 {
1266     int i;
1267     uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1268     for (i = 0; i < width; ++i) {
1269         uint32_t val = values[i];
1270 #if IMAGE_BYTE_ORDER == MSBFirst
1271         WRITE(image, pixel++, Blue(val));
1272         WRITE(image, pixel++, Green(val));
1273         WRITE(image, pixel++, Red(val));
1274 #else
1275         WRITE(image, pixel++, Red(val));
1276         WRITE(image, pixel++, Green(val));
1277         WRITE(image, pixel++, Blue(val));
1278 #endif
1279     }
1280 }
1281
1282 static FASTCALL void
1283 fbStore_r5g6b5 (pixman_image_t *image,
1284                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1285 {
1286     int i;
1287     uint16_t *pixel = ((uint16_t *) bits) + x;
1288     for (i = 0; i < width; ++i) {
1289         uint32_t s = values[i];
1290         WRITE(image, pixel++, ((s >> 3) & 0x001f) |
1291               ((s >> 5) & 0x07e0) |
1292               ((s >> 8) & 0xf800));
1293     }
1294 }
1295
1296 static FASTCALL void
1297 fbStore_b5g6r5 (pixman_image_t *image,
1298                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1299 {
1300     int i;
1301     uint16_t  *pixel = ((uint16_t *) bits) + x;
1302     for (i = 0; i < width; ++i) {
1303         Split(values[i]);
1304         WRITE(image, pixel++, ((b << 8) & 0xf800) |
1305               ((g << 3) & 0x07e0) |
1306               ((r >> 3)         ));
1307     }
1308 }
1309
1310 static FASTCALL void
1311 fbStore_a1r5g5b5 (pixman_image_t *image,
1312                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1313 {
1314     int i;
1315     uint16_t  *pixel = ((uint16_t *) bits) + x;
1316     for (i = 0; i < width; ++i) {
1317         Splita(values[i]);
1318         WRITE(image, pixel++, ((a << 8) & 0x8000) |
1319               ((r << 7) & 0x7c00) |
1320               ((g << 2) & 0x03e0) |
1321               ((b >> 3)         ));
1322     }
1323 }
1324
1325 static FASTCALL void
1326 fbStore_x1r5g5b5 (pixman_image_t *image,
1327                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1328 {
1329     int i;
1330     uint16_t  *pixel = ((uint16_t *) bits) + x;
1331     for (i = 0; i < width; ++i) {
1332         Split(values[i]);
1333         WRITE(image, pixel++, ((r << 7) & 0x7c00) |
1334               ((g << 2) & 0x03e0) |
1335               ((b >> 3)         ));
1336     }
1337 }
1338
1339 static FASTCALL void
1340 fbStore_a1b5g5r5 (pixman_image_t *image,
1341                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1342 {
1343     int i;
1344     uint16_t  *pixel = ((uint16_t *) bits) + x;
1345     for (i = 0; i < width; ++i) {
1346         Splita(values[i]);
1347         WRITE(image, pixel++, ((a << 8) & 0x8000) |
1348               ((b << 7) & 0x7c00) |
1349               ((g << 2) & 0x03e0) |
1350               ((r >> 3)         ));
1351     }
1352 }
1353
1354 static FASTCALL void
1355 fbStore_x1b5g5r5 (pixman_image_t *image,
1356                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1357 {
1358     int i;
1359     uint16_t  *pixel = ((uint16_t *) bits) + x;
1360     for (i = 0; i < width; ++i) {
1361         Split(values[i]);
1362         WRITE(image, pixel++, ((b << 7) & 0x7c00) |
1363               ((g << 2) & 0x03e0) |
1364               ((r >> 3)         ));
1365     }
1366 }
1367
1368 static FASTCALL void
1369 fbStore_a4r4g4b4 (pixman_image_t *image,
1370                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1371 {
1372     int i;
1373     uint16_t  *pixel = ((uint16_t *) bits) + x;
1374     for (i = 0; i < width; ++i) {
1375         Splita(values[i]);
1376         WRITE(image, pixel++, ((a << 8) & 0xf000) |
1377               ((r << 4) & 0x0f00) |
1378               ((g     ) & 0x00f0) |
1379               ((b >> 4)         ));
1380     }
1381 }
1382
1383 static FASTCALL void
1384 fbStore_x4r4g4b4 (pixman_image_t *image,
1385                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1386 {
1387     int i;
1388     uint16_t  *pixel = ((uint16_t *) bits) + x;
1389     for (i = 0; i < width; ++i) {
1390         Split(values[i]);
1391         WRITE(image, pixel++, ((r << 4) & 0x0f00) |
1392               ((g     ) & 0x00f0) |
1393               ((b >> 4)         ));
1394     }
1395 }
1396
1397 static FASTCALL void
1398 fbStore_a4b4g4r4 (pixman_image_t *image,
1399                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1400 {
1401     int i;
1402     uint16_t  *pixel = ((uint16_t *) bits) + x;
1403     for (i = 0; i < width; ++i) {
1404         Splita(values[i]);
1405         WRITE(image, pixel++, ((a << 8) & 0xf000) |
1406               ((b << 4) & 0x0f00) |
1407               ((g     ) & 0x00f0) |
1408               ((r >> 4)         ));
1409     }
1410 }
1411
1412 static FASTCALL void
1413 fbStore_x4b4g4r4 (pixman_image_t *image,
1414                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1415 {
1416     int i;
1417     uint16_t  *pixel = ((uint16_t *) bits) + x;
1418     for (i = 0; i < width; ++i) {
1419         Split(values[i]);
1420         WRITE(image, pixel++, ((b << 4) & 0x0f00) |
1421               ((g     ) & 0x00f0) |
1422               ((r >> 4)         ));
1423     }
1424 }
1425
1426 static FASTCALL void
1427 fbStore_a8 (pixman_image_t *image,
1428             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1429 {
1430     int i;
1431     uint8_t   *pixel = ((uint8_t *) bits) + x;
1432     for (i = 0; i < width; ++i) {
1433         WRITE(image, pixel++, values[i] >> 24);
1434     }
1435 }
1436
1437 static FASTCALL void
1438 fbStore_r3g3b2 (pixman_image_t *image,
1439                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1440 {
1441     int i;
1442     uint8_t   *pixel = ((uint8_t *) bits) + x;
1443     for (i = 0; i < width; ++i) {
1444         Split(values[i]);
1445         WRITE(image, pixel++,
1446               ((r     ) & 0xe0) |
1447               ((g >> 3) & 0x1c) |
1448               ((b >> 6)       ));
1449     }
1450 }
1451
1452 static FASTCALL void
1453 fbStore_b2g3r3 (pixman_image_t *image,
1454                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1455 {
1456     int i;
1457     uint8_t   *pixel = ((uint8_t *) bits) + x;
1458     for (i = 0; i < width; ++i) {
1459         Split(values[i]);
1460         WRITE(image, pixel++,
1461               ((b     ) & 0xc0) |
1462               ((g >> 2) & 0x38) |
1463               ((r >> 5)       ));
1464     }
1465 }
1466
1467 static FASTCALL void
1468 fbStore_a2r2g2b2 (pixman_image_t *image,
1469                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1470 {
1471     int i;
1472     uint8_t   *pixel = ((uint8_t *) bits) + x;
1473     for (i = 0; i < width; ++i) {
1474         Splita(values[i]);
1475         WRITE(image, pixel++, ((a     ) & 0xc0) |
1476               ((r >> 2) & 0x30) |
1477               ((g >> 4) & 0x0c) |
1478               ((b >> 6)       ));
1479     }
1480 }
1481
1482 static FASTCALL void
1483 fbStore_c8 (pixman_image_t *image,
1484             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1485 {
1486     int i;
1487     uint8_t   *pixel = ((uint8_t *) bits) + x;
1488     for (i = 0; i < width; ++i) {
1489         WRITE(image, pixel++, miIndexToEnt24(indexed,values[i]));
1490     }
1491 }
1492
1493 static FASTCALL void
1494 fbStore_x4a4 (pixman_image_t *image,
1495               uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1496 {
1497     int i;
1498     uint8_t   *pixel = ((uint8_t *) bits) + x;
1499     for (i = 0; i < width; ++i) {
1500         WRITE(image, pixel++, values[i] >> 28);
1501     }
1502 }
1503
1504 #define Store8(img,l,o,v)  (WRITE(img, (uint8_t *)(l) + ((o) >> 3), (v)))
1505 #if IMAGE_BYTE_ORDER == MSBFirst
1506 #define Store4(img,l,o,v)  Store8(img,l,o,((o) & 4 ?                            \
1507                                    (Fetch8(img,l,o) & 0xf0) | (v) :             \
1508                                    (Fetch8(img,l,o) & 0x0f) | ((v) << 4)))
1509 #else
1510 #define Store4(img,l,o,v)  Store8(img,l,o,((o) & 4 ?                           \
1511                                    (Fetch8(img,l,o) & 0x0f) | ((v) << 4) : \
1512                                    (Fetch8(img,l,o) & 0xf0) | (v)))
1513 #endif
1514
1515 static FASTCALL void
1516 fbStore_a4 (pixman_image_t *image,
1517             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1518 {
1519     int i;
1520     for (i = 0; i < width; ++i) {
1521         Store4(image, bits, i + x, values[i]>>28);
1522     }
1523 }
1524
1525 static FASTCALL void
1526 fbStore_r1g2b1 (pixman_image_t *image,
1527                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1528 {
1529     int i;
1530     for (i = 0; i < width; ++i) {
1531         uint32_t  pixel;
1532
1533         Split(values[i]);
1534         pixel = (((r >> 4) & 0x8) |
1535                  ((g >> 5) & 0x6) |
1536                  ((b >> 7)      ));
1537         Store4(image, bits, i + x, pixel);
1538     }
1539 }
1540
1541 static FASTCALL void
1542 fbStore_b1g2r1 (pixman_image_t *image,
1543                 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1544 {
1545     int i;
1546     for (i = 0; i < width; ++i) {
1547         uint32_t  pixel;
1548
1549         Split(values[i]);
1550         pixel = (((b >> 4) & 0x8) |
1551                  ((g >> 5) & 0x6) |
1552                  ((r >> 7)      ));
1553         Store4(image, bits, i + x, pixel);
1554     }
1555 }
1556
1557 static FASTCALL void
1558 fbStore_a1r1g1b1 (pixman_image_t *image,
1559                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1560 {
1561     int i;
1562     for (i = 0; i < width; ++i) {
1563         uint32_t  pixel;
1564         Splita(values[i]);
1565         pixel = (((a >> 4) & 0x8) |
1566                  ((r >> 5) & 0x4) |
1567                  ((g >> 6) & 0x2) |
1568                  ((b >> 7)      ));
1569         Store4(image, bits, i + x, pixel);
1570     }
1571 }
1572
1573 static FASTCALL void
1574 fbStore_a1b1g1r1 (pixman_image_t *image,
1575                   uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1576 {
1577     int i;
1578     for (i = 0; i < width; ++i) {
1579         uint32_t  pixel;
1580         Splita(values[i]);
1581         pixel = (((a >> 4) & 0x8) |
1582                  ((b >> 5) & 0x4) |
1583                  ((g >> 6) & 0x2) |
1584                  ((r >> 7)      ));
1585         Store4(image, bits, i + x, pixel);
1586     }
1587 }
1588
1589 static FASTCALL void
1590 fbStore_c4 (pixman_image_t *image,
1591             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1592 {
1593     int i;
1594     for (i = 0; i < width; ++i) {
1595         uint32_t  pixel;
1596
1597         pixel = miIndexToEnt24(indexed, values[i]);
1598         Store4(image, bits, i + x, pixel);
1599     }
1600 }
1601
1602 static FASTCALL void
1603 fbStore_a1 (pixman_image_t *image,
1604             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1605 {
1606     int i;
1607     for (i = 0; i < width; ++i) {
1608         uint32_t  *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
1609         uint32_t  mask = FbStipMask((i+x) & 0x1f, 1);
1610
1611         uint32_t v = values[i] & 0x80000000 ? mask : 0;
1612         WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
1613     }
1614 }
1615
1616 static FASTCALL void
1617 fbStore_g1 (pixman_image_t *image,
1618             uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
1619 {
1620     int i;
1621     for (i = 0; i < width; ++i) {
1622         uint32_t  *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
1623         uint32_t  mask = FbStipMask((i+x) & 0x1f, 1);
1624
1625         uint32_t v = miIndexToEntY24(indexed,values[i]) ? mask : 0;
1626         WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
1627     }
1628 }
1629
1630
1631 storeProc32 ACCESS(pixman_storeProcForPicture32) (bits_image_t * pict)
1632 {
1633     switch(pict->format) {
1634     case PIXMAN_a8r8g8b8: return fbStore_a8r8g8b8;
1635     case PIXMAN_x8r8g8b8: return fbStore_x8r8g8b8;
1636     case PIXMAN_a8b8g8r8: return fbStore_a8b8g8r8;
1637     case PIXMAN_x8b8g8r8: return fbStore_x8b8g8r8;
1638
1639         /* 24bpp formats */
1640     case PIXMAN_r8g8b8: return fbStore_r8g8b8;
1641     case PIXMAN_b8g8r8: return fbStore_b8g8r8;
1642
1643         /* 16bpp formats */
1644     case PIXMAN_r5g6b5: return fbStore_r5g6b5;
1645     case PIXMAN_b5g6r5: return fbStore_b5g6r5;
1646
1647     case PIXMAN_a1r5g5b5: return fbStore_a1r5g5b5;
1648     case PIXMAN_x1r5g5b5: return fbStore_x1r5g5b5;
1649     case PIXMAN_a1b5g5r5: return fbStore_a1b5g5r5;
1650     case PIXMAN_x1b5g5r5: return fbStore_x1b5g5r5;
1651     case PIXMAN_a4r4g4b4: return fbStore_a4r4g4b4;
1652     case PIXMAN_x4r4g4b4: return fbStore_x4r4g4b4;
1653     case PIXMAN_a4b4g4r4: return fbStore_a4b4g4r4;
1654     case PIXMAN_x4b4g4r4: return fbStore_x4b4g4r4;
1655
1656         /* 8bpp formats */
1657     case PIXMAN_a8: return  fbStore_a8;
1658     case PIXMAN_r3g3b2: return fbStore_r3g3b2;
1659     case PIXMAN_b2g3r3: return fbStore_b2g3r3;
1660     case PIXMAN_a2r2g2b2: return fbStore_a2r2g2b2;
1661     case PIXMAN_c8: return  fbStore_c8;
1662     case PIXMAN_g8: return  fbStore_c8;
1663     case PIXMAN_x4a4: return fbStore_x4a4;
1664
1665         /* 4bpp formats */
1666     case PIXMAN_a4: return  fbStore_a4;
1667     case PIXMAN_r1g2b1: return fbStore_r1g2b1;
1668     case PIXMAN_b1g2r1: return fbStore_b1g2r1;
1669     case PIXMAN_a1r1g1b1: return fbStore_a1r1g1b1;
1670     case PIXMAN_a1b1g1r1: return fbStore_a1b1g1r1;
1671     case PIXMAN_c4: return  fbStore_c4;
1672     case PIXMAN_g4: return  fbStore_c4;
1673
1674         /* 1bpp formats */
1675     case PIXMAN_a1: return  fbStore_a1;
1676     case PIXMAN_g1: return  fbStore_g1;
1677     default:
1678         return NULL;
1679     }
1680 }