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"
36 #include "pixman-accessor.h"
38 #define CONVERT_RGB24_TO_Y15(s) \
39 (((((s) >> 16) & 0xff) * 153 + \
40 (((s) >> 8) & 0xff) * 301 + \
41 (((s) ) & 0xff) * 58) >> 2)
43 #define CONVERT_RGB24_TO_RGB15(s) \
44 ((((s) >> 3) & 0x001f) | \
45 (((s) >> 6) & 0x03e0) | \
46 (((s) >> 9) & 0x7c00))
48 #define RGB15_TO_ENTRY(mif,rgb15) \
51 #define RGB24_TO_ENTRY(mif,rgb24) \
52 RGB15_TO_ENTRY (mif,CONVERT_RGB24_TO_RGB15 (rgb24))
54 #define RGB24_TO_ENTRY_Y(mif,rgb24) \
55 ((mif)->ent[CONVERT_RGB24_TO_Y15 (rgb24)])
58 * YV12 setup and access macros
61 #define YV12_SETUP(image) \
62 bits_image_t *__bits_image = (bits_image_t *)image; \
63 uint32_t *bits = __bits_image->bits; \
64 int stride = __bits_image->rowstride; \
65 int offset0 = stride < 0 ? \
66 ((-stride) >> 1) * ((__bits_image->height - 1) >> 1) - stride : \
67 stride * __bits_image->height; \
68 int offset1 = stride < 0 ? \
69 offset0 + ((-stride) >> 1) * ((__bits_image->height) >> 1) : \
70 offset0 + (offset0 >> 2)
72 /* Note no trailing semicolon on the above macro; if it's there, then
73 * the typical usage of YV12_SETUP(pict); will have an extra trailing ;
74 * that some compilers will interpret as a statement -- and then any further
75 * variable declarations will cause an error.
78 #define YV12_Y(line) \
79 ((uint8_t *) ((bits) + (stride) * (line)))
81 #define YV12_U(line) \
82 ((uint8_t *) ((bits) + offset1 + \
83 ((stride) >> 1) * ((line) >> 1)))
85 #define YV12_V(line) \
86 ((uint8_t *) ((bits) + offset0 + \
87 ((stride) >> 1) * ((line) >> 1)))
89 /********************************** Fetch ************************************/
92 fetch_scanline_a8r8g8b8 (pixman_image_t *image,
100 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
102 MEMCPY_WRAPPED (image,
103 buffer, (const uint32_t *)bits + x,
104 width * sizeof(uint32_t));
108 fetch_scanline_x8r8g8b8 (pixman_image_t *image,
113 const uint32_t *mask,
116 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
117 const uint32_t *pixel = (const uint32_t *)bits + x;
118 const uint32_t *end = pixel + width;
121 *buffer++ = READ (image, pixel++) | 0xff000000;
125 fetch_scanline_a8b8g8r8 (pixman_image_t *image,
130 const uint32_t *mask,
133 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
134 const uint32_t *pixel = (uint32_t *)bits + x;
135 const uint32_t *end = pixel + width;
139 uint32_t p = READ (image, pixel++);
141 *buffer++ = (p & 0xff00ff00) |
148 fetch_scanline_x8b8g8r8 (pixman_image_t *image,
153 const uint32_t *mask,
156 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
157 const uint32_t *pixel = (uint32_t *)bits + x;
158 const uint32_t *end = pixel + width;
162 uint32_t p = READ (image, pixel++);
164 *buffer++ = 0xff000000 |
172 fetch_scanline_b8g8r8a8 (pixman_image_t *image,
177 const uint32_t *mask,
180 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
181 const uint32_t *pixel = (uint32_t *)bits + x;
182 const uint32_t *end = pixel + width;
186 uint32_t p = READ (image, pixel++);
188 *buffer++ = (((p & 0xff000000) >> 24) |
189 ((p & 0x00ff0000) >> 8) |
190 ((p & 0x0000ff00) << 8) |
191 ((p & 0x000000ff) << 24));
196 fetch_scanline_b8g8r8x8 (pixman_image_t *image,
201 const uint32_t *mask,
204 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
205 const uint32_t *pixel = (uint32_t *)bits + x;
206 const uint32_t *end = pixel + width;
210 uint32_t p = READ (image, pixel++);
212 *buffer++ = (0xff000000 |
213 ((p & 0xff000000) >> 24) |
214 ((p & 0x00ff0000) >> 8) |
215 ((p & 0x0000ff00) << 8));
219 /* Expects a uint64_t buffer */
221 fetch_scanline_a2r10g10b10 (pixman_image_t *image,
226 const uint32_t *mask,
229 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
230 const uint32_t *pixel = bits + x;
231 const uint32_t *end = pixel + width;
232 uint64_t *buffer = (uint64_t *)b;
236 uint32_t p = READ (image, pixel++);
237 uint64_t a = p >> 30;
238 uint64_t r = (p >> 20) & 0x3ff;
239 uint64_t g = (p >> 10) & 0x3ff;
240 uint64_t b = p & 0x3ff;
251 *buffer++ = a << 48 | r << 32 | g << 16 | b;
255 /* Expects a uint64_t buffer */
257 fetch_scanline_x2r10g10b10 (pixman_image_t *image,
262 const uint32_t *mask,
265 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
266 const uint32_t *pixel = (uint32_t *)bits + x;
267 const uint32_t *end = pixel + width;
268 uint64_t *buffer = (uint64_t *)b;
272 uint32_t p = READ (image, pixel++);
273 uint64_t r = (p >> 20) & 0x3ff;
274 uint64_t g = (p >> 10) & 0x3ff;
275 uint64_t b = p & 0x3ff;
281 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
285 /* Expects a uint64_t buffer */
287 fetch_scanline_a2b10g10r10 (pixman_image_t *image,
292 const uint32_t *mask,
295 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
296 const uint32_t *pixel = bits + x;
297 const uint32_t *end = pixel + width;
298 uint64_t *buffer = (uint64_t *)b;
302 uint32_t p = READ (image, pixel++);
303 uint64_t a = p >> 30;
304 uint64_t b = (p >> 20) & 0x3ff;
305 uint64_t g = (p >> 10) & 0x3ff;
306 uint64_t r = p & 0x3ff;
317 *buffer++ = a << 48 | r << 32 | g << 16 | b;
321 /* Expects a uint64_t buffer */
323 fetch_scanline_x2b10g10r10 (pixman_image_t *image,
328 const uint32_t *mask,
331 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
332 const uint32_t *pixel = (uint32_t *)bits + x;
333 const uint32_t *end = pixel + width;
334 uint64_t *buffer = (uint64_t *)b;
338 uint32_t p = READ (image, pixel++);
339 uint64_t b = (p >> 20) & 0x3ff;
340 uint64_t g = (p >> 10) & 0x3ff;
341 uint64_t r = p & 0x3ff;
347 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
352 fetch_scanline_r8g8b8 (pixman_image_t *image,
357 const uint32_t *mask,
360 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
361 const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
362 const uint8_t *end = pixel + 3 * width;
366 uint32_t b = 0xff000000;
368 #ifdef WORDS_BIGENDIAN
369 b |= (READ (image, pixel++) << 16);
370 b |= (READ (image, pixel++) << 8);
371 b |= (READ (image, pixel++));
373 b |= (READ (image, pixel++));
374 b |= (READ (image, pixel++) << 8);
375 b |= (READ (image, pixel++) << 16);
383 fetch_scanline_b8g8r8 (pixman_image_t *image,
388 const uint32_t *mask,
391 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
392 const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
393 const uint8_t *end = pixel + 3 * width;
397 uint32_t b = 0xff000000;
398 #ifdef WORDS_BIGENDIAN
399 b |= (READ (image, pixel++));
400 b |= (READ (image, pixel++) << 8);
401 b |= (READ (image, pixel++) << 16);
403 b |= (READ (image, pixel++) << 16);
404 b |= (READ (image, pixel++) << 8);
405 b |= (READ (image, pixel++));
412 fetch_scanline_r5g6b5 (pixman_image_t *image,
417 const uint32_t *mask,
420 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
421 const uint16_t *pixel = (const uint16_t *)bits + x;
422 const uint16_t *end = pixel + width;
426 uint32_t p = READ (image, pixel++);
427 uint32_t r = (((p) << 3) & 0xf8) |
428 (((p) << 5) & 0xfc00) |
429 (((p) << 8) & 0xf80000);
431 r |= (r >> 5) & 0x70007;
432 r |= (r >> 6) & 0x300;
434 *buffer++ = 0xff000000 | r;
439 fetch_scanline_b5g6r5 (pixman_image_t *image,
444 const uint32_t *mask,
447 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
448 const uint16_t *pixel = (const uint16_t *)bits + x;
449 const uint16_t *end = pixel + width;
453 uint32_t p = READ (image, pixel++);
456 b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
457 g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
458 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
460 *buffer++ = 0xff000000 | r | g | b;
465 fetch_scanline_a1r5g5b5 (pixman_image_t *image,
470 const uint32_t *mask,
473 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
474 const uint16_t *pixel = (const uint16_t *)bits + x;
475 const uint16_t *end = pixel + width;
479 uint32_t p = READ (image, pixel++);
482 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
483 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
484 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
485 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
487 *buffer++ = a | r | g | b;
492 fetch_scanline_x1r5g5b5 (pixman_image_t *image,
497 const uint32_t *mask,
500 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
501 const uint16_t *pixel = (const uint16_t *)bits + x;
502 const uint16_t *end = pixel + width;
506 uint32_t p = READ (image, pixel++);
509 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
510 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
511 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
513 *buffer++ = 0xff000000 | r | g | b;
518 fetch_scanline_a1b5g5r5 (pixman_image_t *image,
523 const uint32_t *mask,
526 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
527 const uint16_t *pixel = (const uint16_t *)bits + x;
528 const uint16_t *end = pixel + width;
533 uint32_t p = READ (image, pixel++);
535 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
536 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
537 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
538 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
540 *buffer++ = a | r | g | b;
545 fetch_scanline_x1b5g5r5 (pixman_image_t *image,
550 const uint32_t *mask,
553 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
554 const uint16_t *pixel = (const uint16_t *)bits + x;
555 const uint16_t *end = pixel + width;
559 uint32_t p = READ (image, pixel++);
562 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
563 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
564 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
566 *buffer++ = 0xff000000 | r | g | b;
571 fetch_scanline_a4r4g4b4 (pixman_image_t *image,
576 const uint32_t *mask,
579 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
580 const uint16_t *pixel = (const uint16_t *)bits + x;
581 const uint16_t *end = pixel + width;
585 uint32_t p = READ (image, pixel++);
588 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
589 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
590 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
591 b = ((p & 0x000f) | ((p & 0x000f) << 4));
593 *buffer++ = a | r | g | b;
598 fetch_scanline_x4r4g4b4 (pixman_image_t *image,
603 const uint32_t *mask,
606 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
607 const uint16_t *pixel = (const uint16_t *)bits + x;
608 const uint16_t *end = pixel + width;
612 uint32_t p = READ (image, pixel++);
615 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
616 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
617 b = ((p & 0x000f) | ((p & 0x000f) << 4));
619 *buffer++ = 0xff000000 | r | g | b;
624 fetch_scanline_a4b4g4r4 (pixman_image_t *image,
629 const uint32_t *mask,
632 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
633 const uint16_t *pixel = (const uint16_t *)bits + x;
634 const uint16_t *end = pixel + width;
638 uint32_t p = READ (image, pixel++);
641 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
642 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
643 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
644 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
646 *buffer++ = a | r | g | b;
651 fetch_scanline_x4b4g4r4 (pixman_image_t *image,
656 const uint32_t *mask,
659 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
660 const uint16_t *pixel = (const uint16_t *)bits + x;
661 const uint16_t *end = pixel + width;
665 uint32_t p = READ (image, pixel++);
668 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
669 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
670 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
672 *buffer++ = 0xff000000 | r | g | b;
677 fetch_scanline_a8 (pixman_image_t *image,
682 const uint32_t *mask,
685 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
686 const uint8_t *pixel = (const uint8_t *)bits + x;
687 const uint8_t *end = pixel + width;
690 *buffer++ = READ (image, pixel++) << 24;
694 fetch_scanline_r3g3b2 (pixman_image_t *image,
699 const uint32_t *mask,
702 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
703 const uint8_t *pixel = (const uint8_t *)bits + x;
704 const uint8_t *end = pixel + width;
708 uint32_t p = READ (image, pixel++);
711 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
712 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
718 *buffer++ = 0xff000000 | r | g | b;
723 fetch_scanline_b2g3r3 (pixman_image_t *image,
728 const uint32_t *mask,
731 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
732 const uint8_t *pixel = (const uint8_t *)bits + x;
733 const uint8_t *end = pixel + width;
737 uint32_t p = READ (image, pixel++);
745 g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
749 ((p & 0x06) << 6)) << 16;
751 *buffer++ = 0xff000000 | r | g | b;
756 fetch_scanline_a2r2g2b2 (pixman_image_t *image,
761 const uint32_t *mask,
764 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
765 const uint8_t *pixel = (const uint8_t *)bits + x;
766 const uint8_t *end = pixel + width;
770 uint32_t p = READ (image, pixel++);
773 a = ((p & 0xc0) * 0x55) << 18;
774 r = ((p & 0x30) * 0x55) << 12;
775 g = ((p & 0x0c) * 0x55) << 6;
776 b = ((p & 0x03) * 0x55);
778 *buffer++ = a | r | g | b;
783 fetch_scanline_a2b2g2r2 (pixman_image_t *image,
788 const uint32_t *mask,
791 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
792 const uint8_t *pixel = (const uint8_t *)bits + x;
793 const uint8_t *end = pixel + width;
797 uint32_t p = READ (image, pixel++);
800 a = ((p & 0xc0) * 0x55) << 18;
801 b = ((p & 0x30) * 0x55) >> 6;
802 g = ((p & 0x0c) * 0x55) << 6;
803 r = ((p & 0x03) * 0x55) << 16;
805 *buffer++ = a | r | g | b;
810 fetch_scanline_c8 (pixman_image_t *image,
815 const uint32_t *mask,
818 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
819 const pixman_indexed_t * indexed = image->bits.indexed;
820 const uint8_t *pixel = (const uint8_t *)bits + x;
821 const uint8_t *end = pixel + width;
825 uint32_t p = READ (image, pixel++);
827 *buffer++ = indexed->rgba[p];
832 fetch_scanline_x4a4 (pixman_image_t *image,
837 const uint32_t *mask,
840 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
841 const uint8_t *pixel = (const uint8_t *)bits + x;
842 const uint8_t *end = pixel + width;
846 uint8_t p = READ (image, pixel++) & 0xf;
848 *buffer++ = (p | (p << 4)) << 24;
852 #define FETCH_8(img,l,o) (READ (img, (uint8_t *)(l) + ((o) >> 2)))
853 #ifdef WORDS_BIGENDIAN
854 #define FETCH_4(img,l,o) ((o) & 2 ? FETCH_8 (img,l,o) & 0xf : FETCH_8 (img,l,o) >> 4)
856 #define FETCH_4(img,l,o) ((o) & 2 ? FETCH_8 (img,l,o) >> 4 : FETCH_8 (img,l,o) & 0xf)
860 fetch_scanline_a4 (pixman_image_t *image,
865 const uint32_t *mask,
868 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
871 for (i = 0; i < width; ++i)
873 uint32_t p = FETCH_4 (image, bits, i + x);
882 fetch_scanline_r1g2b1 (pixman_image_t *image,
887 const uint32_t *mask,
890 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
893 for (i = 0; i < width; ++i)
895 uint32_t p = FETCH_4 (image, bits, i + x);
898 r = ((p & 0x8) * 0xff) << 13;
899 g = ((p & 0x6) * 0x55) << 7;
900 b = ((p & 0x1) * 0xff);
902 *buffer++ = 0xff000000 | r | g | b;
907 fetch_scanline_b1g2r1 (pixman_image_t *image,
912 const uint32_t *mask,
915 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
918 for (i = 0; i < width; ++i)
920 uint32_t p = FETCH_4 (image, bits, i + x);
923 b = ((p & 0x8) * 0xff) >> 3;
924 g = ((p & 0x6) * 0x55) << 7;
925 r = ((p & 0x1) * 0xff) << 16;
927 *buffer++ = 0xff000000 | r | g | b;
932 fetch_scanline_a1r1g1b1 (pixman_image_t *image,
937 const uint32_t *mask,
941 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
944 for (i = 0; i < width; ++i)
946 uint32_t p = FETCH_4 (image, bits, i + x);
948 a = ((p & 0x8) * 0xff) << 21;
949 r = ((p & 0x4) * 0xff) << 14;
950 g = ((p & 0x2) * 0xff) << 7;
951 b = ((p & 0x1) * 0xff);
953 *buffer++ = a | r | g | b;
958 fetch_scanline_a1b1g1r1 (pixman_image_t *image,
963 const uint32_t *mask,
966 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
969 for (i = 0; i < width; ++i)
971 uint32_t p = FETCH_4 (image, bits, i + x);
974 a = ((p & 0x8) * 0xff) << 21;
975 r = ((p & 0x4) * 0xff) >> 3;
976 g = ((p & 0x2) * 0xff) << 7;
977 b = ((p & 0x1) * 0xff) << 16;
979 *buffer++ = a | r | g | b;
984 fetch_scanline_c4 (pixman_image_t *image,
989 const uint32_t *mask,
992 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
993 const pixman_indexed_t * indexed = image->bits.indexed;
996 for (i = 0; i < width; ++i)
998 uint32_t p = FETCH_4 (image, bits, i + x);
1000 *buffer++ = indexed->rgba[p];
1005 fetch_scanline_a1 (pixman_image_t *image,
1010 const uint32_t *mask,
1013 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1016 for (i = 0; i < width; ++i)
1018 uint32_t p = READ (image, bits + ((i + x) >> 5));
1021 #ifdef WORDS_BIGENDIAN
1022 a = p >> (0x1f - ((i + x) & 0x1f));
1024 a = p >> ((i + x) & 0x1f);
1031 *buffer++ = a << 24;
1036 fetch_scanline_g1 (pixman_image_t *image,
1041 const uint32_t *mask,
1044 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1045 const pixman_indexed_t * indexed = image->bits.indexed;
1048 for (i = 0; i < width; ++i)
1050 uint32_t p = READ (image, bits + ((i + x) >> 5));
1053 #ifdef WORDS_BIGENDIAN
1054 a = p >> (0x1f - ((i + x) & 0x1f));
1056 a = p >> ((i + x) & 0x1f);
1060 *buffer++ = indexed->rgba[a];
1065 fetch_scanline_yuy2 (pixman_image_t *image,
1070 const uint32_t *mask,
1073 const uint32_t *bits = image->bits.bits + image->bits.rowstride * line;
1076 for (i = 0; i < width; i++)
1081 y = ((uint8_t *) bits)[(x + i) << 1] - 16;
1082 u = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 1] - 128;
1083 v = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 3] - 128;
1085 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1086 r = 0x012b27 * y + 0x019a2e * v;
1087 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1088 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1089 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1090 b = 0x012b27 * y + 0x0206a2 * u;
1092 *buffer++ = 0xff000000 |
1093 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1094 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1095 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1100 fetch_scanline_yv12 (pixman_image_t *image,
1105 const uint32_t *mask,
1109 uint8_t *y_line = YV12_Y (line);
1110 uint8_t *u_line = YV12_U (line);
1111 uint8_t *v_line = YV12_V (line);
1114 for (i = 0; i < width; i++)
1119 y = y_line[x + i] - 16;
1120 u = u_line[(x + i) >> 1] - 128;
1121 v = v_line[(x + i) >> 1] - 128;
1123 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1124 r = 0x012b27 * y + 0x019a2e * v;
1125 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1126 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1127 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1128 b = 0x012b27 * y + 0x0206a2 * u;
1130 *buffer++ = 0xff000000 |
1131 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1132 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1133 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1137 /**************************** Pixel wise fetching *****************************/
1139 /* Despite the type, expects a uint64_t buffer */
1141 fetch_pixels_a2r10g10b10_64 (bits_image_t *pict,
1146 uint64_t *buffer = (uint64_t *)b;
1148 for (i = 0; i < n_pixels; ++i)
1150 int offset = ((uint32_t *)buffer)[2 * i];
1151 int line = ((uint32_t *)buffer)[2 * i + 1];
1153 if (offset == 0xffffffff || line == 0xffffffff)
1159 uint32_t *bits = pict->bits + line * pict->rowstride;
1160 uint32_t p = READ (pict, bits + offset);
1161 uint64_t a = p >> 30;
1162 uint64_t r = (p >> 20) & 0x3ff;
1163 uint64_t g = (p >> 10) & 0x3ff;
1164 uint64_t b = p & 0x3ff;
1166 r = r << 6 | r >> 4;
1167 g = g << 6 | g >> 4;
1168 b = b << 6 | b >> 4;
1175 buffer[i] = a << 48 | r << 32 | g << 16 | b;
1180 /* Despite the type, this function expects a uint64_t buffer */
1182 fetch_pixels_x2r10g10b10_64 (bits_image_t *pict,
1186 uint64_t *buffer = (uint64_t *)b;
1189 for (i = 0; i < n_pixels; ++i)
1191 int offset = ((uint32_t *)buffer)[2 * i];
1192 int line = ((uint32_t *)buffer)[2 * i + 1];
1194 if (offset == 0xffffffff || line == 0xffffffff)
1200 uint32_t *bits = pict->bits + line * pict->rowstride;
1201 uint32_t p = READ (pict, bits + offset);
1202 uint64_t r = (p >> 20) & 0x3ff;
1203 uint64_t g = (p >> 10) & 0x3ff;
1204 uint64_t b = p & 0x3ff;
1206 r = r << 6 | r >> 4;
1207 g = g << 6 | g >> 4;
1208 b = b << 6 | b >> 4;
1210 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
1215 /* Despite the type, expects a uint64_t buffer */
1217 fetch_pixels_a2b10g10r10_64 (bits_image_t *pict,
1221 uint64_t *buffer = (uint64_t *)b;
1224 for (i = 0; i < n_pixels; ++i)
1226 int offset = ((uint32_t *)buffer)[2 * i];
1227 int line = ((uint32_t *)buffer)[2 * i + 1];
1229 if (offset == 0xffffffff || line == 0xffffffff)
1235 uint32_t *bits = pict->bits + line * pict->rowstride;
1236 uint32_t p = READ (pict, bits + offset);
1237 uint64_t a = p >> 30;
1238 uint64_t b = (p >> 20) & 0x3ff;
1239 uint64_t g = (p >> 10) & 0x3ff;
1240 uint64_t r = p & 0x3ff;
1242 r = r << 6 | r >> 4;
1243 g = g << 6 | g >> 4;
1244 b = b << 6 | b >> 4;
1251 buffer[i] = a << 48 | r << 32 | g << 16 | b;
1256 /* Despite the type, this function expects a uint64_t buffer */
1258 fetch_pixels_x2b10g10r10_64 (bits_image_t *pict,
1262 uint64_t *buffer = (uint64_t *)b;
1265 for (i = 0; i < n_pixels; ++i)
1267 int offset = ((uint32_t *)buffer)[2 * i];
1268 int line = ((uint32_t *)buffer)[2 * i + 1];
1270 if (offset == 0xffffffff || line == 0xffffffff)
1276 uint32_t *bits = pict->bits + line * pict->rowstride;
1277 uint32_t p = READ (pict, bits + offset);
1278 uint64_t b = (p >> 20) & 0x3ff;
1279 uint64_t g = (p >> 10) & 0x3ff;
1280 uint64_t r = p & 0x3ff;
1282 r = r << 6 | r >> 4;
1283 g = g << 6 | g >> 4;
1284 b = b << 6 | b >> 4;
1286 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
1292 fetch_pixels_a8r8g8b8 (bits_image_t *pict,
1298 for (i = 0; i < n_pixels; ++i)
1300 int offset = buffer[2 * i];
1301 int line = buffer[2 * i + 1];
1303 if (offset == 0xffffffff || line == 0xffffffff)
1309 uint32_t *bits = pict->bits + line * pict->rowstride;
1310 buffer[i] = READ (pict, (uint32_t *)bits + offset);
1316 fetch_pixels_x8r8g8b8 (bits_image_t *pict,
1322 for (i = 0; i < n_pixels; ++i)
1324 int offset = buffer[2 * i];
1325 int line = buffer[2 * i + 1];
1327 if (offset == 0xffffffff || line == 0xffffffff)
1333 uint32_t *bits = pict->bits + line * pict->rowstride;
1334 buffer[i] = READ (pict, (uint32_t *)bits + offset) | 0xff000000;
1340 fetch_pixels_a8b8g8r8 (bits_image_t *pict,
1346 for (i = 0; i < n_pixels; ++i)
1348 int offset = buffer[2 * i];
1349 int line = buffer[2 * i + 1];
1351 if (offset == 0xffffffff || line == 0xffffffff)
1357 uint32_t *bits = pict->bits + line * pict->rowstride;
1358 uint32_t pixel = READ (pict, (uint32_t *)bits + offset);
1360 buffer[i] = ((pixel & 0xff000000) |
1361 ((pixel >> 16) & 0xff) |
1362 (pixel & 0x0000ff00) |
1363 ((pixel & 0xff) << 16));
1369 fetch_pixels_x8b8g8r8 (bits_image_t *pict,
1375 for (i = 0; i < n_pixels; ++i)
1377 int offset = buffer[2 * i];
1378 int line = buffer[2 * i + 1];
1380 if (offset == 0xffffffff || line == 0xffffffff)
1386 uint32_t *bits = pict->bits + line * pict->rowstride;
1387 uint32_t pixel = READ (pict, (uint32_t *)bits + offset);
1389 buffer[i] = (0xff000000) |
1390 ((pixel >> 16) & 0xff) |
1391 (pixel & 0x0000ff00) |
1392 ((pixel & 0xff) << 16);
1398 fetch_pixels_b8g8r8a8 (bits_image_t *pict,
1404 for (i = 0; i < n_pixels; ++i)
1406 int offset = buffer[2 * i];
1407 int line = buffer[2 * i + 1];
1409 if (offset == 0xffffffff || line == 0xffffffff)
1415 uint32_t *bits = pict->bits + line * pict->rowstride;
1416 uint32_t pixel = READ (pict, (uint32_t *)bits + offset);
1418 buffer[i] = ((pixel & 0xff000000) >> 24 |
1419 (pixel & 0x00ff0000) >> 8 |
1420 (pixel & 0x0000ff00) << 8 |
1421 (pixel & 0x000000ff) << 24);
1427 fetch_pixels_b8g8r8x8 (bits_image_t *pict,
1433 for (i = 0; i < n_pixels; ++i)
1435 int offset = buffer[2 * i];
1436 int line = buffer[2 * i + 1];
1438 if (offset == 0xffffffff || line == 0xffffffff)
1444 uint32_t *bits = pict->bits + line * pict->rowstride;
1445 uint32_t pixel = READ (pict, (uint32_t *)bits + offset);
1447 buffer[i] = ((0xff000000) |
1448 (pixel & 0xff000000) >> 24 |
1449 (pixel & 0x00ff0000) >> 8 |
1450 (pixel & 0x0000ff00) << 8);
1456 fetch_pixels_r8g8b8 (bits_image_t *pict,
1462 for (i = 0; i < n_pixels; ++i)
1464 int offset = buffer[2 * i];
1465 int line = buffer[2 * i + 1];
1467 if (offset == 0xffffffff || line == 0xffffffff)
1473 uint32_t *bits = pict->bits + line * pict->rowstride;
1474 uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1476 #ifdef WORDS_BIGENDIAN
1477 buffer[i] = (0xff000000 |
1478 (READ (pict, pixel + 0) << 16) |
1479 (READ (pict, pixel + 1) << 8) |
1480 (READ (pict, pixel + 2)));
1482 buffer[i] = (0xff000000 |
1483 (READ (pict, pixel + 2) << 16) |
1484 (READ (pict, pixel + 1) << 8) |
1485 (READ (pict, pixel + 0)));
1492 fetch_pixels_b8g8r8 (bits_image_t *pict,
1498 for (i = 0; i < n_pixels; ++i)
1500 int offset = buffer[2 * i];
1501 int line = buffer[2 * i + 1];
1503 if (offset == 0xffffffff || line == 0xffffffff)
1509 uint32_t *bits = pict->bits + line * pict->rowstride;
1510 uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1511 #ifdef WORDS_BIGENDIAN
1512 buffer[i] = (0xff000000 |
1513 (READ (pict, pixel + 2) << 16) |
1514 (READ (pict, pixel + 1) << 8) |
1515 (READ (pict, pixel + 0)));
1517 buffer[i] = (0xff000000 |
1518 (READ (pict, pixel + 0) << 16) |
1519 (READ (pict, pixel + 1) << 8) |
1520 (READ (pict, pixel + 2)));
1527 fetch_pixels_r5g6b5 (bits_image_t *pict,
1533 for (i = 0; i < n_pixels; ++i)
1535 int offset = buffer[2 * i];
1536 int line = buffer[2 * i + 1];
1538 if (offset == 0xffffffff || line == 0xffffffff)
1544 uint32_t *bits = pict->bits + line * pict->rowstride;
1545 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1548 r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1549 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1550 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1552 buffer[i] = (0xff000000 | r | g | b);
1558 fetch_pixels_b5g6r5 (bits_image_t *pict,
1564 for (i = 0; i < n_pixels; ++i)
1566 int offset = buffer[2 * i];
1567 int line = buffer[2 * i + 1];
1569 if (offset == 0xffffffff || line == 0xffffffff)
1576 uint32_t *bits = pict->bits + line * pict->rowstride;
1577 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1579 b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1580 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1581 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1583 buffer[i] = (0xff000000 | r | g | b);
1589 fetch_pixels_a1r5g5b5 (bits_image_t *pict,
1595 for (i = 0; i < n_pixels; ++i)
1597 int offset = buffer[2 * i];
1598 int line = buffer[2 * i + 1];
1600 if (offset == 0xffffffff || line == 0xffffffff)
1606 uint32_t *bits = pict->bits + line * pict->rowstride;
1607 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1608 uint32_t a, r, g, b;
1610 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1611 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1612 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1613 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1615 buffer[i] = (a | r | g | b);
1621 fetch_pixels_x1r5g5b5 (bits_image_t *pict,
1627 for (i = 0; i < n_pixels; ++i)
1629 int offset = buffer[2 * i];
1630 int line = buffer[2 * i + 1];
1632 if (offset == 0xffffffff || line == 0xffffffff)
1638 uint32_t *bits = pict->bits + line * pict->rowstride;
1639 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1642 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1643 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1644 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1646 buffer[i] = (0xff000000 | r | g | b);
1652 fetch_pixels_a1b5g5r5 (bits_image_t *pict,
1658 for (i = 0; i < n_pixels; ++i)
1660 int offset = buffer[2 * i];
1661 int line = buffer[2 * i + 1];
1663 if (offset == 0xffffffff || line == 0xffffffff)
1669 uint32_t *bits = pict->bits + line * pict->rowstride;
1670 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1671 uint32_t a, r, g, b;
1673 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1674 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1675 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1676 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1678 buffer[i] = (a | r | g | b);
1684 fetch_pixels_x1b5g5r5 (bits_image_t *pict,
1690 for (i = 0; i < n_pixels; ++i)
1692 int offset = buffer[2 * i];
1693 int line = buffer[2 * i + 1];
1695 if (offset == 0xffffffff || line == 0xffffffff)
1701 uint32_t *bits = pict->bits + line * pict->rowstride;
1702 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1705 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1706 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1707 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1709 buffer[i] = (0xff000000 | r | g | b);
1715 fetch_pixels_a4r4g4b4 (bits_image_t *pict,
1721 for (i = 0; i < n_pixels; ++i)
1723 int offset = buffer[2 * i];
1724 int line = buffer[2 * i + 1];
1726 if (offset == 0xffffffff || line == 0xffffffff)
1732 uint32_t *bits = pict->bits + line * pict->rowstride;
1733 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1734 uint32_t a, r, g, b;
1736 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1737 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1738 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1739 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1741 buffer[i] = (a | r | g | b);
1747 fetch_pixels_x4r4g4b4 (bits_image_t *pict,
1753 for (i = 0; i < n_pixels; ++i)
1755 int offset = buffer[2 * i];
1756 int line = buffer[2 * i + 1];
1758 if (offset == 0xffffffff || line == 0xffffffff)
1764 uint32_t *bits = pict->bits + line * pict->rowstride;
1765 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1768 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1769 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1770 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1772 buffer[i] = (0xff000000 | r | g | b);
1778 fetch_pixels_a4b4g4r4 (bits_image_t *pict,
1784 for (i = 0; i < n_pixels; ++i)
1786 int offset = buffer[2 * i];
1787 int line = buffer[2 * i + 1];
1789 if (offset == 0xffffffff || line == 0xffffffff)
1795 uint32_t *bits = pict->bits + line * pict->rowstride;
1796 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1797 uint32_t a, r, g, b;
1799 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1800 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1801 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1802 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1804 buffer[i] = (a | r | g | b);
1810 fetch_pixels_x4b4g4r4 (bits_image_t *pict,
1816 for (i = 0; i < n_pixels; ++i)
1818 int offset = buffer[2 * i];
1819 int line = buffer[2 * i + 1];
1821 if (offset == 0xffffffff || line == 0xffffffff)
1827 uint32_t *bits = pict->bits + line * pict->rowstride;
1828 uint32_t pixel = READ (pict, (uint16_t *) bits + offset);
1831 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1832 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1833 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1835 buffer[i] = (0xff000000 | r | g | b);
1841 fetch_pixels_a8 (bits_image_t *pict,
1847 for (i = 0; i < n_pixels; ++i)
1849 int offset = buffer[2 * i];
1850 int line = buffer[2 * i + 1];
1852 if (offset == 0xffffffff || line == 0xffffffff)
1858 uint32_t *bits = pict->bits + line * pict->rowstride;
1859 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
1861 buffer[i] = pixel << 24;
1867 fetch_pixels_r3g3b2 (bits_image_t *pict,
1873 for (i = 0; i < n_pixels; ++i)
1875 int offset = buffer[2 * i];
1876 int line = buffer[2 * i + 1];
1878 if (offset == 0xffffffff || line == 0xffffffff)
1884 uint32_t *bits = pict->bits + line * pict->rowstride;
1885 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
1888 r = ((pixel & 0xe0) |
1889 ((pixel & 0xe0) >> 3) |
1890 ((pixel & 0xc0) >> 6)) << 16;
1892 g = ((pixel & 0x1c) |
1893 ((pixel & 0x18) >> 3) |
1894 ((pixel & 0x1c) << 3)) << 8;
1896 b = (((pixel & 0x03) ) |
1897 ((pixel & 0x03) << 2) |
1898 ((pixel & 0x03) << 4) |
1899 ((pixel & 0x03) << 6));
1901 buffer[i] = (0xff000000 | r | g | b);
1907 fetch_pixels_b2g3r3 (bits_image_t *pict,
1913 for (i = 0; i < n_pixels; ++i)
1915 int offset = buffer[2 * i];
1916 int line = buffer[2 * i + 1];
1918 if (offset == 0xffffffff || line == 0xffffffff)
1924 uint32_t *bits = pict->bits + line * pict->rowstride;
1925 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
1928 b = ((pixel & 0xc0) |
1929 ((pixel & 0xc0) >> 2) |
1930 ((pixel & 0xc0) >> 4) |
1931 ((pixel & 0xc0) >> 6));
1933 g = ((pixel & 0x38) |
1934 ((pixel & 0x38) >> 3) |
1935 ((pixel & 0x30) << 2)) << 8;
1937 r = ((pixel & 0x07) |
1938 ((pixel & 0x07) << 3) |
1939 ((pixel & 0x06) << 6)) << 16;
1941 buffer[i] = (0xff000000 | r | g | b);
1947 fetch_pixels_a2r2g2b2 (bits_image_t *pict,
1953 for (i = 0; i < n_pixels; ++i)
1955 int offset = buffer[2 * i];
1956 int line = buffer[2 * i + 1];
1958 if (offset == 0xffffffff || line == 0xffffffff)
1964 uint32_t *bits = pict->bits + line * pict->rowstride;
1965 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
1966 uint32_t a, r, g, b;
1968 a = ((pixel & 0xc0) * 0x55) << 18;
1969 r = ((pixel & 0x30) * 0x55) << 12;
1970 g = ((pixel & 0x0c) * 0x55) << 6;
1971 b = ((pixel & 0x03) * 0x55);
1973 buffer[i] = a | r | g | b;
1979 fetch_pixels_a2b2g2r2 (bits_image_t *pict,
1985 for (i = 0; i < n_pixels; ++i)
1987 int offset = buffer[2 * i];
1988 int line = buffer[2 * i + 1];
1990 if (offset == 0xffffffff || line == 0xffffffff)
1996 uint32_t *bits = pict->bits + line * pict->rowstride;
1997 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
1998 uint32_t a, r, g, b;
2000 a = ((pixel & 0xc0) * 0x55) << 18;
2001 b = ((pixel & 0x30) * 0x55) >> 6;
2002 g = ((pixel & 0x0c) * 0x55) << 6;
2003 r = ((pixel & 0x03) * 0x55) << 16;
2005 buffer[i] = a | r | g | b;
2011 fetch_pixels_c8 (bits_image_t *pict,
2017 for (i = 0; i < n_pixels; ++i)
2019 int offset = buffer[2 * i];
2020 int line = buffer[2 * i + 1];
2022 if (offset == 0xffffffff || line == 0xffffffff)
2028 uint32_t *bits = pict->bits + line * pict->rowstride;
2029 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
2030 const pixman_indexed_t * indexed = pict->indexed;
2032 buffer[i] = indexed->rgba[pixel];
2038 fetch_pixels_x4a4 (bits_image_t *pict,
2044 for (i = 0; i < n_pixels; ++i)
2046 int offset = buffer[2 * i];
2047 int line = buffer[2 * i + 1];
2049 if (offset == 0xffffffff || line == 0xffffffff)
2055 uint32_t *bits = pict->bits + line * pict->rowstride;
2056 uint32_t pixel = READ (pict, (uint8_t *) bits + offset);
2058 buffer[i] = ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
2064 fetch_pixels_a4 (bits_image_t *pict,
2070 for (i = 0; i < n_pixels; ++i)
2072 int offset = buffer[2 * i];
2073 int line = buffer[2 * i + 1];
2075 if (offset == 0xffffffff || line == 0xffffffff)
2081 uint32_t *bits = pict->bits + line * pict->rowstride;
2082 uint32_t pixel = FETCH_4 (pict, bits, offset);
2084 pixel |= pixel << 4;
2085 buffer[i] = pixel << 24;
2091 fetch_pixels_r1g2b1 (bits_image_t *pict,
2097 for (i = 0; i < n_pixels; ++i)
2099 int offset = buffer[2 * i];
2100 int line = buffer[2 * i + 1];
2102 if (offset == 0xffffffff || line == 0xffffffff)
2108 uint32_t *bits = pict->bits + line * pict->rowstride;
2109 uint32_t pixel = FETCH_4 (pict, bits, offset);
2112 r = ((pixel & 0x8) * 0xff) << 13;
2113 g = ((pixel & 0x6) * 0x55) << 7;
2114 b = ((pixel & 0x1) * 0xff);
2116 buffer[i] = 0xff000000 | r | g | b;
2122 fetch_pixels_b1g2r1 (bits_image_t *pict,
2128 for (i = 0; i < n_pixels; ++i)
2130 int offset = buffer[2 * i];
2131 int line = buffer[2 * i + 1];
2133 if (offset == 0xffffffff || line == 0xffffffff)
2139 uint32_t *bits = pict->bits + line * pict->rowstride;
2140 uint32_t pixel = FETCH_4 (pict, bits, offset);
2143 b = ((pixel & 0x8) * 0xff) >> 3;
2144 g = ((pixel & 0x6) * 0x55) << 7;
2145 r = ((pixel & 0x1) * 0xff) << 16;
2147 buffer[i] = 0xff000000 | r | g | b;
2153 fetch_pixels_a1r1g1b1 (bits_image_t *pict,
2159 for (i = 0; i < n_pixels; ++i)
2161 int offset = buffer[2 * i];
2162 int line = buffer[2 * i + 1];
2164 if (offset == 0xffffffff || line == 0xffffffff)
2170 uint32_t *bits = pict->bits + line * pict->rowstride;
2171 uint32_t pixel = FETCH_4 (pict, bits, offset);
2172 uint32_t a, r, g, b;
2174 a = ((pixel & 0x8) * 0xff) << 21;
2175 r = ((pixel & 0x4) * 0xff) << 14;
2176 g = ((pixel & 0x2) * 0xff) << 7;
2177 b = ((pixel & 0x1) * 0xff);
2179 buffer[i] = a | r | g | b;
2185 fetch_pixels_a1b1g1r1 (bits_image_t *pict,
2191 for (i = 0; i < n_pixels; ++i)
2193 int offset = buffer[2 * i];
2194 int line = buffer[2 * i + 1];
2196 if (offset == 0xffffffff || line == 0xffffffff)
2202 uint32_t *bits = pict->bits + line * pict->rowstride;
2203 uint32_t pixel = FETCH_4 (pict, bits, offset);
2204 uint32_t a, r, g, b;
2206 a = ((pixel & 0x8) * 0xff) << 21;
2207 r = ((pixel & 0x4) * 0xff) >> 3;
2208 g = ((pixel & 0x2) * 0xff) << 7;
2209 b = ((pixel & 0x1) * 0xff) << 16;
2211 buffer[i] = a | r | g | b;
2217 fetch_pixels_c4 (bits_image_t *pict,
2223 for (i = 0; i < n_pixels; ++i)
2225 int offset = buffer[2 * i];
2226 int line = buffer[2 * i + 1];
2228 if (offset == 0xffffffff || line == 0xffffffff)
2234 uint32_t *bits = pict->bits + line * pict->rowstride;
2235 uint32_t pixel = FETCH_4 (pict, bits, offset);
2236 const pixman_indexed_t * indexed = pict->indexed;
2238 buffer[i] = indexed->rgba[pixel];
2244 fetch_pixels_a1 (bits_image_t *pict,
2250 for (i = 0; i < n_pixels; ++i)
2252 int offset = buffer[2 * i];
2253 int line = buffer[2 * i + 1];
2255 if (offset == 0xffffffff || line == 0xffffffff)
2261 uint32_t *bits = pict->bits + line * pict->rowstride;
2262 uint32_t pixel = READ (pict, bits + (offset >> 5));
2265 #ifdef WORDS_BIGENDIAN
2266 a = pixel >> (0x1f - (offset & 0x1f));
2268 a = pixel >> (offset & 0x1f);
2275 buffer[i] = a << 24;
2281 fetch_pixels_g1 (bits_image_t *pict,
2287 for (i = 0; i < n_pixels; ++i)
2289 int offset = buffer[2 * i];
2290 int line = buffer[2 * i + 1];
2292 if (offset == 0xffffffff || line == 0xffffffff)
2298 uint32_t *bits = pict->bits + line * pict->rowstride;
2299 uint32_t pixel = READ (pict, bits + (offset >> 5));
2300 const pixman_indexed_t * indexed = pict->indexed;
2303 #ifdef WORDS_BIGENDIAN
2304 a = pixel >> (0x1f - (offset & 0x1f));
2306 a = pixel >> (offset & 0x1f);
2310 buffer[i] = indexed->rgba[a];
2316 fetch_pixels_yuy2 (bits_image_t *pict,
2322 for (i = 0; i < n_pixels; ++i)
2324 int offset = buffer[2 * i];
2325 int line = buffer[2 * i + 1];
2327 if (offset == 0xffffffff || line == 0xffffffff)
2333 const uint32_t *bits = pict->bits + pict->rowstride * line;
2338 y = ((uint8_t *) bits)[offset << 1] - 16;
2339 u = ((uint8_t *) bits)[((offset << 1) & - 4) + 1] - 128;
2340 v = ((uint8_t *) bits)[((offset << 1) & - 4) + 3] - 128;
2342 /* R = 1.164(Y - 16) + 1.596(V - 128) */
2343 r = 0x012b27 * y + 0x019a2e * v;
2345 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
2346 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
2348 /* B = 1.164(Y - 16) + 2.018(U - 128) */
2349 b = 0x012b27 * y + 0x0206a2 * u;
2351 buffer[i] = 0xff000000 |
2352 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
2353 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
2354 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
2360 fetch_pixels_yv12 (bits_image_t *pict,
2366 for (i = 0; i < n_pixels; ++i)
2368 int offset = buffer[2 * i];
2369 int line = buffer[2 * i + 1];
2371 if (offset == 0xffffffff || line == 0xffffffff)
2378 int16_t y = YV12_Y (line)[offset] - 16;
2379 int16_t u = YV12_U (line)[offset >> 1] - 128;
2380 int16_t v = YV12_V (line)[offset >> 1] - 128;
2383 /* R = 1.164(Y - 16) + 1.596(V - 128) */
2384 r = 0x012b27 * y + 0x019a2e * v;
2386 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
2387 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
2389 /* B = 1.164(Y - 16) + 2.018(U - 128) */
2390 b = 0x012b27 * y + 0x0206a2 * u;
2392 buffer[i] = 0xff000000 |
2393 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
2394 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
2395 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
2400 /*********************************** Store ************************************/
2402 #define SPLIT_A(v) \
2403 uint32_t a = ((v) >> 24), \
2404 r = ((v) >> 16) & 0xff, \
2405 g = ((v) >> 8) & 0xff, \
2409 uint32_t r = ((v) >> 16) & 0xff, \
2410 g = ((v) >> 8) & 0xff, \
2414 store_scanline_a2r10g10b10 (bits_image_t * image,
2420 uint32_t *bits = image->bits + image->rowstride * y;
2421 uint32_t *pixel = bits + x;
2422 uint64_t *values = (uint64_t *)v;
2425 for (i = 0; i < width; ++i)
2427 WRITE (image, pixel++,
2428 ((values[i] >> 32) & 0xc0000000) | // A
2429 ((values[i] >> 18) & 0x3ff00000) | // R
2430 ((values[i] >> 12) & 0xffc00) | // G
2431 ((values[i] >> 6) & 0x3ff)); // B
2436 store_scanline_x2r10g10b10 (bits_image_t * image,
2442 uint32_t *bits = image->bits + image->rowstride * y;
2443 uint64_t *values = (uint64_t *)v;
2444 uint32_t *pixel = bits + x;
2447 for (i = 0; i < width; ++i)
2449 WRITE (image, pixel++,
2450 ((values[i] >> 18) & 0x3ff00000) | // R
2451 ((values[i] >> 12) & 0xffc00) | // G
2452 ((values[i] >> 6) & 0x3ff)); // B
2457 store_scanline_a2b10g10r10 (bits_image_t * image,
2463 uint32_t *bits = image->bits + image->rowstride * y;
2464 uint32_t *pixel = bits + x;
2465 uint64_t *values = (uint64_t *)v;
2468 for (i = 0; i < width; ++i)
2470 WRITE (image, pixel++,
2471 ((values[i] >> 32) & 0xc0000000) | // A
2472 ((values[i] >> 38) & 0x3ff) | // R
2473 ((values[i] >> 12) & 0xffc00) | // G
2474 ((values[i] << 14) & 0x3ff00000)); // B
2479 store_scanline_x2b10g10r10 (bits_image_t * image,
2485 uint32_t *bits = image->bits + image->rowstride * y;
2486 uint64_t *values = (uint64_t *)v;
2487 uint32_t *pixel = bits + x;
2490 for (i = 0; i < width; ++i)
2492 WRITE (image, pixel++,
2493 ((values[i] >> 38) & 0x3ff) | // R
2494 ((values[i] >> 12) & 0xffc00) | // G
2495 ((values[i] << 14) & 0x3ff00000)); // B
2500 store_scanline_a8r8g8b8 (bits_image_t * image,
2504 const uint32_t *values)
2506 uint32_t *bits = image->bits + image->rowstride * y;
2508 MEMCPY_WRAPPED (image, ((uint32_t *)bits) + x, values,
2509 width * sizeof(uint32_t));
2513 store_scanline_x8r8g8b8 (bits_image_t * image,
2517 const uint32_t *values)
2519 uint32_t *bits = image->bits + image->rowstride * y;
2520 uint32_t *pixel = (uint32_t *)bits + x;
2523 for (i = 0; i < width; ++i)
2524 WRITE (image, pixel++, values[i] & 0xffffff);
2528 store_scanline_a8b8g8r8 (bits_image_t * image,
2532 const uint32_t *values)
2534 uint32_t *bits = image->bits + image->rowstride * y;
2535 uint32_t *pixel = (uint32_t *)bits + x;
2538 for (i = 0; i < width; ++i)
2540 WRITE (image, pixel++,
2541 (values[i] & 0xff00ff00) |
2542 ((values[i] >> 16) & 0xff) |
2543 ((values[i] & 0xff) << 16));
2548 store_scanline_x8b8g8r8 (bits_image_t * image,
2552 const uint32_t *values)
2554 uint32_t *bits = image->bits + image->rowstride * y;
2555 uint32_t *pixel = (uint32_t *)bits + x;
2558 for (i = 0; i < width; ++i)
2560 WRITE (image, pixel++,
2561 (values[i] & 0x0000ff00) |
2562 ((values[i] >> 16) & 0xff) |
2563 ((values[i] & 0xff) << 16));
2568 store_scanline_b8g8r8a8 (bits_image_t * image,
2572 const uint32_t *values)
2574 uint32_t *bits = image->bits + image->rowstride * y;
2575 uint32_t *pixel = (uint32_t *)bits + x;
2578 for (i = 0; i < width; ++i)
2580 WRITE (image, pixel++,
2581 ((values[i] >> 24) & 0x000000ff) |
2582 ((values[i] >> 8) & 0x0000ff00) |
2583 ((values[i] << 8) & 0x00ff0000) |
2584 ((values[i] << 24) & 0xff000000));
2589 store_scanline_b8g8r8x8 (bits_image_t * image,
2593 const uint32_t *values)
2595 uint32_t *bits = image->bits + image->rowstride * y;
2596 uint32_t *pixel = (uint32_t *)bits + x;
2599 for (i = 0; i < width; ++i)
2601 WRITE (image, pixel++,
2602 ((values[i] >> 8) & 0x0000ff00) |
2603 ((values[i] << 8) & 0x00ff0000) |
2604 ((values[i] << 24) & 0xff000000));
2609 store_scanline_r8g8b8 (bits_image_t * image,
2613 const uint32_t *values)
2615 uint32_t *bits = image->bits + image->rowstride * y;
2616 uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2619 for (i = 0; i < width; ++i)
2621 uint32_t val = values[i];
2623 #ifdef WORDS_BIGENDIAN
2624 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2625 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2626 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2628 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2629 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2630 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2636 store_scanline_b8g8r8 (bits_image_t * image,
2640 const uint32_t *values)
2642 uint32_t *bits = image->bits + image->rowstride * y;
2643 uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2646 for (i = 0; i < width; ++i)
2648 uint32_t val = values[i];
2650 #ifdef WORDS_BIGENDIAN
2651 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2652 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2653 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2655 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2656 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2657 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2663 store_scanline_r5g6b5 (bits_image_t * image,
2667 const uint32_t *values)
2669 uint32_t *bits = image->bits + image->rowstride * y;
2670 uint16_t *pixel = ((uint16_t *) bits) + x;
2673 for (i = 0; i < width; ++i)
2675 uint32_t s = values[i];
2677 WRITE (image, pixel++,
2678 ((s >> 3) & 0x001f) |
2679 ((s >> 5) & 0x07e0) |
2680 ((s >> 8) & 0xf800));
2685 store_scanline_b5g6r5 (bits_image_t * image,
2689 const uint32_t *values)
2691 uint32_t *bits = image->bits + image->rowstride * y;
2692 uint16_t *pixel = ((uint16_t *) bits) + x;
2695 for (i = 0; i < width; ++i)
2699 WRITE (image, pixel++,
2700 ((b << 8) & 0xf800) |
2701 ((g << 3) & 0x07e0) |
2707 store_scanline_a1r5g5b5 (bits_image_t * image,
2711 const uint32_t *values)
2713 uint32_t *bits = image->bits + image->rowstride * y;
2714 uint16_t *pixel = ((uint16_t *) bits) + x;
2717 for (i = 0; i < width; ++i)
2719 SPLIT_A (values[i]);
2721 WRITE (image, pixel++,
2722 ((a << 8) & 0x8000) |
2723 ((r << 7) & 0x7c00) |
2724 ((g << 2) & 0x03e0) |
2730 store_scanline_x1r5g5b5 (bits_image_t * image,
2734 const uint32_t *values)
2736 uint32_t *bits = image->bits + image->rowstride * y;
2737 uint16_t *pixel = ((uint16_t *) bits) + x;
2740 for (i = 0; i < width; ++i)
2744 WRITE (image, pixel++,
2745 ((r << 7) & 0x7c00) |
2746 ((g << 2) & 0x03e0) |
2752 store_scanline_a1b5g5r5 (bits_image_t * image,
2756 const uint32_t *values)
2758 uint32_t *bits = image->bits + image->rowstride * y;
2759 uint16_t *pixel = ((uint16_t *) bits) + x;
2762 for (i = 0; i < width; ++i)
2764 SPLIT_A (values[i]);
2766 WRITE (image, pixel++,
2767 ((a << 8) & 0x8000) |
2768 ((b << 7) & 0x7c00) |
2769 ((g << 2) & 0x03e0) |
2775 store_scanline_x1b5g5r5 (bits_image_t * image,
2779 const uint32_t *values)
2781 uint32_t *bits = image->bits + image->rowstride * y;
2782 uint16_t *pixel = ((uint16_t *) bits) + x;
2785 for (i = 0; i < width; ++i)
2789 WRITE (image, pixel++, ((b << 7) & 0x7c00) |
2790 ((g << 2) & 0x03e0) |
2796 store_scanline_a4r4g4b4 (bits_image_t * image,
2800 const uint32_t *values)
2802 uint32_t *bits = image->bits + image->rowstride * y;
2803 uint16_t *pixel = ((uint16_t *) bits) + x;
2806 for (i = 0; i < width; ++i)
2808 SPLIT_A (values[i]);
2810 WRITE (image, pixel++,
2811 ((a << 8) & 0xf000) |
2812 ((r << 4) & 0x0f00) |
2819 store_scanline_x4r4g4b4 (bits_image_t * image,
2823 const uint32_t *values)
2825 uint32_t *bits = image->bits + image->rowstride * y;
2826 uint16_t *pixel = ((uint16_t *) bits) + x;
2829 for (i = 0; i < width; ++i)
2833 WRITE (image, pixel++,
2834 ((r << 4) & 0x0f00) |
2841 store_scanline_a4b4g4r4 (bits_image_t * image,
2845 const uint32_t *values)
2847 uint32_t *bits = image->bits + image->rowstride * y;
2848 uint16_t *pixel = ((uint16_t *) bits) + x;
2851 for (i = 0; i < width; ++i)
2853 SPLIT_A (values[i]);
2854 WRITE (image, pixel++, ((a << 8) & 0xf000) |
2855 ((b << 4) & 0x0f00) |
2862 store_scanline_x4b4g4r4 (bits_image_t * image,
2866 const uint32_t *values)
2868 uint32_t *bits = image->bits + image->rowstride * y;
2869 uint16_t *pixel = ((uint16_t *) bits) + x;
2872 for (i = 0; i < width; ++i)
2876 WRITE (image, pixel++,
2877 ((b << 4) & 0x0f00) |
2884 store_scanline_a8 (bits_image_t * image,
2888 const uint32_t *values)
2890 uint32_t *bits = image->bits + image->rowstride * y;
2891 uint8_t *pixel = ((uint8_t *) bits) + x;
2894 for (i = 0; i < width; ++i)
2896 WRITE (image, pixel++, values[i] >> 24);
2901 store_scanline_r3g3b2 (bits_image_t * image,
2905 const uint32_t *values)
2907 uint32_t *bits = image->bits + image->rowstride * y;
2908 uint8_t *pixel = ((uint8_t *) bits) + x;
2911 for (i = 0; i < width; ++i)
2915 WRITE (image, pixel++,
2923 store_scanline_b2g3r3 (bits_image_t * image,
2927 const uint32_t *values)
2929 uint32_t *bits = image->bits + image->rowstride * y;
2930 uint8_t *pixel = ((uint8_t *) bits) + x;
2933 for (i = 0; i < width; ++i)
2937 WRITE (image, pixel++,
2945 store_scanline_a2r2g2b2 (bits_image_t * image,
2949 const uint32_t *values)
2951 uint32_t *bits = image->bits + image->rowstride * y;
2952 uint8_t *pixel = ((uint8_t *) bits) + x;
2955 for (i = 0; i < width; ++i)
2957 SPLIT_A (values[i]);
2959 WRITE (image, pixel++,
2968 store_scanline_a2b2g2r2 (bits_image_t * image,
2972 const uint32_t *values)
2974 uint32_t *bits = image->bits + image->rowstride * y;
2975 uint8_t *pixel = ((uint8_t *) bits) + x;
2978 for (i = 0; i < width; ++i)
2980 SPLIT_A (values[i]);
2991 store_scanline_c8 (bits_image_t * image,
2995 const uint32_t *values)
2997 uint32_t *bits = image->bits + image->rowstride * y;
2998 uint8_t *pixel = ((uint8_t *) bits) + x;
2999 const pixman_indexed_t *indexed = image->indexed;
3002 for (i = 0; i < width; ++i)
3003 WRITE (image, pixel++, RGB24_TO_ENTRY (indexed,values[i]));
3007 store_scanline_x4a4 (bits_image_t * image,
3011 const uint32_t *values)
3013 uint32_t *bits = image->bits + image->rowstride * y;
3014 uint8_t *pixel = ((uint8_t *) bits) + x;
3017 for (i = 0; i < width; ++i)
3018 WRITE (image, pixel++, values[i] >> 28);
3021 #define STORE_8(img,l,o,v) (WRITE (img, (uint8_t *)(l) + ((o) >> 3), (v)))
3022 #ifdef WORDS_BIGENDIAN
3023 #define STORE_4(img,l,o,v) \
3024 STORE_8 (img,l,o,((o) & 4 ? \
3025 (FETCH_8 (img,l,o) & 0xf0) | (v) : \
3026 (FETCH_8 (img,l,o) & 0x0f) | ((v) << 4)))
3028 #define STORE_4(img,l,o,v) \
3029 STORE_8 (img,l,o,((o) & 4 ? \
3030 (FETCH_8 (img,l,o) & 0x0f) | ((v) << 4) : \
3031 (FETCH_8 (img,l,o) & 0xf0) | (v)))
3035 store_scanline_a4 (bits_image_t * image,
3039 const uint32_t *values)
3041 uint32_t *bits = image->bits + image->rowstride * y;
3044 for (i = 0; i < width; ++i)
3045 STORE_4 (image, bits, i + x, values[i] >> 28);
3049 store_scanline_r1g2b1 (bits_image_t * image,
3053 const uint32_t *values)
3055 uint32_t *bits = image->bits + image->rowstride * y;
3058 for (i = 0; i < width; ++i)
3063 pixel = (((r >> 4) & 0x8) |
3066 STORE_4 (image, bits, i + x, pixel);
3071 store_scanline_b1g2r1 (bits_image_t * image,
3075 const uint32_t *values)
3077 uint32_t *bits = image->bits + image->rowstride * y;
3080 for (i = 0; i < width; ++i)
3085 pixel = (((b >> 4) & 0x8) |
3088 STORE_4 (image, bits, i + x, pixel);
3093 store_scanline_a1r1g1b1 (bits_image_t * image,
3097 const uint32_t *values)
3099 uint32_t *bits = image->bits + image->rowstride * y;
3102 for (i = 0; i < width; ++i)
3106 SPLIT_A (values[i]);
3107 pixel = (((a >> 4) & 0x8) |
3111 STORE_4 (image, bits, i + x, pixel);
3116 store_scanline_a1b1g1r1 (bits_image_t * image,
3120 const uint32_t *values)
3122 uint32_t *bits = image->bits + image->rowstride * y;
3125 for (i = 0; i < width; ++i)
3129 SPLIT_A (values[i]);
3130 pixel = (((a >> 4) & 0x8) |
3134 STORE_4 (image, bits, i + x, pixel);
3139 store_scanline_c4 (bits_image_t * image,
3143 const uint32_t *values)
3145 uint32_t *bits = image->bits + image->rowstride * y;
3146 const pixman_indexed_t *indexed = image->indexed;
3149 for (i = 0; i < width; ++i)
3153 pixel = RGB24_TO_ENTRY (indexed, values[i]);
3154 STORE_4 (image, bits, i + x, pixel);
3159 store_scanline_a1 (bits_image_t * image,
3163 const uint32_t *values)
3165 uint32_t *bits = image->bits + image->rowstride * y;
3168 for (i = 0; i < width; ++i)
3170 uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
3173 #ifdef WORDS_BIGENDIAN
3174 mask = 1 << (0x1f - ((i + x) & 0x1f));
3176 mask = 1 << ((i + x) & 0x1f);
3178 v = values[i] & 0x80000000 ? mask : 0;
3180 WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
3185 store_scanline_g1 (bits_image_t * image,
3189 const uint32_t *values)
3191 uint32_t *bits = image->bits + image->rowstride * y;
3192 const pixman_indexed_t *indexed = image->indexed;
3195 for (i = 0; i < width; ++i)
3197 uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
3200 #ifdef WORDS_BIGENDIAN
3201 mask = 1 << (0x1f - ((i + x) & 0x1f));
3203 mask = 1 << ((i + x) & 0x1f);
3205 v = RGB24_TO_ENTRY_Y (indexed, values[i]) ? mask : 0;
3207 WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
3212 * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
3213 * store proc. Despite the type, this function expects a uint64_t buffer.
3216 store_scanline_generic_64 (bits_image_t * image,
3220 const uint32_t *values)
3222 uint32_t *argb8_pixels;
3224 assert (image->common.type == BITS);
3226 argb8_pixels = pixman_malloc_ab (width, sizeof(uint32_t));
3230 /* Contract the scanline. We could do this in place if values weren't
3233 pixman_contract (argb8_pixels, (uint64_t *)values, width);
3235 image->store_scanline_raw_32 (image, x, y, width, argb8_pixels);
3237 free (argb8_pixels);
3240 /* Despite the type, this function expects both buffer
3241 * and mask to be uint64_t
3244 fetch_scanline_generic_64 (pixman_image_t *image,
3249 const uint32_t *mask,
3252 /* Fetch the pixels into the first half of buffer and then expand them in
3255 image->bits.fetch_scanline_raw_32 (image, x, y, width, buffer, NULL, 0);
3257 pixman_expand ((uint64_t *)buffer, buffer, image->bits.format, width);
3260 /* Despite the type, this function expects a uint64_t *buffer */
3262 fetch_pixels_generic_64 (bits_image_t *pict,
3266 pict->fetch_pixels_raw_32 (pict, buffer, n_pixels);
3268 pixman_expand ((uint64_t *)buffer, buffer, pict->format, n_pixels);
3272 * XXX: The transformed fetch path only works at 32-bpp so far. When all
3273 * paths have wide versions, this can be removed.
3275 * WARNING: This function loses precision!
3278 fetch_pixels_generic_lossy_32 (bits_image_t *pict,
3282 /* Since buffer contains n_pixels coordinate pairs, it also has enough
3283 * room for n_pixels 64 bit pixels.
3285 pict->fetch_pixels_raw_64 (pict, buffer, n_pixels);
3287 pixman_contract (buffer, (uint64_t *)buffer, n_pixels);
3292 pixman_format_code_t format;
3293 fetch_scanline_t fetch_scanline_raw_32;
3294 fetch_scanline_t fetch_scanline_raw_64;
3295 fetch_pixels_t fetch_pixels_raw_32;
3296 fetch_pixels_t fetch_pixels_raw_64;
3297 store_scanline_t store_scanline_raw_32;
3298 store_scanline_t store_scanline_raw_64;
3301 #define FORMAT_INFO(format) \
3303 PIXMAN_ ## format, \
3304 fetch_scanline_ ## format, \
3305 fetch_scanline_generic_64, \
3306 fetch_pixels_ ## format, fetch_pixels_generic_64, \
3307 store_scanline_ ## format, store_scanline_generic_64 \
3310 static const format_info_t accessors[] =
3312 /* 32 bpp formats */
3313 FORMAT_INFO (a8r8g8b8),
3314 FORMAT_INFO (x8r8g8b8),
3315 FORMAT_INFO (a8b8g8r8),
3316 FORMAT_INFO (x8b8g8r8),
3317 FORMAT_INFO (b8g8r8a8),
3318 FORMAT_INFO (b8g8r8x8),
3321 FORMAT_INFO (r8g8b8),
3322 FORMAT_INFO (b8g8r8),
3325 FORMAT_INFO (r5g6b5),
3326 FORMAT_INFO (b5g6r5),
3328 FORMAT_INFO (a1r5g5b5),
3329 FORMAT_INFO (x1r5g5b5),
3330 FORMAT_INFO (a1b5g5r5),
3331 FORMAT_INFO (x1b5g5r5),
3332 FORMAT_INFO (a4r4g4b4),
3333 FORMAT_INFO (x4r4g4b4),
3334 FORMAT_INFO (a4b4g4r4),
3335 FORMAT_INFO (x4b4g4r4),
3339 FORMAT_INFO (r3g3b2),
3340 FORMAT_INFO (b2g3r3),
3341 FORMAT_INFO (a2r2g2b2),
3342 FORMAT_INFO (a2b2g2r2),
3346 #define fetch_scanline_g8 fetch_scanline_c8
3347 #define fetch_pixels_g8 fetch_pixels_c8
3348 #define store_scanline_g8 store_scanline_c8
3351 #define fetch_scanline_x4c4 fetch_scanline_c8
3352 #define fetch_pixels_x4c4 fetch_pixels_c8
3353 #define store_scanline_x4c4 store_scanline_c8
3356 #define fetch_scanline_x4g4 fetch_scanline_c8
3357 #define fetch_pixels_x4g4 fetch_pixels_c8
3358 #define store_scanline_x4g4 store_scanline_c8
3365 FORMAT_INFO (r1g2b1),
3366 FORMAT_INFO (b1g2r1),
3367 FORMAT_INFO (a1r1g1b1),
3368 FORMAT_INFO (a1b1g1r1),
3372 #define fetch_scanline_g4 fetch_scanline_c4
3373 #define fetch_pixels_g4 fetch_pixels_c4
3374 #define store_scanline_g4 store_scanline_c4
3383 { PIXMAN_a2r10g10b10,
3384 NULL, fetch_scanline_a2r10g10b10,
3385 fetch_pixels_generic_lossy_32, fetch_pixels_a2r10g10b10_64,
3386 NULL, store_scanline_a2r10g10b10 },
3388 { PIXMAN_x2r10g10b10,
3389 NULL, fetch_scanline_x2r10g10b10,
3390 fetch_pixels_generic_lossy_32, fetch_pixels_x2r10g10b10_64,
3391 NULL, store_scanline_x2r10g10b10 },
3393 { PIXMAN_a2b10g10r10,
3394 NULL, fetch_scanline_a2b10g10r10,
3395 fetch_pixels_generic_lossy_32, fetch_pixels_a2b10g10r10_64,
3396 NULL, store_scanline_a2b10g10r10 },
3398 { PIXMAN_x2b10g10r10,
3399 NULL, fetch_scanline_x2b10g10r10,
3400 fetch_pixels_generic_lossy_32, fetch_pixels_x2b10g10r10_64,
3401 NULL, store_scanline_x2b10g10r10 },
3405 fetch_scanline_yuy2, fetch_scanline_generic_64,
3406 fetch_pixels_yuy2, fetch_pixels_generic_64,
3410 fetch_scanline_yv12, fetch_scanline_generic_64,
3411 fetch_pixels_yv12, fetch_pixels_generic_64,
3418 setup_accessors (bits_image_t *image)
3420 const format_info_t *info = accessors;
3422 while (info->format != PIXMAN_null)
3424 if (info->format == image->format)
3426 image->fetch_scanline_raw_32 = info->fetch_scanline_raw_32;
3427 image->fetch_scanline_raw_64 = info->fetch_scanline_raw_64;
3428 image->fetch_pixels_raw_32 = info->fetch_pixels_raw_32;
3429 image->fetch_pixels_raw_64 = info->fetch_pixels_raw_64;
3430 image->store_scanline_raw_32 = info->store_scanline_raw_32;
3431 image->store_scanline_raw_64 = info->store_scanline_raw_64;
3440 #ifndef PIXMAN_FB_ACCESSORS
3442 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image);
3445 _pixman_bits_image_setup_raw_accessors (bits_image_t *image)
3447 if (image->read_func || image->write_func)
3448 _pixman_bits_image_setup_raw_accessors_accessors (image);
3450 setup_accessors (image);
3456 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image)
3458 setup_accessors (image);