3 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4 * 2005 Lars Knoll & Zack Rusin, Trolltech
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.
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
32 #include "pixman-private.h"
34 #define Red(x) (((x) >> 16) & 0xff)
35 #define Green(x) (((x) >> 8) & 0xff)
36 #define Blue(x) ((x) & 0xff)
39 * YV12 setup and access macros
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.
57 #define YV12_Y(line) \
58 ((uint8_t *) ((bits) + (stride) * (line)))
60 #define YV12_U(line) \
61 ((uint8_t *) ((bits) + offset1 + \
62 ((stride) >> 1) * ((line) >> 1)))
64 #define YV12_V(line) \
65 ((uint8_t *) ((bits) + offset0 + \
66 ((stride) >> 1) * ((line) >> 1)))
68 /*********************************** Fetch ************************************/
71 fbFetch_a8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
73 const uint32_t *bits = pict->bits + y*pict->rowstride;
75 buffer, (const uint32_t *)bits + x,
76 width*sizeof(uint32_t));
80 fbFetch_x8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
86 *buffer++ = READ(pict, pixel++) | 0xff000000;
91 fbFetch_a8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
97 uint32_t p = READ(pict, pixel++);
98 *buffer++ = (p & 0xff00ff00) |
105 fbFetch_x8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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 |
120 fbFetch_r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
133 fbFetch_b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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);
145 b |= (READ(pict, pixel++) << 16);
146 b |= (READ(pict, pixel++) << 8);
147 b |= (READ(pict, pixel++));
154 fbFetch_r5g6b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
171 fbFetch_b5g6r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
187 fbFetch_a1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
205 fbFetch_x1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
222 fbFetch_a1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
240 fbFetch_x1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
257 fbFetch_a4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
275 fbFetch_x4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
292 fbFetch_a4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
310 fbFetch_x4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
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;
327 fbFetch_a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
338 fbFetch_r3g3b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
347 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
348 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
353 *buffer++ = 0xff000000 | r | g | b;
358 fbFetch_b2g3r3 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
371 g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
374 ((p & 0x06) << 6)) << 16;
375 *buffer++ = 0xff000000 | r | g | b;
380 fbFetch_a2r2g2b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
389 a = ((p & 0xc0) * 0x55) << 18;
390 r = ((p & 0x30) * 0x55) << 12;
391 g = ((p & 0x0c) * 0x55) << 6;
392 b = ((p & 0x03) * 0x55);
398 fbFetch_a2b2g2r2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
407 a = ((p & 0xc0) * 0x55) << 18;
408 b = ((p & 0x30) * 0x55) >> 6;
409 g = ((p & 0x0c) * 0x55) << 6;
410 r = ((p & 0x03) * 0x55) << 16;
416 fbFetch_c8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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];
429 fbFetch_x4a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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;
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)
444 #define Fetch4(img,l,o) ((o) & 2 ? Fetch8(img,l,o) >> 4 : Fetch8(img,l,o) & 0xf)
448 fbFetch_a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
450 const uint32_t *bits = pict->bits + y*pict->rowstride;
452 for (i = 0; i < width; ++i) {
453 uint32_t p = Fetch4(pict, bits, i + x);
461 fbFetch_r1g2b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
464 const uint32_t *bits = pict->bits + y*pict->rowstride;
466 for (i = 0; i < width; ++i) {
467 uint32_t p = Fetch4(pict, bits, i + x);
469 r = ((p & 0x8) * 0xff) << 13;
470 g = ((p & 0x6) * 0x55) << 7;
471 b = ((p & 0x1) * 0xff);
472 *buffer++ = 0xff000000|r|g|b;
477 fbFetch_b1g2r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
480 const uint32_t *bits = pict->bits + y*pict->rowstride;
482 for (i = 0; i < width; ++i) {
483 uint32_t p = Fetch4(pict, bits, i + x);
485 b = ((p & 0x8) * 0xff) >> 3;
486 g = ((p & 0x6) * 0x55) << 7;
487 r = ((p & 0x1) * 0xff) << 16;
488 *buffer++ = 0xff000000|r|g|b;
493 fbFetch_a1r1g1b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
496 const uint32_t *bits = pict->bits + y*pict->rowstride;
498 for (i = 0; i < width; ++i) {
499 uint32_t p = Fetch4(pict, bits, i + x);
501 a = ((p & 0x8) * 0xff) << 21;
502 r = ((p & 0x4) * 0xff) << 14;
503 g = ((p & 0x2) * 0xff) << 7;
504 b = ((p & 0x1) * 0xff);
510 fbFetch_a1b1g1r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
513 const uint32_t *bits = pict->bits + y*pict->rowstride;
515 for (i = 0; i < width; ++i) {
516 uint32_t p = Fetch4(pict, bits, i + x);
518 a = ((p & 0x8) * 0xff) << 21;
519 r = ((p & 0x4) * 0xff) >> 3;
520 g = ((p & 0x2) * 0xff) << 7;
521 b = ((p & 0x1) * 0xff) << 16;
527 fbFetch_c4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
529 const uint32_t *bits = pict->bits + y*pict->rowstride;
530 const pixman_indexed_t * indexed = pict->indexed;
532 for (i = 0; i < width; ++i) {
533 uint32_t p = Fetch4(pict, bits, i + x);
535 *buffer++ = indexed->rgba[p];
541 fbFetch_a1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
543 const uint32_t *bits = pict->bits + y*pict->rowstride;
545 for (i = 0; i < width; ++i) {
546 uint32_t p = READ(pict, bits + ((i + x) >> 5));
548 #if BITMAP_BIT_ORDER == MSBFirst
549 a = p >> (0x1f - ((i+x) & 0x1f));
551 a = p >> ((i+x) & 0x1f);
562 fbFetch_g1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
564 const uint32_t *bits = pict->bits + y*pict->rowstride;
565 const pixman_indexed_t * indexed = pict->indexed;
567 for (i = 0; i < width; ++i) {
568 uint32_t p = READ(pict, bits + ((i+x) >> 5));
570 #if BITMAP_BIT_ORDER == MSBFirst
571 a = p >> (0x1f - ((i+x) & 0x1f));
573 a = p >> ((i+x) & 0x1f);
576 *buffer++ = indexed->rgba[a];
581 fbFetch_yuy2 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
587 const uint32_t *bits = pict->bits + pict->rowstride * line;
589 for (i = 0; i < width; i++)
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;
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;
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));
610 fbFetch_yv12 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
613 uint8_t *pY = YV12_Y (line);
614 uint8_t *pU = YV12_U (line);
615 uint8_t *pV = YV12_V (line);
620 for (i = 0; i < width; i++)
623 u = pU[(x + i) >> 1] - 128;
624 v = pV[(x + i) >> 1] - 128;
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;
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));
640 fetchProc32 ACCESS(pixman_fetchProcForPicture32) (bits_image_t * pict)
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;
649 case PIXMAN_r8g8b8: return fbFetch_r8g8b8;
650 case PIXMAN_b8g8r8: return fbFetch_b8g8r8;
653 case PIXMAN_r5g6b5: return fbFetch_r5g6b5;
654 case PIXMAN_b5g6r5: return fbFetch_b5g6r5;
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;
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;
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;
685 case PIXMAN_a1: return fbFetch_a1;
686 case PIXMAN_g1: return fbFetch_g1;
689 case PIXMAN_yuy2: return fbFetch_yuy2;
690 case PIXMAN_yv12: return fbFetch_yv12;
696 /**************************** Pixel wise fetching *****************************/
698 static FASTCALL uint32_t
699 fbFetchPixel_a8r8g8b8 (bits_image_t *pict, int offset, int line)
701 uint32_t *bits = pict->bits + line*pict->rowstride;
702 return READ(pict, (uint32_t *)bits + offset);
705 static FASTCALL uint32_t
706 fbFetchPixel_x8r8g8b8 (bits_image_t *pict, int offset, int line)
708 uint32_t *bits = pict->bits + line*pict->rowstride;
709 return READ(pict, (uint32_t *)bits + offset) | 0xff000000;
712 static FASTCALL uint32_t
713 fbFetchPixel_a8b8g8r8 (bits_image_t *pict, int offset, int line)
715 uint32_t *bits = pict->bits + line*pict->rowstride;
716 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
718 return ((pixel & 0xff000000) |
719 ((pixel >> 16) & 0xff) |
720 (pixel & 0x0000ff00) |
721 ((pixel & 0xff) << 16));
724 static FASTCALL uint32_t
725 fbFetchPixel_x8b8g8r8 (bits_image_t *pict, int offset, int line)
727 uint32_t *bits = pict->bits + line*pict->rowstride;
728 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
730 return ((0xff000000) |
731 ((pixel >> 16) & 0xff) |
732 (pixel & 0x0000ff00) |
733 ((pixel & 0xff) << 16));
736 static FASTCALL uint32_t
737 fbFetchPixel_r8g8b8 (bits_image_t *pict, int offset, int line)
739 uint32_t *bits = pict->bits + line*pict->rowstride;
740 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
741 #if IMAGE_BYTE_ORDER == MSBFirst
743 (READ(pict, pixel + 0) << 16) |
744 (READ(pict, pixel + 1) << 8) |
745 (READ(pict, pixel + 2)));
748 (READ(pict, pixel + 2) << 16) |
749 (READ(pict, pixel + 1) << 8) |
750 (READ(pict, pixel + 0)));
754 static FASTCALL uint32_t
755 fbFetchPixel_b8g8r8 (bits_image_t *pict, int offset, int line)
757 uint32_t *bits = pict->bits + line*pict->rowstride;
758 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
759 #if IMAGE_BYTE_ORDER == MSBFirst
761 (READ(pict, pixel + 2) << 16) |
762 (READ(pict, pixel + 1) << 8) |
763 (READ(pict, pixel + 0)));
766 (READ(pict, pixel + 0) << 16) |
767 (READ(pict, pixel + 1) << 8) |
768 (READ(pict, pixel + 2)));
772 static FASTCALL uint32_t
773 fbFetchPixel_r5g6b5 (bits_image_t *pict, int offset, int line)
776 uint32_t *bits = pict->bits + line*pict->rowstride;
777 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
785 static FASTCALL uint32_t
786 fbFetchPixel_b5g6r5 (bits_image_t *pict, int offset, int line)
789 uint32_t *bits = pict->bits + line*pict->rowstride;
790 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
798 static FASTCALL uint32_t
799 fbFetchPixel_a1r5g5b5 (bits_image_t *pict, int offset, int line)
802 uint32_t *bits = pict->bits + line*pict->rowstride;
803 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
812 static FASTCALL uint32_t
813 fbFetchPixel_x1r5g5b5 (bits_image_t *pict, int offset, int line)
816 uint32_t *bits = pict->bits + line*pict->rowstride;
817 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
825 static FASTCALL uint32_t
826 fbFetchPixel_a1b5g5r5 (bits_image_t *pict, int offset, int line)
829 uint32_t *bits = pict->bits + line*pict->rowstride;
830 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
839 static FASTCALL uint32_t
840 fbFetchPixel_x1b5g5r5 (bits_image_t *pict, int offset, int line)
843 uint32_t *bits = pict->bits + line*pict->rowstride;
844 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
852 static FASTCALL uint32_t
853 fbFetchPixel_a4r4g4b4 (bits_image_t *pict, int offset, int line)
856 uint32_t *bits = pict->bits + line*pict->rowstride;
857 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
866 static FASTCALL uint32_t
867 fbFetchPixel_x4r4g4b4 (bits_image_t *pict, int offset, int line)
870 uint32_t *bits = pict->bits + line*pict->rowstride;
871 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
879 static FASTCALL uint32_t
880 fbFetchPixel_a4b4g4r4 (bits_image_t *pict, int offset, int line)
883 uint32_t *bits = pict->bits + line*pict->rowstride;
884 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
893 static FASTCALL uint32_t
894 fbFetchPixel_x4b4g4r4 (bits_image_t *pict, int offset, int line)
897 uint32_t *bits = pict->bits + line*pict->rowstride;
898 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
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);
906 static FASTCALL uint32_t
907 fbFetchPixel_a8 (bits_image_t *pict, int offset, int line)
909 uint32_t *bits = pict->bits + line*pict->rowstride;
910 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
915 static FASTCALL uint32_t
916 fbFetchPixel_r3g3b2 (bits_image_t *pict, int offset, int line)
919 uint32_t *bits = pict->bits + line*pict->rowstride;
920 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
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);
931 static FASTCALL uint32_t
932 fbFetchPixel_b2g3r3 (bits_image_t *pict, int offset, int line)
935 uint32_t *bits = pict->bits + line*pict->rowstride;
936 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
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);
949 static FASTCALL uint32_t
950 fbFetchPixel_a2r2g2b2 (bits_image_t *pict, int offset, int line)
953 uint32_t *bits = pict->bits + line*pict->rowstride;
954 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
956 a = ((pixel & 0xc0) * 0x55) << 18;
957 r = ((pixel & 0x30) * 0x55) << 12;
958 g = ((pixel & 0x0c) * 0x55) << 6;
959 b = ((pixel & 0x03) * 0x55);
963 static FASTCALL uint32_t
964 fbFetchPixel_a2b2g2r2 (bits_image_t *pict, int offset, int line)
967 uint32_t *bits = pict->bits + line*pict->rowstride;
968 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
970 a = ((pixel & 0xc0) * 0x55) << 18;
971 b = ((pixel & 0x30) * 0x55) >> 6;
972 g = ((pixel & 0x0c) * 0x55) << 6;
973 r = ((pixel & 0x03) * 0x55) << 16;
977 static FASTCALL uint32_t
978 fbFetchPixel_c8 (bits_image_t *pict, int offset, int line)
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];
986 static FASTCALL uint32_t
987 fbFetchPixel_x4a4 (bits_image_t *pict, int offset, int line)
989 uint32_t *bits = pict->bits + line*pict->rowstride;
990 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
992 return ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
995 static FASTCALL uint32_t
996 fbFetchPixel_a4 (bits_image_t *pict, int offset, int line)
998 uint32_t *bits = pict->bits + line*pict->rowstride;
999 uint32_t pixel = Fetch4(pict, bits, offset);
1001 pixel |= pixel << 4;
1005 static FASTCALL uint32_t
1006 fbFetchPixel_r1g2b1 (bits_image_t *pict, int offset, int line)
1009 uint32_t *bits = pict->bits + line*pict->rowstride;
1010 uint32_t pixel = Fetch4(pict, bits, offset);
1012 r = ((pixel & 0x8) * 0xff) << 13;
1013 g = ((pixel & 0x6) * 0x55) << 7;
1014 b = ((pixel & 0x1) * 0xff);
1015 return 0xff000000|r|g|b;
1018 static FASTCALL uint32_t
1019 fbFetchPixel_b1g2r1 (bits_image_t *pict, int offset, int line)
1022 uint32_t *bits = pict->bits + line*pict->rowstride;
1023 uint32_t pixel = Fetch4(pict, bits, offset);
1025 b = ((pixel & 0x8) * 0xff) >> 3;
1026 g = ((pixel & 0x6) * 0x55) << 7;
1027 r = ((pixel & 0x1) * 0xff) << 16;
1028 return 0xff000000|r|g|b;
1031 static FASTCALL uint32_t
1032 fbFetchPixel_a1r1g1b1 (bits_image_t *pict, int offset, int line)
1035 uint32_t *bits = pict->bits + line*pict->rowstride;
1036 uint32_t pixel = Fetch4(pict, bits, offset);
1038 a = ((pixel & 0x8) * 0xff) << 21;
1039 r = ((pixel & 0x4) * 0xff) << 14;
1040 g = ((pixel & 0x2) * 0xff) << 7;
1041 b = ((pixel & 0x1) * 0xff);
1045 static FASTCALL uint32_t
1046 fbFetchPixel_a1b1g1r1 (bits_image_t *pict, int offset, int line)
1049 uint32_t *bits = pict->bits + line*pict->rowstride;
1050 uint32_t pixel = Fetch4(pict, bits, offset);
1052 a = ((pixel & 0x8) * 0xff) << 21;
1053 r = ((pixel & 0x4) * 0xff) >> 3;
1054 g = ((pixel & 0x2) * 0xff) << 7;
1055 b = ((pixel & 0x1) * 0xff) << 16;
1059 static FASTCALL uint32_t
1060 fbFetchPixel_c4 (bits_image_t *pict, int offset, int line)
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;
1066 return indexed->rgba[pixel];
1070 static FASTCALL uint32_t
1071 fbFetchPixel_a1 (bits_image_t *pict, int offset, int line)
1073 uint32_t *bits = pict->bits + line*pict->rowstride;
1074 uint32_t pixel = READ(pict, bits + (offset >> 5));
1076 #if BITMAP_BIT_ORDER == MSBFirst
1077 a = pixel >> (0x1f - (offset & 0x1f));
1079 a = pixel >> (offset & 0x1f);
1088 static FASTCALL uint32_t
1089 fbFetchPixel_g1 (bits_image_t *pict, int offset, int line)
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;
1095 #if BITMAP_BIT_ORDER == MSBFirst
1096 a = pixel >> (0x1f - (offset & 0x1f));
1098 a = pixel >> (offset & 0x1f);
1101 return indexed->rgba[a];
1104 static FASTCALL uint32_t
1105 fbFetchPixel_yuy2 (bits_image_t *pict, int offset, int line)
1110 const uint32_t *bits = pict->bits + pict->rowstride * line;
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;
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;
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);
1129 static FASTCALL uint32_t
1130 fbFetchPixel_yv12 (bits_image_t *pict, int offset, int line)
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;
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;
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);
1151 fetchPixelProc32 ACCESS(pixman_fetchPixelProcForPicture32) (bits_image_t * pict)
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;
1160 case PIXMAN_r8g8b8: return fbFetchPixel_r8g8b8;
1161 case PIXMAN_b8g8r8: return fbFetchPixel_b8g8r8;
1164 case PIXMAN_r5g6b5: return fbFetchPixel_r5g6b5;
1165 case PIXMAN_b5g6r5: return fbFetchPixel_b5g6r5;
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;
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;
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;
1196 case PIXMAN_a1: return fbFetchPixel_a1;
1197 case PIXMAN_g1: return fbFetchPixel_g1;
1200 case PIXMAN_yuy2: return fbFetchPixel_yuy2;
1201 case PIXMAN_yv12: return fbFetchPixel_yv12;
1207 /*********************************** Store ************************************/
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
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)
1216 MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
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)
1224 uint32_t *pixel = (uint32_t *)bits + x;
1225 for (i = 0; i < width; ++i)
1226 WRITE(image, pixel++, values[i] & 0xffffff);
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)
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));
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)
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));
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)
1255 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1256 for (i = 0; i < width; ++i) {
1257 Store24(image, pixel, values[i]);
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)
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));
1275 WRITE(image, pixel++, Red(val));
1276 WRITE(image, pixel++, Green(val));
1277 WRITE(image, pixel++, Blue(val));
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)
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));
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)
1301 uint16_t *pixel = ((uint16_t *) bits) + x;
1302 for (i = 0; i < width; ++i) {
1304 WRITE(image, pixel++, ((b << 8) & 0xf800) |
1305 ((g << 3) & 0x07e0) |
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)
1315 uint16_t *pixel = ((uint16_t *) bits) + x;
1316 for (i = 0; i < width; ++i) {
1318 WRITE(image, pixel++, ((a << 8) & 0x8000) |
1319 ((r << 7) & 0x7c00) |
1320 ((g << 2) & 0x03e0) |
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)
1330 uint16_t *pixel = ((uint16_t *) bits) + x;
1331 for (i = 0; i < width; ++i) {
1333 WRITE(image, pixel++, ((r << 7) & 0x7c00) |
1334 ((g << 2) & 0x03e0) |
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)
1344 uint16_t *pixel = ((uint16_t *) bits) + x;
1345 for (i = 0; i < width; ++i) {
1347 WRITE(image, pixel++, ((a << 8) & 0x8000) |
1348 ((b << 7) & 0x7c00) |
1349 ((g << 2) & 0x03e0) |
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)
1359 uint16_t *pixel = ((uint16_t *) bits) + x;
1360 for (i = 0; i < width; ++i) {
1362 WRITE(image, pixel++, ((b << 7) & 0x7c00) |
1363 ((g << 2) & 0x03e0) |
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)
1373 uint16_t *pixel = ((uint16_t *) bits) + x;
1374 for (i = 0; i < width; ++i) {
1376 WRITE(image, pixel++, ((a << 8) & 0xf000) |
1377 ((r << 4) & 0x0f00) |
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)
1388 uint16_t *pixel = ((uint16_t *) bits) + x;
1389 for (i = 0; i < width; ++i) {
1391 WRITE(image, pixel++, ((r << 4) & 0x0f00) |
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)
1402 uint16_t *pixel = ((uint16_t *) bits) + x;
1403 for (i = 0; i < width; ++i) {
1405 WRITE(image, pixel++, ((a << 8) & 0xf000) |
1406 ((b << 4) & 0x0f00) |
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)
1417 uint16_t *pixel = ((uint16_t *) bits) + x;
1418 for (i = 0; i < width; ++i) {
1420 WRITE(image, pixel++, ((b << 4) & 0x0f00) |
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)
1431 uint8_t *pixel = ((uint8_t *) bits) + x;
1432 for (i = 0; i < width; ++i) {
1433 WRITE(image, pixel++, values[i] >> 24);
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)
1442 uint8_t *pixel = ((uint8_t *) bits) + x;
1443 for (i = 0; i < width; ++i) {
1445 WRITE(image, pixel++,
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)
1457 uint8_t *pixel = ((uint8_t *) bits) + x;
1458 for (i = 0; i < width; ++i) {
1460 WRITE(image, pixel++,
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)
1472 uint8_t *pixel = ((uint8_t *) bits) + x;
1473 for (i = 0; i < width; ++i) {
1475 WRITE(image, pixel++, ((a ) & 0xc0) |
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)
1487 uint8_t *pixel = ((uint8_t *) bits) + x;
1488 for (i = 0; i < width; ++i) {
1489 WRITE(image, pixel++, miIndexToEnt24(indexed,values[i]));
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)
1498 uint8_t *pixel = ((uint8_t *) bits) + x;
1499 for (i = 0; i < width; ++i) {
1500 WRITE(image, pixel++, values[i] >> 28);
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)))
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)))
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)
1520 for (i = 0; i < width; ++i) {
1521 Store4(image, bits, i + x, values[i]>>28);
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)
1530 for (i = 0; i < width; ++i) {
1534 pixel = (((r >> 4) & 0x8) |
1537 Store4(image, bits, i + x, pixel);
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)
1546 for (i = 0; i < width; ++i) {
1550 pixel = (((b >> 4) & 0x8) |
1553 Store4(image, bits, i + x, pixel);
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)
1562 for (i = 0; i < width; ++i) {
1565 pixel = (((a >> 4) & 0x8) |
1569 Store4(image, bits, i + x, pixel);
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)
1578 for (i = 0; i < width; ++i) {
1581 pixel = (((a >> 4) & 0x8) |
1585 Store4(image, bits, i + x, pixel);
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)
1594 for (i = 0; i < width; ++i) {
1597 pixel = miIndexToEnt24(indexed, values[i]);
1598 Store4(image, bits, i + x, pixel);
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)
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);
1611 uint32_t v = values[i] & 0x80000000 ? mask : 0;
1612 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
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)
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);
1625 uint32_t v = miIndexToEntY24(indexed,values[i]) ? mask : 0;
1626 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
1631 storeProc32 ACCESS(pixman_storeProcForPicture32) (bits_image_t * pict)
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;
1640 case PIXMAN_r8g8b8: return fbStore_r8g8b8;
1641 case PIXMAN_b8g8r8: return fbStore_b8g8r8;
1644 case PIXMAN_r5g6b5: return fbStore_r5g6b5;
1645 case PIXMAN_b5g6r5: return fbStore_b5g6r5;
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;
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;
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;
1675 case PIXMAN_a1: return fbStore_a1;
1676 case PIXMAN_g1: return fbStore_g1;