3 * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4 * 2005 Lars Knoll & Zack Rusin, Trolltech
5 * 2008 Aaron Plattner, NVIDIA Corporation
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.
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
35 #include "pixman-private.h"
37 #define Red(x) (((x) >> 16) & 0xff)
38 #define Green(x) (((x) >> 8) & 0xff)
39 #define Blue(x) ((x) & 0xff)
42 * YV12 setup and access macros
45 #define YV12_SETUP(pict) \
46 uint32_t *bits = pict->bits; \
47 int stride = pict->rowstride; \
48 int offset0 = stride < 0 ? \
49 ((-stride) >> 1) * ((pict->height - 1) >> 1) - stride : \
50 stride * pict->height; \
51 int offset1 = stride < 0 ? \
52 offset0 + ((-stride) >> 1) * ((pict->height) >> 1) : \
53 offset0 + (offset0 >> 2)
54 /* Note no trailing semicolon on the above macro; if it's there, then
55 * the typical usage of YV12_SETUP(pict); will have an extra trailing ;
56 * that some compilers will interpret as a statement -- and then any further
57 * variable declarations will cause an error.
60 #define YV12_Y(line) \
61 ((uint8_t *) ((bits) + (stride) * (line)))
63 #define YV12_U(line) \
64 ((uint8_t *) ((bits) + offset1 + \
65 ((stride) >> 1) * ((line) >> 1)))
67 #define YV12_V(line) \
68 ((uint8_t *) ((bits) + offset0 + \
69 ((stride) >> 1) * ((line) >> 1)))
71 /*********************************** Fetch ************************************/
74 fbFetch_a8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
76 const uint32_t *bits = pict->bits + y*pict->rowstride;
78 buffer, (const uint32_t *)bits + x,
79 width*sizeof(uint32_t));
83 fbFetch_x8r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
85 const uint32_t *bits = pict->bits + y*pict->rowstride;
86 const uint32_t *pixel = (const uint32_t *)bits + x;
87 const uint32_t *end = pixel + width;
89 *buffer++ = READ(pict, pixel++) | 0xff000000;
94 fbFetch_a8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
96 const uint32_t *bits = pict->bits + y*pict->rowstride;
97 const uint32_t *pixel = (uint32_t *)bits + x;
98 const uint32_t *end = pixel + width;
100 uint32_t p = READ(pict, pixel++);
101 *buffer++ = (p & 0xff00ff00) |
108 fbFetch_x8b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
110 const uint32_t *bits = pict->bits + y*pict->rowstride;
111 const uint32_t *pixel = (uint32_t *)bits + x;
112 const uint32_t *end = pixel + width;
113 while (pixel < end) {
114 uint32_t p = READ(pict, pixel++);
115 *buffer++ = 0xff000000 |
123 fbFetch_b8g8r8a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
125 const uint32_t *bits = pict->bits + y*pict->rowstride;
126 const uint32_t *pixel = (uint32_t *)bits + x;
127 const uint32_t *end = pixel + width;
128 while (pixel < end) {
129 uint32_t p = READ(pict, pixel++);
130 *buffer++ = ((p & 0xff000000) >> 24) |
131 ((p & 0x00ff0000) >> 8) |
132 ((p & 0x0000ff00) << 8) |
133 ((p & 0x000000ff) << 24);
138 fbFetch_b8g8r8x8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
140 const uint32_t *bits = pict->bits + y*pict->rowstride;
141 const uint32_t *pixel = (uint32_t *)bits + x;
142 const uint32_t *end = pixel + width;
143 while (pixel < end) {
144 uint32_t p = READ(pict, pixel++);
145 *buffer++ = 0xff000000 |
146 ((p & 0xff000000) >> 24) |
147 ((p & 0x00ff0000) >> 8) |
148 ((p & 0x0000ff00) << 8);
153 fbFetch_a2b10g10r10 (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
155 const uint32_t *bits = pict->bits + y*pict->rowstride;
156 const uint32_t *pixel = bits + x;
157 const uint32_t *end = pixel + width;
158 while (pixel < end) {
159 uint32_t p = READ(pict, pixel++);
160 uint64_t a = p >> 30;
161 uint64_t b = (p >> 20) & 0x3ff;
162 uint64_t g = (p >> 10) & 0x3ff;
163 uint64_t r = p & 0x3ff;
174 *buffer++ = a << 48 | r << 32 | g << 16 | b;
179 fbFetch_x2b10g10r10 (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
181 const uint32_t *bits = pict->bits + y*pict->rowstride;
182 const uint32_t *pixel = (uint32_t *)bits + x;
183 const uint32_t *end = pixel + width;
184 while (pixel < end) {
185 uint32_t p = READ(pict, pixel++);
186 uint64_t b = (p >> 20) & 0x3ff;
187 uint64_t g = (p >> 10) & 0x3ff;
188 uint64_t r = p & 0x3ff;
194 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
199 fbFetch_r8g8b8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
201 const uint32_t *bits = pict->bits + y*pict->rowstride;
202 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
203 const uint8_t *end = pixel + 3*width;
204 while (pixel < end) {
205 uint32_t b = Fetch24(pict, pixel) | 0xff000000;
212 fbFetch_b8g8r8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
214 const uint32_t *bits = pict->bits + y*pict->rowstride;
215 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
216 const uint8_t *end = pixel + 3*width;
217 while (pixel < end) {
218 uint32_t b = 0xff000000;
219 #if IMAGE_BYTE_ORDER == MSBFirst
220 b |= (READ(pict, pixel++));
221 b |= (READ(pict, pixel++) << 8);
222 b |= (READ(pict, pixel++) << 16);
224 b |= (READ(pict, pixel++) << 16);
225 b |= (READ(pict, pixel++) << 8);
226 b |= (READ(pict, pixel++));
233 fbFetch_r5g6b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
235 const uint32_t *bits = pict->bits + y*pict->rowstride;
236 const uint16_t *pixel = (const uint16_t *)bits + x;
237 const uint16_t *end = pixel + width;
238 while (pixel < end) {
239 uint32_t p = READ(pict, pixel++);
240 uint32_t r = (((p) << 3) & 0xf8) |
241 (((p) << 5) & 0xfc00) |
242 (((p) << 8) & 0xf80000);
243 r |= (r >> 5) & 0x70007;
244 r |= (r >> 6) & 0x300;
245 *buffer++ = 0xff000000 | r;
250 fbFetch_b5g6r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
253 const uint32_t *bits = pict->bits + y*pict->rowstride;
254 const uint16_t *pixel = (const uint16_t *)bits + x;
255 const uint16_t *end = pixel + width;
256 while (pixel < end) {
257 uint32_t p = READ(pict, pixel++);
258 b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
259 g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
260 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
261 *buffer++ = 0xff000000 | r | g | b;
266 fbFetch_a1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
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++);
275 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
276 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
277 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
278 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
279 *buffer++ = a | r | g | b;
284 fbFetch_x1r5g5b5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
287 const uint32_t *bits = pict->bits + y*pict->rowstride;
288 const uint16_t *pixel = (const uint16_t *)bits + x;
289 const uint16_t *end = pixel + width;
290 while (pixel < end) {
291 uint32_t p = READ(pict, pixel++);
293 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
294 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
295 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
296 *buffer++ = 0xff000000 | r | g | b;
301 fbFetch_a1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
304 const uint32_t *bits = pict->bits + y*pict->rowstride;
305 const uint16_t *pixel = (const uint16_t *)bits + x;
306 const uint16_t *end = pixel + width;
307 while (pixel < end) {
308 uint32_t p = READ(pict, pixel++);
310 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
311 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
312 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
313 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
314 *buffer++ = a | r | g | b;
319 fbFetch_x1b5g5r5 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
322 const uint32_t *bits = pict->bits + y*pict->rowstride;
323 const uint16_t *pixel = (const uint16_t *)bits + x;
324 const uint16_t *end = pixel + width;
325 while (pixel < end) {
326 uint32_t p = READ(pict, pixel++);
328 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
329 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
330 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
331 *buffer++ = 0xff000000 | r | g | b;
336 fbFetch_a4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
339 const uint32_t *bits = pict->bits + y*pict->rowstride;
340 const uint16_t *pixel = (const uint16_t *)bits + x;
341 const uint16_t *end = pixel + width;
342 while (pixel < end) {
343 uint32_t p = READ(pict, pixel++);
345 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
346 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
347 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
348 b = ((p & 0x000f) | ((p & 0x000f) << 4));
349 *buffer++ = a | r | g | b;
354 fbFetch_x4r4g4b4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
357 const uint32_t *bits = pict->bits + y*pict->rowstride;
358 const uint16_t *pixel = (const uint16_t *)bits + x;
359 const uint16_t *end = pixel + width;
360 while (pixel < end) {
361 uint32_t p = READ(pict, pixel++);
363 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
364 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
365 b = ((p & 0x000f) | ((p & 0x000f) << 4));
366 *buffer++ = 0xff000000 | r | g | b;
371 fbFetch_a4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
374 const uint32_t *bits = pict->bits + y*pict->rowstride;
375 const uint16_t *pixel = (const uint16_t *)bits + x;
376 const uint16_t *end = pixel + width;
377 while (pixel < end) {
378 uint32_t p = READ(pict, pixel++);
380 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
381 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
382 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
383 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
384 *buffer++ = a | r | g | b;
389 fbFetch_x4b4g4r4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
392 const uint32_t *bits = pict->bits + y*pict->rowstride;
393 const uint16_t *pixel = (const uint16_t *)bits + x;
394 const uint16_t *end = pixel + width;
395 while (pixel < end) {
396 uint32_t p = READ(pict, pixel++);
398 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
399 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
400 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
401 *buffer++ = 0xff000000 | r | g | b;
406 fbFetch_a8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
408 const uint32_t *bits = pict->bits + y*pict->rowstride;
409 const uint8_t *pixel = (const uint8_t *)bits + x;
410 const uint8_t *end = pixel + width;
411 while (pixel < end) {
412 *buffer++ = READ(pict, pixel++) << 24;
417 fbFetch_r3g3b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
420 const uint32_t *bits = pict->bits + y*pict->rowstride;
421 const uint8_t *pixel = (const uint8_t *)bits + x;
422 const uint8_t *end = pixel + width;
423 while (pixel < end) {
424 uint32_t p = READ(pict, pixel++);
426 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
427 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
432 *buffer++ = 0xff000000 | r | g | b;
437 fbFetch_b2g3r3 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
440 const uint32_t *bits = pict->bits + y*pict->rowstride;
441 const uint8_t *pixel = (const uint8_t *)bits + x;
442 const uint8_t *end = pixel + width;
443 while (pixel < end) {
444 uint32_t p = READ(pict, pixel++);
450 g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
453 ((p & 0x06) << 6)) << 16;
454 *buffer++ = 0xff000000 | r | g | b;
459 fbFetch_a2r2g2b2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
462 const uint32_t *bits = pict->bits + y*pict->rowstride;
463 const uint8_t *pixel = (const uint8_t *)bits + x;
464 const uint8_t *end = pixel + width;
465 while (pixel < end) {
466 uint32_t p = READ(pict, pixel++);
468 a = ((p & 0xc0) * 0x55) << 18;
469 r = ((p & 0x30) * 0x55) << 12;
470 g = ((p & 0x0c) * 0x55) << 6;
471 b = ((p & 0x03) * 0x55);
477 fbFetch_a2b2g2r2 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
480 const uint32_t *bits = pict->bits + y*pict->rowstride;
481 const uint8_t *pixel = (const uint8_t *)bits + x;
482 const uint8_t *end = pixel + width;
483 while (pixel < end) {
484 uint32_t p = READ(pict, pixel++);
486 a = ((p & 0xc0) * 0x55) << 18;
487 b = ((p & 0x30) * 0x55) >> 6;
488 g = ((p & 0x0c) * 0x55) << 6;
489 r = ((p & 0x03) * 0x55) << 16;
495 fbFetch_c8 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
497 const uint32_t *bits = pict->bits + y*pict->rowstride;
498 const pixman_indexed_t * indexed = pict->indexed;
499 const uint8_t *pixel = (const uint8_t *)bits + x;
500 const uint8_t *end = pixel + width;
501 while (pixel < end) {
502 uint32_t p = READ(pict, pixel++);
503 *buffer++ = indexed->rgba[p];
508 fbFetch_x4a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
510 const uint32_t *bits = pict->bits + y*pict->rowstride;
511 const uint8_t *pixel = (const uint8_t *)bits + x;
512 const uint8_t *end = pixel + width;
513 while (pixel < end) {
514 uint8_t p = READ(pict, pixel++) & 0xf;
515 *buffer++ = (p | (p << 4)) << 24;
519 #define Fetch8(img,l,o) (READ(img, (uint8_t *)(l) + ((o) >> 2)))
520 #if IMAGE_BYTE_ORDER == MSBFirst
521 #define Fetch4(img,l,o) ((o) & 2 ? Fetch8(img,l,o) & 0xf : Fetch8(img,l,o) >> 4)
523 #define Fetch4(img,l,o) ((o) & 2 ? Fetch8(img,l,o) >> 4 : Fetch8(img,l,o) & 0xf)
527 fbFetch_a4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
529 const uint32_t *bits = pict->bits + y*pict->rowstride;
531 for (i = 0; i < width; ++i) {
532 uint32_t p = Fetch4(pict, bits, i + x);
540 fbFetch_r1g2b1 (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 = Fetch4(pict, bits, i + x);
548 r = ((p & 0x8) * 0xff) << 13;
549 g = ((p & 0x6) * 0x55) << 7;
550 b = ((p & 0x1) * 0xff);
551 *buffer++ = 0xff000000|r|g|b;
556 fbFetch_b1g2r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
559 const uint32_t *bits = pict->bits + y*pict->rowstride;
561 for (i = 0; i < width; ++i) {
562 uint32_t p = Fetch4(pict, bits, i + x);
564 b = ((p & 0x8) * 0xff) >> 3;
565 g = ((p & 0x6) * 0x55) << 7;
566 r = ((p & 0x1) * 0xff) << 16;
567 *buffer++ = 0xff000000|r|g|b;
572 fbFetch_a1r1g1b1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
575 const uint32_t *bits = pict->bits + y*pict->rowstride;
577 for (i = 0; i < width; ++i) {
578 uint32_t p = Fetch4(pict, bits, i + x);
580 a = ((p & 0x8) * 0xff) << 21;
581 r = ((p & 0x4) * 0xff) << 14;
582 g = ((p & 0x2) * 0xff) << 7;
583 b = ((p & 0x1) * 0xff);
589 fbFetch_a1b1g1r1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
592 const uint32_t *bits = pict->bits + y*pict->rowstride;
594 for (i = 0; i < width; ++i) {
595 uint32_t p = Fetch4(pict, bits, i + x);
597 a = ((p & 0x8) * 0xff) << 21;
598 r = ((p & 0x4) * 0xff) >> 3;
599 g = ((p & 0x2) * 0xff) << 7;
600 b = ((p & 0x1) * 0xff) << 16;
606 fbFetch_c4 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
608 const uint32_t *bits = pict->bits + y*pict->rowstride;
609 const pixman_indexed_t * indexed = pict->indexed;
611 for (i = 0; i < width; ++i) {
612 uint32_t p = Fetch4(pict, bits, i + x);
614 *buffer++ = indexed->rgba[p];
620 fbFetch_a1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
622 const uint32_t *bits = pict->bits + y*pict->rowstride;
624 for (i = 0; i < width; ++i) {
625 uint32_t p = READ(pict, bits + ((i + x) >> 5));
627 #if BITMAP_BIT_ORDER == MSBFirst
628 a = p >> (0x1f - ((i+x) & 0x1f));
630 a = p >> ((i+x) & 0x1f);
641 fbFetch_g1 (bits_image_t *pict, int x, int y, int width, uint32_t *buffer)
643 const uint32_t *bits = pict->bits + y*pict->rowstride;
644 const pixman_indexed_t * indexed = pict->indexed;
646 for (i = 0; i < width; ++i) {
647 uint32_t p = READ(pict, bits + ((i+x) >> 5));
649 #if BITMAP_BIT_ORDER == MSBFirst
650 a = p >> (0x1f - ((i+x) & 0x1f));
652 a = p >> ((i+x) & 0x1f);
655 *buffer++ = indexed->rgba[a];
660 fbFetch_yuy2 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
666 const uint32_t *bits = pict->bits + pict->rowstride * line;
668 for (i = 0; i < width; i++)
670 y = ((uint8_t *) bits)[(x + i) << 1] - 16;
671 u = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 1] - 128;
672 v = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 3] - 128;
674 /* R = 1.164(Y - 16) + 1.596(V - 128) */
675 r = 0x012b27 * y + 0x019a2e * v;
676 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
677 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
678 /* B = 1.164(Y - 16) + 2.018(U - 128) */
679 b = 0x012b27 * y + 0x0206a2 * u;
681 WRITE(pict, buffer++, 0xff000000 |
682 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
683 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
684 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
689 fbFetch_yv12 (bits_image_t *pict, int x, int line, int width, uint32_t *buffer)
692 uint8_t *pY = YV12_Y (line);
693 uint8_t *pU = YV12_U (line);
694 uint8_t *pV = YV12_V (line);
699 for (i = 0; i < width; i++)
702 u = pU[(x + i) >> 1] - 128;
703 v = pV[(x + i) >> 1] - 128;
705 /* R = 1.164(Y - 16) + 1.596(V - 128) */
706 r = 0x012b27 * y + 0x019a2e * v;
707 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
708 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
709 /* B = 1.164(Y - 16) + 2.018(U - 128) */
710 b = 0x012b27 * y + 0x0206a2 * u;
712 WRITE(pict, buffer++, 0xff000000 |
713 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
714 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
715 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0));
719 fetchProc32 ACCESS(pixman_fetchProcForPicture32) (bits_image_t * pict)
721 switch(pict->format) {
722 case PIXMAN_a8r8g8b8: return fbFetch_a8r8g8b8;
723 case PIXMAN_x8r8g8b8: return fbFetch_x8r8g8b8;
724 case PIXMAN_a8b8g8r8: return fbFetch_a8b8g8r8;
725 case PIXMAN_x8b8g8r8: return fbFetch_x8b8g8r8;
726 case PIXMAN_b8g8r8a8: return fbFetch_b8g8r8a8;
727 case PIXMAN_b8g8r8x8: return fbFetch_b8g8r8x8;
728 /* These two require wide compositing */
729 case PIXMAN_a2b10g10r10: return NULL;
730 case PIXMAN_x2b10g10r10: return NULL;
733 case PIXMAN_r8g8b8: return fbFetch_r8g8b8;
734 case PIXMAN_b8g8r8: return fbFetch_b8g8r8;
737 case PIXMAN_r5g6b5: return fbFetch_r5g6b5;
738 case PIXMAN_b5g6r5: return fbFetch_b5g6r5;
740 case PIXMAN_a1r5g5b5: return fbFetch_a1r5g5b5;
741 case PIXMAN_x1r5g5b5: return fbFetch_x1r5g5b5;
742 case PIXMAN_a1b5g5r5: return fbFetch_a1b5g5r5;
743 case PIXMAN_x1b5g5r5: return fbFetch_x1b5g5r5;
744 case PIXMAN_a4r4g4b4: return fbFetch_a4r4g4b4;
745 case PIXMAN_x4r4g4b4: return fbFetch_x4r4g4b4;
746 case PIXMAN_a4b4g4r4: return fbFetch_a4b4g4r4;
747 case PIXMAN_x4b4g4r4: return fbFetch_x4b4g4r4;
750 case PIXMAN_a8: return fbFetch_a8;
751 case PIXMAN_r3g3b2: return fbFetch_r3g3b2;
752 case PIXMAN_b2g3r3: return fbFetch_b2g3r3;
753 case PIXMAN_a2r2g2b2: return fbFetch_a2r2g2b2;
754 case PIXMAN_a2b2g2r2: return fbFetch_a2b2g2r2;
755 case PIXMAN_c8: return fbFetch_c8;
756 case PIXMAN_g8: return fbFetch_c8;
757 case PIXMAN_x4a4: return fbFetch_x4a4;
760 case PIXMAN_a4: return fbFetch_a4;
761 case PIXMAN_r1g2b1: return fbFetch_r1g2b1;
762 case PIXMAN_b1g2r1: return fbFetch_b1g2r1;
763 case PIXMAN_a1r1g1b1: return fbFetch_a1r1g1b1;
764 case PIXMAN_a1b1g1r1: return fbFetch_a1b1g1r1;
765 case PIXMAN_c4: return fbFetch_c4;
766 case PIXMAN_g4: return fbFetch_c4;
769 case PIXMAN_a1: return fbFetch_a1;
770 case PIXMAN_g1: return fbFetch_g1;
773 case PIXMAN_yuy2: return fbFetch_yuy2;
774 case PIXMAN_yv12: return fbFetch_yv12;
781 fbFetch64_generic (bits_image_t *pict, int x, int y, int width, uint64_t *buffer)
783 fetchProc32 fetch32 = ACCESS(pixman_fetchProcForPicture32) (pict);
785 // Fetch the pixels into the first half of buffer and then expand them in
787 fetch32(pict, x, y, width, (uint32_t*)buffer);
788 pixman_expand(buffer, (uint32_t*)buffer, pict->format, width);
791 fetchProc64 ACCESS(pixman_fetchProcForPicture64) (bits_image_t * pict)
793 switch(pict->format) {
794 case PIXMAN_a2b10g10r10: return fbFetch_a2b10g10r10;
795 case PIXMAN_x2b10g10r10: return fbFetch_x2b10g10r10;
796 default: return fbFetch64_generic;
800 /**************************** Pixel wise fetching *****************************/
803 fbFetchPixel_a2b10g10r10 (bits_image_t *pict, uint64_t *buffer, int n_pixels)
807 for (i = 0; i < n_pixels; ++i)
809 int offset = ((uint32_t *)buffer)[2 * i];
810 int line = ((uint32_t *)buffer)[2 * i + 1];
812 if (offset == 0xffffffff || line == 0xffffffff)
818 uint32_t *bits = pict->bits + line*pict->rowstride;
819 uint32_t p = READ(pict, bits + offset);
820 uint64_t a = p >> 30;
821 uint64_t b = (p >> 20) & 0x3ff;
822 uint64_t g = (p >> 10) & 0x3ff;
823 uint64_t r = p & 0x3ff;
834 buffer[i] = a << 48 | r << 32 | g << 16 | b;
840 fbFetchPixel_x2b10g10r10 (bits_image_t *pict, uint64_t *buffer, int n_pixels)
844 for (i = 0; i < n_pixels; ++i)
846 int offset = ((uint32_t *)buffer)[2 * i];
847 int line = ((uint32_t *)buffer)[2 * i + 1];
849 if (offset == 0xffffffff || line == 0xffffffff)
855 uint32_t *bits = pict->bits + line*pict->rowstride;
856 uint32_t p = READ(pict, bits + offset);
857 uint64_t b = (p >> 20) & 0x3ff;
858 uint64_t g = (p >> 10) & 0x3ff;
859 uint64_t r = p & 0x3ff;
865 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
871 fbFetchPixel_a8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
875 for (i = 0; i < n_pixels; ++i)
877 int offset = buffer[2 * i];
878 int line = buffer[2 * i + 1];
880 if (offset == 0xffffffff || line == 0xffffffff)
886 uint32_t *bits = pict->bits + line*pict->rowstride;
887 buffer[i] = READ(pict, (uint32_t *)bits + offset);
893 fbFetchPixel_x8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
897 for (i = 0; i < n_pixels; ++i)
899 int offset = buffer[2 * i];
900 int line = buffer[2 * i + 1];
902 if (offset == 0xffffffff || line == 0xffffffff)
908 uint32_t *bits = pict->bits + line*pict->rowstride;
909 buffer[i] = READ(pict, (uint32_t *)bits + offset) | 0xff000000;
915 fbFetchPixel_a8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
919 for (i = 0; i < n_pixels; ++i)
921 int offset = buffer[2 * i];
922 int line = buffer[2 * i + 1];
924 if (offset == 0xffffffff || line == 0xffffffff)
930 uint32_t *bits = pict->bits + line*pict->rowstride;
931 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
933 buffer[i] = ((pixel & 0xff000000) |
934 ((pixel >> 16) & 0xff) |
935 (pixel & 0x0000ff00) |
936 ((pixel & 0xff) << 16));
942 fbFetchPixel_x8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
946 for (i = 0; i < n_pixels; ++i)
948 int offset = buffer[2 * i];
949 int line = buffer[2 * i + 1];
951 if (offset == 0xffffffff || line == 0xffffffff)
957 uint32_t *bits = pict->bits + line*pict->rowstride;
958 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
960 buffer[i] = ((0xff000000) |
961 ((pixel >> 16) & 0xff) |
962 (pixel & 0x0000ff00) |
963 ((pixel & 0xff) << 16));
969 fbFetchPixel_b8g8r8a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
973 for (i = 0; i < n_pixels; ++i)
975 int offset = buffer[2 * i];
976 int line = buffer[2 * i + 1];
978 if (offset == 0xffffffff || line == 0xffffffff)
984 uint32_t *bits = pict->bits + line*pict->rowstride;
985 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
987 buffer[i] = ((pixel & 0xff000000) >> 24 |
988 (pixel & 0x00ff0000) >> 8 |
989 (pixel & 0x0000ff00) << 8 |
990 (pixel & 0x000000ff) << 24);
996 fbFetchPixel_b8g8r8x8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1000 for (i = 0; i < n_pixels; ++i)
1002 int offset = buffer[2 * i];
1003 int line = buffer[2 * i + 1];
1005 if (offset == 0xffffffff || line == 0xffffffff)
1011 uint32_t *bits = pict->bits + line*pict->rowstride;
1012 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
1014 buffer[i] = ((0xff000000) |
1015 (pixel & 0xff000000) >> 24 |
1016 (pixel & 0x00ff0000) >> 8 |
1017 (pixel & 0x0000ff00) << 8);
1023 fbFetchPixel_r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1027 for (i = 0; i < n_pixels; ++i)
1029 int offset = buffer[2 * i];
1030 int line = buffer[2 * i + 1];
1032 if (offset == 0xffffffff || line == 0xffffffff)
1038 uint32_t *bits = pict->bits + line*pict->rowstride;
1039 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1040 #if IMAGE_BYTE_ORDER == MSBFirst
1041 buffer[i] = (0xff000000 |
1042 (READ(pict, pixel + 0) << 16) |
1043 (READ(pict, pixel + 1) << 8) |
1044 (READ(pict, pixel + 2)));
1046 buffer[i] = (0xff000000 |
1047 (READ(pict, pixel + 2) << 16) |
1048 (READ(pict, pixel + 1) << 8) |
1049 (READ(pict, pixel + 0)));
1056 fbFetchPixel_b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1060 for (i = 0; i < n_pixels; ++i)
1062 int offset = buffer[2 * i];
1063 int line = buffer[2 * i + 1];
1065 if (offset == 0xffffffff || line == 0xffffffff)
1071 uint32_t *bits = pict->bits + line*pict->rowstride;
1072 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1073 #if IMAGE_BYTE_ORDER == MSBFirst
1074 buffer[i] = (0xff000000 |
1075 (READ(pict, pixel + 2) << 16) |
1076 (READ(pict, pixel + 1) << 8) |
1077 (READ(pict, pixel + 0)));
1079 buffer[i] = (0xff000000 |
1080 (READ(pict, pixel + 0) << 16) |
1081 (READ(pict, pixel + 1) << 8) |
1082 (READ(pict, pixel + 2)));
1089 fbFetchPixel_r5g6b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1093 for (i = 0; i < n_pixels; ++i)
1095 int offset = buffer[2 * i];
1096 int line = buffer[2 * i + 1];
1098 if (offset == 0xffffffff || line == 0xffffffff)
1105 uint32_t *bits = pict->bits + line*pict->rowstride;
1106 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1108 r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1109 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1110 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1111 buffer[i] = (0xff000000 | r | g | b);
1117 fbFetchPixel_b5g6r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1121 for (i = 0; i < n_pixels; ++i)
1123 int offset = buffer[2 * i];
1124 int line = buffer[2 * i + 1];
1126 if (offset == 0xffffffff || line == 0xffffffff)
1133 uint32_t *bits = pict->bits + line*pict->rowstride;
1134 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1136 b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1137 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1138 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1139 buffer[i] = (0xff000000 | r | g | b);
1145 fbFetchPixel_a1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1149 for (i = 0; i < n_pixels; ++i)
1151 int offset = buffer[2 * i];
1152 int line = buffer[2 * i + 1];
1154 if (offset == 0xffffffff || line == 0xffffffff)
1161 uint32_t *bits = pict->bits + line*pict->rowstride;
1162 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1164 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1165 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1166 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1167 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1168 buffer[i] = (a | r | g | b);
1174 fbFetchPixel_x1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1178 for (i = 0; i < n_pixels; ++i)
1180 int offset = buffer[2 * i];
1181 int line = buffer[2 * i + 1];
1183 if (offset == 0xffffffff || line == 0xffffffff)
1190 uint32_t *bits = pict->bits + line*pict->rowstride;
1191 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1193 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1194 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1195 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1196 buffer[i] = (0xff000000 | r | g | b);
1202 fbFetchPixel_a1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1206 for (i = 0; i < n_pixels; ++i)
1208 int offset = buffer[2 * i];
1209 int line = buffer[2 * i + 1];
1211 if (offset == 0xffffffff || line == 0xffffffff)
1218 uint32_t *bits = pict->bits + line*pict->rowstride;
1219 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1221 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1222 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1223 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1224 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1225 buffer[i] = (a | r | g | b);
1231 fbFetchPixel_x1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1235 for (i = 0; i < n_pixels; ++i)
1237 int offset = buffer[2 * i];
1238 int line = buffer[2 * i + 1];
1240 if (offset == 0xffffffff || line == 0xffffffff)
1247 uint32_t *bits = pict->bits + line*pict->rowstride;
1248 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1250 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1251 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1252 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1253 buffer[i] = (0xff000000 | r | g | b);
1259 fbFetchPixel_a4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1263 for (i = 0; i < n_pixels; ++i)
1265 int offset = buffer[2 * i];
1266 int line = buffer[2 * i + 1];
1268 if (offset == 0xffffffff || line == 0xffffffff)
1275 uint32_t *bits = pict->bits + line*pict->rowstride;
1276 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1278 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1279 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1280 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1281 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1282 buffer[i] = (a | r | g | b);
1288 fbFetchPixel_x4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1292 for (i = 0; i < n_pixels; ++i)
1294 int offset = buffer[2 * i];
1295 int line = buffer[2 * i + 1];
1297 if (offset == 0xffffffff || line == 0xffffffff)
1304 uint32_t *bits = pict->bits + line*pict->rowstride;
1305 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1307 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1308 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1309 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1310 buffer[i] = (0xff000000 | r | g | b);
1316 fbFetchPixel_a4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1320 for (i = 0; i < n_pixels; ++i)
1322 int offset = buffer[2 * i];
1323 int line = buffer[2 * i + 1];
1325 if (offset == 0xffffffff || line == 0xffffffff)
1332 uint32_t *bits = pict->bits + line*pict->rowstride;
1333 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1335 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1336 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1337 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1338 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1339 buffer[i] = (a | r | g | b);
1345 fbFetchPixel_x4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1349 for (i = 0; i < n_pixels; ++i)
1351 int offset = buffer[2 * i];
1352 int line = buffer[2 * i + 1];
1354 if (offset == 0xffffffff || line == 0xffffffff)
1361 uint32_t *bits = pict->bits + line*pict->rowstride;
1362 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1364 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1365 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1366 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1367 buffer[i] = (0xff000000 | r | g | b);
1373 fbFetchPixel_a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1377 for (i = 0; i < n_pixels; ++i)
1379 int offset = buffer[2 * i];
1380 int line = buffer[2 * i + 1];
1382 if (offset == 0xffffffff || line == 0xffffffff)
1388 uint32_t *bits = pict->bits + line*pict->rowstride;
1389 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1391 buffer[i] = pixel << 24;
1397 fbFetchPixel_r3g3b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1401 for (i = 0; i < n_pixels; ++i)
1403 int offset = buffer[2 * i];
1404 int line = buffer[2 * i + 1];
1406 if (offset == 0xffffffff || line == 0xffffffff)
1413 uint32_t *bits = pict->bits + line*pict->rowstride;
1414 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1416 r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16;
1417 g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8;
1418 b = (((pixel & 0x03) ) |
1419 ((pixel & 0x03) << 2) |
1420 ((pixel & 0x03) << 4) |
1421 ((pixel & 0x03) << 6));
1422 buffer[i] = (0xff000000 | r | g | b);
1428 fbFetchPixel_b2g3r3 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1432 for (i = 0; i < n_pixels; ++i)
1434 int offset = buffer[2 * i];
1435 int line = buffer[2 * i + 1];
1437 if (offset == 0xffffffff || line == 0xffffffff)
1444 uint32_t *bits = pict->bits + line*pict->rowstride;
1445 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1447 b = (((pixel & 0xc0) ) |
1448 ((pixel & 0xc0) >> 2) |
1449 ((pixel & 0xc0) >> 4) |
1450 ((pixel & 0xc0) >> 6));
1451 g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8;
1452 r = (((pixel & 0x07) ) |
1453 ((pixel & 0x07) << 3) |
1454 ((pixel & 0x06) << 6)) << 16;
1455 buffer[i] = (0xff000000 | r | g | b);
1461 fbFetchPixel_a2r2g2b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1465 for (i = 0; i < n_pixels; ++i)
1467 int offset = buffer[2 * i];
1468 int line = buffer[2 * i + 1];
1470 if (offset == 0xffffffff || line == 0xffffffff)
1477 uint32_t *bits = pict->bits + line*pict->rowstride;
1478 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1480 a = ((pixel & 0xc0) * 0x55) << 18;
1481 r = ((pixel & 0x30) * 0x55) << 12;
1482 g = ((pixel & 0x0c) * 0x55) << 6;
1483 b = ((pixel & 0x03) * 0x55);
1484 buffer[i] = a|r|g|b;
1490 fbFetchPixel_a2b2g2r2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1494 for (i = 0; i < n_pixels; ++i)
1496 int offset = buffer[2 * i];
1497 int line = buffer[2 * i + 1];
1499 if (offset == 0xffffffff || line == 0xffffffff)
1506 uint32_t *bits = pict->bits + line*pict->rowstride;
1507 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1509 a = ((pixel & 0xc0) * 0x55) << 18;
1510 b = ((pixel & 0x30) * 0x55) >> 6;
1511 g = ((pixel & 0x0c) * 0x55) << 6;
1512 r = ((pixel & 0x03) * 0x55) << 16;
1513 buffer[i] = a|r|g|b;
1519 fbFetchPixel_c8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1523 for (i = 0; i < n_pixels; ++i)
1525 int offset = buffer[2 * i];
1526 int line = buffer[2 * i + 1];
1528 if (offset == 0xffffffff || line == 0xffffffff)
1534 uint32_t *bits = pict->bits + line*pict->rowstride;
1535 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1536 const pixman_indexed_t * indexed = pict->indexed;
1537 buffer[i] = indexed->rgba[pixel];
1543 fbFetchPixel_x4a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1547 for (i = 0; i < n_pixels; ++i)
1549 int offset = buffer[2 * i];
1550 int line = buffer[2 * i + 1];
1552 if (offset == 0xffffffff || line == 0xffffffff)
1558 uint32_t *bits = pict->bits + line*pict->rowstride;
1559 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1561 buffer[i] = ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1567 fbFetchPixel_a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1571 for (i = 0; i < n_pixels; ++i)
1573 int offset = buffer[2 * i];
1574 int line = buffer[2 * i + 1];
1576 if (offset == 0xffffffff || line == 0xffffffff)
1582 uint32_t *bits = pict->bits + line*pict->rowstride;
1583 uint32_t pixel = Fetch4(pict, bits, offset);
1585 pixel |= pixel << 4;
1586 buffer[i] = pixel << 24;
1592 fbFetchPixel_r1g2b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1596 for (i = 0; i < n_pixels; ++i)
1598 int offset = buffer[2 * i];
1599 int line = buffer[2 * i + 1];
1601 if (offset == 0xffffffff || line == 0xffffffff)
1608 uint32_t *bits = pict->bits + line*pict->rowstride;
1609 uint32_t pixel = Fetch4(pict, bits, offset);
1611 r = ((pixel & 0x8) * 0xff) << 13;
1612 g = ((pixel & 0x6) * 0x55) << 7;
1613 b = ((pixel & 0x1) * 0xff);
1614 buffer[i] = 0xff000000|r|g|b;
1620 fbFetchPixel_b1g2r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1624 for (i = 0; i < n_pixels; ++i)
1626 int offset = buffer[2 * i];
1627 int line = buffer[2 * i + 1];
1629 if (offset == 0xffffffff || line == 0xffffffff)
1636 uint32_t *bits = pict->bits + line*pict->rowstride;
1637 uint32_t pixel = Fetch4(pict, bits, offset);
1639 b = ((pixel & 0x8) * 0xff) >> 3;
1640 g = ((pixel & 0x6) * 0x55) << 7;
1641 r = ((pixel & 0x1) * 0xff) << 16;
1642 buffer[i] = 0xff000000|r|g|b;
1648 fbFetchPixel_a1r1g1b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1652 for (i = 0; i < n_pixels; ++i)
1654 int offset = buffer[2 * i];
1655 int line = buffer[2 * i + 1];
1657 if (offset == 0xffffffff || line == 0xffffffff)
1664 uint32_t *bits = pict->bits + line*pict->rowstride;
1665 uint32_t pixel = Fetch4(pict, bits, offset);
1667 a = ((pixel & 0x8) * 0xff) << 21;
1668 r = ((pixel & 0x4) * 0xff) << 14;
1669 g = ((pixel & 0x2) * 0xff) << 7;
1670 b = ((pixel & 0x1) * 0xff);
1671 buffer[i] = a|r|g|b;
1677 fbFetchPixel_a1b1g1r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1681 for (i = 0; i < n_pixels; ++i)
1683 int offset = buffer[2 * i];
1684 int line = buffer[2 * i + 1];
1686 if (offset == 0xffffffff || line == 0xffffffff)
1693 uint32_t *bits = pict->bits + line*pict->rowstride;
1694 uint32_t pixel = Fetch4(pict, bits, offset);
1696 a = ((pixel & 0x8) * 0xff) << 21;
1697 r = ((pixel & 0x4) * 0xff) >> 3;
1698 g = ((pixel & 0x2) * 0xff) << 7;
1699 b = ((pixel & 0x1) * 0xff) << 16;
1700 buffer[i] = a|r|g|b;
1706 fbFetchPixel_c4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1710 for (i = 0; i < n_pixels; ++i)
1712 int offset = buffer[2 * i];
1713 int line = buffer[2 * i + 1];
1715 if (offset == 0xffffffff || line == 0xffffffff)
1721 uint32_t *bits = pict->bits + line*pict->rowstride;
1722 uint32_t pixel = Fetch4(pict, bits, offset);
1723 const pixman_indexed_t * indexed = pict->indexed;
1725 buffer[i] = indexed->rgba[pixel];
1732 fbFetchPixel_a1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1736 for (i = 0; i < n_pixels; ++i)
1738 int offset = buffer[2 * i];
1739 int line = buffer[2 * i + 1];
1741 if (offset == 0xffffffff || line == 0xffffffff)
1747 uint32_t *bits = pict->bits + line*pict->rowstride;
1748 uint32_t pixel = READ(pict, bits + (offset >> 5));
1750 #if BITMAP_BIT_ORDER == MSBFirst
1751 a = pixel >> (0x1f - (offset & 0x1f));
1753 a = pixel >> (offset & 0x1f);
1759 buffer[i] = a << 24;
1765 fbFetchPixel_g1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1769 for (i = 0; i < n_pixels; ++i)
1771 int offset = buffer[2 * i];
1772 int line = buffer[2 * i + 1];
1774 if (offset == 0xffffffff || line == 0xffffffff)
1780 uint32_t *bits = pict->bits + line*pict->rowstride;
1781 uint32_t pixel = READ(pict, bits + (offset >> 5));
1782 const pixman_indexed_t * indexed = pict->indexed;
1784 #if BITMAP_BIT_ORDER == MSBFirst
1785 a = pixel >> (0x1f - (offset & 0x1f));
1787 a = pixel >> (offset & 0x1f);
1790 buffer[i] = indexed->rgba[a];
1796 fbFetchPixel_yuy2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1800 for (i = 0; i < n_pixels; ++i)
1802 int offset = buffer[2 * i];
1803 int line = buffer[2 * i + 1];
1805 if (offset == 0xffffffff || line == 0xffffffff)
1814 const uint32_t *bits = pict->bits + pict->rowstride * line;
1816 y = ((uint8_t *) bits)[offset << 1] - 16;
1817 u = ((uint8_t *) bits)[((offset << 1) & -4) + 1] - 128;
1818 v = ((uint8_t *) bits)[((offset << 1) & -4) + 3] - 128;
1820 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1821 r = 0x012b27 * y + 0x019a2e * v;
1822 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1823 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1824 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1825 b = 0x012b27 * y + 0x0206a2 * u;
1827 buffer[i] = 0xff000000 |
1828 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1829 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1830 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1836 fbFetchPixel_yv12 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1840 for (i = 0; i < n_pixels; ++i)
1842 int offset = buffer[2 * i];
1843 int line = buffer[2 * i + 1];
1845 if (offset == 0xffffffff || line == 0xffffffff)
1852 int16_t y = YV12_Y (line)[offset] - 16;
1853 int16_t u = YV12_U (line)[offset >> 1] - 128;
1854 int16_t v = YV12_V (line)[offset >> 1] - 128;
1857 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1858 r = 0x012b27 * y + 0x019a2e * v;
1859 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1860 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1861 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1862 b = 0x012b27 * y + 0x0206a2 * u;
1864 buffer[i] = 0xff000000 |
1865 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1866 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1867 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1873 * XXX: The transformed fetch path only works at 32-bpp so far. When all paths
1874 * have wide versions, this can be removed.
1876 * WARNING: This function loses precision!
1879 fbFetchPixel32_generic_lossy (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1881 fetch_pixels_64_t fetch_pixels_64 = ACCESS(pixman_fetchPixelProcForPicture64) (pict);
1883 /* Since buffer contains n_pixels coordinate pairs, it also has enough room for
1884 * n_pixels 64 bit pixels
1886 fetch_pixels_64 (pict, (uint64_t *)buffer, n_pixels);
1888 pixman_contract (buffer, (uint64_t *)buffer, n_pixels);
1892 ACCESS(pixman_fetchPixelProcForPicture32) (bits_image_t * pict)
1894 switch(pict->format) {
1895 case PIXMAN_a8r8g8b8: return fbFetchPixel_a8r8g8b8;
1896 case PIXMAN_x8r8g8b8: return fbFetchPixel_x8r8g8b8;
1897 case PIXMAN_a8b8g8r8: return fbFetchPixel_a8b8g8r8;
1898 case PIXMAN_x8b8g8r8: return fbFetchPixel_x8b8g8r8;
1899 case PIXMAN_b8g8r8a8: return fbFetchPixel_b8g8r8a8;
1900 case PIXMAN_b8g8r8x8: return fbFetchPixel_b8g8r8x8;
1901 /* These two require wide compositing */
1902 case PIXMAN_a2b10g10r10: return fbFetchPixel32_generic_lossy;
1903 case PIXMAN_x2b10g10r10: return fbFetchPixel32_generic_lossy;
1906 case PIXMAN_r8g8b8: return fbFetchPixel_r8g8b8;
1907 case PIXMAN_b8g8r8: return fbFetchPixel_b8g8r8;
1910 case PIXMAN_r5g6b5: return fbFetchPixel_r5g6b5;
1911 case PIXMAN_b5g6r5: return fbFetchPixel_b5g6r5;
1913 case PIXMAN_a1r5g5b5: return fbFetchPixel_a1r5g5b5;
1914 case PIXMAN_x1r5g5b5: return fbFetchPixel_x1r5g5b5;
1915 case PIXMAN_a1b5g5r5: return fbFetchPixel_a1b5g5r5;
1916 case PIXMAN_x1b5g5r5: return fbFetchPixel_x1b5g5r5;
1917 case PIXMAN_a4r4g4b4: return fbFetchPixel_a4r4g4b4;
1918 case PIXMAN_x4r4g4b4: return fbFetchPixel_x4r4g4b4;
1919 case PIXMAN_a4b4g4r4: return fbFetchPixel_a4b4g4r4;
1920 case PIXMAN_x4b4g4r4: return fbFetchPixel_x4b4g4r4;
1923 case PIXMAN_a8: return fbFetchPixel_a8;
1924 case PIXMAN_r3g3b2: return fbFetchPixel_r3g3b2;
1925 case PIXMAN_b2g3r3: return fbFetchPixel_b2g3r3;
1926 case PIXMAN_a2r2g2b2: return fbFetchPixel_a2r2g2b2;
1927 case PIXMAN_a2b2g2r2: return fbFetchPixel_a2b2g2r2;
1928 case PIXMAN_c8: return fbFetchPixel_c8;
1929 case PIXMAN_g8: return fbFetchPixel_c8;
1930 case PIXMAN_x4a4: return fbFetchPixel_x4a4;
1933 case PIXMAN_a4: return fbFetchPixel_a4;
1934 case PIXMAN_r1g2b1: return fbFetchPixel_r1g2b1;
1935 case PIXMAN_b1g2r1: return fbFetchPixel_b1g2r1;
1936 case PIXMAN_a1r1g1b1: return fbFetchPixel_a1r1g1b1;
1937 case PIXMAN_a1b1g1r1: return fbFetchPixel_a1b1g1r1;
1938 case PIXMAN_c4: return fbFetchPixel_c4;
1939 case PIXMAN_g4: return fbFetchPixel_c4;
1942 case PIXMAN_a1: return fbFetchPixel_a1;
1943 case PIXMAN_g1: return fbFetchPixel_g1;
1946 case PIXMAN_yuy2: return fbFetchPixel_yuy2;
1947 case PIXMAN_yv12: return fbFetchPixel_yv12;
1954 fbFetchPixel64_generic (bits_image_t *pict, uint64_t *buffer, int n_pixels)
1956 fetch_pixels_32_t fetch_pixels_32 = ACCESS(pixman_fetchPixelProcForPicture32) (pict);
1958 fetch_pixels_32 (pict, (uint32_t *)buffer, n_pixels);
1960 pixman_expand (buffer, (uint32_t *)buffer, pict->format, n_pixels);
1964 ACCESS(pixman_fetchPixelProcForPicture64) (bits_image_t * pict)
1966 switch(pict->format) {
1967 case PIXMAN_a2b10g10r10: return fbFetchPixel_a2b10g10r10;
1968 case PIXMAN_x2b10g10r10: return fbFetchPixel_x2b10g10r10;
1969 default: return fbFetchPixel64_generic;
1973 /*********************************** Store ************************************/
1975 #define Splita(v) uint32_t a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1976 #define Split(v) uint32_t r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1979 fbStore_a2b10g10r10 (pixman_image_t *image,
1980 uint32_t *bits, const uint64_t *values,
1981 int x, int width, const pixman_indexed_t * indexed)
1984 uint32_t *pixel = bits + x;
1985 for (i = 0; i < width; ++i) {
1986 WRITE(image, pixel++,
1987 ((values[i] >> 32) & 0xc0000000) | // A
1988 ((values[i] >> 38) & 0x3ff) | // R
1989 ((values[i] >> 12) & 0xffc00) | // G
1990 ((values[i] << 14) & 0x3ff00000)); // B
1995 fbStore_x2b10g10r10 (pixman_image_t *image,
1996 uint32_t *bits, const uint64_t *values, int x, int width, const pixman_indexed_t * indexed)
1999 uint32_t *pixel = bits + x;
2000 for (i = 0; i < width; ++i) {
2001 WRITE(image, pixel++,
2002 ((values[i] >> 38) & 0x3ff) | // R
2003 ((values[i] >> 12) & 0xffc00) | // G
2004 ((values[i] << 14) & 0x3ff00000)); // B
2009 fbStore_a8r8g8b8 (pixman_image_t *image,
2010 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2012 MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
2016 fbStore_x8r8g8b8 (pixman_image_t *image,
2017 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2020 uint32_t *pixel = (uint32_t *)bits + x;
2021 for (i = 0; i < width; ++i)
2022 WRITE(image, pixel++, values[i] & 0xffffff);
2026 fbStore_a8b8g8r8 (pixman_image_t *image,
2027 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2030 uint32_t *pixel = (uint32_t *)bits + x;
2031 for (i = 0; i < width; ++i)
2032 WRITE(image, pixel++, (values[i] & 0xff00ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
2036 fbStore_x8b8g8r8 (pixman_image_t *image,
2037 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2040 uint32_t *pixel = (uint32_t *)bits + x;
2041 for (i = 0; i < width; ++i)
2042 WRITE(image, pixel++, (values[i] & 0x0000ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
2046 fbStore_b8g8r8a8 (pixman_image_t *image,
2047 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2050 uint32_t *pixel = (uint32_t *)bits + x;
2051 for (i = 0; i < width; ++i)
2052 WRITE(image, pixel++,
2053 ((values[i] >> 24) & 0x000000ff) |
2054 ((values[i] >> 8) & 0x0000ff00) |
2055 ((values[i] << 8) & 0x00ff0000) |
2056 ((values[i] << 24) & 0xff000000));
2060 fbStore_b8g8r8x8 (pixman_image_t *image,
2061 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2064 uint32_t *pixel = (uint32_t *)bits + x;
2065 for (i = 0; i < width; ++i)
2066 WRITE(image, pixel++,
2067 ((values[i] >> 8) & 0x0000ff00) |
2068 ((values[i] << 8) & 0x00ff0000) |
2069 ((values[i] << 24) & 0xff000000));
2073 fbStore_r8g8b8 (pixman_image_t *image,
2074 uint32_t *bits, const uint32_t *values, int x, int width,
2075 const pixman_indexed_t * indexed)
2078 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
2079 for (i = 0; i < width; ++i) {
2080 Store24(image, pixel, values[i]);
2086 fbStore_b8g8r8 (pixman_image_t *image,
2087 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2090 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
2091 for (i = 0; i < width; ++i) {
2092 uint32_t val = values[i];
2093 #if IMAGE_BYTE_ORDER == MSBFirst
2094 WRITE(image, pixel++, Blue(val));
2095 WRITE(image, pixel++, Green(val));
2096 WRITE(image, pixel++, Red(val));
2098 WRITE(image, pixel++, Red(val));
2099 WRITE(image, pixel++, Green(val));
2100 WRITE(image, pixel++, Blue(val));
2106 fbStore_r5g6b5 (pixman_image_t *image,
2107 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2110 uint16_t *pixel = ((uint16_t *) bits) + x;
2111 for (i = 0; i < width; ++i) {
2112 uint32_t s = values[i];
2113 WRITE(image, pixel++, ((s >> 3) & 0x001f) |
2114 ((s >> 5) & 0x07e0) |
2115 ((s >> 8) & 0xf800));
2120 fbStore_b5g6r5 (pixman_image_t *image,
2121 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2124 uint16_t *pixel = ((uint16_t *) bits) + x;
2125 for (i = 0; i < width; ++i) {
2127 WRITE(image, pixel++, ((b << 8) & 0xf800) |
2128 ((g << 3) & 0x07e0) |
2134 fbStore_a1r5g5b5 (pixman_image_t *image,
2135 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2138 uint16_t *pixel = ((uint16_t *) bits) + x;
2139 for (i = 0; i < width; ++i) {
2141 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2142 ((r << 7) & 0x7c00) |
2143 ((g << 2) & 0x03e0) |
2149 fbStore_x1r5g5b5 (pixman_image_t *image,
2150 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2153 uint16_t *pixel = ((uint16_t *) bits) + x;
2154 for (i = 0; i < width; ++i) {
2156 WRITE(image, pixel++, ((r << 7) & 0x7c00) |
2157 ((g << 2) & 0x03e0) |
2163 fbStore_a1b5g5r5 (pixman_image_t *image,
2164 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2167 uint16_t *pixel = ((uint16_t *) bits) + x;
2168 for (i = 0; i < width; ++i) {
2170 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2171 ((b << 7) & 0x7c00) |
2172 ((g << 2) & 0x03e0) |
2178 fbStore_x1b5g5r5 (pixman_image_t *image,
2179 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2182 uint16_t *pixel = ((uint16_t *) bits) + x;
2183 for (i = 0; i < width; ++i) {
2185 WRITE(image, pixel++, ((b << 7) & 0x7c00) |
2186 ((g << 2) & 0x03e0) |
2192 fbStore_a4r4g4b4 (pixman_image_t *image,
2193 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2196 uint16_t *pixel = ((uint16_t *) bits) + x;
2197 for (i = 0; i < width; ++i) {
2199 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2200 ((r << 4) & 0x0f00) |
2207 fbStore_x4r4g4b4 (pixman_image_t *image,
2208 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2211 uint16_t *pixel = ((uint16_t *) bits) + x;
2212 for (i = 0; i < width; ++i) {
2214 WRITE(image, pixel++, ((r << 4) & 0x0f00) |
2221 fbStore_a4b4g4r4 (pixman_image_t *image,
2222 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2225 uint16_t *pixel = ((uint16_t *) bits) + x;
2226 for (i = 0; i < width; ++i) {
2228 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2229 ((b << 4) & 0x0f00) |
2236 fbStore_x4b4g4r4 (pixman_image_t *image,
2237 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2240 uint16_t *pixel = ((uint16_t *) bits) + x;
2241 for (i = 0; i < width; ++i) {
2243 WRITE(image, pixel++, ((b << 4) & 0x0f00) |
2250 fbStore_a8 (pixman_image_t *image,
2251 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2254 uint8_t *pixel = ((uint8_t *) bits) + x;
2255 for (i = 0; i < width; ++i) {
2256 WRITE(image, pixel++, values[i] >> 24);
2261 fbStore_r3g3b2 (pixman_image_t *image,
2262 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2265 uint8_t *pixel = ((uint8_t *) bits) + x;
2266 for (i = 0; i < width; ++i) {
2268 WRITE(image, pixel++,
2276 fbStore_b2g3r3 (pixman_image_t *image,
2277 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2280 uint8_t *pixel = ((uint8_t *) bits) + x;
2281 for (i = 0; i < width; ++i) {
2283 WRITE(image, pixel++,
2291 fbStore_a2r2g2b2 (pixman_image_t *image,
2292 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2295 uint8_t *pixel = ((uint8_t *) bits) + x;
2296 for (i = 0; i < width; ++i) {
2298 WRITE(image, pixel++, ((a ) & 0xc0) |
2306 fbStore_c8 (pixman_image_t *image,
2307 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2310 uint8_t *pixel = ((uint8_t *) bits) + x;
2311 for (i = 0; i < width; ++i) {
2312 WRITE(image, pixel++, miIndexToEnt24(indexed,values[i]));
2317 fbStore_x4a4 (pixman_image_t *image,
2318 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2321 uint8_t *pixel = ((uint8_t *) bits) + x;
2322 for (i = 0; i < width; ++i) {
2323 WRITE(image, pixel++, values[i] >> 28);
2327 #define Store8(img,l,o,v) (WRITE(img, (uint8_t *)(l) + ((o) >> 3), (v)))
2328 #if IMAGE_BYTE_ORDER == MSBFirst
2329 #define Store4(img,l,o,v) Store8(img,l,o,((o) & 4 ? \
2330 (Fetch8(img,l,o) & 0xf0) | (v) : \
2331 (Fetch8(img,l,o) & 0x0f) | ((v) << 4)))
2333 #define Store4(img,l,o,v) Store8(img,l,o,((o) & 4 ? \
2334 (Fetch8(img,l,o) & 0x0f) | ((v) << 4) : \
2335 (Fetch8(img,l,o) & 0xf0) | (v)))
2339 fbStore_a4 (pixman_image_t *image,
2340 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2343 for (i = 0; i < width; ++i) {
2344 Store4(image, bits, i + x, values[i]>>28);
2349 fbStore_r1g2b1 (pixman_image_t *image,
2350 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2353 for (i = 0; i < width; ++i) {
2357 pixel = (((r >> 4) & 0x8) |
2360 Store4(image, bits, i + x, pixel);
2365 fbStore_b1g2r1 (pixman_image_t *image,
2366 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2369 for (i = 0; i < width; ++i) {
2373 pixel = (((b >> 4) & 0x8) |
2376 Store4(image, bits, i + x, pixel);
2381 fbStore_a1r1g1b1 (pixman_image_t *image,
2382 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2385 for (i = 0; i < width; ++i) {
2388 pixel = (((a >> 4) & 0x8) |
2392 Store4(image, bits, i + x, pixel);
2397 fbStore_a1b1g1r1 (pixman_image_t *image,
2398 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2401 for (i = 0; i < width; ++i) {
2404 pixel = (((a >> 4) & 0x8) |
2408 Store4(image, bits, i + x, pixel);
2413 fbStore_c4 (pixman_image_t *image,
2414 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2417 for (i = 0; i < width; ++i) {
2420 pixel = miIndexToEnt24(indexed, values[i]);
2421 Store4(image, bits, i + x, pixel);
2426 fbStore_a1 (pixman_image_t *image,
2427 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2430 for (i = 0; i < width; ++i) {
2431 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2432 uint32_t mask = FbStipMask((i+x) & 0x1f, 1);
2434 uint32_t v = values[i] & 0x80000000 ? mask : 0;
2435 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2440 fbStore_g1 (pixman_image_t *image,
2441 uint32_t *bits, const uint32_t *values, int x, int width, const pixman_indexed_t * indexed)
2444 for (i = 0; i < width; ++i) {
2445 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2446 uint32_t mask = FbStipMask((i+x) & 0x1f, 1);
2448 uint32_t v = miIndexToEntY24(indexed,values[i]) ? mask : 0;
2449 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2454 storeProc32 ACCESS(pixman_storeProcForPicture32) (bits_image_t * pict)
2456 switch(pict->format) {
2457 case PIXMAN_a8r8g8b8: return fbStore_a8r8g8b8;
2458 case PIXMAN_x8r8g8b8: return fbStore_x8r8g8b8;
2459 case PIXMAN_a8b8g8r8: return fbStore_a8b8g8r8;
2460 case PIXMAN_x8b8g8r8: return fbStore_x8b8g8r8;
2461 case PIXMAN_b8g8r8a8: return fbStore_b8g8r8a8;
2462 case PIXMAN_b8g8r8x8: return fbStore_b8g8r8x8;
2465 case PIXMAN_r8g8b8: return fbStore_r8g8b8;
2466 case PIXMAN_b8g8r8: return fbStore_b8g8r8;
2469 case PIXMAN_r5g6b5: return fbStore_r5g6b5;
2470 case PIXMAN_b5g6r5: return fbStore_b5g6r5;
2472 case PIXMAN_a1r5g5b5: return fbStore_a1r5g5b5;
2473 case PIXMAN_x1r5g5b5: return fbStore_x1r5g5b5;
2474 case PIXMAN_a1b5g5r5: return fbStore_a1b5g5r5;
2475 case PIXMAN_x1b5g5r5: return fbStore_x1b5g5r5;
2476 case PIXMAN_a4r4g4b4: return fbStore_a4r4g4b4;
2477 case PIXMAN_x4r4g4b4: return fbStore_x4r4g4b4;
2478 case PIXMAN_a4b4g4r4: return fbStore_a4b4g4r4;
2479 case PIXMAN_x4b4g4r4: return fbStore_x4b4g4r4;
2482 case PIXMAN_a8: return fbStore_a8;
2483 case PIXMAN_r3g3b2: return fbStore_r3g3b2;
2484 case PIXMAN_b2g3r3: return fbStore_b2g3r3;
2485 case PIXMAN_a2r2g2b2: return fbStore_a2r2g2b2;
2486 case PIXMAN_c8: return fbStore_c8;
2487 case PIXMAN_g8: return fbStore_c8;
2488 case PIXMAN_x4a4: return fbStore_x4a4;
2491 case PIXMAN_a4: return fbStore_a4;
2492 case PIXMAN_r1g2b1: return fbStore_r1g2b1;
2493 case PIXMAN_b1g2r1: return fbStore_b1g2r1;
2494 case PIXMAN_a1r1g1b1: return fbStore_a1r1g1b1;
2495 case PIXMAN_a1b1g1r1: return fbStore_a1b1g1r1;
2496 case PIXMAN_c4: return fbStore_c4;
2497 case PIXMAN_g4: return fbStore_c4;
2500 case PIXMAN_a1: return fbStore_a1;
2501 case PIXMAN_g1: return fbStore_g1;
2508 * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2512 fbStore64_generic (pixman_image_t *image,
2513 uint32_t *bits, const uint64_t *values, int x, int width, const pixman_indexed_t * indexed)
2515 bits_image_t *pict = (bits_image_t*)image;
2516 storeProc32 store32 = ACCESS(pixman_storeProcForPicture32) (pict);
2517 uint32_t *argb8Pixels;
2519 assert(image->common.type == BITS);
2522 argb8Pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2523 if (!argb8Pixels) return;
2525 // Contract the scanline. We could do this in place if values weren't
2527 pixman_contract(argb8Pixels, values, width);
2528 store32(image, bits, argb8Pixels, x, width, indexed);
2533 storeProc64 ACCESS(pixman_storeProcForPicture64) (bits_image_t * pict)
2535 switch(pict->format) {
2536 case PIXMAN_a2b10g10r10: return fbStore_a2b10g10r10;
2537 case PIXMAN_x2b10g10r10: return fbStore_x2b10g10r10;
2538 default: return fbStore64_generic;