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(image); 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,
99 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
101 MEMCPY_WRAPPED (image,
102 buffer, (const uint32_t *)bits + x,
103 width * sizeof(uint32_t));
107 fetch_scanline_x8r8g8b8 (pixman_image_t *image,
112 const uint32_t *mask)
114 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
115 const uint32_t *pixel = (const uint32_t *)bits + x;
116 const uint32_t *end = pixel + width;
119 *buffer++ = READ (image, pixel++) | 0xff000000;
123 fetch_scanline_a8b8g8r8 (pixman_image_t *image,
128 const uint32_t *mask)
130 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
131 const uint32_t *pixel = (uint32_t *)bits + x;
132 const uint32_t *end = pixel + width;
136 uint32_t p = READ (image, pixel++);
138 *buffer++ = (p & 0xff00ff00) |
145 fetch_scanline_x8b8g8r8 (pixman_image_t *image,
150 const uint32_t *mask)
152 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
153 const uint32_t *pixel = (uint32_t *)bits + x;
154 const uint32_t *end = pixel + width;
158 uint32_t p = READ (image, pixel++);
160 *buffer++ = 0xff000000 |
168 fetch_scanline_b8g8r8a8 (pixman_image_t *image,
173 const uint32_t *mask)
175 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
176 const uint32_t *pixel = (uint32_t *)bits + x;
177 const uint32_t *end = pixel + width;
181 uint32_t p = READ (image, pixel++);
183 *buffer++ = (((p & 0xff000000) >> 24) |
184 ((p & 0x00ff0000) >> 8) |
185 ((p & 0x0000ff00) << 8) |
186 ((p & 0x000000ff) << 24));
191 fetch_scanline_b8g8r8x8 (pixman_image_t *image,
196 const uint32_t *mask)
198 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
199 const uint32_t *pixel = (uint32_t *)bits + x;
200 const uint32_t *end = pixel + width;
204 uint32_t p = READ (image, pixel++);
206 *buffer++ = (0xff000000 |
207 ((p & 0xff000000) >> 24) |
208 ((p & 0x00ff0000) >> 8) |
209 ((p & 0x0000ff00) << 8));
213 /* Expects a uint64_t buffer */
215 fetch_scanline_a2r10g10b10 (pixman_image_t *image,
220 const uint32_t *mask)
222 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
223 const uint32_t *pixel = bits + x;
224 const uint32_t *end = pixel + width;
225 uint64_t *buffer = (uint64_t *)b;
229 uint32_t p = READ (image, pixel++);
230 uint64_t a = p >> 30;
231 uint64_t r = (p >> 20) & 0x3ff;
232 uint64_t g = (p >> 10) & 0x3ff;
233 uint64_t b = p & 0x3ff;
244 *buffer++ = a << 48 | r << 32 | g << 16 | b;
248 /* Expects a uint64_t buffer */
250 fetch_scanline_x2r10g10b10 (pixman_image_t *image,
255 const uint32_t *mask)
257 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
258 const uint32_t *pixel = (uint32_t *)bits + x;
259 const uint32_t *end = pixel + width;
260 uint64_t *buffer = (uint64_t *)b;
264 uint32_t p = READ (image, pixel++);
265 uint64_t r = (p >> 20) & 0x3ff;
266 uint64_t g = (p >> 10) & 0x3ff;
267 uint64_t b = p & 0x3ff;
273 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
277 /* Expects a uint64_t buffer */
279 fetch_scanline_a2b10g10r10 (pixman_image_t *image,
284 const uint32_t *mask)
286 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
287 const uint32_t *pixel = bits + x;
288 const uint32_t *end = pixel + width;
289 uint64_t *buffer = (uint64_t *)b;
293 uint32_t p = READ (image, pixel++);
294 uint64_t a = p >> 30;
295 uint64_t b = (p >> 20) & 0x3ff;
296 uint64_t g = (p >> 10) & 0x3ff;
297 uint64_t r = p & 0x3ff;
308 *buffer++ = a << 48 | r << 32 | g << 16 | b;
312 /* Expects a uint64_t buffer */
314 fetch_scanline_x2b10g10r10 (pixman_image_t *image,
319 const uint32_t *mask)
321 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
322 const uint32_t *pixel = (uint32_t *)bits + x;
323 const uint32_t *end = pixel + width;
324 uint64_t *buffer = (uint64_t *)b;
328 uint32_t p = READ (image, pixel++);
329 uint64_t b = (p >> 20) & 0x3ff;
330 uint64_t g = (p >> 10) & 0x3ff;
331 uint64_t r = p & 0x3ff;
337 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
342 fetch_scanline_r8g8b8 (pixman_image_t *image,
347 const uint32_t *mask)
349 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
350 const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
351 const uint8_t *end = pixel + 3 * width;
355 uint32_t b = 0xff000000;
357 #ifdef WORDS_BIGENDIAN
358 b |= (READ (image, pixel++) << 16);
359 b |= (READ (image, pixel++) << 8);
360 b |= (READ (image, pixel++));
362 b |= (READ (image, pixel++));
363 b |= (READ (image, pixel++) << 8);
364 b |= (READ (image, pixel++) << 16);
372 fetch_scanline_b8g8r8 (pixman_image_t *image,
377 const uint32_t *mask)
379 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
380 const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
381 const uint8_t *end = pixel + 3 * width;
385 uint32_t b = 0xff000000;
386 #ifdef WORDS_BIGENDIAN
387 b |= (READ (image, pixel++));
388 b |= (READ (image, pixel++) << 8);
389 b |= (READ (image, pixel++) << 16);
391 b |= (READ (image, pixel++) << 16);
392 b |= (READ (image, pixel++) << 8);
393 b |= (READ (image, pixel++));
400 fetch_scanline_r5g6b5 (pixman_image_t *image,
405 const uint32_t *mask)
407 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
408 const uint16_t *pixel = (const uint16_t *)bits + x;
409 const uint16_t *end = pixel + width;
413 uint32_t p = READ (image, pixel++);
414 uint32_t r = (((p) << 3) & 0xf8) |
415 (((p) << 5) & 0xfc00) |
416 (((p) << 8) & 0xf80000);
418 r |= (r >> 5) & 0x70007;
419 r |= (r >> 6) & 0x300;
421 *buffer++ = 0xff000000 | r;
426 fetch_scanline_b5g6r5 (pixman_image_t *image,
431 const uint32_t *mask)
433 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
434 const uint16_t *pixel = (const uint16_t *)bits + x;
435 const uint16_t *end = pixel + width;
439 uint32_t p = READ (image, pixel++);
442 b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
443 g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
444 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
446 *buffer++ = 0xff000000 | r | g | b;
451 fetch_scanline_a1r5g5b5 (pixman_image_t *image,
456 const uint32_t *mask)
458 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
459 const uint16_t *pixel = (const uint16_t *)bits + x;
460 const uint16_t *end = pixel + width;
464 uint32_t p = READ (image, pixel++);
467 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
468 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
469 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
470 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
472 *buffer++ = a | r | g | b;
477 fetch_scanline_x1r5g5b5 (pixman_image_t *image,
482 const uint32_t *mask)
484 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
485 const uint16_t *pixel = (const uint16_t *)bits + x;
486 const uint16_t *end = pixel + width;
490 uint32_t p = READ (image, pixel++);
493 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
494 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
495 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
497 *buffer++ = 0xff000000 | r | g | b;
502 fetch_scanline_a1b5g5r5 (pixman_image_t *image,
507 const uint32_t *mask)
509 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
510 const uint16_t *pixel = (const uint16_t *)bits + x;
511 const uint16_t *end = pixel + width;
516 uint32_t p = READ (image, pixel++);
518 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
519 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
520 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
521 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
523 *buffer++ = a | r | g | b;
528 fetch_scanline_x1b5g5r5 (pixman_image_t *image,
533 const uint32_t *mask)
535 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
536 const uint16_t *pixel = (const uint16_t *)bits + x;
537 const uint16_t *end = pixel + width;
541 uint32_t p = READ (image, pixel++);
544 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
545 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
546 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
548 *buffer++ = 0xff000000 | r | g | b;
553 fetch_scanline_a4r4g4b4 (pixman_image_t *image,
558 const uint32_t *mask)
560 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
561 const uint16_t *pixel = (const uint16_t *)bits + x;
562 const uint16_t *end = pixel + width;
566 uint32_t p = READ (image, pixel++);
569 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
570 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
571 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
572 b = ((p & 0x000f) | ((p & 0x000f) << 4));
574 *buffer++ = a | r | g | b;
579 fetch_scanline_x4r4g4b4 (pixman_image_t *image,
584 const uint32_t *mask)
586 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
587 const uint16_t *pixel = (const uint16_t *)bits + x;
588 const uint16_t *end = pixel + width;
592 uint32_t p = READ (image, pixel++);
595 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
596 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
597 b = ((p & 0x000f) | ((p & 0x000f) << 4));
599 *buffer++ = 0xff000000 | r | g | b;
604 fetch_scanline_a4b4g4r4 (pixman_image_t *image,
609 const uint32_t *mask)
611 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
612 const uint16_t *pixel = (const uint16_t *)bits + x;
613 const uint16_t *end = pixel + width;
617 uint32_t p = READ (image, pixel++);
620 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
621 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
622 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
623 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
625 *buffer++ = a | r | g | b;
630 fetch_scanline_x4b4g4r4 (pixman_image_t *image,
635 const uint32_t *mask)
637 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
638 const uint16_t *pixel = (const uint16_t *)bits + x;
639 const uint16_t *end = pixel + width;
643 uint32_t p = READ (image, pixel++);
646 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
647 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
648 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
650 *buffer++ = 0xff000000 | r | g | b;
655 fetch_scanline_a8 (pixman_image_t *image,
660 const uint32_t *mask)
662 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
663 const uint8_t *pixel = (const uint8_t *)bits + x;
664 const uint8_t *end = pixel + width;
667 *buffer++ = READ (image, pixel++) << 24;
671 fetch_scanline_r3g3b2 (pixman_image_t *image,
676 const uint32_t *mask)
678 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
679 const uint8_t *pixel = (const uint8_t *)bits + x;
680 const uint8_t *end = pixel + width;
684 uint32_t p = READ (image, pixel++);
687 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
688 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
694 *buffer++ = 0xff000000 | r | g | b;
699 fetch_scanline_b2g3r3 (pixman_image_t *image,
704 const uint32_t *mask)
706 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
707 const uint8_t *pixel = (const uint8_t *)bits + x;
708 const uint8_t *end = pixel + width;
712 uint32_t p = READ (image, pixel++);
720 g = (p & 0x38) << 10;
730 *buffer++ = 0xff000000 | r | g | b;
735 fetch_scanline_a2r2g2b2 (pixman_image_t *image,
740 const uint32_t *mask)
742 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
743 const uint8_t *pixel = (const uint8_t *)bits + x;
744 const uint8_t *end = pixel + width;
748 uint32_t p = READ (image, pixel++);
751 a = ((p & 0xc0) * 0x55) << 18;
752 r = ((p & 0x30) * 0x55) << 12;
753 g = ((p & 0x0c) * 0x55) << 6;
754 b = ((p & 0x03) * 0x55);
756 *buffer++ = a | r | g | b;
761 fetch_scanline_a2b2g2r2 (pixman_image_t *image,
766 const uint32_t *mask)
768 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
769 const uint8_t *pixel = (const uint8_t *)bits + x;
770 const uint8_t *end = pixel + width;
774 uint32_t p = READ (image, pixel++);
777 a = ((p & 0xc0) * 0x55) << 18;
778 b = ((p & 0x30) * 0x55) >> 4;
779 g = ((p & 0x0c) * 0x55) << 6;
780 r = ((p & 0x03) * 0x55) << 16;
782 *buffer++ = a | r | g | b;
787 fetch_scanline_c8 (pixman_image_t *image,
792 const uint32_t *mask)
794 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
795 const pixman_indexed_t * indexed = image->bits.indexed;
796 const uint8_t *pixel = (const uint8_t *)bits + x;
797 const uint8_t *end = pixel + width;
801 uint32_t p = READ (image, pixel++);
803 *buffer++ = indexed->rgba[p];
808 fetch_scanline_x4a4 (pixman_image_t *image,
813 const uint32_t *mask)
815 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
816 const uint8_t *pixel = (const uint8_t *)bits + x;
817 const uint8_t *end = pixel + width;
821 uint8_t p = READ (image, pixel++) & 0xf;
823 *buffer++ = (p | (p << 4)) << 24;
827 #define FETCH_8(img,l,o) (READ (img, (((uint8_t *)(l)) + ((o) >> 3))))
828 #ifdef WORDS_BIGENDIAN
829 #define FETCH_4(img,l,o) \
830 (((4 * (o)) & 4) ? (FETCH_8 (img,l, 4 * (o)) & 0xf) : (FETCH_8 (img,l,(4 * (o))) >> 4))
832 #define FETCH_4(img,l,o) \
833 (((4 * (o)) & 4) ? (FETCH_8 (img, l, 4 * (o)) >> 4) : (FETCH_8 (img, l, (4 * (o))) & 0xf))
837 fetch_scanline_a4 (pixman_image_t *image,
842 const uint32_t *mask)
844 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
847 for (i = 0; i < width; ++i)
849 uint32_t p = FETCH_4 (image, bits, i + x);
858 fetch_scanline_r1g2b1 (pixman_image_t *image,
863 const uint32_t *mask)
865 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
868 for (i = 0; i < width; ++i)
870 uint32_t p = FETCH_4 (image, bits, i + x);
873 r = ((p & 0x8) * 0xff) << 13;
874 g = ((p & 0x6) * 0x55) << 7;
875 b = ((p & 0x1) * 0xff);
877 *buffer++ = 0xff000000 | r | g | b;
882 fetch_scanline_b1g2r1 (pixman_image_t *image,
887 const uint32_t *mask)
889 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
892 for (i = 0; i < width; ++i)
894 uint32_t p = FETCH_4 (image, bits, i + x);
897 b = ((p & 0x8) * 0xff) >> 3;
898 g = ((p & 0x6) * 0x55) << 7;
899 r = ((p & 0x1) * 0xff) << 16;
901 *buffer++ = 0xff000000 | r | g | b;
906 fetch_scanline_a1r1g1b1 (pixman_image_t *image,
911 const uint32_t *mask)
914 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
917 for (i = 0; i < width; ++i)
919 uint32_t p = FETCH_4 (image, bits, i + x);
921 a = ((p & 0x8) * 0xff) << 21;
922 r = ((p & 0x4) * 0xff) << 14;
923 g = ((p & 0x2) * 0xff) << 7;
924 b = ((p & 0x1) * 0xff);
926 *buffer++ = a | r | g | b;
931 fetch_scanline_a1b1g1r1 (pixman_image_t *image,
936 const uint32_t *mask)
938 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
941 for (i = 0; i < width; ++i)
943 uint32_t p = FETCH_4 (image, bits, i + x);
946 a = ((p & 0x8) * 0xff) << 21;
947 b = ((p & 0x4) * 0xff) >> 2;
948 g = ((p & 0x2) * 0xff) << 7;
949 r = ((p & 0x1) * 0xff) << 16;
951 *buffer++ = a | r | g | b;
956 fetch_scanline_c4 (pixman_image_t *image,
961 const uint32_t *mask)
963 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
964 const pixman_indexed_t * indexed = image->bits.indexed;
967 for (i = 0; i < width; ++i)
969 uint32_t p = FETCH_4 (image, bits, i + x);
971 *buffer++ = indexed->rgba[p];
976 fetch_scanline_a1 (pixman_image_t *image,
981 const uint32_t *mask)
983 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
986 for (i = 0; i < width; ++i)
988 uint32_t p = READ (image, bits + ((i + x) >> 5));
991 #ifdef WORDS_BIGENDIAN
992 a = p >> (0x1f - ((i + x) & 0x1f));
994 a = p >> ((i + x) & 0x1f);
1001 *buffer++ = a << 24;
1006 fetch_scanline_g1 (pixman_image_t *image,
1011 const uint32_t *mask)
1013 const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1014 const pixman_indexed_t * indexed = image->bits.indexed;
1017 for (i = 0; i < width; ++i)
1019 uint32_t p = READ (image, bits + ((i + x) >> 5));
1022 #ifdef WORDS_BIGENDIAN
1023 a = p >> (0x1f - ((i + x) & 0x1f));
1025 a = p >> ((i + x) & 0x1f);
1029 *buffer++ = indexed->rgba[a];
1034 fetch_scanline_yuy2 (pixman_image_t *image,
1039 const uint32_t *mask)
1041 const uint32_t *bits = image->bits.bits + image->bits.rowstride * line;
1044 for (i = 0; i < width; i++)
1049 y = ((uint8_t *) bits)[(x + i) << 1] - 16;
1050 u = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 1] - 128;
1051 v = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 3] - 128;
1053 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1054 r = 0x012b27 * y + 0x019a2e * v;
1055 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1056 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1057 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1058 b = 0x012b27 * y + 0x0206a2 * u;
1060 *buffer++ = 0xff000000 |
1061 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1062 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1063 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1068 fetch_scanline_yv12 (pixman_image_t *image,
1073 const uint32_t *mask)
1076 uint8_t *y_line = YV12_Y (line);
1077 uint8_t *u_line = YV12_U (line);
1078 uint8_t *v_line = YV12_V (line);
1081 for (i = 0; i < width; i++)
1086 y = y_line[x + i] - 16;
1087 u = u_line[(x + i) >> 1] - 128;
1088 v = v_line[(x + i) >> 1] - 128;
1090 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1091 r = 0x012b27 * y + 0x019a2e * v;
1092 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1093 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1094 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1095 b = 0x012b27 * y + 0x0206a2 * u;
1097 *buffer++ = 0xff000000 |
1098 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1099 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1100 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1104 /**************************** Pixel wise fetching *****************************/
1106 /* Despite the type, expects a uint64_t buffer */
1108 fetch_pixel_a2r10g10b10 (bits_image_t *image,
1112 uint32_t *bits = image->bits + line * image->rowstride;
1113 uint32_t p = READ (image, bits + offset);
1114 uint64_t a = p >> 30;
1115 uint64_t r = (p >> 20) & 0x3ff;
1116 uint64_t g = (p >> 10) & 0x3ff;
1117 uint64_t b = p & 0x3ff;
1119 r = r << 6 | r >> 4;
1120 g = g << 6 | g >> 4;
1121 b = b << 6 | b >> 4;
1128 return a << 48 | r << 32 | g << 16 | b;
1131 /* Despite the type, this function expects a uint64_t buffer */
1133 fetch_pixel_x2r10g10b10 (bits_image_t *image,
1137 uint32_t *bits = image->bits + line * image->rowstride;
1138 uint32_t p = READ (image, bits + offset);
1139 uint64_t r = (p >> 20) & 0x3ff;
1140 uint64_t g = (p >> 10) & 0x3ff;
1141 uint64_t b = p & 0x3ff;
1143 r = r << 6 | r >> 4;
1144 g = g << 6 | g >> 4;
1145 b = b << 6 | b >> 4;
1147 return 0xffffULL << 48 | r << 32 | g << 16 | b;
1150 /* Despite the type, expects a uint64_t buffer */
1152 fetch_pixel_a2b10g10r10 (bits_image_t *image,
1156 uint32_t *bits = image->bits + line * image->rowstride;
1157 uint32_t p = READ (image, bits + offset);
1158 uint64_t a = p >> 30;
1159 uint64_t b = (p >> 20) & 0x3ff;
1160 uint64_t g = (p >> 10) & 0x3ff;
1161 uint64_t r = p & 0x3ff;
1163 r = r << 6 | r >> 4;
1164 g = g << 6 | g >> 4;
1165 b = b << 6 | b >> 4;
1172 return a << 48 | r << 32 | g << 16 | b;
1175 /* Despite the type, this function expects a uint64_t buffer */
1177 fetch_pixel_x2b10g10r10 (bits_image_t *image,
1181 uint32_t *bits = image->bits + line * image->rowstride;
1182 uint32_t p = READ (image, bits + offset);
1183 uint64_t b = (p >> 20) & 0x3ff;
1184 uint64_t g = (p >> 10) & 0x3ff;
1185 uint64_t r = p & 0x3ff;
1187 r = r << 6 | r >> 4;
1188 g = g << 6 | g >> 4;
1189 b = b << 6 | b >> 4;
1191 return 0xffffULL << 48 | r << 32 | g << 16 | b;
1195 fetch_pixel_a8r8g8b8 (bits_image_t *image,
1199 uint32_t *bits = image->bits + line * image->rowstride;
1200 return READ (image, (uint32_t *)bits + offset);
1204 fetch_pixel_x8r8g8b8 (bits_image_t *image,
1208 uint32_t *bits = image->bits + line * image->rowstride;
1210 return READ (image, (uint32_t *)bits + offset) | 0xff000000;
1214 fetch_pixel_a8b8g8r8 (bits_image_t *image,
1218 uint32_t *bits = image->bits + line * image->rowstride;
1219 uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1221 return ((pixel & 0xff000000) |
1222 ((pixel >> 16) & 0xff) |
1223 (pixel & 0x0000ff00) |
1224 ((pixel & 0xff) << 16));
1228 fetch_pixel_x8b8g8r8 (bits_image_t *image,
1232 uint32_t *bits = image->bits + line * image->rowstride;
1233 uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1235 return ((0xff000000) |
1236 ((pixel >> 16) & 0xff) |
1237 (pixel & 0x0000ff00) |
1238 ((pixel & 0xff) << 16));
1242 fetch_pixel_b8g8r8a8 (bits_image_t *image,
1246 uint32_t *bits = image->bits + line * image->rowstride;
1247 uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1249 return ((pixel & 0xff000000) >> 24 |
1250 (pixel & 0x00ff0000) >> 8 |
1251 (pixel & 0x0000ff00) << 8 |
1252 (pixel & 0x000000ff) << 24);
1256 fetch_pixel_b8g8r8x8 (bits_image_t *image,
1260 uint32_t *bits = image->bits + line * image->rowstride;
1261 uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1263 return ((0xff000000) |
1264 (pixel & 0xff000000) >> 24 |
1265 (pixel & 0x00ff0000) >> 8 |
1266 (pixel & 0x0000ff00) << 8);
1270 fetch_pixel_r8g8b8 (bits_image_t *image,
1274 uint32_t *bits = image->bits + line * image->rowstride;
1275 uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1277 #ifdef WORDS_BIGENDIAN
1278 return (0xff000000 |
1279 (READ (image, pixel + 0) << 16) |
1280 (READ (image, pixel + 1) << 8) |
1281 (READ (image, pixel + 2)));
1283 return (0xff000000 |
1284 (READ (image, pixel + 2) << 16) |
1285 (READ (image, pixel + 1) << 8) |
1286 (READ (image, pixel + 0)));
1291 fetch_pixel_b8g8r8 (bits_image_t *image,
1295 uint32_t *bits = image->bits + line * image->rowstride;
1296 uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1297 #ifdef WORDS_BIGENDIAN
1298 return (0xff000000 |
1299 (READ (image, pixel + 2) << 16) |
1300 (READ (image, pixel + 1) << 8) |
1301 (READ (image, pixel + 0)));
1303 return (0xff000000 |
1304 (READ (image, pixel + 0) << 16) |
1305 (READ (image, pixel + 1) << 8) |
1306 (READ (image, pixel + 2)));
1311 fetch_pixel_r5g6b5 (bits_image_t *image,
1315 uint32_t *bits = image->bits + line * image->rowstride;
1316 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1319 r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1320 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1321 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1323 return (0xff000000 | r | g | b);
1327 fetch_pixel_b5g6r5 (bits_image_t *image,
1332 uint32_t *bits = image->bits + line * image->rowstride;
1333 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1335 b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1336 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1337 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1339 return (0xff000000 | r | g | b);
1343 fetch_pixel_a1r5g5b5 (bits_image_t *image,
1347 uint32_t *bits = image->bits + line * image->rowstride;
1348 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1349 uint32_t a, r, g, b;
1351 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1352 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1353 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1354 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1356 return (a | r | g | b);
1360 fetch_pixel_x1r5g5b5 (bits_image_t *image,
1364 uint32_t *bits = image->bits + line * image->rowstride;
1365 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1368 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1369 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1370 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1372 return (0xff000000 | r | g | b);
1376 fetch_pixel_a1b5g5r5 (bits_image_t *image,
1380 uint32_t *bits = image->bits + line * image->rowstride;
1381 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1382 uint32_t a, r, g, b;
1384 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1385 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1386 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1387 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1389 return (a | r | g | b);
1393 fetch_pixel_x1b5g5r5 (bits_image_t *image,
1397 uint32_t *bits = image->bits + line * image->rowstride;
1398 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1401 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1402 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1403 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1405 return (0xff000000 | r | g | b);
1409 fetch_pixel_a4r4g4b4 (bits_image_t *image,
1413 uint32_t *bits = image->bits + line * image->rowstride;
1414 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1415 uint32_t a, r, g, b;
1417 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1418 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1419 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1420 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1422 return (a | r | g | b);
1426 fetch_pixel_x4r4g4b4 (bits_image_t *image,
1430 uint32_t *bits = image->bits + line * image->rowstride;
1431 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1434 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1435 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1436 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1438 return (0xff000000 | r | g | b);
1442 fetch_pixel_a4b4g4r4 (bits_image_t *image,
1446 uint32_t *bits = image->bits + line * image->rowstride;
1447 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1448 uint32_t a, r, g, b;
1450 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1451 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1452 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1453 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1455 return (a | r | g | b);
1459 fetch_pixel_x4b4g4r4 (bits_image_t *image,
1463 uint32_t *bits = image->bits + line * image->rowstride;
1464 uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1467 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1468 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1469 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1471 return (0xff000000 | r | g | b);
1475 fetch_pixel_a8 (bits_image_t *image,
1479 uint32_t *bits = image->bits + line * image->rowstride;
1480 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1486 fetch_pixel_r3g3b2 (bits_image_t *image,
1490 uint32_t *bits = image->bits + line * image->rowstride;
1491 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1494 r = ((pixel & 0xe0) |
1495 ((pixel & 0xe0) >> 3) |
1496 ((pixel & 0xc0) >> 6)) << 16;
1498 g = ((pixel & 0x1c) |
1499 ((pixel & 0x18) >> 3) |
1500 ((pixel & 0x1c) << 3)) << 8;
1502 b = (((pixel & 0x03) ) |
1503 ((pixel & 0x03) << 2) |
1504 ((pixel & 0x03) << 4) |
1505 ((pixel & 0x03) << 6));
1507 return (0xff000000 | r | g | b);
1511 fetch_pixel_b2g3r3 (bits_image_t *image,
1515 uint32_t *bits = image->bits + line * image->rowstride;
1516 uint32_t p = READ (image, (uint8_t *) bits + offset);
1524 g = (p & 0x38) << 10;
1529 r = (p & 0x7) << 21;
1534 return 0xff000000 | r | g | b;
1538 fetch_pixel_a2r2g2b2 (bits_image_t *image,
1542 uint32_t *bits = image->bits + line * image->rowstride;
1543 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1544 uint32_t a, r, g, b;
1546 a = ((pixel & 0xc0) * 0x55) << 18;
1547 r = ((pixel & 0x30) * 0x55) << 12;
1548 g = ((pixel & 0x0c) * 0x55) << 6;
1549 b = ((pixel & 0x03) * 0x55);
1551 return a | r | g | b;
1555 fetch_pixel_a2b2g2r2 (bits_image_t *image,
1559 uint32_t *bits = image->bits + line * image->rowstride;
1560 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1561 uint32_t a, r, g, b;
1563 a = ((pixel & 0xc0) * 0x55) << 18;
1564 b = ((pixel & 0x30) * 0x55) >> 4;
1565 g = ((pixel & 0x0c) * 0x55) << 6;
1566 r = ((pixel & 0x03) * 0x55) << 16;
1568 return a | r | g | b;
1572 fetch_pixel_c8 (bits_image_t *image,
1576 uint32_t *bits = image->bits + line * image->rowstride;
1577 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1578 const pixman_indexed_t * indexed = image->indexed;
1580 return indexed->rgba[pixel];
1584 fetch_pixel_x4a4 (bits_image_t *image,
1588 uint32_t *bits = image->bits + line * image->rowstride;
1589 uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1591 return ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1595 fetch_pixel_a4 (bits_image_t *image,
1599 uint32_t *bits = image->bits + line * image->rowstride;
1600 uint32_t pixel = FETCH_4 (image, bits, offset);
1602 pixel |= pixel << 4;
1607 fetch_pixel_r1g2b1 (bits_image_t *image,
1611 uint32_t *bits = image->bits + line * image->rowstride;
1612 uint32_t pixel = FETCH_4 (image, bits, offset);
1615 r = ((pixel & 0x8) * 0xff) << 13;
1616 g = ((pixel & 0x6) * 0x55) << 7;
1617 b = ((pixel & 0x1) * 0xff);
1619 return 0xff000000 | r | g | b;
1623 fetch_pixel_b1g2r1 (bits_image_t *image,
1627 uint32_t *bits = image->bits + line * image->rowstride;
1628 uint32_t pixel = FETCH_4 (image, bits, offset);
1631 b = ((pixel & 0x8) * 0xff) >> 3;
1632 g = ((pixel & 0x6) * 0x55) << 7;
1633 r = ((pixel & 0x1) * 0xff) << 16;
1635 return 0xff000000 | r | g | b;
1639 fetch_pixel_a1r1g1b1 (bits_image_t *image,
1643 uint32_t *bits = image->bits + line * image->rowstride;
1644 uint32_t pixel = FETCH_4 (image, bits, offset);
1645 uint32_t a, r, g, b;
1647 a = ((pixel & 0x8) * 0xff) << 21;
1648 r = ((pixel & 0x4) * 0xff) << 14;
1649 g = ((pixel & 0x2) * 0xff) << 7;
1650 b = ((pixel & 0x1) * 0xff);
1652 return a | r | g | b;
1656 fetch_pixel_a1b1g1r1 (bits_image_t *image,
1660 uint32_t *bits = image->bits + line * image->rowstride;
1661 uint32_t pixel = FETCH_4 (image, bits, offset);
1662 uint32_t a, r, g, b;
1664 a = ((pixel & 0x8) * 0xff) << 21;
1665 b = ((pixel & 0x4) * 0xff) >> 2;
1666 g = ((pixel & 0x2) * 0xff) << 7;
1667 r = ((pixel & 0x1) * 0xff) << 16;
1669 return a | r | g | b;
1673 fetch_pixel_c4 (bits_image_t *image,
1677 uint32_t *bits = image->bits + line * image->rowstride;
1678 uint32_t pixel = FETCH_4 (image, bits, offset);
1679 const pixman_indexed_t * indexed = image->indexed;
1681 return indexed->rgba[pixel];
1685 fetch_pixel_a1 (bits_image_t *image,
1689 uint32_t *bits = image->bits + line * image->rowstride;
1690 uint32_t pixel = READ (image, bits + (offset >> 5));
1693 #ifdef WORDS_BIGENDIAN
1694 a = pixel >> (0x1f - (offset & 0x1f));
1696 a = pixel >> (offset & 0x1f);
1707 fetch_pixel_g1 (bits_image_t *image,
1711 uint32_t *bits = image->bits + line * image->rowstride;
1712 uint32_t pixel = READ (image, bits + (offset >> 5));
1713 const pixman_indexed_t * indexed = image->indexed;
1716 #ifdef WORDS_BIGENDIAN
1717 a = pixel >> (0x1f - (offset & 0x1f));
1719 a = pixel >> (offset & 0x1f);
1723 return indexed->rgba[a];
1727 fetch_pixel_yuy2 (bits_image_t *image,
1731 const uint32_t *bits = image->bits + image->rowstride * line;
1736 y = ((uint8_t *) bits)[offset << 1] - 16;
1737 u = ((uint8_t *) bits)[((offset << 1) & - 4) + 1] - 128;
1738 v = ((uint8_t *) bits)[((offset << 1) & - 4) + 3] - 128;
1740 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1741 r = 0x012b27 * y + 0x019a2e * v;
1743 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1744 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1746 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1747 b = 0x012b27 * y + 0x0206a2 * u;
1750 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1751 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1752 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1756 fetch_pixel_yv12 (bits_image_t *image,
1761 int16_t y = YV12_Y (line)[offset] - 16;
1762 int16_t u = YV12_U (line)[offset >> 1] - 128;
1763 int16_t v = YV12_V (line)[offset >> 1] - 128;
1766 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1767 r = 0x012b27 * y + 0x019a2e * v;
1769 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1770 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1772 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1773 b = 0x012b27 * y + 0x0206a2 * u;
1776 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1777 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1778 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1781 /*********************************** Store ************************************/
1783 #define SPLIT_A(v) \
1784 uint32_t a = ((v) >> 24), \
1785 r = ((v) >> 16) & 0xff, \
1786 g = ((v) >> 8) & 0xff, \
1790 uint32_t r = ((v) >> 16) & 0xff, \
1791 g = ((v) >> 8) & 0xff, \
1795 store_scanline_a2r10g10b10 (bits_image_t * image,
1801 uint32_t *bits = image->bits + image->rowstride * y;
1802 uint32_t *pixel = bits + x;
1803 uint64_t *values = (uint64_t *)v;
1806 for (i = 0; i < width; ++i)
1808 WRITE (image, pixel++,
1809 ((values[i] >> 32) & 0xc0000000) |
1810 ((values[i] >> 18) & 0x3ff00000) |
1811 ((values[i] >> 12) & 0xffc00) |
1812 ((values[i] >> 6) & 0x3ff));
1817 store_scanline_x2r10g10b10 (bits_image_t * image,
1823 uint32_t *bits = image->bits + image->rowstride * y;
1824 uint64_t *values = (uint64_t *)v;
1825 uint32_t *pixel = bits + x;
1828 for (i = 0; i < width; ++i)
1830 WRITE (image, pixel++,
1831 ((values[i] >> 18) & 0x3ff00000) |
1832 ((values[i] >> 12) & 0xffc00) |
1833 ((values[i] >> 6) & 0x3ff));
1838 store_scanline_a2b10g10r10 (bits_image_t * image,
1844 uint32_t *bits = image->bits + image->rowstride * y;
1845 uint32_t *pixel = bits + x;
1846 uint64_t *values = (uint64_t *)v;
1849 for (i = 0; i < width; ++i)
1851 WRITE (image, pixel++,
1852 ((values[i] >> 32) & 0xc0000000) |
1853 ((values[i] >> 38) & 0x3ff) |
1854 ((values[i] >> 12) & 0xffc00) |
1855 ((values[i] << 14) & 0x3ff00000));
1860 store_scanline_x2b10g10r10 (bits_image_t * image,
1866 uint32_t *bits = image->bits + image->rowstride * y;
1867 uint64_t *values = (uint64_t *)v;
1868 uint32_t *pixel = bits + x;
1871 for (i = 0; i < width; ++i)
1873 WRITE (image, pixel++,
1874 ((values[i] >> 38) & 0x3ff) |
1875 ((values[i] >> 12) & 0xffc00) |
1876 ((values[i] << 14) & 0x3ff00000));
1881 store_scanline_a8r8g8b8 (bits_image_t * image,
1885 const uint32_t *values)
1887 uint32_t *bits = image->bits + image->rowstride * y;
1889 MEMCPY_WRAPPED (image, ((uint32_t *)bits) + x, values,
1890 width * sizeof(uint32_t));
1894 store_scanline_x8r8g8b8 (bits_image_t * image,
1898 const uint32_t *values)
1900 uint32_t *bits = image->bits + image->rowstride * y;
1901 uint32_t *pixel = (uint32_t *)bits + x;
1904 for (i = 0; i < width; ++i)
1905 WRITE (image, pixel++, values[i] & 0xffffff);
1909 store_scanline_a8b8g8r8 (bits_image_t * image,
1913 const uint32_t *values)
1915 uint32_t *bits = image->bits + image->rowstride * y;
1916 uint32_t *pixel = (uint32_t *)bits + x;
1919 for (i = 0; i < width; ++i)
1921 WRITE (image, pixel++,
1922 (values[i] & 0xff00ff00) |
1923 ((values[i] >> 16) & 0xff) |
1924 ((values[i] & 0xff) << 16));
1929 store_scanline_x8b8g8r8 (bits_image_t * image,
1933 const uint32_t *values)
1935 uint32_t *bits = image->bits + image->rowstride * y;
1936 uint32_t *pixel = (uint32_t *)bits + x;
1939 for (i = 0; i < width; ++i)
1941 WRITE (image, pixel++,
1942 (values[i] & 0x0000ff00) |
1943 ((values[i] >> 16) & 0xff) |
1944 ((values[i] & 0xff) << 16));
1949 store_scanline_b8g8r8a8 (bits_image_t * image,
1953 const uint32_t *values)
1955 uint32_t *bits = image->bits + image->rowstride * y;
1956 uint32_t *pixel = (uint32_t *)bits + x;
1959 for (i = 0; i < width; ++i)
1961 WRITE (image, pixel++,
1962 ((values[i] >> 24) & 0x000000ff) |
1963 ((values[i] >> 8) & 0x0000ff00) |
1964 ((values[i] << 8) & 0x00ff0000) |
1965 ((values[i] << 24) & 0xff000000));
1970 store_scanline_b8g8r8x8 (bits_image_t * image,
1974 const uint32_t *values)
1976 uint32_t *bits = image->bits + image->rowstride * y;
1977 uint32_t *pixel = (uint32_t *)bits + x;
1980 for (i = 0; i < width; ++i)
1982 WRITE (image, pixel++,
1983 ((values[i] >> 8) & 0x0000ff00) |
1984 ((values[i] << 8) & 0x00ff0000) |
1985 ((values[i] << 24) & 0xff000000));
1990 store_scanline_r8g8b8 (bits_image_t * image,
1994 const uint32_t *values)
1996 uint32_t *bits = image->bits + image->rowstride * y;
1997 uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2000 for (i = 0; i < width; ++i)
2002 uint32_t val = values[i];
2004 #ifdef WORDS_BIGENDIAN
2005 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2006 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2007 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2009 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2010 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2011 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2017 store_scanline_b8g8r8 (bits_image_t * image,
2021 const uint32_t *values)
2023 uint32_t *bits = image->bits + image->rowstride * y;
2024 uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2027 for (i = 0; i < width; ++i)
2029 uint32_t val = values[i];
2031 #ifdef WORDS_BIGENDIAN
2032 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2033 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2034 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2036 WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2037 WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2038 WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2044 store_scanline_r5g6b5 (bits_image_t * image,
2048 const uint32_t *values)
2050 uint32_t *bits = image->bits + image->rowstride * y;
2051 uint16_t *pixel = ((uint16_t *) bits) + x;
2054 for (i = 0; i < width; ++i)
2056 uint32_t s = values[i];
2058 WRITE (image, pixel++,
2059 ((s >> 3) & 0x001f) |
2060 ((s >> 5) & 0x07e0) |
2061 ((s >> 8) & 0xf800));
2066 store_scanline_b5g6r5 (bits_image_t * image,
2070 const uint32_t *values)
2072 uint32_t *bits = image->bits + image->rowstride * y;
2073 uint16_t *pixel = ((uint16_t *) bits) + x;
2076 for (i = 0; i < width; ++i)
2080 WRITE (image, pixel++,
2081 ((b << 8) & 0xf800) |
2082 ((g << 3) & 0x07e0) |
2088 store_scanline_a1r5g5b5 (bits_image_t * image,
2092 const uint32_t *values)
2094 uint32_t *bits = image->bits + image->rowstride * y;
2095 uint16_t *pixel = ((uint16_t *) bits) + x;
2098 for (i = 0; i < width; ++i)
2100 SPLIT_A (values[i]);
2102 WRITE (image, pixel++,
2103 ((a << 8) & 0x8000) |
2104 ((r << 7) & 0x7c00) |
2105 ((g << 2) & 0x03e0) |
2111 store_scanline_x1r5g5b5 (bits_image_t * image,
2115 const uint32_t *values)
2117 uint32_t *bits = image->bits + image->rowstride * y;
2118 uint16_t *pixel = ((uint16_t *) bits) + x;
2121 for (i = 0; i < width; ++i)
2125 WRITE (image, pixel++,
2126 ((r << 7) & 0x7c00) |
2127 ((g << 2) & 0x03e0) |
2133 store_scanline_a1b5g5r5 (bits_image_t * image,
2137 const uint32_t *values)
2139 uint32_t *bits = image->bits + image->rowstride * y;
2140 uint16_t *pixel = ((uint16_t *) bits) + x;
2143 for (i = 0; i < width; ++i)
2145 SPLIT_A (values[i]);
2147 WRITE (image, pixel++,
2148 ((a << 8) & 0x8000) |
2149 ((b << 7) & 0x7c00) |
2150 ((g << 2) & 0x03e0) |
2156 store_scanline_x1b5g5r5 (bits_image_t * image,
2160 const uint32_t *values)
2162 uint32_t *bits = image->bits + image->rowstride * y;
2163 uint16_t *pixel = ((uint16_t *) bits) + x;
2166 for (i = 0; i < width; ++i)
2170 WRITE (image, pixel++, ((b << 7) & 0x7c00) |
2171 ((g << 2) & 0x03e0) |
2177 store_scanline_a4r4g4b4 (bits_image_t * image,
2181 const uint32_t *values)
2183 uint32_t *bits = image->bits + image->rowstride * y;
2184 uint16_t *pixel = ((uint16_t *) bits) + x;
2187 for (i = 0; i < width; ++i)
2189 SPLIT_A (values[i]);
2191 WRITE (image, pixel++,
2192 ((a << 8) & 0xf000) |
2193 ((r << 4) & 0x0f00) |
2200 store_scanline_x4r4g4b4 (bits_image_t * image,
2204 const uint32_t *values)
2206 uint32_t *bits = image->bits + image->rowstride * y;
2207 uint16_t *pixel = ((uint16_t *) bits) + x;
2210 for (i = 0; i < width; ++i)
2214 WRITE (image, pixel++,
2215 ((r << 4) & 0x0f00) |
2222 store_scanline_a4b4g4r4 (bits_image_t * image,
2226 const uint32_t *values)
2228 uint32_t *bits = image->bits + image->rowstride * y;
2229 uint16_t *pixel = ((uint16_t *) bits) + x;
2232 for (i = 0; i < width; ++i)
2234 SPLIT_A (values[i]);
2235 WRITE (image, pixel++, ((a << 8) & 0xf000) |
2236 ((b << 4) & 0x0f00) |
2243 store_scanline_x4b4g4r4 (bits_image_t * image,
2247 const uint32_t *values)
2249 uint32_t *bits = image->bits + image->rowstride * y;
2250 uint16_t *pixel = ((uint16_t *) bits) + x;
2253 for (i = 0; i < width; ++i)
2257 WRITE (image, pixel++,
2258 ((b << 4) & 0x0f00) |
2265 store_scanline_a8 (bits_image_t * image,
2269 const uint32_t *values)
2271 uint32_t *bits = image->bits + image->rowstride * y;
2272 uint8_t *pixel = ((uint8_t *) bits) + x;
2275 for (i = 0; i < width; ++i)
2277 WRITE (image, pixel++, values[i] >> 24);
2282 store_scanline_r3g3b2 (bits_image_t * image,
2286 const uint32_t *values)
2288 uint32_t *bits = image->bits + image->rowstride * y;
2289 uint8_t *pixel = ((uint8_t *) bits) + x;
2292 for (i = 0; i < width; ++i)
2296 WRITE (image, pixel++,
2304 store_scanline_b2g3r3 (bits_image_t * image,
2308 const uint32_t *values)
2310 uint32_t *bits = image->bits + image->rowstride * y;
2311 uint8_t *pixel = ((uint8_t *) bits) + x;
2314 for (i = 0; i < width; ++i)
2318 WRITE (image, pixel++,
2326 store_scanline_a2r2g2b2 (bits_image_t * image,
2330 const uint32_t *values)
2332 uint32_t *bits = image->bits + image->rowstride * y;
2333 uint8_t *pixel = ((uint8_t *) bits) + x;
2336 for (i = 0; i < width; ++i)
2338 SPLIT_A (values[i]);
2340 WRITE (image, pixel++,
2349 store_scanline_a2b2g2r2 (bits_image_t * image,
2353 const uint32_t *values)
2355 uint32_t *bits = image->bits + image->rowstride * y;
2356 uint8_t *pixel = ((uint8_t *) bits) + x;
2359 for (i = 0; i < width; ++i)
2361 SPLIT_A (values[i]);
2372 store_scanline_c8 (bits_image_t * image,
2376 const uint32_t *values)
2378 uint32_t *bits = image->bits + image->rowstride * y;
2379 uint8_t *pixel = ((uint8_t *) bits) + x;
2380 const pixman_indexed_t *indexed = image->indexed;
2383 for (i = 0; i < width; ++i)
2384 WRITE (image, pixel++, RGB24_TO_ENTRY (indexed,values[i]));
2388 store_scanline_x4a4 (bits_image_t * image,
2392 const uint32_t *values)
2394 uint32_t *bits = image->bits + image->rowstride * y;
2395 uint8_t *pixel = ((uint8_t *) bits) + x;
2398 for (i = 0; i < width; ++i)
2399 WRITE (image, pixel++, values[i] >> 28);
2402 #define STORE_8(img,l,o,v) (WRITE (img, (uint8_t *)(l) + ((o) >> 3), (v)))
2403 #ifdef WORDS_BIGENDIAN
2405 #define STORE_4(img,l,o,v) \
2409 int v4 = (v) & 0x0f; \
2411 STORE_8 (img, l, bo, ( \
2413 (FETCH_8 (img, l, bo) & 0xf0) | (v4) : \
2414 (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4))); \
2418 #define STORE_4(img,l,o,v) \
2422 int v4 = (v) & 0x0f; \
2424 STORE_8 (img, l, bo, ( \
2426 (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4) : \
2427 (FETCH_8 (img, l, bo) & 0xf0) | (v4))); \
2432 store_scanline_a4 (bits_image_t * image,
2436 const uint32_t *values)
2438 uint32_t *bits = image->bits + image->rowstride * y;
2441 for (i = 0; i < width; ++i)
2442 STORE_4 (image, bits, i + x, values[i] >> 28);
2446 store_scanline_r1g2b1 (bits_image_t * image,
2450 const uint32_t *values)
2452 uint32_t *bits = image->bits + image->rowstride * y;
2455 for (i = 0; i < width; ++i)
2460 pixel = (((r >> 4) & 0x8) |
2463 STORE_4 (image, bits, i + x, pixel);
2468 store_scanline_b1g2r1 (bits_image_t * image,
2472 const uint32_t *values)
2474 uint32_t *bits = image->bits + image->rowstride * y;
2477 for (i = 0; i < width; ++i)
2482 pixel = (((b >> 4) & 0x8) |
2485 STORE_4 (image, bits, i + x, pixel);
2490 store_scanline_a1r1g1b1 (bits_image_t * image,
2494 const uint32_t *values)
2496 uint32_t *bits = image->bits + image->rowstride * y;
2499 for (i = 0; i < width; ++i)
2503 SPLIT_A (values[i]);
2504 pixel = (((a >> 4) & 0x8) |
2509 STORE_4 (image, bits, i + x, pixel);
2514 store_scanline_a1b1g1r1 (bits_image_t * image,
2518 const uint32_t *values)
2520 uint32_t *bits = image->bits + image->rowstride * y;
2523 for (i = 0; i < width; ++i)
2527 SPLIT_A (values[i]);
2528 pixel = (((a >> 4) & 0x8) |
2533 STORE_4 (image, bits, i + x, pixel);
2538 store_scanline_c4 (bits_image_t * image,
2542 const uint32_t *values)
2544 uint32_t *bits = image->bits + image->rowstride * y;
2545 const pixman_indexed_t *indexed = image->indexed;
2548 for (i = 0; i < width; ++i)
2552 pixel = RGB24_TO_ENTRY (indexed, values[i]);
2553 STORE_4 (image, bits, i + x, pixel);
2558 store_scanline_a1 (bits_image_t * image,
2562 const uint32_t *values)
2564 uint32_t *bits = image->bits + image->rowstride * y;
2567 for (i = 0; i < width; ++i)
2569 uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
2572 #ifdef WORDS_BIGENDIAN
2573 mask = 1 << (0x1f - ((i + x) & 0x1f));
2575 mask = 1 << ((i + x) & 0x1f);
2577 v = values[i] & 0x80000000 ? mask : 0;
2579 WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
2584 store_scanline_g1 (bits_image_t * image,
2588 const uint32_t *values)
2590 uint32_t *bits = image->bits + image->rowstride * y;
2591 const pixman_indexed_t *indexed = image->indexed;
2594 for (i = 0; i < width; ++i)
2596 uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
2599 #ifdef WORDS_BIGENDIAN
2600 mask = 1 << (0x1f - ((i + x) & 0x1f));
2602 mask = 1 << ((i + x) & 0x1f);
2604 v = RGB24_TO_ENTRY_Y (indexed, values[i]) ? mask : 0;
2606 WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
2611 * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2612 * store proc. Despite the type, this function expects a uint64_t buffer.
2615 store_scanline_generic_64 (bits_image_t * image,
2619 const uint32_t *values)
2621 uint32_t *argb8_pixels;
2623 assert (image->common.type == BITS);
2625 argb8_pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2629 /* Contract the scanline. We could do this in place if values weren't
2632 pixman_contract (argb8_pixels, (uint64_t *)values, width);
2634 image->store_scanline_raw_32 (image, x, y, width, argb8_pixels);
2636 free (argb8_pixels);
2639 /* Despite the type, this function expects both buffer
2640 * and mask to be uint64_t
2643 fetch_scanline_generic_64 (pixman_image_t *image,
2648 const uint32_t *mask)
2650 /* Fetch the pixels into the first half of buffer and then expand them in
2653 image->bits.fetch_scanline_raw_32 (image, x, y, width, buffer, NULL);
2655 pixman_expand ((uint64_t *)buffer, buffer, image->bits.format, width);
2658 /* Despite the type, this function expects a uint64_t *buffer */
2660 fetch_pixel_generic_64 (bits_image_t *image,
2664 uint32_t pixel32 = image->fetch_pixel_raw_32 (image, offset, line);
2667 pixman_expand ((uint64_t *)&result, &pixel32, image->format, 1);
2673 * XXX: The transformed fetch path only works at 32-bpp so far. When all
2674 * paths have wide versions, this can be removed.
2676 * WARNING: This function loses precision!
2679 fetch_pixel_generic_lossy_32 (bits_image_t *image,
2683 uint64_t pixel64 = image->fetch_pixel_raw_64 (image, offset, line);
2686 pixman_contract (&result, &pixel64, 1);
2693 pixman_format_code_t format;
2694 fetch_scanline_t fetch_scanline_raw_32;
2695 fetch_scanline_t fetch_scanline_raw_64;
2696 fetch_pixel_32_t fetch_pixel_raw_32;
2697 fetch_pixel_64_t fetch_pixel_raw_64;
2698 store_scanline_t store_scanline_raw_32;
2699 store_scanline_t store_scanline_raw_64;
2702 #define FORMAT_INFO(format) \
2704 PIXMAN_ ## format, \
2705 fetch_scanline_ ## format, \
2706 fetch_scanline_generic_64, \
2707 fetch_pixel_ ## format, fetch_pixel_generic_64, \
2708 store_scanline_ ## format, store_scanline_generic_64 \
2711 static const format_info_t accessors[] =
2713 /* 32 bpp formats */
2714 FORMAT_INFO (a8r8g8b8),
2715 FORMAT_INFO (x8r8g8b8),
2716 FORMAT_INFO (a8b8g8r8),
2717 FORMAT_INFO (x8b8g8r8),
2718 FORMAT_INFO (b8g8r8a8),
2719 FORMAT_INFO (b8g8r8x8),
2722 FORMAT_INFO (r8g8b8),
2723 FORMAT_INFO (b8g8r8),
2726 FORMAT_INFO (r5g6b5),
2727 FORMAT_INFO (b5g6r5),
2729 FORMAT_INFO (a1r5g5b5),
2730 FORMAT_INFO (x1r5g5b5),
2731 FORMAT_INFO (a1b5g5r5),
2732 FORMAT_INFO (x1b5g5r5),
2733 FORMAT_INFO (a4r4g4b4),
2734 FORMAT_INFO (x4r4g4b4),
2735 FORMAT_INFO (a4b4g4r4),
2736 FORMAT_INFO (x4b4g4r4),
2740 FORMAT_INFO (r3g3b2),
2741 FORMAT_INFO (b2g3r3),
2742 FORMAT_INFO (a2r2g2b2),
2743 FORMAT_INFO (a2b2g2r2),
2747 #define fetch_scanline_g8 fetch_scanline_c8
2748 #define fetch_pixel_g8 fetch_pixel_c8
2749 #define store_scanline_g8 store_scanline_c8
2752 #define fetch_scanline_x4c4 fetch_scanline_c8
2753 #define fetch_pixel_x4c4 fetch_pixel_c8
2754 #define store_scanline_x4c4 store_scanline_c8
2757 #define fetch_scanline_x4g4 fetch_scanline_c8
2758 #define fetch_pixel_x4g4 fetch_pixel_c8
2759 #define store_scanline_x4g4 store_scanline_c8
2766 FORMAT_INFO (r1g2b1),
2767 FORMAT_INFO (b1g2r1),
2768 FORMAT_INFO (a1r1g1b1),
2769 FORMAT_INFO (a1b1g1r1),
2773 #define fetch_scanline_g4 fetch_scanline_c4
2774 #define fetch_pixel_g4 fetch_pixel_c4
2775 #define store_scanline_g4 store_scanline_c4
2784 { PIXMAN_a2r10g10b10,
2785 NULL, fetch_scanline_a2r10g10b10,
2786 fetch_pixel_generic_lossy_32, fetch_pixel_a2r10g10b10,
2787 NULL, store_scanline_a2r10g10b10 },
2789 { PIXMAN_x2r10g10b10,
2790 NULL, fetch_scanline_x2r10g10b10,
2791 fetch_pixel_generic_lossy_32, fetch_pixel_x2r10g10b10,
2792 NULL, store_scanline_x2r10g10b10 },
2794 { PIXMAN_a2b10g10r10,
2795 NULL, fetch_scanline_a2b10g10r10,
2796 fetch_pixel_generic_lossy_32, fetch_pixel_a2b10g10r10,
2797 NULL, store_scanline_a2b10g10r10 },
2799 { PIXMAN_x2b10g10r10,
2800 NULL, fetch_scanline_x2b10g10r10,
2801 fetch_pixel_generic_lossy_32, fetch_pixel_x2b10g10r10,
2802 NULL, store_scanline_x2b10g10r10 },
2806 fetch_scanline_yuy2, fetch_scanline_generic_64,
2807 fetch_pixel_yuy2, fetch_pixel_generic_64,
2811 fetch_scanline_yv12, fetch_scanline_generic_64,
2812 fetch_pixel_yv12, fetch_pixel_generic_64,
2819 setup_accessors (bits_image_t *image)
2821 const format_info_t *info = accessors;
2823 while (info->format != PIXMAN_null)
2825 if (info->format == image->format)
2827 image->fetch_scanline_raw_32 = info->fetch_scanline_raw_32;
2828 image->fetch_scanline_raw_64 = info->fetch_scanline_raw_64;
2829 image->fetch_pixel_raw_32 = info->fetch_pixel_raw_32;
2830 image->fetch_pixel_raw_64 = info->fetch_pixel_raw_64;
2831 image->store_scanline_raw_32 = info->store_scanline_raw_32;
2832 image->store_scanline_raw_64 = info->store_scanline_raw_64;
2841 #ifndef PIXMAN_FB_ACCESSORS
2843 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image);
2846 _pixman_bits_image_setup_raw_accessors (bits_image_t *image)
2848 if (image->read_func || image->write_func)
2849 _pixman_bits_image_setup_raw_accessors_accessors (image);
2851 setup_accessors (image);
2857 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image)
2859 setup_accessors (image);