51dd5efb68e10958a00df309cefa7534bb7ed72f
[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  *             2008 Aaron Plattner, NVIDIA Corporation
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and its
8  * documentation for any purpose is hereby granted without fee, provided that
9  * the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of Keith Packard not be used in
12  * advertising or publicity pertaining to distribution of the software without
13  * specific, written prior permission.  Keith Packard makes no
14  * representations about the suitability of this software for any purpose.  It
15  * is provided "as is" without express or implied warranty.
16  *
17  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
18  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
22  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
23  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24  * SOFTWARE.
25  */
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #include <stdlib.h>
32 #include <string.h>
33 #include <assert.h>
34
35 #include "pixman-private.h"
36 #include "pixman-accessor.h"
37
38 #define CvtR8G8B8toY15(s)       (((((s) >> 16) & 0xff) * 153 + \
39                                   (((s) >>  8) & 0xff) * 301 +          \
40                                   (((s)      ) & 0xff) * 58) >> 2)
41 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) |  \
42                             (((s) >> 6) & 0x03e0) |  \
43                             (((s) >> 9) & 0x7c00))
44 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
45 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
46
47 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(rgb24)])
48
49 /*
50  * YV12 setup and access macros
51  */
52
53 #define YV12_SETUP(pict) \
54         uint32_t *bits = pict->bits; \
55         int stride = pict->rowstride; \
56         int offset0 = stride < 0 ? \
57                 ((-stride) >> 1) * ((pict->height - 1) >> 1) - stride : \
58                 stride * pict->height; \
59         int offset1 = stride < 0 ? \
60                 offset0 + ((-stride) >> 1) * ((pict->height) >> 1) : \
61                 offset0 + (offset0 >> 2)
62 /* Note no trailing semicolon on the above macro; if it's there, then
63  * the typical usage of YV12_SETUP(pict); will have an extra trailing ;
64  * that some compilers will interpret as a statement -- and then any further
65  * variable declarations will cause an error.
66  */
67
68 #define YV12_Y(line)            \
69     ((uint8_t *) ((bits) + (stride) * (line)))
70
71 #define YV12_U(line)          \
72     ((uint8_t *) ((bits) + offset1 + \
73                 ((stride) >> 1) * ((line) >> 1)))
74
75 #define YV12_V(line)          \
76     ((uint8_t *) ((bits) + offset0 + \
77                 ((stride) >> 1) * ((line) >> 1)))
78
79 /*********************************** Fetch ************************************/
80
81 static void
82 fbFetch_a8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
83 {
84     const uint32_t *bits = pict->bits + y*pict->rowstride;
85     MEMCPY_WRAPPED(pict,
86                    buffer, (const uint32_t *)bits + x,
87                    width*sizeof(uint32_t));
88 }
89
90 static void
91 fbFetch_x8r8g8b8 (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 = (const uint32_t *)bits + x;
95     const uint32_t *end = pixel + width;
96     while (pixel < end) {
97         *buffer++ = READ(pict, pixel++) | 0xff000000;
98     }
99 }
100
101 static void
102 fbFetch_a8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
103 {
104     const uint32_t *bits = pict->bits + y*pict->rowstride;
105     const uint32_t *pixel = (uint32_t *)bits + x;
106     const uint32_t *end = pixel + width;
107     while (pixel < end) {
108         uint32_t p = READ(pict, pixel++);
109         *buffer++ = (p & 0xff00ff00) |
110                     ((p >> 16) & 0xff) |
111             ((p & 0xff) << 16);
112     }
113 }
114
115 static void
116 fbFetch_x8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
117 {
118     const uint32_t *bits = pict->bits + y*pict->rowstride;
119     const uint32_t *pixel = (uint32_t *)bits + x;
120     const uint32_t *end = pixel + width;
121     while (pixel < end) {
122         uint32_t p = READ(pict, pixel++);
123         *buffer++ = 0xff000000 |
124             (p & 0x0000ff00) |
125             ((p >> 16) & 0xff) |
126             ((p & 0xff) << 16);
127     }
128 }
129
130 static void
131 fbFetch_b8g8r8a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
132 {
133     const uint32_t *bits = pict->bits + y*pict->rowstride;
134     const uint32_t *pixel = (uint32_t *)bits + x;
135     const uint32_t *end = pixel + width;
136     while (pixel < end) {
137         uint32_t p = READ(pict, pixel++);
138         *buffer++ = ((p & 0xff000000) >> 24) |
139             ((p & 0x00ff0000) >> 8) |
140             ((p & 0x0000ff00) << 8) |
141             ((p & 0x000000ff) << 24);
142     }
143 }
144
145 static void
146 fbFetch_b8g8r8x8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
147 {
148     const uint32_t *bits = pict->bits + y*pict->rowstride;
149     const uint32_t *pixel = (uint32_t *)bits + x;
150     const uint32_t *end = pixel + width;
151     while (pixel < end) {
152         uint32_t p = READ(pict, pixel++);
153         *buffer++ = 0xff000000 |
154             ((p & 0xff000000) >> 24) |
155             ((p & 0x00ff0000) >> 8) |
156             ((p & 0x0000ff00) << 8);
157     }
158 }
159
160 static void
161 fbFetch_a2b10g10r10 (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
162 {
163     const uint32_t *bits = pict->bits + y*pict->rowstride;
164     const uint32_t *pixel = bits + x;
165     const uint32_t *end = pixel + width;
166     while (pixel < end) {
167         uint32_t p = READ(pict, pixel++);
168         uint64_t a = p >> 30;
169         uint64_t b = (p >> 20) & 0x3ff;
170         uint64_t g = (p >> 10) & 0x3ff;
171         uint64_t r = p & 0x3ff;
172
173         r = r << 6 | r >> 4;
174         g = g << 6 | g >> 4;
175         b = b << 6 | b >> 4;
176
177         a <<= 62;
178         a |= a >> 2;
179         a |= a >> 4;
180         a |= a >> 8;
181
182         *buffer++ = a << 48 | r << 32 | g << 16 | b;
183     }
184 }
185
186 static void
187 fbFetch_x2b10g10r10 (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
188 {
189     const uint32_t *bits = pict->bits + y*pict->rowstride;
190     const uint32_t *pixel = (uint32_t *)bits + x;
191     const uint32_t *end = pixel + width;
192     while (pixel < end) {
193         uint32_t p = READ(pict, pixel++);
194         uint64_t b = (p >> 20) & 0x3ff;
195         uint64_t g = (p >> 10) & 0x3ff;
196         uint64_t r = p & 0x3ff;
197
198         r = r << 6 | r >> 4;
199         g = g << 6 | g >> 4;
200         b = b << 6 | b >> 4;
201
202         *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
203     }
204 }
205
206 static void
207 fbFetch_r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
208 {
209     const uint32_t *bits = pict->bits + y*pict->rowstride;
210     const uint8_t *pixel = (const uint8_t *)bits + 3*x;
211     const uint8_t *end = pixel + 3*width;
212     while (pixel < end) {
213         uint32_t b = 0xff000000;
214 #ifdef WORDS_BIGENDIAN
215         b |= (READ(pict, pixel++) << 16);
216         b |= (READ(pict, pixel++) << 8);
217         b |= (READ(pict, pixel++));
218 #else
219         b |= (READ(pict, pixel++));
220         b |= (READ(pict, pixel++) << 8);
221         b |= (READ(pict, pixel++) << 16);
222 #endif
223         *buffer++ = b;
224     }
225 }
226
227 static void
228 fbFetch_b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
229 {
230     const uint32_t *bits = pict->bits + y*pict->rowstride;
231     const uint8_t *pixel = (const uint8_t *)bits + 3*x;
232     const uint8_t *end = pixel + 3*width;
233     while (pixel < end) {
234         uint32_t b = 0xff000000;
235 #ifdef WORDS_BIGENDIAN
236         b |= (READ(pict, pixel++));
237         b |= (READ(pict, pixel++) << 8);
238         b |= (READ(pict, pixel++) << 16);
239 #else
240         b |= (READ(pict, pixel++) << 16);
241         b |= (READ(pict, pixel++) << 8);
242         b |= (READ(pict, pixel++));
243 #endif
244         *buffer++ = b;
245     }
246 }
247
248 static void
249 fbFetch_r5g6b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
250 {
251     const uint32_t *bits = pict->bits + y*pict->rowstride;
252     const uint16_t *pixel = (const uint16_t *)bits + x;
253     const uint16_t *end = pixel + width;
254     while (pixel < end) {
255         uint32_t p = READ(pict, pixel++);
256         uint32_t r = (((p) << 3) & 0xf8) |
257             (((p) << 5) & 0xfc00) |
258             (((p) << 8) & 0xf80000);
259         r |= (r >> 5) & 0x70007;
260         r |= (r >> 6) & 0x300;
261         *buffer++ = 0xff000000 | r;
262     }
263 }
264
265 static void
266 fbFetch_b5g6r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
267 {
268     uint32_t  r,g,b;
269     const uint32_t *bits = pict->bits + y*pict->rowstride;
270     const uint16_t *pixel = (const uint16_t *)bits + x;
271     const uint16_t *end = pixel + width;
272     while (pixel < end) {
273         uint32_t  p = READ(pict, pixel++);
274         b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
275         g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
276         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
277         *buffer++ = 0xff000000 | r | g | b;
278     }
279 }
280
281 static void
282 fbFetch_a1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
283 {
284     uint32_t  r,g,b, a;
285     const uint32_t *bits = pict->bits + y*pict->rowstride;
286     const uint16_t *pixel = (const uint16_t *)bits + x;
287     const uint16_t *end = pixel + width;
288     while (pixel < end) {
289         uint32_t  p = READ(pict, pixel++);
290
291         a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
292         r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
293         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
294         b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
295         *buffer++ = a | r | g | b;
296     }
297 }
298
299 static void
300 fbFetch_x1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
301 {
302     uint32_t  r,g,b;
303     const uint32_t *bits = pict->bits + y*pict->rowstride;
304     const uint16_t *pixel = (const uint16_t *)bits + x;
305     const uint16_t *end = pixel + width;
306     while (pixel < end) {
307         uint32_t  p = READ(pict, pixel++);
308
309         r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
310         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
311         b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
312         *buffer++ = 0xff000000 | r | g | b;
313     }
314 }
315
316 static void
317 fbFetch_a1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
318 {
319     uint32_t  r,g,b, a;
320     const uint32_t *bits = pict->bits + y*pict->rowstride;
321     const uint16_t *pixel = (const uint16_t *)bits + x;
322     const uint16_t *end = pixel + width;
323     while (pixel < end) {
324         uint32_t  p = READ(pict, pixel++);
325
326         a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
327         b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
328         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
329         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
330         *buffer++ = a | r | g | b;
331     }
332 }
333
334 static void
335 fbFetch_x1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
336 {
337     uint32_t  r,g,b;
338     const uint32_t *bits = pict->bits + y*pict->rowstride;
339     const uint16_t *pixel = (const uint16_t *)bits + x;
340     const uint16_t *end = pixel + width;
341     while (pixel < end) {
342         uint32_t  p = READ(pict, pixel++);
343
344         b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
345         g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
346         r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
347         *buffer++ = 0xff000000 | r | g | b;
348     }
349 }
350
351 static void
352 fbFetch_a4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
353 {
354     uint32_t  r,g,b, a;
355     const uint32_t *bits = pict->bits + y*pict->rowstride;
356     const uint16_t *pixel = (const uint16_t *)bits + x;
357     const uint16_t *end = pixel + width;
358     while (pixel < end) {
359         uint32_t  p = READ(pict, pixel++);
360
361         a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
362         r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
363         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
364         b = ((p & 0x000f) | ((p & 0x000f) << 4));
365         *buffer++ = a | r | g | b;
366     }
367 }
368
369 static void
370 fbFetch_x4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
371 {
372     uint32_t  r,g,b;
373     const uint32_t *bits = pict->bits + y*pict->rowstride;
374     const uint16_t *pixel = (const uint16_t *)bits + x;
375     const uint16_t *end = pixel + width;
376     while (pixel < end) {
377         uint32_t  p = READ(pict, pixel++);
378
379         r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
380         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
381         b = ((p & 0x000f) | ((p & 0x000f) << 4));
382         *buffer++ = 0xff000000 | r | g | b;
383     }
384 }
385
386 static void
387 fbFetch_a4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
388 {
389     uint32_t  r,g,b, a;
390     const uint32_t *bits = pict->bits + y*pict->rowstride;
391     const uint16_t *pixel = (const uint16_t *)bits + x;
392     const uint16_t *end = pixel + width;
393     while (pixel < end) {
394         uint32_t  p = READ(pict, pixel++);
395
396         a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
397         b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
398         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
399         r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
400         *buffer++ = a | r | g | b;
401     }
402 }
403
404 static void
405 fbFetch_x4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
406 {
407     uint32_t  r,g,b;
408     const uint32_t *bits = pict->bits + y*pict->rowstride;
409     const uint16_t *pixel = (const uint16_t *)bits + x;
410     const uint16_t *end = pixel + width;
411     while (pixel < end) {
412         uint32_t  p = READ(pict, pixel++);
413
414         b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
415         g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
416         r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
417         *buffer++ = 0xff000000 | r | g | b;
418     }
419 }
420
421 static void
422 fbFetch_a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
423 {
424     const uint32_t *bits = pict->bits + y*pict->rowstride;
425     const uint8_t *pixel = (const uint8_t *)bits + x;
426     const uint8_t *end = pixel + width;
427     while (pixel < end) {
428         *buffer++ = READ(pict, pixel++) << 24;
429     }
430 }
431
432 static void
433 fbFetch_r3g3b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
434 {
435     uint32_t  r,g,b;
436     const uint32_t *bits = pict->bits + y*pict->rowstride;
437     const uint8_t *pixel = (const uint8_t *)bits + x;
438     const uint8_t *end = pixel + width;
439     while (pixel < end) {
440         uint32_t  p = READ(pict, pixel++);
441
442         r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
443         g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
444         b = (((p & 0x03)     ) |
445              ((p & 0x03) << 2) |
446              ((p & 0x03) << 4) |
447              ((p & 0x03) << 6));
448         *buffer++ = 0xff000000 | r | g | b;
449     }
450 }
451
452 static void
453 fbFetch_b2g3r3 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
454 {
455     uint32_t  r,g,b;
456     const uint32_t *bits = pict->bits + y*pict->rowstride;
457     const uint8_t *pixel = (const uint8_t *)bits + x;
458     const uint8_t *end = pixel + width;
459     while (pixel < end) {
460         uint32_t  p = READ(pict, pixel++);
461
462         b = (((p & 0xc0)     ) |
463              ((p & 0xc0) >> 2) |
464              ((p & 0xc0) >> 4) |
465              ((p & 0xc0) >> 6));
466         g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
467         r = (((p & 0x07)     ) |
468              ((p & 0x07) << 3) |
469              ((p & 0x06) << 6)) << 16;
470         *buffer++ = 0xff000000 | r | g | b;
471     }
472 }
473
474 static void
475 fbFetch_a2r2g2b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
476 {
477     uint32_t   a,r,g,b;
478     const uint32_t *bits = pict->bits + y*pict->rowstride;
479     const uint8_t *pixel = (const uint8_t *)bits + x;
480     const uint8_t *end = pixel + width;
481     while (pixel < end) {
482         uint32_t  p = READ(pict, pixel++);
483
484         a = ((p & 0xc0) * 0x55) << 18;
485         r = ((p & 0x30) * 0x55) << 12;
486         g = ((p & 0x0c) * 0x55) << 6;
487         b = ((p & 0x03) * 0x55);
488         *buffer++ = a|r|g|b;
489     }
490 }
491
492 static void
493 fbFetch_a2b2g2r2 (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     const uint8_t *pixel = (const uint8_t *)bits + x;
498     const uint8_t *end = pixel + width;
499     while (pixel < end) {
500         uint32_t  p = READ(pict, pixel++);
501
502         a = ((p & 0xc0) * 0x55) << 18;
503         b = ((p & 0x30) * 0x55) >> 6;
504         g = ((p & 0x0c) * 0x55) << 6;
505         r = ((p & 0x03) * 0x55) << 16;
506         *buffer++ = a|r|g|b;
507     }
508 }
509
510 static void
511 fbFetch_c8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
512 {
513     const uint32_t *bits = pict->bits + y*pict->rowstride;
514     const pixman_indexed_t * indexed = pict->indexed;
515     const uint8_t *pixel = (const uint8_t *)bits + x;
516     const uint8_t *end = pixel + width;
517     while (pixel < end) {
518         uint32_t  p = READ(pict, pixel++);
519         *buffer++ = indexed->rgba[p];
520     }
521 }
522
523 static void
524 fbFetch_x4a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
525 {
526     const uint32_t *bits = pict->bits + y*pict->rowstride;
527     const uint8_t *pixel = (const uint8_t *)bits + x;
528     const uint8_t *end = pixel + width;
529     while (pixel < end) {
530         uint8_t p = READ(pict, pixel++) & 0xf;
531         *buffer++ = (p | (p << 4)) << 24;
532     }
533 }
534
535 #define Fetch8(img,l,o)    (READ(img, (uint8_t *)(l) + ((o) >> 2)))
536 #ifdef WORDS_BIGENDIAN
537 #define Fetch4(img,l,o)    ((o) & 2 ? Fetch8(img,l,o) & 0xf : Fetch8(img,l,o) >> 4)
538 #else
539 #define Fetch4(img,l,o)    ((o) & 2 ? Fetch8(img,l,o) >> 4 : Fetch8(img,l,o) & 0xf)
540 #endif
541
542 static void
543 fbFetch_a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
544 {
545     const uint32_t *bits = pict->bits + y*pict->rowstride;
546     int i;
547     for (i = 0; i < width; ++i) {
548         uint32_t  p = Fetch4(pict, bits, i + x);
549
550         p |= p << 4;
551         *buffer++ = p << 24;
552     }
553 }
554
555 static void
556 fbFetch_r1g2b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
557 {
558     uint32_t  r,g,b;
559     const uint32_t *bits = pict->bits + y*pict->rowstride;
560     int i;
561     for (i = 0; i < width; ++i) {
562         uint32_t  p = Fetch4(pict, bits, i + x);
563
564         r = ((p & 0x8) * 0xff) << 13;
565         g = ((p & 0x6) * 0x55) << 7;
566         b = ((p & 0x1) * 0xff);
567         *buffer++ = 0xff000000|r|g|b;
568     }
569 }
570
571 static void
572 fbFetch_b1g2r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
573 {
574     uint32_t  r,g,b;
575     const uint32_t *bits = pict->bits + y*pict->rowstride;
576     int i;
577     for (i = 0; i < width; ++i) {
578         uint32_t  p = Fetch4(pict, bits, i + x);
579
580         b = ((p & 0x8) * 0xff) >> 3;
581         g = ((p & 0x6) * 0x55) << 7;
582         r = ((p & 0x1) * 0xff) << 16;
583         *buffer++ = 0xff000000|r|g|b;
584     }
585 }
586
587 static void
588 fbFetch_a1r1g1b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
589 {
590     uint32_t  a,r,g,b;
591     const uint32_t *bits = pict->bits + y*pict->rowstride;
592     int i;
593     for (i = 0; i < width; ++i) {
594         uint32_t  p = Fetch4(pict, bits, i + x);
595
596         a = ((p & 0x8) * 0xff) << 21;
597         r = ((p & 0x4) * 0xff) << 14;
598         g = ((p & 0x2) * 0xff) << 7;
599         b = ((p & 0x1) * 0xff);
600         *buffer++ = a|r|g|b;
601     }
602 }
603
604 static void
605 fbFetch_a1b1g1r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
606 {
607     uint32_t  a,r,g,b;
608     const uint32_t *bits = pict->bits + y*pict->rowstride;
609     int i;
610     for (i = 0; i < width; ++i) {
611         uint32_t  p = Fetch4(pict, bits, i + x);
612
613         a = ((p & 0x8) * 0xff) << 21;
614         r = ((p & 0x4) * 0xff) >> 3;
615         g = ((p & 0x2) * 0xff) << 7;
616         b = ((p & 0x1) * 0xff) << 16;
617         *buffer++ = a|r|g|b;
618     }
619 }
620
621 static void
622 fbFetch_c4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
623 {
624     const uint32_t *bits = pict->bits + y*pict->rowstride;
625     const pixman_indexed_t * indexed = pict->indexed;
626     int i;
627     for (i = 0; i < width; ++i) {
628         uint32_t  p = Fetch4(pict, bits, i + x);
629
630         *buffer++ = indexed->rgba[p];
631     }
632 }
633
634
635 static void
636 fbFetch_a1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
637 {
638     const uint32_t *bits = pict->bits + y*pict->rowstride;
639     int i;
640     for (i = 0; i < width; ++i) {
641         uint32_t  p = READ(pict, bits + ((i + x) >> 5));
642         uint32_t  a;
643 #ifdef WORDS_BIGENDIAN
644         a = p >> (0x1f - ((i+x) & 0x1f));
645 #else
646         a = p >> ((i+x) & 0x1f);
647 #endif
648         a = a & 1;
649         a |= a << 1;
650         a |= a << 2;
651         a |= a << 4;
652         *buffer++ = a << 24;
653     }
654 }
655
656 static void
657 fbFetch_g1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
658 {
659     const uint32_t *bits = pict->bits + y*pict->rowstride;
660     const pixman_indexed_t * indexed = pict->indexed;
661     int i;
662     for (i = 0; i < width; ++i) {
663         uint32_t p = READ(pict, bits + ((i+x) >> 5));
664         uint32_t a;
665 #ifdef WORDS_BIGENDIAN
666         a = p >> (0x1f - ((i+x) & 0x1f));
667 #else
668         a = p >> ((i+x) & 0x1f);
669 #endif
670         a = a & 1;
671         *buffer++ = indexed->rgba[a];
672     }
673 }
674
675 static void
676 fbFetch_yuy2 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
677 {
678     int16_t y, u, v;
679     int32_t r, g, b;
680     int   i;
681
682     const uint32_t *bits = pict->bits + pict->rowstride * line;
683
684     for (i = 0; i < width; i++)
685     {
686         y = ((uint8_t *) bits)[(x + i) << 1] - 16;
687         u = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 1] - 128;
688         v = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 3] - 128;
689
690         /* R = 1.164(Y - 16) + 1.596(V - 128) */
691         r = 0x012b27 * y + 0x019a2e * v;
692         /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
693         g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
694         /* B = 1.164(Y - 16) + 2.018(U - 128) */
695         b = 0x012b27 * y + 0x0206a2 * u;
696
697         WRITE(pict, buffer++, 0xff000000 |
698               (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
699               (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
700               (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
701     }
702 }
703
704 static void
705 fbFetch_yv12 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
706 {
707     YV12_SETUP(pict);
708     uint8_t *pY = YV12_Y (line);
709     uint8_t *pU = YV12_U (line);
710     uint8_t *pV = YV12_V (line);
711     int16_t y, u, v;
712     int32_t r, g, b;
713     int   i;
714
715     for (i = 0; i < width; i++)
716     {
717         y = pY[x + i] - 16;
718         u = pU[(x + i) >> 1] - 128;
719         v = pV[(x + i) >> 1] - 128;
720
721         /* R = 1.164(Y - 16) + 1.596(V - 128) */
722         r = 0x012b27 * y + 0x019a2e * v;
723         /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
724         g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
725         /* B = 1.164(Y - 16) + 2.018(U - 128) */
726         b = 0x012b27 * y + 0x0206a2 * u;
727
728         WRITE(pict, buffer++, 0xff000000 |
729             (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
730             (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
731             (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
732     }
733 }
734
735 /**************************** Pixel wise fetching *****************************/
736
737 static void
738 fbFetchPixel_a2b10g10r10 (bits_image_t *pict, uint64_t *buffer, int n_pixels)
739 {
740     int i;
741
742     for (i = 0; i < n_pixels; ++i)
743     {
744         int offset = ((uint32_t *)buffer)[2 * i];
745         int line = ((uint32_t *)buffer)[2 * i + 1];
746
747         if (offset == 0xffffffff || line == 0xffffffff)
748         {
749             buffer[i] = 0;
750         }
751         else
752         {
753             uint32_t *bits = pict->bits + line*pict->rowstride;
754             uint32_t p = READ(pict, bits + offset);
755             uint64_t a = p >> 30;
756             uint64_t b = (p >> 20) & 0x3ff;
757             uint64_t g = (p >> 10) & 0x3ff;
758             uint64_t r = p & 0x3ff;
759             
760             r = r << 6 | r >> 4;
761             g = g << 6 | g >> 4;
762             b = b << 6 | b >> 4;
763             
764             a <<= 62;
765             a |= a >> 2;
766             a |= a >> 4;
767             a |= a >> 8;
768             
769             buffer[i] = a << 48 | r << 32 | g << 16 | b;
770         }
771     }
772 }
773
774 static void
775 fbFetchPixel_x2b10g10r10 (bits_image_t *pict, uint64_t *buffer, int n_pixels)
776 {
777     int i;
778     
779     for (i = 0; i < n_pixels; ++i)
780     {
781         int offset = ((uint32_t *)buffer)[2 * i];
782         int line = ((uint32_t *)buffer)[2 * i + 1];
783
784         if (offset == 0xffffffff || line == 0xffffffff)
785         {
786             buffer[i] = 0;
787         }
788         else
789         {
790             uint32_t *bits = pict->bits + line*pict->rowstride;
791             uint32_t p = READ(pict, bits + offset);
792             uint64_t b = (p >> 20) & 0x3ff;
793             uint64_t g = (p >> 10) & 0x3ff;
794             uint64_t r = p & 0x3ff;
795             
796             r = r << 6 | r >> 4;
797             g = g << 6 | g >> 4;
798             b = b << 6 | b >> 4;
799             
800             buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
801         }
802     }
803 }
804
805 static void
806 fbFetchPixel_a8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
807 {
808     int i;
809     
810     for (i = 0; i < n_pixels; ++i)
811     {
812         int offset = buffer[2 * i];
813         int line = buffer[2 * i + 1];
814         
815         if (offset == 0xffffffff || line == 0xffffffff)
816         {
817             buffer[i] = 0;
818         }
819         else
820         {
821             uint32_t *bits = pict->bits + line*pict->rowstride;
822             buffer[i] = READ(pict, (uint32_t *)bits + offset);
823         }
824     }
825 }
826
827 static void
828 fbFetchPixel_x8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
829 {
830     int i;
831     
832     for (i = 0; i < n_pixels; ++i)
833     {
834         int offset = buffer[2 * i];
835         int line = buffer[2 * i + 1];
836         
837         if (offset == 0xffffffff || line == 0xffffffff)
838         {
839             buffer[i] = 0;
840         }
841         else
842         {
843             uint32_t *bits = pict->bits + line*pict->rowstride;
844             buffer[i] = READ(pict, (uint32_t *)bits + offset) | 0xff000000;
845         }
846     }
847 }
848
849 static void
850 fbFetchPixel_a8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
851 {
852     int i;
853     
854     for (i = 0; i < n_pixels; ++i)
855     {
856         int offset = buffer[2 * i];
857         int line = buffer[2 * i + 1];
858         
859         if (offset == 0xffffffff || line == 0xffffffff)
860         {
861             buffer[i] = 0;
862         }
863         else
864         {
865             uint32_t *bits = pict->bits + line*pict->rowstride;
866             uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
867             
868             buffer[i] = ((pixel & 0xff000000) |
869                          ((pixel >> 16) & 0xff) |
870                          (pixel & 0x0000ff00) |
871                          ((pixel & 0xff) << 16));
872         }
873     }
874 }
875
876 static void
877 fbFetchPixel_x8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
878 {
879     int i;
880     
881     for (i = 0; i < n_pixels; ++i)
882     {
883         int offset = buffer[2 * i];
884         int line = buffer[2 * i + 1];
885         
886         if (offset == 0xffffffff || line == 0xffffffff)
887         {
888             buffer[i] = 0;
889         }
890         else
891         {
892             uint32_t *bits = pict->bits + line*pict->rowstride;
893             uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
894             
895             buffer[i] = ((0xff000000) |
896                          ((pixel >> 16) & 0xff) |
897                          (pixel & 0x0000ff00) |
898                          ((pixel & 0xff) << 16));
899         }
900     }
901 }
902
903 static void
904 fbFetchPixel_b8g8r8a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
905 {
906     int i;
907
908     for (i = 0; i < n_pixels; ++i)
909     {
910         int offset = buffer[2 * i];
911         int line = buffer[2 * i + 1];
912
913         if (offset == 0xffffffff || line == 0xffffffff)
914         {
915             buffer[i] = 0;
916         }
917         else
918         {
919             uint32_t *bits = pict->bits + line*pict->rowstride;
920             uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
921             
922             buffer[i] = ((pixel & 0xff000000) >> 24 |
923                          (pixel & 0x00ff0000) >> 8 |
924                          (pixel & 0x0000ff00) << 8 |
925                          (pixel & 0x000000ff) << 24);
926         }
927     }
928 }
929
930 static void
931 fbFetchPixel_b8g8r8x8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
932 {
933     int i;
934
935     for (i = 0; i < n_pixels; ++i)
936     {
937         int offset = buffer[2 * i];
938         int line = buffer[2 * i + 1];
939         
940         if (offset == 0xffffffff || line == 0xffffffff)
941         {
942             buffer[i] = 0;
943         }
944         else
945         {
946             uint32_t *bits = pict->bits + line*pict->rowstride;
947             uint32_t  pixel = READ(pict, (uint32_t *)bits + offset);
948             
949             buffer[i] = ((0xff000000) |
950                          (pixel & 0xff000000) >> 24 |
951                          (pixel & 0x00ff0000) >> 8 |
952                          (pixel & 0x0000ff00) << 8);
953         }
954     }
955 }
956
957 static void
958 fbFetchPixel_r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
959 {
960     int i;
961
962     for (i = 0; i < n_pixels; ++i)
963     {
964         int offset = buffer[2 * i];
965         int line = buffer[2 * i + 1];
966
967         if (offset == 0xffffffff || line == 0xffffffff)
968         {
969             buffer[i] = 0;
970         }
971         else
972         {
973             uint32_t *bits = pict->bits + line*pict->rowstride;
974             uint8_t   *pixel = ((uint8_t *) bits) + (offset*3);
975 #ifdef WORDS_BIGENDIAN
976             buffer[i] = (0xff000000 |
977                          (READ(pict, pixel + 0) << 16) |
978                          (READ(pict, pixel + 1) << 8) |
979                          (READ(pict, pixel + 2)));
980 #else
981             buffer[i] = (0xff000000 |
982                          (READ(pict, pixel + 2) << 16) |
983                          (READ(pict, pixel + 1) << 8) |
984                          (READ(pict, pixel + 0)));
985 #endif
986         }
987     }
988 }
989
990 static void
991 fbFetchPixel_b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
992 {
993     int i;
994
995     for (i = 0; i < n_pixels; ++i)
996     {
997         int offset = buffer[2 * i];
998         int line = buffer[2 * i + 1];
999
1000         if (offset == 0xffffffff || line == 0xffffffff)
1001         {
1002             buffer[i] = 0;
1003         }
1004         else
1005         {
1006             uint32_t *bits = pict->bits + line*pict->rowstride;
1007             uint8_t   *pixel = ((uint8_t *) bits) + (offset*3);
1008 #ifdef WORDS_BIGENDIAN
1009             buffer[i] = (0xff000000 |
1010                          (READ(pict, pixel + 2) << 16) |
1011                          (READ(pict, pixel + 1) << 8) |
1012                          (READ(pict, pixel + 0)));
1013 #else
1014             buffer[i] = (0xff000000 |
1015                          (READ(pict, pixel + 0) << 16) |
1016                          (READ(pict, pixel + 1) << 8) |
1017                          (READ(pict, pixel + 2)));
1018 #endif
1019         }
1020     }
1021 }
1022
1023 static void
1024 fbFetchPixel_r5g6b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1025 {
1026     int i;
1027
1028     for (i = 0; i < n_pixels; ++i)
1029     {
1030         int offset = buffer[2 * i];
1031         int line = buffer[2 * i + 1];
1032
1033         if (offset == 0xffffffff || line == 0xffffffff)
1034         {
1035             buffer[i] = 0;
1036         }
1037         else
1038         {
1039             uint32_t  r,g,b;
1040             uint32_t *bits = pict->bits + line*pict->rowstride;
1041             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1042             
1043             r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1044             g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1045             b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1046             buffer[i] = (0xff000000 | r | g | b);
1047         }
1048     }
1049 }
1050
1051 static void
1052 fbFetchPixel_b5g6r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1053 {
1054     int i;
1055
1056     for (i = 0; i < n_pixels; ++i)
1057     {
1058         int offset = buffer[2 * i];
1059         int line = buffer[2 * i + 1];
1060
1061         if (offset == 0xffffffff || line == 0xffffffff)
1062         {
1063             buffer[i] = 0;
1064         }
1065         else
1066         {
1067             uint32_t  r,g,b;
1068             uint32_t *bits = pict->bits + line*pict->rowstride;
1069             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1070             
1071             b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1072             g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1073             r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1074             buffer[i] = (0xff000000 | r | g | b);
1075         }
1076     }
1077 }
1078
1079 static void
1080 fbFetchPixel_a1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1081 {
1082     int i;
1083
1084     for (i = 0; i < n_pixels; ++i)
1085     {
1086         int offset = buffer[2 * i];
1087         int line = buffer[2 * i + 1];
1088
1089         if (offset == 0xffffffff || line == 0xffffffff)
1090         {
1091             buffer[i] = 0;
1092         }
1093         else
1094         {
1095             uint32_t  a,r,g,b;
1096             uint32_t *bits = pict->bits + line*pict->rowstride;
1097             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1098             
1099             a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1100             r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1101             g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1102             b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1103             buffer[i] = (a | r | g | b);
1104         }
1105     }
1106 }
1107
1108 static void
1109 fbFetchPixel_x1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1110 {
1111     int i;
1112
1113     for (i = 0; i < n_pixels; ++i)
1114     {
1115         int offset = buffer[2 * i];
1116         int line = buffer[2 * i + 1];
1117
1118         if (offset == 0xffffffff || line == 0xffffffff)
1119         {
1120             buffer[i] = 0;
1121         }
1122         else
1123         {
1124             uint32_t  r,g,b;
1125             uint32_t *bits = pict->bits + line*pict->rowstride;
1126             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1127             
1128             r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1129             g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1130             b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1131             buffer[i] = (0xff000000 | r | g | b);
1132         }
1133     }
1134 }
1135
1136 static void
1137 fbFetchPixel_a1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1138 {
1139     int i;
1140
1141     for (i = 0; i < n_pixels; ++i)
1142     {
1143         int offset = buffer[2 * i];
1144         int line = buffer[2 * i + 1];
1145
1146         if (offset == 0xffffffff || line == 0xffffffff)
1147         {
1148             buffer[i] = 0;
1149         }
1150         else
1151         {
1152             uint32_t  a,r,g,b;
1153             uint32_t *bits = pict->bits + line*pict->rowstride;
1154             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1155             
1156             a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1157             b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1158             g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1159             r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1160             buffer[i] = (a | r | g | b);
1161         }
1162     }
1163 }
1164
1165 static void
1166 fbFetchPixel_x1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1167 {
1168     int i;
1169
1170     for (i = 0; i < n_pixels; ++i)
1171     {
1172         int offset = buffer[2 * i];
1173         int line = buffer[2 * i + 1];
1174
1175         if (offset == 0xffffffff || line == 0xffffffff)
1176         {
1177             buffer[i] = 0;
1178         }
1179         else
1180         {
1181             uint32_t  r,g,b;
1182             uint32_t *bits = pict->bits + line*pict->rowstride;
1183             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1184             
1185             b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1186             g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1187             r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1188             buffer[i] = (0xff000000 | r | g | b);
1189         }
1190     }
1191 }
1192
1193 static void
1194 fbFetchPixel_a4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1195 {
1196     int i;
1197
1198     for (i = 0; i < n_pixels; ++i)
1199     {
1200         int offset = buffer[2 * i];
1201         int line = buffer[2 * i + 1];
1202
1203         if (offset == 0xffffffff || line == 0xffffffff)
1204         {
1205             buffer[i] = 0;
1206         }
1207         else
1208         {
1209             uint32_t  a,r,g,b;
1210             uint32_t *bits = pict->bits + line*pict->rowstride;
1211             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1212             
1213             a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1214             r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1215             g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1216             b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1217             buffer[i] = (a | r | g | b);
1218         }
1219     }
1220 }
1221
1222 static void
1223 fbFetchPixel_x4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1224 {
1225     int i;
1226
1227     for (i = 0; i < n_pixels; ++i)
1228     {
1229         int offset = buffer[2 * i];
1230         int line = buffer[2 * i + 1];
1231
1232         if (offset == 0xffffffff || line == 0xffffffff)
1233         {
1234             buffer[i] = 0;
1235         }
1236         else
1237         {
1238             uint32_t  r,g,b;
1239             uint32_t *bits = pict->bits + line*pict->rowstride;
1240             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1241             
1242             r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1243             g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1244             b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1245             buffer[i] = (0xff000000 | r | g | b);
1246         }
1247     }
1248 }
1249
1250 static void
1251 fbFetchPixel_a4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1252 {
1253     int i;
1254
1255     for (i = 0; i < n_pixels; ++i)
1256     {
1257         int offset = buffer[2 * i];
1258         int line = buffer[2 * i + 1];
1259
1260         if (offset == 0xffffffff || line == 0xffffffff)
1261         {
1262             buffer[i] = 0;
1263         }
1264         else
1265         {
1266             uint32_t  a,r,g,b;
1267             uint32_t *bits = pict->bits + line*pict->rowstride;
1268             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1269             
1270             a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1271             b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1272             g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1273             r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1274             buffer[i] = (a | r | g | b);
1275         }
1276     }
1277 }
1278
1279 static void
1280 fbFetchPixel_x4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1281 {
1282     int i;
1283
1284     for (i = 0; i < n_pixels; ++i)
1285     {
1286         int offset = buffer[2 * i];
1287         int line = buffer[2 * i + 1];
1288
1289         if (offset == 0xffffffff || line == 0xffffffff)
1290         {
1291             buffer[i] = 0;
1292         }
1293         else
1294         {
1295             uint32_t  r,g,b;
1296             uint32_t *bits = pict->bits + line*pict->rowstride;
1297             uint32_t  pixel = READ(pict, (uint16_t *) bits + offset);
1298             
1299             b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1300             g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1301             r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1302             buffer[i] = (0xff000000 | r | g | b);
1303         }
1304     }
1305 }
1306
1307 static void
1308 fbFetchPixel_a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1309 {
1310     int i;
1311
1312     for (i = 0; i < n_pixels; ++i)
1313     {
1314         int offset = buffer[2 * i];
1315         int line = buffer[2 * i + 1];
1316
1317         if (offset == 0xffffffff || line == 0xffffffff)
1318         {
1319             buffer[i] = 0;
1320         }
1321         else
1322         {
1323             uint32_t *bits = pict->bits + line*pict->rowstride;
1324             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1325             
1326             buffer[i] = pixel << 24;
1327         }
1328     }
1329 }
1330
1331 static void
1332 fbFetchPixel_r3g3b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1333 {
1334     int i;
1335
1336     for (i = 0; i < n_pixels; ++i)
1337     {
1338         int offset = buffer[2 * i];
1339         int line = buffer[2 * i + 1];
1340
1341         if (offset == 0xffffffff || line == 0xffffffff)
1342         {
1343             buffer[i] = 0;
1344         }
1345         else
1346         {
1347             uint32_t  r,g,b;
1348             uint32_t *bits = pict->bits + line*pict->rowstride;
1349             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1350             
1351             r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16;
1352             g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8;
1353             b = (((pixel & 0x03)     ) |
1354                  ((pixel & 0x03) << 2) |
1355                  ((pixel & 0x03) << 4) |
1356                  ((pixel & 0x03) << 6));
1357             buffer[i] = (0xff000000 | r | g | b);
1358         }
1359     }
1360 }
1361
1362 static void
1363 fbFetchPixel_b2g3r3 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1364 {
1365     int i;
1366
1367     for (i = 0; i < n_pixels; ++i)
1368     {
1369         int offset = buffer[2 * i];
1370         int line = buffer[2 * i + 1];
1371
1372         if (offset == 0xffffffff || line == 0xffffffff)
1373         {
1374             buffer[i] = 0;
1375         }
1376         else
1377         {
1378             uint32_t  r,g,b;
1379             uint32_t *bits = pict->bits + line*pict->rowstride;
1380             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1381             
1382             b = (((pixel & 0xc0)     ) |
1383                  ((pixel & 0xc0) >> 2) |
1384                  ((pixel & 0xc0) >> 4) |
1385                  ((pixel & 0xc0) >> 6));
1386             g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8;
1387             r = (((pixel & 0x07)     ) |
1388                  ((pixel & 0x07) << 3) |
1389                  ((pixel & 0x06) << 6)) << 16;
1390             buffer[i] = (0xff000000 | r | g | b);
1391         }
1392     }
1393 }
1394
1395 static void
1396 fbFetchPixel_a2r2g2b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1397 {
1398     int i;
1399
1400     for (i = 0; i < n_pixels; ++i)
1401     {
1402         int offset = buffer[2 * i];
1403         int line = buffer[2 * i + 1];
1404
1405         if (offset == 0xffffffff || line == 0xffffffff)
1406         {
1407             buffer[i] = 0;
1408         }
1409         else
1410         {
1411             uint32_t   a,r,g,b;
1412             uint32_t *bits = pict->bits + line*pict->rowstride;
1413             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1414             
1415             a = ((pixel & 0xc0) * 0x55) << 18;
1416             r = ((pixel & 0x30) * 0x55) << 12;
1417             g = ((pixel & 0x0c) * 0x55) << 6;
1418             b = ((pixel & 0x03) * 0x55);
1419             buffer[i] = a|r|g|b;
1420         }
1421     }
1422 }
1423
1424 static void
1425 fbFetchPixel_a2b2g2r2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1426 {
1427     int i;
1428
1429     for (i = 0; i < n_pixels; ++i)
1430     {
1431         int offset = buffer[2 * i];
1432         int line = buffer[2 * i + 1];
1433
1434         if (offset == 0xffffffff || line == 0xffffffff)
1435         {
1436             buffer[i] = 0;
1437         }
1438         else
1439         {
1440             uint32_t   a,r,g,b;
1441             uint32_t *bits = pict->bits + line*pict->rowstride;
1442             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1443             
1444             a = ((pixel & 0xc0) * 0x55) << 18;
1445             b = ((pixel & 0x30) * 0x55) >> 6;
1446             g = ((pixel & 0x0c) * 0x55) << 6;
1447             r = ((pixel & 0x03) * 0x55) << 16;
1448             buffer[i] = a|r|g|b;
1449         }
1450     }
1451 }
1452
1453 static void
1454 fbFetchPixel_c8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1455 {
1456     int i;
1457
1458     for (i = 0; i < n_pixels; ++i)
1459     {
1460         int offset = buffer[2 * i];
1461         int line = buffer[2 * i + 1];
1462
1463         if (offset == 0xffffffff || line == 0xffffffff)
1464         {
1465             buffer[i] = 0;
1466         }
1467         else
1468         {
1469             uint32_t *bits = pict->bits + line*pict->rowstride;
1470             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1471             const pixman_indexed_t * indexed = pict->indexed;
1472             buffer[i] = indexed->rgba[pixel];
1473         }
1474     }
1475 }
1476
1477 static void
1478 fbFetchPixel_x4a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1479 {
1480     int i;
1481
1482     for (i = 0; i < n_pixels; ++i)
1483     {
1484         int offset = buffer[2 * i];
1485         int line = buffer[2 * i + 1];
1486
1487         if (offset == 0xffffffff || line == 0xffffffff)
1488         {
1489             buffer[i] = 0;
1490         }
1491         else
1492         {
1493             uint32_t *bits = pict->bits + line*pict->rowstride;
1494             uint32_t   pixel = READ(pict, (uint8_t *) bits + offset);
1495             
1496             buffer[i] = ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1497         }
1498     }
1499 }
1500
1501 static void
1502 fbFetchPixel_a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1503 {
1504     int i;
1505
1506     for (i = 0; i < n_pixels; ++i)
1507     {
1508         int offset = buffer[2 * i];
1509         int line = buffer[2 * i + 1];
1510
1511         if (offset == 0xffffffff || line == 0xffffffff)
1512         {
1513             buffer[i] = 0;
1514         }
1515         else
1516         {
1517             uint32_t *bits = pict->bits + line*pict->rowstride;
1518             uint32_t  pixel = Fetch4(pict, bits, offset);
1519             
1520             pixel |= pixel << 4;
1521             buffer[i] = pixel << 24;
1522         }
1523     }
1524 }
1525
1526 static void
1527 fbFetchPixel_r1g2b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1528 {
1529     int i;
1530
1531     for (i = 0; i < n_pixels; ++i)
1532     {
1533         int offset = buffer[2 * i];
1534         int line = buffer[2 * i + 1];
1535         
1536         if (offset == 0xffffffff || line == 0xffffffff)
1537         {
1538             buffer[i] = 0;
1539         }
1540         else
1541         {
1542             uint32_t  r,g,b;
1543             uint32_t *bits = pict->bits + line*pict->rowstride;
1544             uint32_t  pixel = Fetch4(pict, bits, offset);
1545             
1546             r = ((pixel & 0x8) * 0xff) << 13;
1547             g = ((pixel & 0x6) * 0x55) << 7;
1548             b = ((pixel & 0x1) * 0xff);
1549             buffer[i] = 0xff000000|r|g|b;
1550         }
1551     }
1552 }
1553
1554 static void
1555 fbFetchPixel_b1g2r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1556 {
1557     int i;
1558
1559     for (i = 0; i < n_pixels; ++i)
1560     {
1561         int offset = buffer[2 * i];
1562         int line = buffer[2 * i + 1];
1563
1564         if (offset == 0xffffffff || line == 0xffffffff)
1565         {
1566             buffer[i] = 0;
1567         }
1568         else
1569         {
1570             uint32_t  r,g,b;
1571             uint32_t *bits = pict->bits + line*pict->rowstride;
1572             uint32_t  pixel = Fetch4(pict, bits, offset);
1573             
1574             b = ((pixel & 0x8) * 0xff) >> 3;
1575             g = ((pixel & 0x6) * 0x55) << 7;
1576             r = ((pixel & 0x1) * 0xff) << 16;
1577             buffer[i] = 0xff000000|r|g|b;
1578         }
1579     }
1580 }
1581
1582 static void
1583 fbFetchPixel_a1r1g1b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1584 {
1585     int i;
1586
1587     for (i = 0; i < n_pixels; ++i)
1588     {
1589         int offset = buffer[2 * i];
1590         int line = buffer[2 * i + 1];
1591
1592         if (offset == 0xffffffff || line == 0xffffffff)
1593         {
1594             buffer[i] = 0;
1595         }
1596         else
1597         {
1598             uint32_t  a,r,g,b;
1599             uint32_t *bits = pict->bits + line*pict->rowstride;
1600             uint32_t  pixel = Fetch4(pict, bits, offset);
1601             
1602             a = ((pixel & 0x8) * 0xff) << 21;
1603             r = ((pixel & 0x4) * 0xff) << 14;
1604             g = ((pixel & 0x2) * 0xff) << 7;
1605             b = ((pixel & 0x1) * 0xff);
1606             buffer[i] = a|r|g|b;
1607         }
1608     }
1609 }
1610
1611 static void
1612 fbFetchPixel_a1b1g1r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1613 {
1614     int i;
1615
1616     for (i = 0; i < n_pixels; ++i)
1617     {
1618         int offset = buffer[2 * i];
1619         int line = buffer[2 * i + 1];
1620
1621         if (offset == 0xffffffff || line == 0xffffffff)
1622         {
1623             buffer[i] = 0;
1624         }
1625         else
1626         {
1627             uint32_t  a,r,g,b;
1628             uint32_t *bits = pict->bits + line*pict->rowstride;
1629             uint32_t  pixel = Fetch4(pict, bits, offset);
1630             
1631             a = ((pixel & 0x8) * 0xff) << 21;
1632             r = ((pixel & 0x4) * 0xff) >> 3;
1633             g = ((pixel & 0x2) * 0xff) << 7;
1634             b = ((pixel & 0x1) * 0xff) << 16;
1635             buffer[i] = a|r|g|b;
1636         }
1637     }
1638 }
1639
1640 static void
1641 fbFetchPixel_c4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1642 {
1643     int i;
1644
1645     for (i = 0; i < n_pixels; ++i)
1646     {
1647         int offset = buffer[2 * i];
1648         int line = buffer[2 * i + 1];
1649
1650         if (offset == 0xffffffff || line == 0xffffffff)
1651         {
1652             buffer[i] = 0;
1653         }
1654         else
1655         {
1656             uint32_t *bits = pict->bits + line*pict->rowstride;
1657             uint32_t  pixel = Fetch4(pict, bits, offset);
1658             const pixman_indexed_t * indexed = pict->indexed;
1659             
1660             buffer[i] = indexed->rgba[pixel];
1661         }
1662     }
1663 }
1664
1665
1666 static void
1667 fbFetchPixel_a1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1668 {
1669     int i;
1670
1671     for (i = 0; i < n_pixels; ++i)
1672     {
1673         int offset = buffer[2 * i];
1674         int line = buffer[2 * i + 1];
1675
1676         if (offset == 0xffffffff || line == 0xffffffff)
1677         {
1678             buffer[i] = 0;
1679         }
1680         else
1681         {
1682             uint32_t *bits = pict->bits + line*pict->rowstride;
1683             uint32_t  pixel = READ(pict, bits + (offset >> 5));
1684             uint32_t  a;
1685 #ifdef WORDS_BIGENDIAN
1686             a = pixel >> (0x1f - (offset & 0x1f));
1687 #else
1688             a = pixel >> (offset & 0x1f);
1689 #endif
1690             a = a & 1;
1691             a |= a << 1;
1692             a |= a << 2;
1693             a |= a << 4;
1694             buffer[i] = a << 24;
1695         }
1696     }
1697 }
1698
1699 static void
1700 fbFetchPixel_g1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1701 {
1702     int i;
1703
1704     for (i = 0; i < n_pixels; ++i)
1705     {
1706         int offset = buffer[2 * i];
1707         int line = buffer[2 * i + 1];
1708
1709         if (offset == 0xffffffff || line == 0xffffffff)
1710         {
1711             buffer[i] = 0;
1712         }
1713         else
1714         {
1715             uint32_t *bits = pict->bits + line*pict->rowstride;
1716             uint32_t pixel = READ(pict, bits + (offset >> 5));
1717             const pixman_indexed_t * indexed = pict->indexed;
1718             uint32_t a;
1719 #ifdef WORDS_BIGENDIAN
1720             a = pixel >> (0x1f - (offset & 0x1f));
1721 #else
1722             a = pixel >> (offset & 0x1f);
1723 #endif
1724             a = a & 1;
1725             buffer[i] = indexed->rgba[a];
1726         }
1727     }
1728 }
1729
1730 static void
1731 fbFetchPixel_yuy2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1732 {
1733     int i;
1734
1735     for (i = 0; i < n_pixels; ++i)
1736     {
1737         int offset = buffer[2 * i];
1738         int line = buffer[2 * i + 1];
1739
1740         if (offset == 0xffffffff || line == 0xffffffff)
1741         {
1742             buffer[i] = 0;
1743         }
1744         else
1745         {
1746             int16_t y, u, v;
1747             int32_t r, g, b;
1748             
1749             const uint32_t *bits = pict->bits + pict->rowstride * line;
1750             
1751             y = ((uint8_t *) bits)[offset << 1] - 16;
1752             u = ((uint8_t *) bits)[((offset << 1) & -4) + 1] - 128;
1753             v = ((uint8_t *) bits)[((offset << 1) & -4) + 3] - 128;
1754             
1755             /* R = 1.164(Y - 16) + 1.596(V - 128) */
1756             r = 0x012b27 * y + 0x019a2e * v;
1757             /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1758             g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1759             /* B = 1.164(Y - 16) + 2.018(U - 128) */
1760             b = 0x012b27 * y + 0x0206a2 * u;
1761             
1762             buffer[i] = 0xff000000 |
1763                 (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
1764                 (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
1765                 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1766         }
1767     }
1768 }
1769
1770 static void
1771 fbFetchPixel_yv12 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1772 {
1773     int i;
1774
1775     for (i = 0; i < n_pixels; ++i)
1776     {
1777         int offset = buffer[2 * i];
1778         int line = buffer[2 * i + 1];
1779
1780         if (offset == 0xffffffff || line == 0xffffffff)
1781         {
1782             buffer[i] = 0;
1783         }
1784         else
1785         {
1786             YV12_SETUP(pict);
1787             int16_t y = YV12_Y (line)[offset] - 16;
1788             int16_t u = YV12_U (line)[offset >> 1] - 128;
1789             int16_t v = YV12_V (line)[offset >> 1] - 128;
1790             int32_t r, g, b;
1791             
1792             /* R = 1.164(Y - 16) + 1.596(V - 128) */
1793             r = 0x012b27 * y + 0x019a2e * v;
1794             /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1795             g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1796             /* B = 1.164(Y - 16) + 2.018(U - 128) */
1797             b = 0x012b27 * y + 0x0206a2 * u;
1798             
1799             buffer[i] = 0xff000000 |
1800                 (r >= 0 ? r < 0x1000000 ? r         & 0xff0000 : 0xff0000 : 0) |
1801                 (g >= 0 ? g < 0x1000000 ? (g >> 8)  & 0x00ff00 : 0x00ff00 : 0) |
1802                 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1803         }
1804     }
1805 }
1806
1807 /*********************************** Store ************************************/
1808
1809 #define Splita(v)       uint32_t        a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1810 #define Split(v)        uint32_t        r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1811
1812 static void
1813 fbStore_a2b10g10r10 (pixman_image_t *image,
1814                      uint32_t *bits, const uint64_t *values,
1815                      int x, int width)
1816 {
1817     int i;
1818     uint32_t *pixel = bits + x;
1819     for (i = 0; i < width; ++i) {
1820         WRITE(image, pixel++,
1821             ((values[i] >> 32) & 0xc0000000) | // A
1822             ((values[i] >> 38) & 0x3ff) |      // R
1823             ((values[i] >> 12) & 0xffc00) |    // G
1824             ((values[i] << 14) & 0x3ff00000)); // B
1825     }
1826 }
1827
1828 static void
1829 fbStore_x2b10g10r10 (pixman_image_t *image,
1830                      uint32_t *bits, const uint64_t *values, int x, int width)
1831 {
1832     int i;
1833     uint32_t *pixel = bits + x;
1834     for (i = 0; i < width; ++i) {
1835         WRITE(image, pixel++,
1836             ((values[i] >> 38) & 0x3ff) |      // R
1837             ((values[i] >> 12) & 0xffc00) |    // G
1838             ((values[i] << 14) & 0x3ff00000)); // B
1839     }
1840 }
1841
1842 static void
1843 fbStore_a8r8g8b8 (pixman_image_t *image,
1844                   uint32_t *bits, const uint32_t *values, int x, int width)
1845 {
1846     MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
1847 }
1848
1849 static void
1850 fbStore_x8r8g8b8 (pixman_image_t *image,
1851                   uint32_t *bits, const uint32_t *values, int x, int width)
1852 {
1853     int i;
1854     uint32_t *pixel = (uint32_t *)bits + x;
1855     for (i = 0; i < width; ++i)
1856         WRITE(image, pixel++, values[i] & 0xffffff);
1857 }
1858
1859 static void
1860 fbStore_a8b8g8r8 (pixman_image_t *image,
1861                   uint32_t *bits, const uint32_t *values, int x, int width)
1862 {
1863     int i;
1864     uint32_t *pixel = (uint32_t *)bits + x;
1865     for (i = 0; i < width; ++i)
1866         WRITE(image, pixel++, (values[i] & 0xff00ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1867 }
1868
1869 static void
1870 fbStore_x8b8g8r8 (pixman_image_t *image,
1871                   uint32_t *bits, const uint32_t *values, int x, int width)
1872 {
1873     int i;
1874     uint32_t *pixel = (uint32_t *)bits + x;
1875     for (i = 0; i < width; ++i)
1876         WRITE(image, pixel++, (values[i] & 0x0000ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1877 }
1878
1879 static void
1880 fbStore_b8g8r8a8 (pixman_image_t *image,
1881                   uint32_t *bits, const uint32_t *values, int x, int width)
1882 {
1883     int i;
1884     uint32_t *pixel = (uint32_t *)bits + x;
1885     for (i = 0; i < width; ++i)
1886         WRITE(image, pixel++,
1887             ((values[i] >> 24) & 0x000000ff) |
1888             ((values[i] >>  8) & 0x0000ff00) |
1889             ((values[i] <<  8) & 0x00ff0000) |
1890             ((values[i] << 24) & 0xff000000));
1891 }
1892
1893 static void
1894 fbStore_b8g8r8x8 (pixman_image_t *image,
1895                   uint32_t *bits, const uint32_t *values, int x, int width)
1896 {
1897     int i;
1898     uint32_t *pixel = (uint32_t *)bits + x;
1899     for (i = 0; i < width; ++i)
1900         WRITE(image, pixel++,
1901             ((values[i] >>  8) & 0x0000ff00) |
1902             ((values[i] <<  8) & 0x00ff0000) |
1903             ((values[i] << 24) & 0xff000000));
1904 }
1905
1906 static void
1907 fbStore_r8g8b8 (pixman_image_t *image,
1908                 uint32_t *bits, const uint32_t *values, int x, int width)
1909 {
1910     int i;
1911     uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1912     for (i = 0; i < width; ++i)
1913     {
1914         uint32_t val = values[i];
1915 #ifdef WORDS_BIGENDIAN
1916         WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
1917         WRITE(image, pixel++, (val & 0x0000ff00) >>  8);
1918         WRITE(image, pixel++, (val & 0x000000ff) >>  0);
1919 #else
1920         WRITE(image, pixel++, (val & 0x000000ff) >>  0);
1921         WRITE(image, pixel++, (val & 0x0000ff00) >>  8);
1922         WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
1923 #endif
1924     }
1925 }
1926
1927 static void
1928 fbStore_b8g8r8 (pixman_image_t *image,
1929                 uint32_t *bits, const uint32_t *values, int x, int width)
1930 {
1931     int i;
1932     uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1933     for (i = 0; i < width; ++i)
1934     {
1935         uint32_t val = values[i];
1936 #ifdef WORDS_BIGENDIAN
1937         WRITE(image, pixel++, (val & 0x000000ff) >>  0);
1938         WRITE(image, pixel++, (val & 0x0000ff00) >>  8);
1939         WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
1940 #else
1941         WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
1942         WRITE(image, pixel++, (val & 0x0000ff00) >>  8);
1943         WRITE(image, pixel++, (val & 0x000000ff) >>  0);
1944 #endif
1945     }
1946 }
1947
1948 static void
1949 fbStore_r5g6b5 (pixman_image_t *image,
1950                 uint32_t *bits, const uint32_t *values, int x, int width)
1951 {
1952     int i;
1953     uint16_t *pixel = ((uint16_t *) bits) + x;
1954     for (i = 0; i < width; ++i) {
1955         uint32_t s = values[i];
1956         WRITE(image, pixel++, ((s >> 3) & 0x001f) |
1957               ((s >> 5) & 0x07e0) |
1958               ((s >> 8) & 0xf800));
1959     }
1960 }
1961
1962 static void
1963 fbStore_b5g6r5 (pixman_image_t *image,
1964                 uint32_t *bits, const uint32_t *values, int x, int width)
1965 {
1966     int i;
1967     uint16_t  *pixel = ((uint16_t *) bits) + x;
1968     for (i = 0; i < width; ++i) {
1969         Split(values[i]);
1970         WRITE(image, pixel++, ((b << 8) & 0xf800) |
1971               ((g << 3) & 0x07e0) |
1972               ((r >> 3)         ));
1973     }
1974 }
1975
1976 static void
1977 fbStore_a1r5g5b5 (pixman_image_t *image,
1978                   uint32_t *bits, const uint32_t *values, int x, int width)
1979 {
1980     int i;
1981     uint16_t  *pixel = ((uint16_t *) bits) + x;
1982     for (i = 0; i < width; ++i) {
1983         Splita(values[i]);
1984         WRITE(image, pixel++, ((a << 8) & 0x8000) |
1985               ((r << 7) & 0x7c00) |
1986               ((g << 2) & 0x03e0) |
1987               ((b >> 3)         ));
1988     }
1989 }
1990
1991 static void
1992 fbStore_x1r5g5b5 (pixman_image_t *image,
1993                   uint32_t *bits, const uint32_t *values, int x, int width)
1994 {
1995     int i;
1996     uint16_t  *pixel = ((uint16_t *) bits) + x;
1997     for (i = 0; i < width; ++i) {
1998         Split(values[i]);
1999         WRITE(image, pixel++, ((r << 7) & 0x7c00) |
2000               ((g << 2) & 0x03e0) |
2001               ((b >> 3)         ));
2002     }
2003 }
2004
2005 static void
2006 fbStore_a1b5g5r5 (pixman_image_t *image,
2007                   uint32_t *bits, const uint32_t *values, int x, int width)
2008 {
2009     int i;
2010     uint16_t  *pixel = ((uint16_t *) bits) + x;
2011     for (i = 0; i < width; ++i) {
2012         Splita(values[i]);
2013         WRITE(image, pixel++, ((a << 8) & 0x8000) |
2014               ((b << 7) & 0x7c00) |
2015               ((g << 2) & 0x03e0) |
2016               ((r >> 3)         ));
2017     }
2018 }
2019
2020 static void
2021 fbStore_x1b5g5r5 (pixman_image_t *image,
2022                   uint32_t *bits, const uint32_t *values, int x, int width)
2023 {
2024     int i;
2025     uint16_t  *pixel = ((uint16_t *) bits) + x;
2026     for (i = 0; i < width; ++i) {
2027         Split(values[i]);
2028         WRITE(image, pixel++, ((b << 7) & 0x7c00) |
2029               ((g << 2) & 0x03e0) |
2030               ((r >> 3)         ));
2031     }
2032 }
2033
2034 static void
2035 fbStore_a4r4g4b4 (pixman_image_t *image,
2036                   uint32_t *bits, const uint32_t *values, int x, int width)
2037 {
2038     int i;
2039     uint16_t  *pixel = ((uint16_t *) bits) + x;
2040     for (i = 0; i < width; ++i) {
2041         Splita(values[i]);
2042         WRITE(image, pixel++, ((a << 8) & 0xf000) |
2043               ((r << 4) & 0x0f00) |
2044               ((g     ) & 0x00f0) |
2045               ((b >> 4)         ));
2046     }
2047 }
2048
2049 static void
2050 fbStore_x4r4g4b4 (pixman_image_t *image,
2051                   uint32_t *bits, const uint32_t *values, int x, int width)
2052 {
2053     int i;
2054     uint16_t  *pixel = ((uint16_t *) bits) + x;
2055     for (i = 0; i < width; ++i) {
2056         Split(values[i]);
2057         WRITE(image, pixel++, ((r << 4) & 0x0f00) |
2058               ((g     ) & 0x00f0) |
2059               ((b >> 4)         ));
2060     }
2061 }
2062
2063 static void
2064 fbStore_a4b4g4r4 (pixman_image_t *image,
2065                   uint32_t *bits, const uint32_t *values, int x, int width)
2066 {
2067     int i;
2068     uint16_t  *pixel = ((uint16_t *) bits) + x;
2069     for (i = 0; i < width; ++i) {
2070         Splita(values[i]);
2071         WRITE(image, pixel++, ((a << 8) & 0xf000) |
2072               ((b << 4) & 0x0f00) |
2073               ((g     ) & 0x00f0) |
2074               ((r >> 4)         ));
2075     }
2076 }
2077
2078 static void
2079 fbStore_x4b4g4r4 (pixman_image_t *image,
2080                   uint32_t *bits, const uint32_t *values, int x, int width)
2081 {
2082     int i;
2083     uint16_t  *pixel = ((uint16_t *) bits) + x;
2084     for (i = 0; i < width; ++i) {
2085         Split(values[i]);
2086         WRITE(image, pixel++, ((b << 4) & 0x0f00) |
2087               ((g     ) & 0x00f0) |
2088               ((r >> 4)         ));
2089     }
2090 }
2091
2092 static void
2093 fbStore_a8 (pixman_image_t *image,
2094             uint32_t *bits, const uint32_t *values, int x, int width)
2095 {
2096     int i;
2097     uint8_t   *pixel = ((uint8_t *) bits) + x;
2098     for (i = 0; i < width; ++i) {
2099         WRITE(image, pixel++, values[i] >> 24);
2100     }
2101 }
2102
2103 static void
2104 fbStore_r3g3b2 (pixman_image_t *image,
2105                 uint32_t *bits, const uint32_t *values, int x, int width)
2106 {
2107     int i;
2108     uint8_t   *pixel = ((uint8_t *) bits) + x;
2109     for (i = 0; i < width; ++i) {
2110         Split(values[i]);
2111         WRITE(image, pixel++,
2112               ((r     ) & 0xe0) |
2113               ((g >> 3) & 0x1c) |
2114               ((b >> 6)       ));
2115     }
2116 }
2117
2118 static void
2119 fbStore_b2g3r3 (pixman_image_t *image,
2120                 uint32_t *bits, const uint32_t *values, int x, int width)
2121 {
2122     int i;
2123     uint8_t   *pixel = ((uint8_t *) bits) + x;
2124     for (i = 0; i < width; ++i) {
2125         Split(values[i]);
2126         WRITE(image, pixel++,
2127               ((b     ) & 0xc0) |
2128               ((g >> 2) & 0x38) |
2129               ((r >> 5)       ));
2130     }
2131 }
2132
2133 static void
2134 fbStore_a2r2g2b2 (pixman_image_t *image,
2135                   uint32_t *bits, const uint32_t *values, int x, int width)
2136 {
2137     int i;
2138     uint8_t   *pixel = ((uint8_t *) bits) + x;
2139     for (i = 0; i < width; ++i) {
2140         Splita(values[i]);
2141         WRITE(image, pixel++, ((a     ) & 0xc0) |
2142               ((r >> 2) & 0x30) |
2143               ((g >> 4) & 0x0c) |
2144               ((b >> 6)       ));
2145     }
2146 }
2147
2148 static void
2149 fbStore_a2b2g2r2 (pixman_image_t *image,
2150                   uint32_t *bits, const uint32_t *values, int x, int width)
2151 {
2152     int i;
2153     uint8_t   *pixel = ((uint8_t *) bits) + x;
2154     for (i = 0; i < width; ++i) {
2155         Splita(values[i]);
2156         *(pixel++) =  ((a     ) & 0xc0) |
2157             ((b >> 2) & 0x30) |
2158             ((g >> 4) & 0x0c) |
2159             ((r >> 6)       );
2160     }
2161 }
2162
2163 static void
2164 fbStore_c8 (pixman_image_t *image,
2165             uint32_t *bits, const uint32_t *values, int x, int width)
2166 {
2167     const pixman_indexed_t *indexed = image->bits.indexed;
2168     int i;
2169     uint8_t   *pixel = ((uint8_t *) bits) + x;
2170     for (i = 0; i < width; ++i) {
2171         WRITE(image, pixel++, miIndexToEnt24(indexed,values[i]));
2172     }
2173 }
2174
2175 static void
2176 fbStore_x4a4 (pixman_image_t *image,
2177               uint32_t *bits, const uint32_t *values, int x, int width)
2178 {
2179     int i;
2180     uint8_t   *pixel = ((uint8_t *) bits) + x;
2181     for (i = 0; i < width; ++i) {
2182         WRITE(image, pixel++, values[i] >> 28);
2183     }
2184 }
2185
2186 #define Store8(img,l,o,v)  (WRITE(img, (uint8_t *)(l) + ((o) >> 3), (v)))
2187 #ifdef WORDS_BIGENDIAN
2188 #define Store4(img,l,o,v)  Store8(img,l,o,((o) & 4 ?                            \
2189                                    (Fetch8(img,l,o) & 0xf0) | (v) :             \
2190                                    (Fetch8(img,l,o) & 0x0f) | ((v) << 4)))
2191 #else
2192 #define Store4(img,l,o,v)  Store8(img,l,o,((o) & 4 ?                           \
2193                                    (Fetch8(img,l,o) & 0x0f) | ((v) << 4) : \
2194                                    (Fetch8(img,l,o) & 0xf0) | (v)))
2195 #endif
2196
2197 static void
2198 fbStore_a4 (pixman_image_t *image,
2199             uint32_t *bits, const uint32_t *values, int x, int width)
2200 {
2201     int i;
2202     for (i = 0; i < width; ++i) {
2203         Store4(image, bits, i + x, values[i]>>28);
2204     }
2205 }
2206
2207 static void
2208 fbStore_r1g2b1 (pixman_image_t *image,
2209                 uint32_t *bits, const uint32_t *values, int x, int width)
2210 {
2211     int i;
2212     for (i = 0; i < width; ++i) {
2213         uint32_t  pixel;
2214
2215         Split(values[i]);
2216         pixel = (((r >> 4) & 0x8) |
2217                  ((g >> 5) & 0x6) |
2218                  ((b >> 7)      ));
2219         Store4(image, bits, i + x, pixel);
2220     }
2221 }
2222
2223 static void
2224 fbStore_b1g2r1 (pixman_image_t *image,
2225                 uint32_t *bits, const uint32_t *values, int x, int width)
2226 {
2227     int i;
2228     for (i = 0; i < width; ++i) {
2229         uint32_t  pixel;
2230
2231         Split(values[i]);
2232         pixel = (((b >> 4) & 0x8) |
2233                  ((g >> 5) & 0x6) |
2234                  ((r >> 7)      ));
2235         Store4(image, bits, i + x, pixel);
2236     }
2237 }
2238
2239 static void
2240 fbStore_a1r1g1b1 (pixman_image_t *image,
2241                   uint32_t *bits, const uint32_t *values, int x, int width)
2242 {
2243     int i;
2244     for (i = 0; i < width; ++i) {
2245         uint32_t  pixel;
2246         Splita(values[i]);
2247         pixel = (((a >> 4) & 0x8) |
2248                  ((r >> 5) & 0x4) |
2249                  ((g >> 6) & 0x2) |
2250                  ((b >> 7)      ));
2251         Store4(image, bits, i + x, pixel);
2252     }
2253 }
2254
2255 static void
2256 fbStore_a1b1g1r1 (pixman_image_t *image,
2257                   uint32_t *bits, const uint32_t *values, int x, int width)
2258 {
2259     int i;
2260     for (i = 0; i < width; ++i) {
2261         uint32_t  pixel;
2262         Splita(values[i]);
2263         pixel = (((a >> 4) & 0x8) |
2264                  ((b >> 5) & 0x4) |
2265                  ((g >> 6) & 0x2) |
2266                  ((r >> 7)      ));
2267         Store4(image, bits, i + x, pixel);
2268     }
2269 }
2270
2271 static void
2272 fbStore_c4 (pixman_image_t *image,
2273             uint32_t *bits, const uint32_t *values, int x, int width)
2274 {
2275     const pixman_indexed_t *indexed = image->bits.indexed;
2276     int i;
2277     for (i = 0; i < width; ++i) {
2278         uint32_t  pixel;
2279
2280         pixel = miIndexToEnt24(indexed, values[i]);
2281         Store4(image, bits, i + x, pixel);
2282     }
2283 }
2284
2285 static void
2286 fbStore_a1 (pixman_image_t *image,
2287             uint32_t *bits, const uint32_t *values, int x, int width)
2288 {
2289     int i;
2290     for (i = 0; i < width; ++i)
2291     {
2292         uint32_t  *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2293         uint32_t mask, v;
2294 #ifdef WORDS_BIGENDIAN
2295         mask = 1 << (0x1f - ((i+x) & 0x1f));
2296 #else
2297         mask = 1 << ((i+x) & 0x1f);
2298 #endif
2299         v = values[i] & 0x80000000 ? mask : 0;
2300         WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2301     }
2302 }
2303
2304 static void
2305 fbStore_g1 (pixman_image_t *image,
2306             uint32_t *bits, const uint32_t *values, int x, int width)
2307 {
2308     const pixman_indexed_t *indexed = image->bits.indexed;
2309     int i;
2310     for (i = 0; i < width; ++i)
2311     {
2312         uint32_t  *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2313         uint32_t  mask, v;
2314 #ifdef WORDS_BIGENDIAN
2315         mask = 1 << (0x1f - ((i+x) & 0x1f));
2316 #else
2317         mask = 1 << ((i + x) & 0x1f);
2318 #endif
2319         v = miIndexToEntY24 (indexed, values[i]) ? mask : 0;
2320         WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2321     }
2322 }
2323
2324 /*
2325  * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2326  * store proc.
2327  */
2328 static void
2329 fbStore64_generic (pixman_image_t *image,
2330                    uint32_t *bits, const uint64_t *values, int x, int width)
2331 {
2332     uint32_t *argb8Pixels;
2333
2334     assert(image->common.type == BITS);
2335
2336     argb8Pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2337     if (!argb8Pixels)
2338         return;
2339
2340     /* Contract the scanline.  We could do this in place if values weren't
2341      * const.
2342      */
2343     pixman_contract(argb8Pixels, values, width);
2344     
2345     image->bits.store_scanline_raw_32 (image, bits, argb8Pixels, x, width);
2346
2347     free(argb8Pixels);
2348 }
2349
2350 static void
2351 fbFetch64_generic (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
2352 {
2353     /* Fetch the pixels into the first half of buffer and then expand them in
2354      * place.
2355      */
2356     pict->fetch_scanline_raw_32 (pict, x, y, width, (uint32_t*)buffer);
2357     
2358     pixman_expand (buffer, (uint32_t*)buffer, pict->format, width);
2359 }
2360
2361 static void
2362 fbFetchPixel64_generic (bits_image_t *pict, uint64_t *buffer, int n_pixels)
2363 {
2364     pict->fetch_pixels_raw_32 (pict, (uint32_t *)buffer, n_pixels);
2365     
2366     pixman_expand (buffer, (uint32_t *)buffer, pict->format, n_pixels);
2367 }
2368
2369 /*
2370  * XXX: The transformed fetch path only works at 32-bpp so far.  When all paths
2371  * have wide versions, this can be removed.
2372  *
2373  * WARNING: This function loses precision!
2374  */
2375 static void
2376 fbFetchPixel32_generic_lossy (bits_image_t *pict, uint32_t *buffer, int n_pixels)
2377 {
2378     /* Since buffer contains n_pixels coordinate pairs, it also has enough room for
2379      * n_pixels 64 bit pixels
2380      */
2381     pict->fetch_pixels_raw_64 (pict, (uint64_t *)buffer, n_pixels);
2382     
2383     pixman_contract (buffer, (uint64_t *)buffer, n_pixels);
2384 }
2385
2386 typedef struct
2387 {
2388     pixman_format_code_t                format;
2389     fetchProc32                         fetch_scanline_raw_32;
2390     fetchProc64                         fetch_scanline_raw_64;
2391     fetch_pixels_32_t                   fetch_pixels_raw_32;
2392     fetch_pixels_64_t                   fetch_pixels_raw_64;
2393     storeProc32                         store_scanline_raw_32;
2394     storeProc64                         store_scanline_raw_64;
2395 } format_info_t;
2396
2397 #define FORMAT_INFO(format)                                             \
2398     {                                                                   \
2399         PIXMAN_##format,                                                \
2400             fbFetch_##format, fbFetch64_generic,                        \
2401             fbFetchPixel_##format, fbFetchPixel64_generic,              \
2402             fbStore_##format, fbStore64_generic                         \
2403     }
2404
2405 static const format_info_t accessors[] =
2406 {
2407 /* 32 bpp formats */
2408     FORMAT_INFO (a8r8g8b8),
2409     FORMAT_INFO (x8r8g8b8),
2410     FORMAT_INFO (a8b8g8r8),
2411     FORMAT_INFO (x8b8g8r8),
2412     FORMAT_INFO (b8g8r8a8),
2413     FORMAT_INFO (b8g8r8x8),
2414
2415 /* 24bpp formats */
2416     FORMAT_INFO (r8g8b8),
2417     FORMAT_INFO (b8g8r8),
2418     
2419 /* 16bpp formats */
2420     FORMAT_INFO (r5g6b5),
2421     FORMAT_INFO (b5g6r5),
2422     
2423     FORMAT_INFO (a1r5g5b5),
2424     FORMAT_INFO (x1r5g5b5),
2425     FORMAT_INFO (a1b5g5r5),
2426     FORMAT_INFO (x1b5g5r5),
2427     FORMAT_INFO (a4r4g4b4),
2428     FORMAT_INFO (x4r4g4b4),
2429     FORMAT_INFO (a4b4g4r4),
2430     FORMAT_INFO (x4b4g4r4),
2431     
2432 /* 8bpp formats */
2433     FORMAT_INFO (a8),
2434     FORMAT_INFO (r3g3b2),
2435     FORMAT_INFO (b2g3r3),
2436     FORMAT_INFO (a2r2g2b2),
2437     FORMAT_INFO (a2b2g2r2),
2438     
2439     FORMAT_INFO (c8),
2440
2441 #define fbFetch_g8 fbFetch_c8
2442 #define fbFetchPixel_g8 fbFetchPixel_c8
2443 #define fbStore_g8 fbStore_c8
2444     FORMAT_INFO (g8),
2445 #define fbFetch_x4c4 fbFetch_c8
2446 #define fbFetchPixel_x4c4 fbFetchPixel_c8
2447 #define fbStore_x4c4 fbStore_c8
2448     FORMAT_INFO (x4c4),
2449 #define fbFetch_x4g4 fbFetch_c8
2450 #define fbFetchPixel_x4g4 fbFetchPixel_c8
2451 #define fbStore_x4g4 fbStore_c8
2452     FORMAT_INFO (x4g4),
2453     
2454     FORMAT_INFO (x4a4),
2455     
2456 /* 4bpp formats */
2457     FORMAT_INFO (a4),
2458     FORMAT_INFO (r1g2b1),
2459     FORMAT_INFO (b1g2r1),
2460     FORMAT_INFO (a1r1g1b1),
2461     FORMAT_INFO (a1b1g1r1),
2462     
2463     FORMAT_INFO (c4),
2464 #define fbFetch_g4 fbFetch_c4
2465 #define fbFetchPixel_g4 fbFetchPixel_c4
2466 #define fbStore_g4 fbStore_c4
2467     FORMAT_INFO (g4),
2468     
2469 /* 1bpp formats */
2470     FORMAT_INFO (a1),
2471     FORMAT_INFO (g1),
2472
2473 /* Wide formats */
2474     
2475     { PIXMAN_a2b10g10r10,
2476       NULL, fbFetch_a2b10g10r10,
2477       fbFetchPixel32_generic_lossy, fbFetchPixel_a2b10g10r10,
2478       NULL, fbStore_a2b10g10r10 },
2479
2480     { PIXMAN_x2b10g10r10,
2481       NULL, fbFetch_x2b10g10r10,
2482       fbFetchPixel32_generic_lossy, fbFetchPixel_x2b10g10r10,
2483       NULL, fbStore_x2b10g10r10 },
2484
2485 /* YUV formats */
2486     { PIXMAN_yuy2,
2487       fbFetch_yuy2, fbFetch64_generic,
2488       fbFetchPixel_yuy2, fbFetchPixel64_generic,
2489       NULL, NULL },
2490
2491     { PIXMAN_yv12,
2492       fbFetch_yv12, fbFetch64_generic,
2493       fbFetchPixel_yv12, fbFetchPixel64_generic,
2494       NULL, NULL },
2495     
2496     { PIXMAN_null },
2497 };
2498
2499 static void
2500 setup_accessors (bits_image_t *image)
2501 {
2502     const format_info_t *info = accessors;
2503
2504     while (info->format != PIXMAN_null)
2505     {
2506         if (info->format == image->format)
2507         {
2508             image->fetch_scanline_raw_32 = info->fetch_scanline_raw_32;
2509             image->fetch_scanline_raw_64 = info->fetch_scanline_raw_64;
2510             image->fetch_pixels_raw_32 = info->fetch_pixels_raw_32;
2511             image->fetch_pixels_raw_64 = info->fetch_pixels_raw_64;
2512             image->store_scanline_raw_32 = info->store_scanline_raw_32;
2513             image->store_scanline_raw_64 = info->store_scanline_raw_64;
2514
2515             return;
2516         }
2517
2518         info++;
2519     }
2520 }
2521
2522 #ifndef PIXMAN_FB_ACCESSORS
2523 void
2524 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image);
2525
2526 void
2527 _pixman_bits_image_setup_raw_accessors (bits_image_t *image)
2528 {
2529     if (image->common.read_func || image->common.write_func)
2530         _pixman_bits_image_setup_raw_accessors_accessors (image);
2531     else
2532         setup_accessors (image);
2533 }
2534
2535 #else
2536
2537 void
2538 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image)
2539 {
2540     setup_accessors (image);
2541 }
2542
2543 #endif