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) (((((s) >> 16) & 0xff) * 153 + \
39 (((s) >> 8) & 0xff) * 301 + \
40 (((s) ) & 0xff) * 58) >> 2)
41 #define CONVERT_RGB24_TO_RGB15(s) ((((s) >> 3) & 0x001f) | \
42 (((s) >> 6) & 0x03e0) | \
43 (((s) >> 9) & 0x7c00))
44 #define RGB16_TO_ENTRY(mif,rgb15) ((mif)->ent[rgb15])
45 #define RGB24_TO_ENTRY(mif,rgb24) RGB16_TO_ENTRY(mif,CONVERT_RGB24_TO_RGB15(rgb24))
47 #define RGB24_TO_ENTRY_Y(mif,rgb24) ((mif)->ent[CONVERT_RGB24_TO_Y15(rgb24)])
50 * YV12 setup and access macros
53 #define YV12_SETUP(image) \
54 bits_image_t *__bits_image = (bits_image_t *)image; \
55 uint32_t *bits = __bits_image->bits; \
56 int stride = __bits_image->rowstride; \
57 int offset0 = stride < 0 ? \
58 ((-stride) >> 1) * ((__bits_image->height - 1) >> 1) - stride : \
59 stride * __bits_image->height; \
60 int offset1 = stride < 0 ? \
61 offset0 + ((-stride) >> 1) * ((__bits_image->height) >> 1) : \
62 offset0 + (offset0 >> 2)
63 /* Note no trailing semicolon on the above macro; if it's there, then
64 * the typical usage of YV12_SETUP(pict); will have an extra trailing ;
65 * that some compilers will interpret as a statement -- and then any further
66 * variable declarations will cause an error.
69 #define YV12_Y(line) \
70 ((uint8_t *) ((bits) + (stride) * (line)))
72 #define YV12_U(line) \
73 ((uint8_t *) ((bits) + offset1 + \
74 ((stride) >> 1) * ((line) >> 1)))
76 #define YV12_V(line) \
77 ((uint8_t *) ((bits) + offset0 + \
78 ((stride) >> 1) * ((line) >> 1)))
80 /*********************************** Fetch ************************************/
83 fetch_scanline_a8r8g8b8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
84 const uint32_t *mask, uint32_t mask_bits)
86 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
88 buffer, (const uint32_t *)bits + x,
89 width*sizeof(uint32_t));
93 fetch_scanline_x8r8g8b8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
94 const uint32_t *mask, uint32_t mask_bits)
96 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
97 const uint32_t *pixel = (const uint32_t *)bits + x;
98 const uint32_t *end = pixel + width;
100 *buffer++ = READ(image, pixel++) | 0xff000000;
105 fetch_scanline_a8b8g8r8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
106 const uint32_t *mask, uint32_t mask_bits)
108 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
109 const uint32_t *pixel = (uint32_t *)bits + x;
110 const uint32_t *end = pixel + width;
111 while (pixel < end) {
112 uint32_t p = READ(image, pixel++);
113 *buffer++ = (p & 0xff00ff00) |
120 fetch_scanline_x8b8g8r8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
121 const uint32_t *mask, uint32_t mask_bits)
123 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
124 const uint32_t *pixel = (uint32_t *)bits + x;
125 const uint32_t *end = pixel + width;
126 while (pixel < end) {
127 uint32_t p = READ(image, pixel++);
128 *buffer++ = 0xff000000 |
136 fetch_scanline_b8g8r8a8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
137 const uint32_t *mask, uint32_t mask_bits)
139 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
140 const uint32_t *pixel = (uint32_t *)bits + x;
141 const uint32_t *end = pixel + width;
142 while (pixel < end) {
143 uint32_t p = READ(image, pixel++);
144 *buffer++ = ((p & 0xff000000) >> 24) |
145 ((p & 0x00ff0000) >> 8) |
146 ((p & 0x0000ff00) << 8) |
147 ((p & 0x000000ff) << 24);
152 fetch_scanline_b8g8r8x8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
153 const uint32_t *mask, uint32_t mask_bits)
155 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
156 const uint32_t *pixel = (uint32_t *)bits + x;
157 const uint32_t *end = pixel + width;
158 while (pixel < end) {
159 uint32_t p = READ(image, pixel++);
160 *buffer++ = 0xff000000 |
161 ((p & 0xff000000) >> 24) |
162 ((p & 0x00ff0000) >> 8) |
163 ((p & 0x0000ff00) << 8);
167 /* Expects a uint64_t buffer */
169 fetch_scanline_a2r10g10b10 (pixman_image_t *image, int x, int y, int width, uint32_t *b,
170 const uint32_t *mask, uint32_t mask_bits)
172 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
173 const uint32_t *pixel = bits + x;
174 const uint32_t *end = pixel + width;
175 uint64_t *buffer = (uint64_t *)b;
177 while (pixel < end) {
178 uint32_t p = READ(image, pixel++);
179 uint64_t a = p >> 30;
180 uint64_t r = (p >> 20) & 0x3ff;
181 uint64_t g = (p >> 10) & 0x3ff;
182 uint64_t b = p & 0x3ff;
193 *buffer++ = a << 48 | r << 32 | g << 16 | b;
197 /* Expects a uint64_t buffer */
199 fetch_scanline_x2r10g10b10 (pixman_image_t *image, int x, int y, int width, uint32_t *b,
200 const uint32_t *mask, uint32_t mask_bits)
202 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
203 const uint32_t *pixel = (uint32_t *)bits + x;
204 const uint32_t *end = pixel + width;
205 uint64_t *buffer = (uint64_t *)b;
207 while (pixel < end) {
208 uint32_t p = READ(image, pixel++);
209 uint64_t r = (p >> 20) & 0x3ff;
210 uint64_t g = (p >> 10) & 0x3ff;
211 uint64_t b = p & 0x3ff;
217 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
222 /* Expects a uint64_t buffer */
224 fetch_scanline_a2b10g10r10 (pixman_image_t *image, int x, int y, int width, uint32_t *b,
225 const uint32_t *mask, uint32_t mask_bits)
227 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
228 const uint32_t *pixel = bits + x;
229 const uint32_t *end = pixel + width;
230 uint64_t *buffer = (uint64_t *)b;
232 while (pixel < end) {
233 uint32_t p = READ(image, pixel++);
234 uint64_t a = p >> 30;
235 uint64_t b = (p >> 20) & 0x3ff;
236 uint64_t g = (p >> 10) & 0x3ff;
237 uint64_t r = p & 0x3ff;
248 *buffer++ = a << 48 | r << 32 | g << 16 | b;
252 /* Expects a uint64_t buffer */
254 fetch_scanline_x2b10g10r10 (pixman_image_t *image, int x, int y, int width, uint32_t *b,
255 const uint32_t *mask, uint32_t mask_bits)
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;
262 while (pixel < end) {
263 uint32_t p = READ(image, pixel++);
264 uint64_t b = (p >> 20) & 0x3ff;
265 uint64_t g = (p >> 10) & 0x3ff;
266 uint64_t r = p & 0x3ff;
272 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
277 fetch_scanline_r8g8b8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
278 const uint32_t *mask, uint32_t mask_bits)
280 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
281 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
282 const uint8_t *end = pixel + 3*width;
283 while (pixel < end) {
284 uint32_t b = 0xff000000;
285 #ifdef WORDS_BIGENDIAN
286 b |= (READ(image, pixel++) << 16);
287 b |= (READ(image, pixel++) << 8);
288 b |= (READ(image, pixel++));
290 b |= (READ(image, pixel++));
291 b |= (READ(image, pixel++) << 8);
292 b |= (READ(image, pixel++) << 16);
299 fetch_scanline_b8g8r8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
300 const uint32_t *mask, uint32_t mask_bits)
302 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
303 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
304 const uint8_t *end = pixel + 3*width;
305 while (pixel < end) {
306 uint32_t b = 0xff000000;
307 #ifdef WORDS_BIGENDIAN
308 b |= (READ(image, pixel++));
309 b |= (READ(image, pixel++) << 8);
310 b |= (READ(image, pixel++) << 16);
312 b |= (READ(image, pixel++) << 16);
313 b |= (READ(image, pixel++) << 8);
314 b |= (READ(image, pixel++));
321 fetch_scanline_r5g6b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
322 const uint32_t *mask, uint32_t mask_bits)
324 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
325 const uint16_t *pixel = (const uint16_t *)bits + x;
326 const uint16_t *end = pixel + width;
327 while (pixel < end) {
328 uint32_t p = READ(image, pixel++);
329 uint32_t r = (((p) << 3) & 0xf8) |
330 (((p) << 5) & 0xfc00) |
331 (((p) << 8) & 0xf80000);
332 r |= (r >> 5) & 0x70007;
333 r |= (r >> 6) & 0x300;
334 *buffer++ = 0xff000000 | r;
339 fetch_scanline_b5g6r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
340 const uint32_t *mask, uint32_t mask_bits)
343 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
344 const uint16_t *pixel = (const uint16_t *)bits + x;
345 const uint16_t *end = pixel + width;
346 while (pixel < end) {
347 uint32_t p = READ(image, pixel++);
348 b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
349 g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
350 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
351 *buffer++ = 0xff000000 | r | g | b;
356 fetch_scanline_a1r5g5b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
357 const uint32_t *mask, uint32_t mask_bits)
360 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
361 const uint16_t *pixel = (const uint16_t *)bits + x;
362 const uint16_t *end = pixel + width;
363 while (pixel < end) {
364 uint32_t p = READ(image, pixel++);
366 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
367 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
368 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
369 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
370 *buffer++ = a | r | g | b;
375 fetch_scanline_x1r5g5b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
376 const uint32_t *mask, uint32_t mask_bits)
379 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
380 const uint16_t *pixel = (const uint16_t *)bits + x;
381 const uint16_t *end = pixel + width;
382 while (pixel < end) {
383 uint32_t p = READ(image, pixel++);
385 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
386 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
387 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
388 *buffer++ = 0xff000000 | r | g | b;
393 fetch_scanline_a1b5g5r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
394 const uint32_t *mask, uint32_t mask_bits)
397 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
398 const uint16_t *pixel = (const uint16_t *)bits + x;
399 const uint16_t *end = pixel + width;
400 while (pixel < end) {
401 uint32_t p = READ(image, pixel++);
403 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
404 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
405 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
406 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
407 *buffer++ = a | r | g | b;
412 fetch_scanline_x1b5g5r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
413 const uint32_t *mask, uint32_t mask_bits)
416 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
417 const uint16_t *pixel = (const uint16_t *)bits + x;
418 const uint16_t *end = pixel + width;
419 while (pixel < end) {
420 uint32_t p = READ(image, pixel++);
422 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
423 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
424 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
425 *buffer++ = 0xff000000 | r | g | b;
430 fetch_scanline_a4r4g4b4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
431 const uint32_t *mask, uint32_t mask_bits)
434 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
435 const uint16_t *pixel = (const uint16_t *)bits + x;
436 const uint16_t *end = pixel + width;
437 while (pixel < end) {
438 uint32_t p = READ(image, pixel++);
440 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
441 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
442 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
443 b = ((p & 0x000f) | ((p & 0x000f) << 4));
444 *buffer++ = a | r | g | b;
449 fetch_scanline_x4r4g4b4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
450 const uint32_t *mask, uint32_t mask_bits)
453 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
454 const uint16_t *pixel = (const uint16_t *)bits + x;
455 const uint16_t *end = pixel + width;
456 while (pixel < end) {
457 uint32_t p = READ(image, pixel++);
459 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
460 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
461 b = ((p & 0x000f) | ((p & 0x000f) << 4));
462 *buffer++ = 0xff000000 | r | g | b;
467 fetch_scanline_a4b4g4r4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
468 const uint32_t *mask, uint32_t mask_bits)
471 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
472 const uint16_t *pixel = (const uint16_t *)bits + x;
473 const uint16_t *end = pixel + width;
474 while (pixel < end) {
475 uint32_t p = READ(image, pixel++);
477 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
478 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
479 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
480 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
481 *buffer++ = a | r | g | b;
486 fetch_scanline_x4b4g4r4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
487 const uint32_t *mask, uint32_t mask_bits)
490 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
491 const uint16_t *pixel = (const uint16_t *)bits + x;
492 const uint16_t *end = pixel + width;
493 while (pixel < end) {
494 uint32_t p = READ(image, pixel++);
496 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
497 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
498 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
499 *buffer++ = 0xff000000 | r | g | b;
504 fetch_scanline_a8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
505 const uint32_t *mask, uint32_t mask_bits)
507 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
508 const uint8_t *pixel = (const uint8_t *)bits + x;
509 const uint8_t *end = pixel + width;
510 while (pixel < end) {
511 *buffer++ = READ(image, pixel++) << 24;
516 fetch_scanline_r3g3b2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
517 const uint32_t *mask, uint32_t mask_bits)
520 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
521 const uint8_t *pixel = (const uint8_t *)bits + x;
522 const uint8_t *end = pixel + width;
523 while (pixel < end) {
524 uint32_t p = READ(image, pixel++);
526 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
527 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
532 *buffer++ = 0xff000000 | r | g | b;
537 fetch_scanline_b2g3r3 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
538 const uint32_t *mask, uint32_t mask_bits)
541 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
542 const uint8_t *pixel = (const uint8_t *)bits + x;
543 const uint8_t *end = pixel + width;
544 while (pixel < end) {
545 uint32_t p = READ(image, pixel++);
551 g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
554 ((p & 0x06) << 6)) << 16;
555 *buffer++ = 0xff000000 | r | g | b;
560 fetch_scanline_a2r2g2b2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
561 const uint32_t *mask, uint32_t mask_bits)
564 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
565 const uint8_t *pixel = (const uint8_t *)bits + x;
566 const uint8_t *end = pixel + width;
567 while (pixel < end) {
568 uint32_t p = READ(image, pixel++);
570 a = ((p & 0xc0) * 0x55) << 18;
571 r = ((p & 0x30) * 0x55) << 12;
572 g = ((p & 0x0c) * 0x55) << 6;
573 b = ((p & 0x03) * 0x55);
579 fetch_scanline_a2b2g2r2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
580 const uint32_t *mask, uint32_t mask_bits)
583 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
584 const uint8_t *pixel = (const uint8_t *)bits + x;
585 const uint8_t *end = pixel + width;
586 while (pixel < end) {
587 uint32_t p = READ(image, pixel++);
589 a = ((p & 0xc0) * 0x55) << 18;
590 b = ((p & 0x30) * 0x55) >> 6;
591 g = ((p & 0x0c) * 0x55) << 6;
592 r = ((p & 0x03) * 0x55) << 16;
598 fetch_scanline_c8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
599 const uint32_t *mask, uint32_t mask_bits)
601 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
602 const pixman_indexed_t * indexed = image->bits.indexed;
603 const uint8_t *pixel = (const uint8_t *)bits + x;
604 const uint8_t *end = pixel + width;
605 while (pixel < end) {
606 uint32_t p = READ(image, pixel++);
607 *buffer++ = indexed->rgba[p];
612 fetch_scanline_x4a4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
613 const uint32_t *mask, uint32_t mask_bits)
615 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
616 const uint8_t *pixel = (const uint8_t *)bits + x;
617 const uint8_t *end = pixel + width;
618 while (pixel < end) {
619 uint8_t p = READ(image, pixel++) & 0xf;
620 *buffer++ = (p | (p << 4)) << 24;
624 #define FETCH_8(img,l,o) (READ(img, (uint8_t *)(l) + ((o) >> 2)))
625 #ifdef WORDS_BIGENDIAN
626 #define FETCH_4(img,l,o) ((o) & 2 ? FETCH_8(img,l,o) & 0xf : FETCH_8(img,l,o) >> 4)
628 #define FETCH_4(img,l,o) ((o) & 2 ? FETCH_8(img,l,o) >> 4 : FETCH_8(img,l,o) & 0xf)
632 fetch_scanline_a4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
633 const uint32_t *mask, uint32_t mask_bits)
635 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
637 for (i = 0; i < width; ++i) {
638 uint32_t p = FETCH_4(image, bits, i + x);
646 fetch_scanline_r1g2b1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
647 const uint32_t *mask, uint32_t mask_bits)
650 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
652 for (i = 0; i < width; ++i) {
653 uint32_t p = FETCH_4(image, bits, i + x);
655 r = ((p & 0x8) * 0xff) << 13;
656 g = ((p & 0x6) * 0x55) << 7;
657 b = ((p & 0x1) * 0xff);
658 *buffer++ = 0xff000000|r|g|b;
663 fetch_scanline_b1g2r1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
664 const uint32_t *mask, uint32_t mask_bits)
667 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
669 for (i = 0; i < width; ++i) {
670 uint32_t p = FETCH_4(image, bits, i + x);
672 b = ((p & 0x8) * 0xff) >> 3;
673 g = ((p & 0x6) * 0x55) << 7;
674 r = ((p & 0x1) * 0xff) << 16;
675 *buffer++ = 0xff000000|r|g|b;
680 fetch_scanline_a1r1g1b1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
681 const uint32_t *mask, uint32_t mask_bits)
684 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
686 for (i = 0; i < width; ++i) {
687 uint32_t p = FETCH_4(image, bits, i + x);
689 a = ((p & 0x8) * 0xff) << 21;
690 r = ((p & 0x4) * 0xff) << 14;
691 g = ((p & 0x2) * 0xff) << 7;
692 b = ((p & 0x1) * 0xff);
698 fetch_scanline_a1b1g1r1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
699 const uint32_t *mask, uint32_t mask_bits)
702 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
704 for (i = 0; i < width; ++i) {
705 uint32_t p = FETCH_4(image, bits, i + x);
707 a = ((p & 0x8) * 0xff) << 21;
708 r = ((p & 0x4) * 0xff) >> 3;
709 g = ((p & 0x2) * 0xff) << 7;
710 b = ((p & 0x1) * 0xff) << 16;
716 fetch_scanline_c4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
717 const uint32_t *mask, uint32_t mask_bits)
719 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
720 const pixman_indexed_t * indexed = image->bits.indexed;
722 for (i = 0; i < width; ++i) {
723 uint32_t p = FETCH_4 (image, bits, i + x);
725 *buffer++ = indexed->rgba[p];
731 fetch_scanline_a1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
732 const uint32_t *mask, uint32_t mask_bits)
734 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
736 for (i = 0; i < width; ++i) {
737 uint32_t p = READ(image, bits + ((i + x) >> 5));
739 #ifdef WORDS_BIGENDIAN
740 a = p >> (0x1f - ((i+x) & 0x1f));
742 a = p >> ((i+x) & 0x1f);
753 fetch_scanline_g1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
754 const uint32_t *mask, uint32_t mask_bits)
756 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
757 const pixman_indexed_t * indexed = image->bits.indexed;
759 for (i = 0; i < width; ++i) {
760 uint32_t p = READ(image, bits + ((i+x) >> 5));
762 #ifdef WORDS_BIGENDIAN
763 a = p >> (0x1f - ((i+x) & 0x1f));
765 a = p >> ((i+x) & 0x1f);
768 *buffer++ = indexed->rgba[a];
773 fetch_scanline_yuy2 (pixman_image_t *image, int x, int line, int width, uint32_t *buffer,
774 const uint32_t *mask, uint32_t mask_bits)
780 const uint32_t *bits = image->bits.bits + image->bits.rowstride * line;
782 for (i = 0; i < width; i++)
784 y = ((uint8_t *) bits)[(x + i) << 1] - 16;
785 u = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 1] - 128;
786 v = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 3] - 128;
788 /* R = 1.164(Y - 16) + 1.596(V - 128) */
789 r = 0x012b27 * y + 0x019a2e * v;
790 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
791 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
792 /* B = 1.164(Y - 16) + 2.018(U - 128) */
793 b = 0x012b27 * y + 0x0206a2 * u;
795 *buffer++ = 0xff000000 |
796 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
797 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
798 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
803 fetch_scanline_yv12 (pixman_image_t *image, int x, int line, int width, uint32_t *buffer,
804 const uint32_t *mask, uint32_t mask_bits)
807 uint8_t *y_line = YV12_Y (line);
808 uint8_t *u_line = YV12_U (line);
809 uint8_t *v_line = YV12_V (line);
814 for (i = 0; i < width; i++)
816 y = y_line[x + i] - 16;
817 u = u_line[(x + i) >> 1] - 128;
818 v = v_line[(x + i) >> 1] - 128;
820 /* R = 1.164(Y - 16) + 1.596(V - 128) */
821 r = 0x012b27 * y + 0x019a2e * v;
822 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
823 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
824 /* B = 1.164(Y - 16) + 2.018(U - 128) */
825 b = 0x012b27 * y + 0x0206a2 * u;
827 *buffer++ = 0xff000000 |
828 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
829 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
830 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
834 /**************************** Pixel wise fetching *****************************/
836 /* Despite the type, expects a uint64_t buffer */
838 fetch_pixels_a2r10g10b10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
841 uint64_t *buffer = (uint64_t *)b;
843 for (i = 0; i < n_pixels; ++i)
845 int offset = ((uint32_t *)buffer)[2 * i];
846 int line = ((uint32_t *)buffer)[2 * i + 1];
848 if (offset == 0xffffffff || line == 0xffffffff)
854 uint32_t *bits = pict->bits + line*pict->rowstride;
855 uint32_t p = READ(pict, bits + offset);
856 uint64_t a = p >> 30;
857 uint64_t r = (p >> 20) & 0x3ff;
858 uint64_t g = (p >> 10) & 0x3ff;
859 uint64_t b = p & 0x3ff;
870 buffer[i] = a << 48 | r << 32 | g << 16 | b;
875 /* Despite the type, this function expects a uint64_t buffer */
877 fetch_pixels_x2r10g10b10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
879 uint64_t *buffer = (uint64_t *)b;
882 for (i = 0; i < n_pixels; ++i)
884 int offset = ((uint32_t *)buffer)[2 * i];
885 int line = ((uint32_t *)buffer)[2 * i + 1];
887 if (offset == 0xffffffff || line == 0xffffffff)
893 uint32_t *bits = pict->bits + line*pict->rowstride;
894 uint32_t p = READ(pict, bits + offset);
895 uint64_t r = (p >> 20) & 0x3ff;
896 uint64_t g = (p >> 10) & 0x3ff;
897 uint64_t b = p & 0x3ff;
903 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
908 /* Despite the type, expects a uint64_t buffer */
910 fetch_pixels_a2b10g10r10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
913 uint64_t *buffer = (uint64_t *)b;
915 for (i = 0; i < n_pixels; ++i)
917 int offset = ((uint32_t *)buffer)[2 * i];
918 int line = ((uint32_t *)buffer)[2 * i + 1];
920 if (offset == 0xffffffff || line == 0xffffffff)
926 uint32_t *bits = pict->bits + line*pict->rowstride;
927 uint32_t p = READ(pict, bits + offset);
928 uint64_t a = p >> 30;
929 uint64_t b = (p >> 20) & 0x3ff;
930 uint64_t g = (p >> 10) & 0x3ff;
931 uint64_t r = p & 0x3ff;
942 buffer[i] = a << 48 | r << 32 | g << 16 | b;
947 /* Despite the type, this function expects a uint64_t buffer */
949 fetch_pixels_x2b10g10r10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
951 uint64_t *buffer = (uint64_t *)b;
954 for (i = 0; i < n_pixels; ++i)
956 int offset = ((uint32_t *)buffer)[2 * i];
957 int line = ((uint32_t *)buffer)[2 * i + 1];
959 if (offset == 0xffffffff || line == 0xffffffff)
965 uint32_t *bits = pict->bits + line*pict->rowstride;
966 uint32_t p = READ(pict, bits + offset);
967 uint64_t b = (p >> 20) & 0x3ff;
968 uint64_t g = (p >> 10) & 0x3ff;
969 uint64_t r = p & 0x3ff;
975 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
981 fetch_pixels_a8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
985 for (i = 0; i < n_pixels; ++i)
987 int offset = buffer[2 * i];
988 int line = buffer[2 * i + 1];
990 if (offset == 0xffffffff || line == 0xffffffff)
996 uint32_t *bits = pict->bits + line*pict->rowstride;
997 buffer[i] = READ(pict, (uint32_t *)bits + offset);
1003 fetch_pixels_x8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1007 for (i = 0; i < n_pixels; ++i)
1009 int offset = buffer[2 * i];
1010 int line = buffer[2 * i + 1];
1012 if (offset == 0xffffffff || line == 0xffffffff)
1018 uint32_t *bits = pict->bits + line*pict->rowstride;
1019 buffer[i] = READ(pict, (uint32_t *)bits + offset) | 0xff000000;
1025 fetch_pixels_a8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1029 for (i = 0; i < n_pixels; ++i)
1031 int offset = buffer[2 * i];
1032 int line = buffer[2 * i + 1];
1034 if (offset == 0xffffffff || line == 0xffffffff)
1040 uint32_t *bits = pict->bits + line*pict->rowstride;
1041 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
1043 buffer[i] = ((pixel & 0xff000000) |
1044 ((pixel >> 16) & 0xff) |
1045 (pixel & 0x0000ff00) |
1046 ((pixel & 0xff) << 16));
1052 fetch_pixels_x8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1056 for (i = 0; i < n_pixels; ++i)
1058 int offset = buffer[2 * i];
1059 int line = buffer[2 * i + 1];
1061 if (offset == 0xffffffff || line == 0xffffffff)
1067 uint32_t *bits = pict->bits + line*pict->rowstride;
1068 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
1070 buffer[i] = ((0xff000000) |
1071 ((pixel >> 16) & 0xff) |
1072 (pixel & 0x0000ff00) |
1073 ((pixel & 0xff) << 16));
1079 fetch_pixels_b8g8r8a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1083 for (i = 0; i < n_pixels; ++i)
1085 int offset = buffer[2 * i];
1086 int line = buffer[2 * i + 1];
1088 if (offset == 0xffffffff || line == 0xffffffff)
1094 uint32_t *bits = pict->bits + line*pict->rowstride;
1095 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
1097 buffer[i] = ((pixel & 0xff000000) >> 24 |
1098 (pixel & 0x00ff0000) >> 8 |
1099 (pixel & 0x0000ff00) << 8 |
1100 (pixel & 0x000000ff) << 24);
1106 fetch_pixels_b8g8r8x8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1110 for (i = 0; i < n_pixels; ++i)
1112 int offset = buffer[2 * i];
1113 int line = buffer[2 * i + 1];
1115 if (offset == 0xffffffff || line == 0xffffffff)
1121 uint32_t *bits = pict->bits + line*pict->rowstride;
1122 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
1124 buffer[i] = ((0xff000000) |
1125 (pixel & 0xff000000) >> 24 |
1126 (pixel & 0x00ff0000) >> 8 |
1127 (pixel & 0x0000ff00) << 8);
1133 fetch_pixels_r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1137 for (i = 0; i < n_pixels; ++i)
1139 int offset = buffer[2 * i];
1140 int line = buffer[2 * i + 1];
1142 if (offset == 0xffffffff || line == 0xffffffff)
1148 uint32_t *bits = pict->bits + line*pict->rowstride;
1149 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1150 #ifdef WORDS_BIGENDIAN
1151 buffer[i] = (0xff000000 |
1152 (READ(pict, pixel + 0) << 16) |
1153 (READ(pict, pixel + 1) << 8) |
1154 (READ(pict, pixel + 2)));
1156 buffer[i] = (0xff000000 |
1157 (READ(pict, pixel + 2) << 16) |
1158 (READ(pict, pixel + 1) << 8) |
1159 (READ(pict, pixel + 0)));
1166 fetch_pixels_b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1170 for (i = 0; i < n_pixels; ++i)
1172 int offset = buffer[2 * i];
1173 int line = buffer[2 * i + 1];
1175 if (offset == 0xffffffff || line == 0xffffffff)
1181 uint32_t *bits = pict->bits + line*pict->rowstride;
1182 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1183 #ifdef WORDS_BIGENDIAN
1184 buffer[i] = (0xff000000 |
1185 (READ(pict, pixel + 2) << 16) |
1186 (READ(pict, pixel + 1) << 8) |
1187 (READ(pict, pixel + 0)));
1189 buffer[i] = (0xff000000 |
1190 (READ(pict, pixel + 0) << 16) |
1191 (READ(pict, pixel + 1) << 8) |
1192 (READ(pict, pixel + 2)));
1199 fetch_pixels_r5g6b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1203 for (i = 0; i < n_pixels; ++i)
1205 int offset = buffer[2 * i];
1206 int line = buffer[2 * i + 1];
1208 if (offset == 0xffffffff || line == 0xffffffff)
1215 uint32_t *bits = pict->bits + line*pict->rowstride;
1216 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1218 r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1219 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1220 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1221 buffer[i] = (0xff000000 | r | g | b);
1227 fetch_pixels_b5g6r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1231 for (i = 0; i < n_pixels; ++i)
1233 int offset = buffer[2 * i];
1234 int line = buffer[2 * i + 1];
1236 if (offset == 0xffffffff || line == 0xffffffff)
1243 uint32_t *bits = pict->bits + line*pict->rowstride;
1244 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1246 b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1247 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1248 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1249 buffer[i] = (0xff000000 | r | g | b);
1255 fetch_pixels_a1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1259 for (i = 0; i < n_pixels; ++i)
1261 int offset = buffer[2 * i];
1262 int line = buffer[2 * i + 1];
1264 if (offset == 0xffffffff || line == 0xffffffff)
1271 uint32_t *bits = pict->bits + line*pict->rowstride;
1272 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1274 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1275 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1276 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1277 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1278 buffer[i] = (a | r | g | b);
1284 fetch_pixels_x1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1288 for (i = 0; i < n_pixels; ++i)
1290 int offset = buffer[2 * i];
1291 int line = buffer[2 * i + 1];
1293 if (offset == 0xffffffff || line == 0xffffffff)
1300 uint32_t *bits = pict->bits + line*pict->rowstride;
1301 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1303 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1304 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1305 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1306 buffer[i] = (0xff000000 | r | g | b);
1312 fetch_pixels_a1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1316 for (i = 0; i < n_pixels; ++i)
1318 int offset = buffer[2 * i];
1319 int line = buffer[2 * i + 1];
1321 if (offset == 0xffffffff || line == 0xffffffff)
1328 uint32_t *bits = pict->bits + line*pict->rowstride;
1329 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1331 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1332 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1333 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1334 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1335 buffer[i] = (a | r | g | b);
1341 fetch_pixels_x1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1345 for (i = 0; i < n_pixels; ++i)
1347 int offset = buffer[2 * i];
1348 int line = buffer[2 * i + 1];
1350 if (offset == 0xffffffff || line == 0xffffffff)
1357 uint32_t *bits = pict->bits + line*pict->rowstride;
1358 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1360 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1361 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1362 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1363 buffer[i] = (0xff000000 | r | g | b);
1369 fetch_pixels_a4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1373 for (i = 0; i < n_pixels; ++i)
1375 int offset = buffer[2 * i];
1376 int line = buffer[2 * i + 1];
1378 if (offset == 0xffffffff || line == 0xffffffff)
1385 uint32_t *bits = pict->bits + line*pict->rowstride;
1386 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1388 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1389 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1390 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1391 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1392 buffer[i] = (a | r | g | b);
1398 fetch_pixels_x4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1402 for (i = 0; i < n_pixels; ++i)
1404 int offset = buffer[2 * i];
1405 int line = buffer[2 * i + 1];
1407 if (offset == 0xffffffff || line == 0xffffffff)
1414 uint32_t *bits = pict->bits + line*pict->rowstride;
1415 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1417 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1418 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1419 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1420 buffer[i] = (0xff000000 | r | g | b);
1426 fetch_pixels_a4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1430 for (i = 0; i < n_pixels; ++i)
1432 int offset = buffer[2 * i];
1433 int line = buffer[2 * i + 1];
1435 if (offset == 0xffffffff || line == 0xffffffff)
1442 uint32_t *bits = pict->bits + line*pict->rowstride;
1443 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1445 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1446 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1447 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1448 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1449 buffer[i] = (a | r | g | b);
1455 fetch_pixels_x4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1459 for (i = 0; i < n_pixels; ++i)
1461 int offset = buffer[2 * i];
1462 int line = buffer[2 * i + 1];
1464 if (offset == 0xffffffff || line == 0xffffffff)
1471 uint32_t *bits = pict->bits + line*pict->rowstride;
1472 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1474 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1475 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1476 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1477 buffer[i] = (0xff000000 | r | g | b);
1483 fetch_pixels_a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1487 for (i = 0; i < n_pixels; ++i)
1489 int offset = buffer[2 * i];
1490 int line = buffer[2 * i + 1];
1492 if (offset == 0xffffffff || line == 0xffffffff)
1498 uint32_t *bits = pict->bits + line*pict->rowstride;
1499 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1501 buffer[i] = pixel << 24;
1507 fetch_pixels_r3g3b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1511 for (i = 0; i < n_pixels; ++i)
1513 int offset = buffer[2 * i];
1514 int line = buffer[2 * i + 1];
1516 if (offset == 0xffffffff || line == 0xffffffff)
1523 uint32_t *bits = pict->bits + line*pict->rowstride;
1524 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1526 r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16;
1527 g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8;
1528 b = (((pixel & 0x03) ) |
1529 ((pixel & 0x03) << 2) |
1530 ((pixel & 0x03) << 4) |
1531 ((pixel & 0x03) << 6));
1532 buffer[i] = (0xff000000 | r | g | b);
1538 fetch_pixels_b2g3r3 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1542 for (i = 0; i < n_pixels; ++i)
1544 int offset = buffer[2 * i];
1545 int line = buffer[2 * i + 1];
1547 if (offset == 0xffffffff || line == 0xffffffff)
1554 uint32_t *bits = pict->bits + line*pict->rowstride;
1555 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1557 b = (((pixel & 0xc0) ) |
1558 ((pixel & 0xc0) >> 2) |
1559 ((pixel & 0xc0) >> 4) |
1560 ((pixel & 0xc0) >> 6));
1561 g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8;
1562 r = (((pixel & 0x07) ) |
1563 ((pixel & 0x07) << 3) |
1564 ((pixel & 0x06) << 6)) << 16;
1565 buffer[i] = (0xff000000 | r | g | b);
1571 fetch_pixels_a2r2g2b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1575 for (i = 0; i < n_pixels; ++i)
1577 int offset = buffer[2 * i];
1578 int line = buffer[2 * i + 1];
1580 if (offset == 0xffffffff || line == 0xffffffff)
1587 uint32_t *bits = pict->bits + line*pict->rowstride;
1588 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1590 a = ((pixel & 0xc0) * 0x55) << 18;
1591 r = ((pixel & 0x30) * 0x55) << 12;
1592 g = ((pixel & 0x0c) * 0x55) << 6;
1593 b = ((pixel & 0x03) * 0x55);
1594 buffer[i] = a|r|g|b;
1600 fetch_pixels_a2b2g2r2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1604 for (i = 0; i < n_pixels; ++i)
1606 int offset = buffer[2 * i];
1607 int line = buffer[2 * i + 1];
1609 if (offset == 0xffffffff || line == 0xffffffff)
1616 uint32_t *bits = pict->bits + line*pict->rowstride;
1617 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1619 a = ((pixel & 0xc0) * 0x55) << 18;
1620 b = ((pixel & 0x30) * 0x55) >> 6;
1621 g = ((pixel & 0x0c) * 0x55) << 6;
1622 r = ((pixel & 0x03) * 0x55) << 16;
1623 buffer[i] = a|r|g|b;
1629 fetch_pixels_c8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1633 for (i = 0; i < n_pixels; ++i)
1635 int offset = buffer[2 * i];
1636 int line = buffer[2 * i + 1];
1638 if (offset == 0xffffffff || line == 0xffffffff)
1644 uint32_t *bits = pict->bits + line*pict->rowstride;
1645 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1646 const pixman_indexed_t * indexed = pict->indexed;
1647 buffer[i] = indexed->rgba[pixel];
1653 fetch_pixels_x4a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1657 for (i = 0; i < n_pixels; ++i)
1659 int offset = buffer[2 * i];
1660 int line = buffer[2 * i + 1];
1662 if (offset == 0xffffffff || line == 0xffffffff)
1668 uint32_t *bits = pict->bits + line*pict->rowstride;
1669 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1671 buffer[i] = ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1677 fetch_pixels_a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1681 for (i = 0; i < n_pixels; ++i)
1683 int offset = buffer[2 * i];
1684 int line = buffer[2 * i + 1];
1686 if (offset == 0xffffffff || line == 0xffffffff)
1692 uint32_t *bits = pict->bits + line*pict->rowstride;
1693 uint32_t pixel = FETCH_4 (pict, bits, offset);
1695 pixel |= pixel << 4;
1696 buffer[i] = pixel << 24;
1702 fetch_pixels_r1g2b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1706 for (i = 0; i < n_pixels; ++i)
1708 int offset = buffer[2 * i];
1709 int line = buffer[2 * i + 1];
1711 if (offset == 0xffffffff || line == 0xffffffff)
1718 uint32_t *bits = pict->bits + line*pict->rowstride;
1719 uint32_t pixel = FETCH_4 (pict, bits, offset);
1721 r = ((pixel & 0x8) * 0xff) << 13;
1722 g = ((pixel & 0x6) * 0x55) << 7;
1723 b = ((pixel & 0x1) * 0xff);
1724 buffer[i] = 0xff000000|r|g|b;
1730 fetch_pixels_b1g2r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1734 for (i = 0; i < n_pixels; ++i)
1736 int offset = buffer[2 * i];
1737 int line = buffer[2 * i + 1];
1739 if (offset == 0xffffffff || line == 0xffffffff)
1746 uint32_t *bits = pict->bits + line*pict->rowstride;
1747 uint32_t pixel = FETCH_4 (pict, bits, offset);
1749 b = ((pixel & 0x8) * 0xff) >> 3;
1750 g = ((pixel & 0x6) * 0x55) << 7;
1751 r = ((pixel & 0x1) * 0xff) << 16;
1752 buffer[i] = 0xff000000|r|g|b;
1758 fetch_pixels_a1r1g1b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1762 for (i = 0; i < n_pixels; ++i)
1764 int offset = buffer[2 * i];
1765 int line = buffer[2 * i + 1];
1767 if (offset == 0xffffffff || line == 0xffffffff)
1774 uint32_t *bits = pict->bits + line*pict->rowstride;
1775 uint32_t pixel = FETCH_4 (pict, bits, offset);
1777 a = ((pixel & 0x8) * 0xff) << 21;
1778 r = ((pixel & 0x4) * 0xff) << 14;
1779 g = ((pixel & 0x2) * 0xff) << 7;
1780 b = ((pixel & 0x1) * 0xff);
1781 buffer[i] = a|r|g|b;
1787 fetch_pixels_a1b1g1r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1791 for (i = 0; i < n_pixels; ++i)
1793 int offset = buffer[2 * i];
1794 int line = buffer[2 * i + 1];
1796 if (offset == 0xffffffff || line == 0xffffffff)
1803 uint32_t *bits = pict->bits + line*pict->rowstride;
1804 uint32_t pixel = FETCH_4 (pict, bits, offset);
1806 a = ((pixel & 0x8) * 0xff) << 21;
1807 r = ((pixel & 0x4) * 0xff) >> 3;
1808 g = ((pixel & 0x2) * 0xff) << 7;
1809 b = ((pixel & 0x1) * 0xff) << 16;
1810 buffer[i] = a|r|g|b;
1816 fetch_pixels_c4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1820 for (i = 0; i < n_pixels; ++i)
1822 int offset = buffer[2 * i];
1823 int line = buffer[2 * i + 1];
1825 if (offset == 0xffffffff || line == 0xffffffff)
1831 uint32_t *bits = pict->bits + line*pict->rowstride;
1832 uint32_t pixel = FETCH_4 (pict, bits, offset);
1833 const pixman_indexed_t * indexed = pict->indexed;
1835 buffer[i] = indexed->rgba[pixel];
1842 fetch_pixels_a1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1846 for (i = 0; i < n_pixels; ++i)
1848 int offset = buffer[2 * i];
1849 int line = buffer[2 * i + 1];
1851 if (offset == 0xffffffff || line == 0xffffffff)
1857 uint32_t *bits = pict->bits + line*pict->rowstride;
1858 uint32_t pixel = READ(pict, bits + (offset >> 5));
1860 #ifdef WORDS_BIGENDIAN
1861 a = pixel >> (0x1f - (offset & 0x1f));
1863 a = pixel >> (offset & 0x1f);
1869 buffer[i] = a << 24;
1875 fetch_pixels_g1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1879 for (i = 0; i < n_pixels; ++i)
1881 int offset = buffer[2 * i];
1882 int line = buffer[2 * i + 1];
1884 if (offset == 0xffffffff || line == 0xffffffff)
1890 uint32_t *bits = pict->bits + line*pict->rowstride;
1891 uint32_t pixel = READ(pict, bits + (offset >> 5));
1892 const pixman_indexed_t * indexed = pict->indexed;
1894 #ifdef WORDS_BIGENDIAN
1895 a = pixel >> (0x1f - (offset & 0x1f));
1897 a = pixel >> (offset & 0x1f);
1900 buffer[i] = indexed->rgba[a];
1906 fetch_pixels_yuy2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1910 for (i = 0; i < n_pixels; ++i)
1912 int offset = buffer[2 * i];
1913 int line = buffer[2 * i + 1];
1915 if (offset == 0xffffffff || line == 0xffffffff)
1924 const uint32_t *bits = pict->bits + pict->rowstride * line;
1926 y = ((uint8_t *) bits)[offset << 1] - 16;
1927 u = ((uint8_t *) bits)[((offset << 1) & -4) + 1] - 128;
1928 v = ((uint8_t *) bits)[((offset << 1) & -4) + 3] - 128;
1930 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1931 r = 0x012b27 * y + 0x019a2e * v;
1932 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1933 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1934 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1935 b = 0x012b27 * y + 0x0206a2 * u;
1937 buffer[i] = 0xff000000 |
1938 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1939 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1940 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1946 fetch_pixels_yv12 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1950 for (i = 0; i < n_pixels; ++i)
1952 int offset = buffer[2 * i];
1953 int line = buffer[2 * i + 1];
1955 if (offset == 0xffffffff || line == 0xffffffff)
1962 int16_t y = YV12_Y (line)[offset] - 16;
1963 int16_t u = YV12_U (line)[offset >> 1] - 128;
1964 int16_t v = YV12_V (line)[offset >> 1] - 128;
1967 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1968 r = 0x012b27 * y + 0x019a2e * v;
1969 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1970 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1971 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1972 b = 0x012b27 * y + 0x0206a2 * u;
1974 buffer[i] = 0xff000000 |
1975 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1976 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1977 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1982 /*********************************** Store ************************************/
1984 #define SPLIT_A(v) uint32_t a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1985 #define SPLIT(v) uint32_t r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1988 store_scanline_a2r10g10b10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
1990 uint32_t *bits = image->bits + image->rowstride * y;
1991 uint32_t *pixel = bits + x;
1992 uint64_t *values = (uint64_t *)v;
1995 for (i = 0; i < width; ++i) {
1996 WRITE(image, pixel++,
1997 ((values[i] >> 32) & 0xc0000000) | // A
1998 ((values[i] >> 18) & 0x3ff00000) | // R
1999 ((values[i] >> 12) & 0xffc00) | // G
2000 ((values[i] >> 6) & 0x3ff)); // B
2005 store_scanline_x2r10g10b10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
2007 uint32_t *bits = image->bits + image->rowstride * y;
2008 uint64_t *values = (uint64_t *)v;
2009 uint32_t *pixel = bits + x;
2012 for (i = 0; i < width; ++i) {
2013 WRITE(image, pixel++,
2014 ((values[i] >> 18) & 0x3ff00000) | // R
2015 ((values[i] >> 12) & 0xffc00) | // G
2016 ((values[i] >> 6) & 0x3ff)); // B
2021 store_scanline_a2b10g10r10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
2023 uint32_t *bits = image->bits + image->rowstride * y;
2024 uint32_t *pixel = bits + x;
2025 uint64_t *values = (uint64_t *)v;
2028 for (i = 0; i < width; ++i) {
2029 WRITE(image, pixel++,
2030 ((values[i] >> 32) & 0xc0000000) | // A
2031 ((values[i] >> 38) & 0x3ff) | // R
2032 ((values[i] >> 12) & 0xffc00) | // G
2033 ((values[i] << 14) & 0x3ff00000)); // B
2038 store_scanline_x2b10g10r10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
2040 uint32_t *bits = image->bits + image->rowstride * y;
2041 uint64_t *values = (uint64_t *)v;
2042 uint32_t *pixel = bits + x;
2045 for (i = 0; i < width; ++i) {
2046 WRITE(image, pixel++,
2047 ((values[i] >> 38) & 0x3ff) | // R
2048 ((values[i] >> 12) & 0xffc00) | // G
2049 ((values[i] << 14) & 0x3ff00000)); // B
2054 store_scanline_a8r8g8b8 (bits_image_t *image,
2055 int x, int y, int width,
2056 const uint32_t *values)
2058 uint32_t *bits = image->bits + image->rowstride * y;
2060 MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
2064 store_scanline_x8r8g8b8 (bits_image_t *image,
2065 int x, int y, int width,
2066 const uint32_t *values)
2068 uint32_t *bits = image->bits + image->rowstride * y;
2069 uint32_t *pixel = (uint32_t *)bits + x;
2072 for (i = 0; i < width; ++i)
2073 WRITE(image, pixel++, values[i] & 0xffffff);
2077 store_scanline_a8b8g8r8 (bits_image_t *image,
2078 int x, int y, int width,
2079 const uint32_t *values)
2081 uint32_t *bits = image->bits + image->rowstride * y;
2082 uint32_t *pixel = (uint32_t *)bits + x;
2085 for (i = 0; i < width; ++i)
2086 WRITE(image, pixel++, (values[i] & 0xff00ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
2090 store_scanline_x8b8g8r8 (bits_image_t *image,
2091 int x, int y, int width,
2092 const uint32_t *values)
2094 uint32_t *bits = image->bits + image->rowstride * y;
2095 uint32_t *pixel = (uint32_t *)bits + x;
2098 for (i = 0; i < width; ++i)
2099 WRITE(image, pixel++, (values[i] & 0x0000ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
2103 store_scanline_b8g8r8a8 (bits_image_t *image,
2104 int x, int y, int width,
2105 const uint32_t *values)
2107 uint32_t *bits = image->bits + image->rowstride * y;
2108 uint32_t *pixel = (uint32_t *)bits + x;
2111 for (i = 0; i < width; ++i)
2112 WRITE(image, pixel++,
2113 ((values[i] >> 24) & 0x000000ff) |
2114 ((values[i] >> 8) & 0x0000ff00) |
2115 ((values[i] << 8) & 0x00ff0000) |
2116 ((values[i] << 24) & 0xff000000));
2120 store_scanline_b8g8r8x8 (bits_image_t *image,
2121 int x, int y, int width,
2122 const uint32_t *values)
2124 uint32_t *bits = image->bits + image->rowstride * y;
2125 uint32_t *pixel = (uint32_t *)bits + x;
2128 for (i = 0; i < width; ++i)
2129 WRITE(image, pixel++,
2130 ((values[i] >> 8) & 0x0000ff00) |
2131 ((values[i] << 8) & 0x00ff0000) |
2132 ((values[i] << 24) & 0xff000000));
2136 store_scanline_r8g8b8 (bits_image_t *image,
2137 int x, int y, int width,
2138 const uint32_t *values)
2140 uint32_t *bits = image->bits + image->rowstride * y;
2141 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
2144 for (i = 0; i < width; ++i)
2146 uint32_t val = values[i];
2147 #ifdef WORDS_BIGENDIAN
2148 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2149 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2150 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2152 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2153 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2154 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2160 store_scanline_b8g8r8 (bits_image_t *image,
2161 int x, int y, int width,
2162 const uint32_t *values)
2164 uint32_t *bits = image->bits + image->rowstride * y;
2165 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
2168 for (i = 0; i < width; ++i)
2170 uint32_t val = values[i];
2171 #ifdef WORDS_BIGENDIAN
2172 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2173 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2174 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2176 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2177 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2178 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2184 store_scanline_r5g6b5 (bits_image_t *image,
2185 int x, int y, int width,
2186 const uint32_t *values)
2188 uint32_t *bits = image->bits + image->rowstride * y;
2189 uint16_t *pixel = ((uint16_t *) bits) + x;
2192 for (i = 0; i < width; ++i) {
2193 uint32_t s = values[i];
2194 WRITE(image, pixel++, ((s >> 3) & 0x001f) |
2195 ((s >> 5) & 0x07e0) |
2196 ((s >> 8) & 0xf800));
2201 store_scanline_b5g6r5 (bits_image_t *image,
2202 int x, int y, int width,
2203 const uint32_t *values)
2205 uint32_t *bits = image->bits + image->rowstride * y;
2206 uint16_t *pixel = ((uint16_t *) bits) + x;
2209 for (i = 0; i < width; ++i) {
2211 WRITE(image, pixel++, ((b << 8) & 0xf800) |
2212 ((g << 3) & 0x07e0) |
2218 store_scanline_a1r5g5b5 (bits_image_t *image,
2219 int x, int y, int width,
2220 const uint32_t *values)
2222 uint32_t *bits = image->bits + image->rowstride * y;
2223 uint16_t *pixel = ((uint16_t *) bits) + x;
2226 for (i = 0; i < width; ++i) {
2228 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2229 ((r << 7) & 0x7c00) |
2230 ((g << 2) & 0x03e0) |
2236 store_scanline_x1r5g5b5 (bits_image_t *image,
2237 int x, int y, int width,
2238 const uint32_t *values)
2240 uint32_t *bits = image->bits + image->rowstride * y;
2241 uint16_t *pixel = ((uint16_t *) bits) + x;
2244 for (i = 0; i < width; ++i) {
2246 WRITE(image, pixel++, ((r << 7) & 0x7c00) |
2247 ((g << 2) & 0x03e0) |
2253 store_scanline_a1b5g5r5 (bits_image_t *image,
2254 int x, int y, int width,
2255 const uint32_t *values)
2257 uint32_t *bits = image->bits + image->rowstride * y;
2258 uint16_t *pixel = ((uint16_t *) bits) + x;
2261 for (i = 0; i < width; ++i) {
2263 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2264 ((b << 7) & 0x7c00) |
2265 ((g << 2) & 0x03e0) |
2271 store_scanline_x1b5g5r5 (bits_image_t *image,
2272 int x, int y, int width,
2273 const uint32_t *values)
2275 uint32_t *bits = image->bits + image->rowstride * y;
2276 uint16_t *pixel = ((uint16_t *) bits) + x;
2279 for (i = 0; i < width; ++i) {
2281 WRITE(image, pixel++, ((b << 7) & 0x7c00) |
2282 ((g << 2) & 0x03e0) |
2288 store_scanline_a4r4g4b4 (bits_image_t *image,
2289 int x, int y, int width,
2290 const uint32_t *values)
2292 uint32_t *bits = image->bits + image->rowstride * y;
2293 uint16_t *pixel = ((uint16_t *) bits) + x;
2296 for (i = 0; i < width; ++i) {
2298 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2299 ((r << 4) & 0x0f00) |
2306 store_scanline_x4r4g4b4 (bits_image_t *image,
2307 int x, int y, int width,
2308 const uint32_t *values)
2310 uint32_t *bits = image->bits + image->rowstride * y;
2311 uint16_t *pixel = ((uint16_t *) bits) + x;
2314 for (i = 0; i < width; ++i) {
2316 WRITE(image, pixel++, ((r << 4) & 0x0f00) |
2323 store_scanline_a4b4g4r4 (bits_image_t *image,
2324 int x, int y, int width,
2325 const uint32_t *values)
2327 uint32_t *bits = image->bits + image->rowstride * y;
2328 uint16_t *pixel = ((uint16_t *) bits) + x;
2331 for (i = 0; i < width; ++i) {
2333 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2334 ((b << 4) & 0x0f00) |
2341 store_scanline_x4b4g4r4 (bits_image_t *image,
2342 int x, int y, int width,
2343 const uint32_t *values)
2345 uint32_t *bits = image->bits + image->rowstride * y;
2346 uint16_t *pixel = ((uint16_t *) bits) + x;
2349 for (i = 0; i < width; ++i) {
2351 WRITE(image, pixel++, ((b << 4) & 0x0f00) |
2358 store_scanline_a8 (bits_image_t *image,
2359 int x, int y, int width,
2360 const uint32_t *values)
2362 uint32_t *bits = image->bits + image->rowstride * y;
2363 uint8_t *pixel = ((uint8_t *) bits) + x;
2366 for (i = 0; i < width; ++i) {
2367 WRITE(image, pixel++, values[i] >> 24);
2372 store_scanline_r3g3b2 (bits_image_t *image,
2373 int x, int y, int width,
2374 const uint32_t *values)
2376 uint32_t *bits = image->bits + image->rowstride * y;
2377 uint8_t *pixel = ((uint8_t *) bits) + x;
2380 for (i = 0; i < width; ++i) {
2382 WRITE(image, pixel++,
2390 store_scanline_b2g3r3 (bits_image_t *image,
2391 int x, int y, int width,
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) {
2400 WRITE(image, pixel++,
2408 store_scanline_a2r2g2b2 (bits_image_t *image,
2409 int x, int y, int width,
2410 const uint32_t *values)
2412 uint32_t *bits = image->bits + image->rowstride * y;
2413 uint8_t *pixel = ((uint8_t *) bits) + x;
2416 for (i = 0; i < width; ++i) {
2418 WRITE(image, pixel++, ((a ) & 0xc0) |
2426 store_scanline_a2b2g2r2 (bits_image_t *image,
2427 int x, int y, int width,
2428 const uint32_t *values)
2430 uint32_t *bits = image->bits + image->rowstride * y;
2431 uint8_t *pixel = ((uint8_t *) bits) + x;
2434 for (i = 0; i < width; ++i) {
2436 *(pixel++) = ((a ) & 0xc0) |
2444 store_scanline_c8 (bits_image_t *image,
2445 int x, int y, int width,
2446 const uint32_t *values)
2448 uint32_t *bits = image->bits + image->rowstride * y;
2449 uint8_t *pixel = ((uint8_t *) bits) + x;
2450 const pixman_indexed_t *indexed = image->indexed;
2453 for (i = 0; i < width; ++i) {
2454 WRITE(image, pixel++, RGB24_TO_ENTRY(indexed,values[i]));
2459 store_scanline_x4a4 (bits_image_t *image,
2460 int x, int y, int width,
2461 const uint32_t *values)
2463 uint32_t *bits = image->bits + image->rowstride * y;
2464 uint8_t *pixel = ((uint8_t *) bits) + x;
2467 for (i = 0; i < width; ++i) {
2468 WRITE(image, pixel++, values[i] >> 28);
2472 #define STORE_8(img,l,o,v) (WRITE(img, (uint8_t *)(l) + ((o) >> 3), (v)))
2473 #ifdef WORDS_BIGENDIAN
2474 #define STORE_4(img,l,o,v) STORE_8(img,l,o,((o) & 4 ? \
2475 (FETCH_8(img,l,o) & 0xf0) | (v) : \
2476 (FETCH_8(img,l,o) & 0x0f) | ((v) << 4)))
2478 #define STORE_4(img,l,o,v) STORE_8(img,l,o,((o) & 4 ? \
2479 (FETCH_8(img,l,o) & 0x0f) | ((v) << 4) : \
2480 (FETCH_8(img,l,o) & 0xf0) | (v)))
2484 store_scanline_a4 (bits_image_t *image,
2485 int x, int y, int width,
2486 const uint32_t *values)
2488 uint32_t *bits = image->bits + image->rowstride * y;
2491 for (i = 0; i < width; ++i) {
2492 STORE_4(image, bits, i + x, values[i]>>28);
2497 store_scanline_r1g2b1 (bits_image_t *image,
2498 int x, int y, int width,
2499 const uint32_t *values)
2501 uint32_t *bits = image->bits + image->rowstride * y;
2504 for (i = 0; i < width; ++i) {
2508 pixel = (((r >> 4) & 0x8) |
2511 STORE_4(image, bits, i + x, pixel);
2516 store_scanline_b1g2r1 (bits_image_t *image,
2517 int x, int y, int width,
2518 const uint32_t *values)
2520 uint32_t *bits = image->bits + image->rowstride * y;
2523 for (i = 0; i < width; ++i) {
2527 pixel = (((b >> 4) & 0x8) |
2530 STORE_4(image, bits, i + x, pixel);
2535 store_scanline_a1r1g1b1 (bits_image_t *image,
2536 int x, int y, int width,
2537 const uint32_t *values)
2539 uint32_t *bits = image->bits + image->rowstride * y;
2542 for (i = 0; i < width; ++i) {
2545 pixel = (((a >> 4) & 0x8) |
2549 STORE_4(image, bits, i + x, pixel);
2554 store_scanline_a1b1g1r1 (bits_image_t *image,
2555 int x, int y, int width,
2556 const uint32_t *values)
2558 uint32_t *bits = image->bits + image->rowstride * y;
2561 for (i = 0; i < width; ++i) {
2564 pixel = (((a >> 4) & 0x8) |
2568 STORE_4(image, bits, i + x, pixel);
2573 store_scanline_c4 (bits_image_t *image,
2574 int x, int y, int width,
2575 const uint32_t *values)
2577 uint32_t *bits = image->bits + image->rowstride * y;
2578 const pixman_indexed_t *indexed = image->indexed;
2581 for (i = 0; i < width; ++i) {
2584 pixel = RGB24_TO_ENTRY(indexed, values[i]);
2585 STORE_4(image, bits, i + x, pixel);
2590 store_scanline_a1 (bits_image_t *image,
2591 int x, int y, int width,
2592 const uint32_t *values)
2594 uint32_t *bits = image->bits + image->rowstride * y;
2597 for (i = 0; i < width; ++i)
2599 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2601 #ifdef WORDS_BIGENDIAN
2602 mask = 1 << (0x1f - ((i+x) & 0x1f));
2604 mask = 1 << ((i+x) & 0x1f);
2606 v = values[i] & 0x80000000 ? mask : 0;
2607 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2612 store_scanline_g1 (bits_image_t *image,
2613 int x, int y, int width,
2614 const uint32_t *values)
2616 uint32_t *bits = image->bits + image->rowstride * y;
2617 const pixman_indexed_t *indexed = image->indexed;
2620 for (i = 0; i < width; ++i)
2622 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2624 #ifdef WORDS_BIGENDIAN
2625 mask = 1 << (0x1f - ((i+x) & 0x1f));
2627 mask = 1 << ((i + x) & 0x1f);
2629 v = RGB24_TO_ENTRY_Y (indexed, values[i]) ? mask : 0;
2630 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2635 * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2636 * store proc. Despite the type, this function expects a uint64_t buffer.
2639 store_scanline_generic_64 (bits_image_t *image, int x, int y, int width, const uint32_t *values)
2641 uint32_t *argb8_pixels;
2643 assert(image->common.type == BITS);
2645 argb8_pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2649 /* Contract the scanline. We could do this in place if values weren't
2652 pixman_contract(argb8_pixels, (uint64_t *)values, width);
2654 image->store_scanline_raw_32 (image, x, y, width, argb8_pixels);
2659 /* Despite the type, this function expects both buffer and mask to be uint64_t */
2661 fetch_scanline_generic_64 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
2662 const uint32_t *mask, uint32_t mask_bits)
2664 /* Fetch the pixels into the first half of buffer and then expand them in
2667 image->bits.fetch_scanline_raw_32 (image, x, y, width, buffer, NULL, 0);
2669 pixman_expand ((uint64_t *)buffer, buffer, image->bits.format, width);
2672 /* Despite the type, this function expects a uint64_t *buffer */
2674 fetch_pixels_generic_64 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
2676 pict->fetch_pixels_raw_32 (pict, buffer, n_pixels);
2678 pixman_expand ((uint64_t *)buffer, buffer, pict->format, n_pixels);
2682 * XXX: The transformed fetch path only works at 32-bpp so far. When all paths
2683 * have wide versions, this can be removed.
2685 * WARNING: This function loses precision!
2688 fetch_pixels_generic_lossy_32 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
2690 /* Since buffer contains n_pixels coordinate pairs, it also has enough room for
2691 * n_pixels 64 bit pixels.
2693 pict->fetch_pixels_raw_64 (pict, buffer, n_pixels);
2695 pixman_contract (buffer, (uint64_t *)buffer, n_pixels);
2700 pixman_format_code_t format;
2701 fetch_scanline_t fetch_scanline_raw_32;
2702 fetch_scanline_t fetch_scanline_raw_64;
2703 fetch_pixels_t fetch_pixels_raw_32;
2704 fetch_pixels_t fetch_pixels_raw_64;
2705 store_scanline_t store_scanline_raw_32;
2706 store_scanline_t store_scanline_raw_64;
2709 #define FORMAT_INFO(format) \
2712 fetch_scanline_##format, fetch_scanline_generic_64, \
2713 fetch_pixels_##format, fetch_pixels_generic_64, \
2714 store_scanline_##format, store_scanline_generic_64 \
2717 static const format_info_t accessors[] =
2719 /* 32 bpp formats */
2720 FORMAT_INFO (a8r8g8b8),
2721 FORMAT_INFO (x8r8g8b8),
2722 FORMAT_INFO (a8b8g8r8),
2723 FORMAT_INFO (x8b8g8r8),
2724 FORMAT_INFO (b8g8r8a8),
2725 FORMAT_INFO (b8g8r8x8),
2728 FORMAT_INFO (r8g8b8),
2729 FORMAT_INFO (b8g8r8),
2732 FORMAT_INFO (r5g6b5),
2733 FORMAT_INFO (b5g6r5),
2735 FORMAT_INFO (a1r5g5b5),
2736 FORMAT_INFO (x1r5g5b5),
2737 FORMAT_INFO (a1b5g5r5),
2738 FORMAT_INFO (x1b5g5r5),
2739 FORMAT_INFO (a4r4g4b4),
2740 FORMAT_INFO (x4r4g4b4),
2741 FORMAT_INFO (a4b4g4r4),
2742 FORMAT_INFO (x4b4g4r4),
2746 FORMAT_INFO (r3g3b2),
2747 FORMAT_INFO (b2g3r3),
2748 FORMAT_INFO (a2r2g2b2),
2749 FORMAT_INFO (a2b2g2r2),
2753 #define fetch_scanline_g8 fetch_scanline_c8
2754 #define fetch_pixels_g8 fetch_pixels_c8
2755 #define store_scanline_g8 store_scanline_c8
2757 #define fetch_scanline_x4c4 fetch_scanline_c8
2758 #define fetch_pixels_x4c4 fetch_pixels_c8
2759 #define store_scanline_x4c4 store_scanline_c8
2761 #define fetch_scanline_x4g4 fetch_scanline_c8
2762 #define fetch_pixels_x4g4 fetch_pixels_c8
2763 #define store_scanline_x4g4 store_scanline_c8
2770 FORMAT_INFO (r1g2b1),
2771 FORMAT_INFO (b1g2r1),
2772 FORMAT_INFO (a1r1g1b1),
2773 FORMAT_INFO (a1b1g1r1),
2776 #define fetch_scanline_g4 fetch_scanline_c4
2777 #define fetch_pixels_g4 fetch_pixels_c4
2778 #define store_scanline_g4 store_scanline_c4
2787 { PIXMAN_a2r10g10b10,
2788 NULL, fetch_scanline_a2r10g10b10,
2789 fetch_pixels_generic_lossy_32, fetch_pixels_a2r10g10b10_64,
2790 NULL, store_scanline_a2r10g10b10 },
2792 { PIXMAN_x2r10g10b10,
2793 NULL, fetch_scanline_x2r10g10b10,
2794 fetch_pixels_generic_lossy_32, fetch_pixels_x2r10g10b10_64,
2795 NULL, store_scanline_x2r10g10b10 },
2797 { PIXMAN_a2b10g10r10,
2798 NULL, fetch_scanline_a2b10g10r10,
2799 fetch_pixels_generic_lossy_32, fetch_pixels_a2b10g10r10_64,
2800 NULL, store_scanline_a2b10g10r10 },
2802 { PIXMAN_x2b10g10r10,
2803 NULL, fetch_scanline_x2b10g10r10,
2804 fetch_pixels_generic_lossy_32, fetch_pixels_x2b10g10r10_64,
2805 NULL, store_scanline_x2b10g10r10 },
2809 fetch_scanline_yuy2, fetch_scanline_generic_64,
2810 fetch_pixels_yuy2, fetch_pixels_generic_64,
2814 fetch_scanline_yv12, fetch_scanline_generic_64,
2815 fetch_pixels_yv12, fetch_pixels_generic_64,
2822 setup_accessors (bits_image_t *image)
2824 const format_info_t *info = accessors;
2826 while (info->format != PIXMAN_null)
2828 if (info->format == image->format)
2830 image->fetch_scanline_raw_32 = info->fetch_scanline_raw_32;
2831 image->fetch_scanline_raw_64 = info->fetch_scanline_raw_64;
2832 image->fetch_pixels_raw_32 = info->fetch_pixels_raw_32;
2833 image->fetch_pixels_raw_64 = info->fetch_pixels_raw_64;
2834 image->store_scanline_raw_32 = info->store_scanline_raw_32;
2835 image->store_scanline_raw_64 = info->store_scanline_raw_64;
2844 #ifndef PIXMAN_FB_ACCESSORS
2846 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image);
2849 _pixman_bits_image_setup_raw_accessors (bits_image_t *image)
2851 if (image->common.read_func || image->common.write_func)
2852 _pixman_bits_image_setup_raw_accessors_accessors (image);
2854 setup_accessors (image);
2860 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image)
2862 setup_accessors (image);