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 CvtR8G8B8toY15(s) (((((s) >> 16) & 0xff) * 153 + \
39 (((s) >> 8) & 0xff) * 301 + \
40 (((s) ) & 0xff) * 58) >> 2)
41 #define miCvtR8G8B8to15(s) ((((s) >> 3) & 0x001f) | \
42 (((s) >> 6) & 0x03e0) | \
43 (((s) >> 9) & 0x7c00))
44 #define miIndexToEnt15(mif,rgb15) ((mif)->ent[rgb15])
45 #define miIndexToEnt24(mif,rgb24) miIndexToEnt15(mif,miCvtR8G8B8to15(rgb24))
47 #define miIndexToEntY24(mif,rgb24) ((mif)->ent[CvtR8G8B8toY15(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 fbFetch_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 fbFetch_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 fbFetch_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 fbFetch_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 fbFetch_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 fbFetch_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 fbFetch_a2b10g10r10 (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 b = (p >> 20) & 0x3ff;
181 uint64_t g = (p >> 10) & 0x3ff;
182 uint64_t r = p & 0x3ff;
193 *buffer++ = a << 48 | r << 32 | g << 16 | b;
197 /* Expects a uint64_t buffer */
199 fbFetch_x2b10g10r10 (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 b = (p >> 20) & 0x3ff;
210 uint64_t g = (p >> 10) & 0x3ff;
211 uint64_t r = p & 0x3ff;
217 *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
222 fbFetch_r8g8b8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
223 const uint32_t *mask, uint32_t mask_bits)
225 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
226 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
227 const uint8_t *end = pixel + 3*width;
228 while (pixel < end) {
229 uint32_t b = 0xff000000;
230 #ifdef WORDS_BIGENDIAN
231 b |= (READ(image, pixel++) << 16);
232 b |= (READ(image, pixel++) << 8);
233 b |= (READ(image, pixel++));
235 b |= (READ(image, pixel++));
236 b |= (READ(image, pixel++) << 8);
237 b |= (READ(image, pixel++) << 16);
244 fbFetch_b8g8r8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
245 const uint32_t *mask, uint32_t mask_bits)
247 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
248 const uint8_t *pixel = (const uint8_t *)bits + 3*x;
249 const uint8_t *end = pixel + 3*width;
250 while (pixel < end) {
251 uint32_t b = 0xff000000;
252 #ifdef WORDS_BIGENDIAN
253 b |= (READ(image, pixel++));
254 b |= (READ(image, pixel++) << 8);
255 b |= (READ(image, pixel++) << 16);
257 b |= (READ(image, pixel++) << 16);
258 b |= (READ(image, pixel++) << 8);
259 b |= (READ(image, pixel++));
266 fbFetch_r5g6b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
267 const uint32_t *mask, uint32_t mask_bits)
269 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
270 const uint16_t *pixel = (const uint16_t *)bits + x;
271 const uint16_t *end = pixel + width;
272 while (pixel < end) {
273 uint32_t p = READ(image, pixel++);
274 uint32_t r = (((p) << 3) & 0xf8) |
275 (((p) << 5) & 0xfc00) |
276 (((p) << 8) & 0xf80000);
277 r |= (r >> 5) & 0x70007;
278 r |= (r >> 6) & 0x300;
279 *buffer++ = 0xff000000 | r;
284 fbFetch_b5g6r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
285 const uint32_t *mask, uint32_t mask_bits)
288 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
289 const uint16_t *pixel = (const uint16_t *)bits + x;
290 const uint16_t *end = pixel + width;
291 while (pixel < end) {
292 uint32_t p = READ(image, pixel++);
293 b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
294 g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
295 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
296 *buffer++ = 0xff000000 | r | g | b;
301 fbFetch_a1r5g5b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
302 const uint32_t *mask, uint32_t mask_bits)
305 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
306 const uint16_t *pixel = (const uint16_t *)bits + x;
307 const uint16_t *end = pixel + width;
308 while (pixel < end) {
309 uint32_t p = READ(image, pixel++);
311 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
312 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
313 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
314 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
315 *buffer++ = a | r | g | b;
320 fbFetch_x1r5g5b5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
321 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++);
330 r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
331 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
332 b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
333 *buffer++ = 0xff000000 | r | g | b;
338 fbFetch_a1b5g5r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
339 const uint32_t *mask, uint32_t mask_bits)
342 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
343 const uint16_t *pixel = (const uint16_t *)bits + x;
344 const uint16_t *end = pixel + width;
345 while (pixel < end) {
346 uint32_t p = READ(image, pixel++);
348 a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
349 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
350 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
351 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
352 *buffer++ = a | r | g | b;
357 fbFetch_x1b5g5r5 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
358 const uint32_t *mask, uint32_t mask_bits)
361 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
362 const uint16_t *pixel = (const uint16_t *)bits + x;
363 const uint16_t *end = pixel + width;
364 while (pixel < end) {
365 uint32_t p = READ(image, pixel++);
367 b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
368 g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
369 r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
370 *buffer++ = 0xff000000 | r | g | b;
375 fbFetch_a4r4g4b4 (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 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
386 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
387 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
388 b = ((p & 0x000f) | ((p & 0x000f) << 4));
389 *buffer++ = a | r | g | b;
394 fbFetch_x4r4g4b4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
395 const uint32_t *mask, uint32_t mask_bits)
398 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
399 const uint16_t *pixel = (const uint16_t *)bits + x;
400 const uint16_t *end = pixel + width;
401 while (pixel < end) {
402 uint32_t p = READ(image, pixel++);
404 r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
405 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
406 b = ((p & 0x000f) | ((p & 0x000f) << 4));
407 *buffer++ = 0xff000000 | r | g | b;
412 fbFetch_a4b4g4r4 (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 a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
423 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
424 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
425 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
426 *buffer++ = a | r | g | b;
431 fbFetch_x4b4g4r4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
432 const uint32_t *mask, uint32_t mask_bits)
435 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
436 const uint16_t *pixel = (const uint16_t *)bits + x;
437 const uint16_t *end = pixel + width;
438 while (pixel < end) {
439 uint32_t p = READ(image, pixel++);
441 b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
442 g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
443 r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
444 *buffer++ = 0xff000000 | r | g | b;
449 fbFetch_a8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
450 const uint32_t *mask, uint32_t mask_bits)
452 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
453 const uint8_t *pixel = (const uint8_t *)bits + x;
454 const uint8_t *end = pixel + width;
455 while (pixel < end) {
456 *buffer++ = READ(image, pixel++) << 24;
461 fbFetch_r3g3b2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
462 const uint32_t *mask, uint32_t mask_bits)
465 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
466 const uint8_t *pixel = (const uint8_t *)bits + x;
467 const uint8_t *end = pixel + width;
468 while (pixel < end) {
469 uint32_t p = READ(image, pixel++);
471 r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
472 g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
477 *buffer++ = 0xff000000 | r | g | b;
482 fbFetch_b2g3r3 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
483 const uint32_t *mask, uint32_t mask_bits)
486 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
487 const uint8_t *pixel = (const uint8_t *)bits + x;
488 const uint8_t *end = pixel + width;
489 while (pixel < end) {
490 uint32_t p = READ(image, pixel++);
496 g = ((p & 0x38) | ((p & 0x38) >> 3) | ((p & 0x30) << 2)) << 8;
499 ((p & 0x06) << 6)) << 16;
500 *buffer++ = 0xff000000 | r | g | b;
505 fbFetch_a2r2g2b2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
506 const uint32_t *mask, uint32_t mask_bits)
509 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
510 const uint8_t *pixel = (const uint8_t *)bits + x;
511 const uint8_t *end = pixel + width;
512 while (pixel < end) {
513 uint32_t p = READ(image, pixel++);
515 a = ((p & 0xc0) * 0x55) << 18;
516 r = ((p & 0x30) * 0x55) << 12;
517 g = ((p & 0x0c) * 0x55) << 6;
518 b = ((p & 0x03) * 0x55);
524 fbFetch_a2b2g2r2 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
525 const uint32_t *mask, uint32_t mask_bits)
528 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
529 const uint8_t *pixel = (const uint8_t *)bits + x;
530 const uint8_t *end = pixel + width;
531 while (pixel < end) {
532 uint32_t p = READ(image, pixel++);
534 a = ((p & 0xc0) * 0x55) << 18;
535 b = ((p & 0x30) * 0x55) >> 6;
536 g = ((p & 0x0c) * 0x55) << 6;
537 r = ((p & 0x03) * 0x55) << 16;
543 fbFetch_c8 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
544 const uint32_t *mask, uint32_t mask_bits)
546 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
547 const pixman_indexed_t * indexed = image->bits.indexed;
548 const uint8_t *pixel = (const uint8_t *)bits + x;
549 const uint8_t *end = pixel + width;
550 while (pixel < end) {
551 uint32_t p = READ(image, pixel++);
552 *buffer++ = indexed->rgba[p];
557 fbFetch_x4a4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
558 const uint32_t *mask, uint32_t mask_bits)
560 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
561 const uint8_t *pixel = (const uint8_t *)bits + x;
562 const uint8_t *end = pixel + width;
563 while (pixel < end) {
564 uint8_t p = READ(image, pixel++) & 0xf;
565 *buffer++ = (p | (p << 4)) << 24;
569 #define Fetch8(img,l,o) (READ(img, (uint8_t *)(l) + ((o) >> 2)))
570 #ifdef WORDS_BIGENDIAN
571 #define Fetch4(img,l,o) ((o) & 2 ? Fetch8(img,l,o) & 0xf : Fetch8(img,l,o) >> 4)
573 #define Fetch4(img,l,o) ((o) & 2 ? Fetch8(img,l,o) >> 4 : Fetch8(img,l,o) & 0xf)
577 fbFetch_a4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
578 const uint32_t *mask, uint32_t mask_bits)
580 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
582 for (i = 0; i < width; ++i) {
583 uint32_t p = Fetch4(image, bits, i + x);
591 fbFetch_r1g2b1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
592 const uint32_t *mask, uint32_t mask_bits)
595 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
597 for (i = 0; i < width; ++i) {
598 uint32_t p = Fetch4(image, bits, i + x);
600 r = ((p & 0x8) * 0xff) << 13;
601 g = ((p & 0x6) * 0x55) << 7;
602 b = ((p & 0x1) * 0xff);
603 *buffer++ = 0xff000000|r|g|b;
608 fbFetch_b1g2r1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
609 const uint32_t *mask, uint32_t mask_bits)
612 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
614 for (i = 0; i < width; ++i) {
615 uint32_t p = Fetch4(image, bits, i + x);
617 b = ((p & 0x8) * 0xff) >> 3;
618 g = ((p & 0x6) * 0x55) << 7;
619 r = ((p & 0x1) * 0xff) << 16;
620 *buffer++ = 0xff000000|r|g|b;
625 fbFetch_a1r1g1b1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
626 const uint32_t *mask, uint32_t mask_bits)
629 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
631 for (i = 0; i < width; ++i) {
632 uint32_t p = Fetch4(image, bits, i + x);
634 a = ((p & 0x8) * 0xff) << 21;
635 r = ((p & 0x4) * 0xff) << 14;
636 g = ((p & 0x2) * 0xff) << 7;
637 b = ((p & 0x1) * 0xff);
643 fbFetch_a1b1g1r1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
644 const uint32_t *mask, uint32_t mask_bits)
647 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
649 for (i = 0; i < width; ++i) {
650 uint32_t p = Fetch4(image, bits, i + x);
652 a = ((p & 0x8) * 0xff) << 21;
653 r = ((p & 0x4) * 0xff) >> 3;
654 g = ((p & 0x2) * 0xff) << 7;
655 b = ((p & 0x1) * 0xff) << 16;
661 fbFetch_c4 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
662 const uint32_t *mask, uint32_t mask_bits)
664 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
665 const pixman_indexed_t * indexed = image->bits.indexed;
667 for (i = 0; i < width; ++i) {
668 uint32_t p = Fetch4 (image, bits, i + x);
670 *buffer++ = indexed->rgba[p];
676 fbFetch_a1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
677 const uint32_t *mask, uint32_t mask_bits)
679 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
681 for (i = 0; i < width; ++i) {
682 uint32_t p = READ(image, bits + ((i + x) >> 5));
684 #ifdef WORDS_BIGENDIAN
685 a = p >> (0x1f - ((i+x) & 0x1f));
687 a = p >> ((i+x) & 0x1f);
698 fbFetch_g1 (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
699 const uint32_t *mask, uint32_t mask_bits)
701 const uint32_t *bits = image->bits.bits + y*image->bits.rowstride;
702 const pixman_indexed_t * indexed = image->bits.indexed;
704 for (i = 0; i < width; ++i) {
705 uint32_t p = READ(image, bits + ((i+x) >> 5));
707 #ifdef WORDS_BIGENDIAN
708 a = p >> (0x1f - ((i+x) & 0x1f));
710 a = p >> ((i+x) & 0x1f);
713 *buffer++ = indexed->rgba[a];
718 fbFetch_yuy2 (pixman_image_t *image, int x, int line, int width, uint32_t *buffer,
719 const uint32_t *mask, uint32_t mask_bits)
725 const uint32_t *bits = image->bits.bits + image->bits.rowstride * line;
727 for (i = 0; i < width; i++)
729 y = ((uint8_t *) bits)[(x + i) << 1] - 16;
730 u = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 1] - 128;
731 v = ((uint8_t *) bits)[(((x + i) << 1) & -4) + 3] - 128;
733 /* R = 1.164(Y - 16) + 1.596(V - 128) */
734 r = 0x012b27 * y + 0x019a2e * v;
735 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
736 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
737 /* B = 1.164(Y - 16) + 2.018(U - 128) */
738 b = 0x012b27 * y + 0x0206a2 * u;
740 *buffer++ = 0xff000000 |
741 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
742 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
743 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
748 fbFetch_yv12 (pixman_image_t *image, int x, int line, int width, uint32_t *buffer,
749 const uint32_t *mask, uint32_t mask_bits)
752 uint8_t *pY = YV12_Y (line);
753 uint8_t *pU = YV12_U (line);
754 uint8_t *pV = YV12_V (line);
759 for (i = 0; i < width; i++)
762 u = pU[(x + i) >> 1] - 128;
763 v = pV[(x + i) >> 1] - 128;
765 /* R = 1.164(Y - 16) + 1.596(V - 128) */
766 r = 0x012b27 * y + 0x019a2e * v;
767 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
768 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
769 /* B = 1.164(Y - 16) + 2.018(U - 128) */
770 b = 0x012b27 * y + 0x0206a2 * u;
772 *buffer++ = 0xff000000 |
773 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
774 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
775 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
779 /**************************** Pixel wise fetching *****************************/
781 /* Despite the type, expects a uint64_t buffer */
783 fbFetchPixel_a2b10g10r10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
786 uint64_t *buffer = (uint64_t *)b;
788 for (i = 0; i < n_pixels; ++i)
790 int offset = ((uint32_t *)buffer)[2 * i];
791 int line = ((uint32_t *)buffer)[2 * i + 1];
793 if (offset == 0xffffffff || line == 0xffffffff)
799 uint32_t *bits = pict->bits + line*pict->rowstride;
800 uint32_t p = READ(pict, bits + offset);
801 uint64_t a = p >> 30;
802 uint64_t b = (p >> 20) & 0x3ff;
803 uint64_t g = (p >> 10) & 0x3ff;
804 uint64_t r = p & 0x3ff;
815 buffer[i] = a << 48 | r << 32 | g << 16 | b;
820 /* Despite the type, this function expects a uint64_t buffer */
822 fbFetchPixel_x2b10g10r10_64 (bits_image_t *pict, uint32_t *b, int n_pixels)
824 uint64_t *buffer = (uint64_t *)b;
827 for (i = 0; i < n_pixels; ++i)
829 int offset = ((uint32_t *)buffer)[2 * i];
830 int line = ((uint32_t *)buffer)[2 * i + 1];
832 if (offset == 0xffffffff || line == 0xffffffff)
838 uint32_t *bits = pict->bits + line*pict->rowstride;
839 uint32_t p = READ(pict, bits + offset);
840 uint64_t b = (p >> 20) & 0x3ff;
841 uint64_t g = (p >> 10) & 0x3ff;
842 uint64_t r = p & 0x3ff;
848 buffer[i] = 0xffffULL << 48 | r << 32 | g << 16 | b;
854 fbFetchPixel_a8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
858 for (i = 0; i < n_pixels; ++i)
860 int offset = buffer[2 * i];
861 int line = buffer[2 * i + 1];
863 if (offset == 0xffffffff || line == 0xffffffff)
869 uint32_t *bits = pict->bits + line*pict->rowstride;
870 buffer[i] = READ(pict, (uint32_t *)bits + offset);
876 fbFetchPixel_x8r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
880 for (i = 0; i < n_pixels; ++i)
882 int offset = buffer[2 * i];
883 int line = buffer[2 * i + 1];
885 if (offset == 0xffffffff || line == 0xffffffff)
891 uint32_t *bits = pict->bits + line*pict->rowstride;
892 buffer[i] = READ(pict, (uint32_t *)bits + offset) | 0xff000000;
898 fbFetchPixel_a8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
902 for (i = 0; i < n_pixels; ++i)
904 int offset = buffer[2 * i];
905 int line = buffer[2 * i + 1];
907 if (offset == 0xffffffff || line == 0xffffffff)
913 uint32_t *bits = pict->bits + line*pict->rowstride;
914 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
916 buffer[i] = ((pixel & 0xff000000) |
917 ((pixel >> 16) & 0xff) |
918 (pixel & 0x0000ff00) |
919 ((pixel & 0xff) << 16));
925 fbFetchPixel_x8b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
929 for (i = 0; i < n_pixels; ++i)
931 int offset = buffer[2 * i];
932 int line = buffer[2 * i + 1];
934 if (offset == 0xffffffff || line == 0xffffffff)
940 uint32_t *bits = pict->bits + line*pict->rowstride;
941 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
943 buffer[i] = ((0xff000000) |
944 ((pixel >> 16) & 0xff) |
945 (pixel & 0x0000ff00) |
946 ((pixel & 0xff) << 16));
952 fbFetchPixel_b8g8r8a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
956 for (i = 0; i < n_pixels; ++i)
958 int offset = buffer[2 * i];
959 int line = buffer[2 * i + 1];
961 if (offset == 0xffffffff || line == 0xffffffff)
967 uint32_t *bits = pict->bits + line*pict->rowstride;
968 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
970 buffer[i] = ((pixel & 0xff000000) >> 24 |
971 (pixel & 0x00ff0000) >> 8 |
972 (pixel & 0x0000ff00) << 8 |
973 (pixel & 0x000000ff) << 24);
979 fbFetchPixel_b8g8r8x8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
983 for (i = 0; i < n_pixels; ++i)
985 int offset = buffer[2 * i];
986 int line = buffer[2 * i + 1];
988 if (offset == 0xffffffff || line == 0xffffffff)
994 uint32_t *bits = pict->bits + line*pict->rowstride;
995 uint32_t pixel = READ(pict, (uint32_t *)bits + offset);
997 buffer[i] = ((0xff000000) |
998 (pixel & 0xff000000) >> 24 |
999 (pixel & 0x00ff0000) >> 8 |
1000 (pixel & 0x0000ff00) << 8);
1006 fbFetchPixel_r8g8b8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1010 for (i = 0; i < n_pixels; ++i)
1012 int offset = buffer[2 * i];
1013 int line = buffer[2 * i + 1];
1015 if (offset == 0xffffffff || line == 0xffffffff)
1021 uint32_t *bits = pict->bits + line*pict->rowstride;
1022 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1023 #ifdef WORDS_BIGENDIAN
1024 buffer[i] = (0xff000000 |
1025 (READ(pict, pixel + 0) << 16) |
1026 (READ(pict, pixel + 1) << 8) |
1027 (READ(pict, pixel + 2)));
1029 buffer[i] = (0xff000000 |
1030 (READ(pict, pixel + 2) << 16) |
1031 (READ(pict, pixel + 1) << 8) |
1032 (READ(pict, pixel + 0)));
1039 fbFetchPixel_b8g8r8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1043 for (i = 0; i < n_pixels; ++i)
1045 int offset = buffer[2 * i];
1046 int line = buffer[2 * i + 1];
1048 if (offset == 0xffffffff || line == 0xffffffff)
1054 uint32_t *bits = pict->bits + line*pict->rowstride;
1055 uint8_t *pixel = ((uint8_t *) bits) + (offset*3);
1056 #ifdef WORDS_BIGENDIAN
1057 buffer[i] = (0xff000000 |
1058 (READ(pict, pixel + 2) << 16) |
1059 (READ(pict, pixel + 1) << 8) |
1060 (READ(pict, pixel + 0)));
1062 buffer[i] = (0xff000000 |
1063 (READ(pict, pixel + 0) << 16) |
1064 (READ(pict, pixel + 1) << 8) |
1065 (READ(pict, pixel + 2)));
1072 fbFetchPixel_r5g6b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1076 for (i = 0; i < n_pixels; ++i)
1078 int offset = buffer[2 * i];
1079 int line = buffer[2 * i + 1];
1081 if (offset == 0xffffffff || line == 0xffffffff)
1088 uint32_t *bits = pict->bits + line*pict->rowstride;
1089 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1091 r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1092 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1093 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1094 buffer[i] = (0xff000000 | r | g | b);
1100 fbFetchPixel_b5g6r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1104 for (i = 0; i < n_pixels; ++i)
1106 int offset = buffer[2 * i];
1107 int line = buffer[2 * i + 1];
1109 if (offset == 0xffffffff || line == 0xffffffff)
1116 uint32_t *bits = pict->bits + line*pict->rowstride;
1117 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1119 b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1120 g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1121 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1122 buffer[i] = (0xff000000 | r | g | b);
1128 fbFetchPixel_a1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1132 for (i = 0; i < n_pixels; ++i)
1134 int offset = buffer[2 * i];
1135 int line = buffer[2 * i + 1];
1137 if (offset == 0xffffffff || line == 0xffffffff)
1144 uint32_t *bits = pict->bits + line*pict->rowstride;
1145 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1147 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1148 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1149 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1150 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1151 buffer[i] = (a | r | g | b);
1157 fbFetchPixel_x1r5g5b5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1161 for (i = 0; i < n_pixels; ++i)
1163 int offset = buffer[2 * i];
1164 int line = buffer[2 * i + 1];
1166 if (offset == 0xffffffff || line == 0xffffffff)
1173 uint32_t *bits = pict->bits + line*pict->rowstride;
1174 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1176 r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1177 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1178 b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1179 buffer[i] = (0xff000000 | r | g | b);
1185 fbFetchPixel_a1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1189 for (i = 0; i < n_pixels; ++i)
1191 int offset = buffer[2 * i];
1192 int line = buffer[2 * i + 1];
1194 if (offset == 0xffffffff || line == 0xffffffff)
1201 uint32_t *bits = pict->bits + line*pict->rowstride;
1202 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1204 a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1205 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1206 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1207 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1208 buffer[i] = (a | r | g | b);
1214 fbFetchPixel_x1b5g5r5 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1218 for (i = 0; i < n_pixels; ++i)
1220 int offset = buffer[2 * i];
1221 int line = buffer[2 * i + 1];
1223 if (offset == 0xffffffff || line == 0xffffffff)
1230 uint32_t *bits = pict->bits + line*pict->rowstride;
1231 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1233 b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1234 g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1235 r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1236 buffer[i] = (0xff000000 | r | g | b);
1242 fbFetchPixel_a4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1246 for (i = 0; i < n_pixels; ++i)
1248 int offset = buffer[2 * i];
1249 int line = buffer[2 * i + 1];
1251 if (offset == 0xffffffff || line == 0xffffffff)
1258 uint32_t *bits = pict->bits + line*pict->rowstride;
1259 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1261 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1262 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1263 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1264 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1265 buffer[i] = (a | r | g | b);
1271 fbFetchPixel_x4r4g4b4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1275 for (i = 0; i < n_pixels; ++i)
1277 int offset = buffer[2 * i];
1278 int line = buffer[2 * i + 1];
1280 if (offset == 0xffffffff || line == 0xffffffff)
1287 uint32_t *bits = pict->bits + line*pict->rowstride;
1288 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1290 r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1291 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1292 b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1293 buffer[i] = (0xff000000 | r | g | b);
1299 fbFetchPixel_a4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1303 for (i = 0; i < n_pixels; ++i)
1305 int offset = buffer[2 * i];
1306 int line = buffer[2 * i + 1];
1308 if (offset == 0xffffffff || line == 0xffffffff)
1315 uint32_t *bits = pict->bits + line*pict->rowstride;
1316 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1318 a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1319 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1320 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1321 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1322 buffer[i] = (a | r | g | b);
1328 fbFetchPixel_x4b4g4r4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1332 for (i = 0; i < n_pixels; ++i)
1334 int offset = buffer[2 * i];
1335 int line = buffer[2 * i + 1];
1337 if (offset == 0xffffffff || line == 0xffffffff)
1344 uint32_t *bits = pict->bits + line*pict->rowstride;
1345 uint32_t pixel = READ(pict, (uint16_t *) bits + offset);
1347 b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1348 g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1349 r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1350 buffer[i] = (0xff000000 | r | g | b);
1356 fbFetchPixel_a8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1360 for (i = 0; i < n_pixels; ++i)
1362 int offset = buffer[2 * i];
1363 int line = buffer[2 * i + 1];
1365 if (offset == 0xffffffff || line == 0xffffffff)
1371 uint32_t *bits = pict->bits + line*pict->rowstride;
1372 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1374 buffer[i] = pixel << 24;
1380 fbFetchPixel_r3g3b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1384 for (i = 0; i < n_pixels; ++i)
1386 int offset = buffer[2 * i];
1387 int line = buffer[2 * i + 1];
1389 if (offset == 0xffffffff || line == 0xffffffff)
1396 uint32_t *bits = pict->bits + line*pict->rowstride;
1397 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1399 r = ((pixel & 0xe0) | ((pixel & 0xe0) >> 3) | ((pixel & 0xc0) >> 6)) << 16;
1400 g = ((pixel & 0x1c) | ((pixel & 0x18) >> 3) | ((pixel & 0x1c) << 3)) << 8;
1401 b = (((pixel & 0x03) ) |
1402 ((pixel & 0x03) << 2) |
1403 ((pixel & 0x03) << 4) |
1404 ((pixel & 0x03) << 6));
1405 buffer[i] = (0xff000000 | r | g | b);
1411 fbFetchPixel_b2g3r3 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1415 for (i = 0; i < n_pixels; ++i)
1417 int offset = buffer[2 * i];
1418 int line = buffer[2 * i + 1];
1420 if (offset == 0xffffffff || line == 0xffffffff)
1427 uint32_t *bits = pict->bits + line*pict->rowstride;
1428 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1430 b = (((pixel & 0xc0) ) |
1431 ((pixel & 0xc0) >> 2) |
1432 ((pixel & 0xc0) >> 4) |
1433 ((pixel & 0xc0) >> 6));
1434 g = ((pixel & 0x38) | ((pixel & 0x38) >> 3) | ((pixel & 0x30) << 2)) << 8;
1435 r = (((pixel & 0x07) ) |
1436 ((pixel & 0x07) << 3) |
1437 ((pixel & 0x06) << 6)) << 16;
1438 buffer[i] = (0xff000000 | r | g | b);
1444 fbFetchPixel_a2r2g2b2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1448 for (i = 0; i < n_pixels; ++i)
1450 int offset = buffer[2 * i];
1451 int line = buffer[2 * i + 1];
1453 if (offset == 0xffffffff || line == 0xffffffff)
1460 uint32_t *bits = pict->bits + line*pict->rowstride;
1461 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1463 a = ((pixel & 0xc0) * 0x55) << 18;
1464 r = ((pixel & 0x30) * 0x55) << 12;
1465 g = ((pixel & 0x0c) * 0x55) << 6;
1466 b = ((pixel & 0x03) * 0x55);
1467 buffer[i] = a|r|g|b;
1473 fbFetchPixel_a2b2g2r2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1477 for (i = 0; i < n_pixels; ++i)
1479 int offset = buffer[2 * i];
1480 int line = buffer[2 * i + 1];
1482 if (offset == 0xffffffff || line == 0xffffffff)
1489 uint32_t *bits = pict->bits + line*pict->rowstride;
1490 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1492 a = ((pixel & 0xc0) * 0x55) << 18;
1493 b = ((pixel & 0x30) * 0x55) >> 6;
1494 g = ((pixel & 0x0c) * 0x55) << 6;
1495 r = ((pixel & 0x03) * 0x55) << 16;
1496 buffer[i] = a|r|g|b;
1502 fbFetchPixel_c8 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1506 for (i = 0; i < n_pixels; ++i)
1508 int offset = buffer[2 * i];
1509 int line = buffer[2 * i + 1];
1511 if (offset == 0xffffffff || line == 0xffffffff)
1517 uint32_t *bits = pict->bits + line*pict->rowstride;
1518 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1519 const pixman_indexed_t * indexed = pict->indexed;
1520 buffer[i] = indexed->rgba[pixel];
1526 fbFetchPixel_x4a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1530 for (i = 0; i < n_pixels; ++i)
1532 int offset = buffer[2 * i];
1533 int line = buffer[2 * i + 1];
1535 if (offset == 0xffffffff || line == 0xffffffff)
1541 uint32_t *bits = pict->bits + line*pict->rowstride;
1542 uint32_t pixel = READ(pict, (uint8_t *) bits + offset);
1544 buffer[i] = ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1550 fbFetchPixel_a4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1554 for (i = 0; i < n_pixels; ++i)
1556 int offset = buffer[2 * i];
1557 int line = buffer[2 * i + 1];
1559 if (offset == 0xffffffff || line == 0xffffffff)
1565 uint32_t *bits = pict->bits + line*pict->rowstride;
1566 uint32_t pixel = Fetch4 (pict, bits, offset);
1568 pixel |= pixel << 4;
1569 buffer[i] = pixel << 24;
1575 fbFetchPixel_r1g2b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1579 for (i = 0; i < n_pixels; ++i)
1581 int offset = buffer[2 * i];
1582 int line = buffer[2 * i + 1];
1584 if (offset == 0xffffffff || line == 0xffffffff)
1591 uint32_t *bits = pict->bits + line*pict->rowstride;
1592 uint32_t pixel = Fetch4 (pict, bits, offset);
1594 r = ((pixel & 0x8) * 0xff) << 13;
1595 g = ((pixel & 0x6) * 0x55) << 7;
1596 b = ((pixel & 0x1) * 0xff);
1597 buffer[i] = 0xff000000|r|g|b;
1603 fbFetchPixel_b1g2r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1607 for (i = 0; i < n_pixels; ++i)
1609 int offset = buffer[2 * i];
1610 int line = buffer[2 * i + 1];
1612 if (offset == 0xffffffff || line == 0xffffffff)
1619 uint32_t *bits = pict->bits + line*pict->rowstride;
1620 uint32_t pixel = Fetch4 (pict, bits, offset);
1622 b = ((pixel & 0x8) * 0xff) >> 3;
1623 g = ((pixel & 0x6) * 0x55) << 7;
1624 r = ((pixel & 0x1) * 0xff) << 16;
1625 buffer[i] = 0xff000000|r|g|b;
1631 fbFetchPixel_a1r1g1b1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1635 for (i = 0; i < n_pixels; ++i)
1637 int offset = buffer[2 * i];
1638 int line = buffer[2 * i + 1];
1640 if (offset == 0xffffffff || line == 0xffffffff)
1647 uint32_t *bits = pict->bits + line*pict->rowstride;
1648 uint32_t pixel = Fetch4 (pict, bits, offset);
1650 a = ((pixel & 0x8) * 0xff) << 21;
1651 r = ((pixel & 0x4) * 0xff) << 14;
1652 g = ((pixel & 0x2) * 0xff) << 7;
1653 b = ((pixel & 0x1) * 0xff);
1654 buffer[i] = a|r|g|b;
1660 fbFetchPixel_a1b1g1r1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1664 for (i = 0; i < n_pixels; ++i)
1666 int offset = buffer[2 * i];
1667 int line = buffer[2 * i + 1];
1669 if (offset == 0xffffffff || line == 0xffffffff)
1676 uint32_t *bits = pict->bits + line*pict->rowstride;
1677 uint32_t pixel = Fetch4 (pict, bits, offset);
1679 a = ((pixel & 0x8) * 0xff) << 21;
1680 r = ((pixel & 0x4) * 0xff) >> 3;
1681 g = ((pixel & 0x2) * 0xff) << 7;
1682 b = ((pixel & 0x1) * 0xff) << 16;
1683 buffer[i] = a|r|g|b;
1689 fbFetchPixel_c4 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1693 for (i = 0; i < n_pixels; ++i)
1695 int offset = buffer[2 * i];
1696 int line = buffer[2 * i + 1];
1698 if (offset == 0xffffffff || line == 0xffffffff)
1704 uint32_t *bits = pict->bits + line*pict->rowstride;
1705 uint32_t pixel = Fetch4 (pict, bits, offset);
1706 const pixman_indexed_t * indexed = pict->indexed;
1708 buffer[i] = indexed->rgba[pixel];
1715 fbFetchPixel_a1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1719 for (i = 0; i < n_pixels; ++i)
1721 int offset = buffer[2 * i];
1722 int line = buffer[2 * i + 1];
1724 if (offset == 0xffffffff || line == 0xffffffff)
1730 uint32_t *bits = pict->bits + line*pict->rowstride;
1731 uint32_t pixel = READ(pict, bits + (offset >> 5));
1733 #ifdef WORDS_BIGENDIAN
1734 a = pixel >> (0x1f - (offset & 0x1f));
1736 a = pixel >> (offset & 0x1f);
1742 buffer[i] = a << 24;
1748 fbFetchPixel_g1 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1752 for (i = 0; i < n_pixels; ++i)
1754 int offset = buffer[2 * i];
1755 int line = buffer[2 * i + 1];
1757 if (offset == 0xffffffff || line == 0xffffffff)
1763 uint32_t *bits = pict->bits + line*pict->rowstride;
1764 uint32_t pixel = READ(pict, bits + (offset >> 5));
1765 const pixman_indexed_t * indexed = pict->indexed;
1767 #ifdef WORDS_BIGENDIAN
1768 a = pixel >> (0x1f - (offset & 0x1f));
1770 a = pixel >> (offset & 0x1f);
1773 buffer[i] = indexed->rgba[a];
1779 fbFetchPixel_yuy2 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1783 for (i = 0; i < n_pixels; ++i)
1785 int offset = buffer[2 * i];
1786 int line = buffer[2 * i + 1];
1788 if (offset == 0xffffffff || line == 0xffffffff)
1797 const uint32_t *bits = pict->bits + pict->rowstride * line;
1799 y = ((uint8_t *) bits)[offset << 1] - 16;
1800 u = ((uint8_t *) bits)[((offset << 1) & -4) + 1] - 128;
1801 v = ((uint8_t *) bits)[((offset << 1) & -4) + 3] - 128;
1803 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1804 r = 0x012b27 * y + 0x019a2e * v;
1805 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1806 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1807 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1808 b = 0x012b27 * y + 0x0206a2 * u;
1810 buffer[i] = 0xff000000 |
1811 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1812 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1813 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1819 fbFetchPixel_yv12 (bits_image_t *pict, uint32_t *buffer, int n_pixels)
1823 for (i = 0; i < n_pixels; ++i)
1825 int offset = buffer[2 * i];
1826 int line = buffer[2 * i + 1];
1828 if (offset == 0xffffffff || line == 0xffffffff)
1835 int16_t y = YV12_Y (line)[offset] - 16;
1836 int16_t u = YV12_U (line)[offset >> 1] - 128;
1837 int16_t v = YV12_V (line)[offset >> 1] - 128;
1840 /* R = 1.164(Y - 16) + 1.596(V - 128) */
1841 r = 0x012b27 * y + 0x019a2e * v;
1842 /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1843 g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1844 /* B = 1.164(Y - 16) + 2.018(U - 128) */
1845 b = 0x012b27 * y + 0x0206a2 * u;
1847 buffer[i] = 0xff000000 |
1848 (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1849 (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1850 (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1855 /*********************************** Store ************************************/
1857 #define Splita(v) uint32_t a = ((v) >> 24), r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1858 #define Split(v) uint32_t r = ((v) >> 16) & 0xff, g = ((v) >> 8) & 0xff, b = (v) & 0xff
1861 fbStore_a2b10g10r10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
1863 uint32_t *bits = image->bits + image->rowstride * y;
1864 uint32_t *pixel = bits + x;
1865 uint64_t *values = (uint64_t *)v;
1868 for (i = 0; i < width; ++i) {
1869 WRITE(image, pixel++,
1870 ((values[i] >> 32) & 0xc0000000) | // A
1871 ((values[i] >> 38) & 0x3ff) | // R
1872 ((values[i] >> 12) & 0xffc00) | // G
1873 ((values[i] << 14) & 0x3ff00000)); // B
1878 fbStore_x2b10g10r10 (bits_image_t *image, int x, int y, int width, const uint32_t *v)
1880 uint32_t *bits = image->bits + image->rowstride * y;
1881 uint64_t *values = (uint64_t *)v;
1882 uint32_t *pixel = bits + x;
1885 for (i = 0; i < width; ++i) {
1886 WRITE(image, pixel++,
1887 ((values[i] >> 38) & 0x3ff) | // R
1888 ((values[i] >> 12) & 0xffc00) | // G
1889 ((values[i] << 14) & 0x3ff00000)); // B
1894 fbStore_a8r8g8b8 (bits_image_t *image,
1895 int x, int y, int width,
1896 const uint32_t *values)
1898 uint32_t *bits = image->bits + image->rowstride * y;
1900 MEMCPY_WRAPPED(image, ((uint32_t *)bits) + x, values, width*sizeof(uint32_t));
1904 fbStore_x8r8g8b8 (bits_image_t *image,
1905 int x, int y, int width,
1906 const uint32_t *values)
1908 uint32_t *bits = image->bits + image->rowstride * y;
1909 uint32_t *pixel = (uint32_t *)bits + x;
1912 for (i = 0; i < width; ++i)
1913 WRITE(image, pixel++, values[i] & 0xffffff);
1917 fbStore_a8b8g8r8 (bits_image_t *image,
1918 int x, int y, int width,
1919 const uint32_t *values)
1921 uint32_t *bits = image->bits + image->rowstride * y;
1922 uint32_t *pixel = (uint32_t *)bits + x;
1925 for (i = 0; i < width; ++i)
1926 WRITE(image, pixel++, (values[i] & 0xff00ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1930 fbStore_x8b8g8r8 (bits_image_t *image,
1931 int x, int y, int width,
1932 const uint32_t *values)
1934 uint32_t *bits = image->bits + image->rowstride * y;
1935 uint32_t *pixel = (uint32_t *)bits + x;
1938 for (i = 0; i < width; ++i)
1939 WRITE(image, pixel++, (values[i] & 0x0000ff00) | ((values[i] >> 16) & 0xff) | ((values[i] & 0xff) << 16));
1943 fbStore_b8g8r8a8 (bits_image_t *image,
1944 int x, int y, int width,
1945 const uint32_t *values)
1947 uint32_t *bits = image->bits + image->rowstride * y;
1948 uint32_t *pixel = (uint32_t *)bits + x;
1951 for (i = 0; i < width; ++i)
1952 WRITE(image, pixel++,
1953 ((values[i] >> 24) & 0x000000ff) |
1954 ((values[i] >> 8) & 0x0000ff00) |
1955 ((values[i] << 8) & 0x00ff0000) |
1956 ((values[i] << 24) & 0xff000000));
1960 fbStore_b8g8r8x8 (bits_image_t *image,
1961 int x, int y, int width,
1962 const uint32_t *values)
1964 uint32_t *bits = image->bits + image->rowstride * y;
1965 uint32_t *pixel = (uint32_t *)bits + x;
1968 for (i = 0; i < width; ++i)
1969 WRITE(image, pixel++,
1970 ((values[i] >> 8) & 0x0000ff00) |
1971 ((values[i] << 8) & 0x00ff0000) |
1972 ((values[i] << 24) & 0xff000000));
1976 fbStore_r8g8b8 (bits_image_t *image,
1977 int x, int y, int width,
1978 const uint32_t *values)
1980 uint32_t *bits = image->bits + image->rowstride * y;
1981 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
1984 for (i = 0; i < width; ++i)
1986 uint32_t val = values[i];
1987 #ifdef WORDS_BIGENDIAN
1988 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
1989 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
1990 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
1992 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
1993 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
1994 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2000 fbStore_b8g8r8 (bits_image_t *image,
2001 int x, int y, int width,
2002 const uint32_t *values)
2004 uint32_t *bits = image->bits + image->rowstride * y;
2005 uint8_t *pixel = ((uint8_t *) bits) + 3*x;
2008 for (i = 0; i < width; ++i)
2010 uint32_t val = values[i];
2011 #ifdef WORDS_BIGENDIAN
2012 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2013 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2014 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2016 WRITE(image, pixel++, (val & 0x00ff0000) >> 16);
2017 WRITE(image, pixel++, (val & 0x0000ff00) >> 8);
2018 WRITE(image, pixel++, (val & 0x000000ff) >> 0);
2024 fbStore_r5g6b5 (bits_image_t *image,
2025 int x, int y, int width,
2026 const uint32_t *values)
2028 uint32_t *bits = image->bits + image->rowstride * y;
2029 uint16_t *pixel = ((uint16_t *) bits) + x;
2032 for (i = 0; i < width; ++i) {
2033 uint32_t s = values[i];
2034 WRITE(image, pixel++, ((s >> 3) & 0x001f) |
2035 ((s >> 5) & 0x07e0) |
2036 ((s >> 8) & 0xf800));
2041 fbStore_b5g6r5 (bits_image_t *image,
2042 int x, int y, int width,
2043 const uint32_t *values)
2045 uint32_t *bits = image->bits + image->rowstride * y;
2046 uint16_t *pixel = ((uint16_t *) bits) + x;
2049 for (i = 0; i < width; ++i) {
2051 WRITE(image, pixel++, ((b << 8) & 0xf800) |
2052 ((g << 3) & 0x07e0) |
2058 fbStore_a1r5g5b5 (bits_image_t *image,
2059 int x, int y, int width,
2060 const uint32_t *values)
2062 uint32_t *bits = image->bits + image->rowstride * y;
2063 uint16_t *pixel = ((uint16_t *) bits) + x;
2066 for (i = 0; i < width; ++i) {
2068 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2069 ((r << 7) & 0x7c00) |
2070 ((g << 2) & 0x03e0) |
2076 fbStore_x1r5g5b5 (bits_image_t *image,
2077 int x, int y, int width,
2078 const uint32_t *values)
2080 uint32_t *bits = image->bits + image->rowstride * y;
2081 uint16_t *pixel = ((uint16_t *) bits) + x;
2084 for (i = 0; i < width; ++i) {
2086 WRITE(image, pixel++, ((r << 7) & 0x7c00) |
2087 ((g << 2) & 0x03e0) |
2093 fbStore_a1b5g5r5 (bits_image_t *image,
2094 int x, int y, int width,
2095 const uint32_t *values)
2097 uint32_t *bits = image->bits + image->rowstride * y;
2098 uint16_t *pixel = ((uint16_t *) bits) + x;
2101 for (i = 0; i < width; ++i) {
2103 WRITE(image, pixel++, ((a << 8) & 0x8000) |
2104 ((b << 7) & 0x7c00) |
2105 ((g << 2) & 0x03e0) |
2111 fbStore_x1b5g5r5 (bits_image_t *image,
2112 int x, int y, int width,
2113 const uint32_t *values)
2115 uint32_t *bits = image->bits + image->rowstride * y;
2116 uint16_t *pixel = ((uint16_t *) bits) + x;
2119 for (i = 0; i < width; ++i) {
2121 WRITE(image, pixel++, ((b << 7) & 0x7c00) |
2122 ((g << 2) & 0x03e0) |
2128 fbStore_a4r4g4b4 (bits_image_t *image,
2129 int x, int y, int width,
2130 const uint32_t *values)
2132 uint32_t *bits = image->bits + image->rowstride * y;
2133 uint16_t *pixel = ((uint16_t *) bits) + x;
2136 for (i = 0; i < width; ++i) {
2138 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2139 ((r << 4) & 0x0f00) |
2146 fbStore_x4r4g4b4 (bits_image_t *image,
2147 int x, int y, int width,
2148 const uint32_t *values)
2150 uint32_t *bits = image->bits + image->rowstride * y;
2151 uint16_t *pixel = ((uint16_t *) bits) + x;
2154 for (i = 0; i < width; ++i) {
2156 WRITE(image, pixel++, ((r << 4) & 0x0f00) |
2163 fbStore_a4b4g4r4 (bits_image_t *image,
2164 int x, int y, int width,
2165 const uint32_t *values)
2167 uint32_t *bits = image->bits + image->rowstride * y;
2168 uint16_t *pixel = ((uint16_t *) bits) + x;
2171 for (i = 0; i < width; ++i) {
2173 WRITE(image, pixel++, ((a << 8) & 0xf000) |
2174 ((b << 4) & 0x0f00) |
2181 fbStore_x4b4g4r4 (bits_image_t *image,
2182 int x, int y, int width,
2183 const uint32_t *values)
2185 uint32_t *bits = image->bits + image->rowstride * y;
2186 uint16_t *pixel = ((uint16_t *) bits) + x;
2189 for (i = 0; i < width; ++i) {
2191 WRITE(image, pixel++, ((b << 4) & 0x0f00) |
2198 fbStore_a8 (bits_image_t *image,
2199 int x, int y, int width,
2200 const uint32_t *values)
2202 uint32_t *bits = image->bits + image->rowstride * y;
2203 uint8_t *pixel = ((uint8_t *) bits) + x;
2206 for (i = 0; i < width; ++i) {
2207 WRITE(image, pixel++, values[i] >> 24);
2212 fbStore_r3g3b2 (bits_image_t *image,
2213 int x, int y, int width,
2214 const uint32_t *values)
2216 uint32_t *bits = image->bits + image->rowstride * y;
2217 uint8_t *pixel = ((uint8_t *) bits) + x;
2220 for (i = 0; i < width; ++i) {
2222 WRITE(image, pixel++,
2230 fbStore_b2g3r3 (bits_image_t *image,
2231 int x, int y, int width,
2232 const uint32_t *values)
2234 uint32_t *bits = image->bits + image->rowstride * y;
2235 uint8_t *pixel = ((uint8_t *) bits) + x;
2238 for (i = 0; i < width; ++i) {
2240 WRITE(image, pixel++,
2248 fbStore_a2r2g2b2 (bits_image_t *image,
2249 int x, int y, int width,
2250 const uint32_t *values)
2252 uint32_t *bits = image->bits + image->rowstride * y;
2253 uint8_t *pixel = ((uint8_t *) bits) + x;
2256 for (i = 0; i < width; ++i) {
2258 WRITE(image, pixel++, ((a ) & 0xc0) |
2266 fbStore_a2b2g2r2 (bits_image_t *image,
2267 int x, int y, int width,
2268 const uint32_t *values)
2270 uint32_t *bits = image->bits + image->rowstride * y;
2271 uint8_t *pixel = ((uint8_t *) bits) + x;
2274 for (i = 0; i < width; ++i) {
2276 *(pixel++) = ((a ) & 0xc0) |
2284 fbStore_c8 (bits_image_t *image,
2285 int x, int y, int width,
2286 const uint32_t *values)
2288 uint32_t *bits = image->bits + image->rowstride * y;
2289 uint8_t *pixel = ((uint8_t *) bits) + x;
2290 const pixman_indexed_t *indexed = image->indexed;
2293 for (i = 0; i < width; ++i) {
2294 WRITE(image, pixel++, miIndexToEnt24(indexed,values[i]));
2299 fbStore_x4a4 (bits_image_t *image,
2300 int x, int y, int width,
2301 const uint32_t *values)
2303 uint32_t *bits = image->bits + image->rowstride * y;
2304 uint8_t *pixel = ((uint8_t *) bits) + x;
2307 for (i = 0; i < width; ++i) {
2308 WRITE(image, pixel++, values[i] >> 28);
2312 #define Store8(img,l,o,v) (WRITE(img, (uint8_t *)(l) + ((o) >> 3), (v)))
2313 #ifdef WORDS_BIGENDIAN
2314 #define Store4(img,l,o,v) Store8(img,l,o,((o) & 4 ? \
2315 (Fetch8(img,l,o) & 0xf0) | (v) : \
2316 (Fetch8(img,l,o) & 0x0f) | ((v) << 4)))
2318 #define Store4(img,l,o,v) Store8(img,l,o,((o) & 4 ? \
2319 (Fetch8(img,l,o) & 0x0f) | ((v) << 4) : \
2320 (Fetch8(img,l,o) & 0xf0) | (v)))
2324 fbStore_a4 (bits_image_t *image,
2325 int x, int y, int width,
2326 const uint32_t *values)
2328 uint32_t *bits = image->bits + image->rowstride * y;
2331 for (i = 0; i < width; ++i) {
2332 Store4(image, bits, i + x, values[i]>>28);
2337 fbStore_r1g2b1 (bits_image_t *image,
2338 int x, int y, int width,
2339 const uint32_t *values)
2341 uint32_t *bits = image->bits + image->rowstride * y;
2344 for (i = 0; i < width; ++i) {
2348 pixel = (((r >> 4) & 0x8) |
2351 Store4(image, bits, i + x, pixel);
2356 fbStore_b1g2r1 (bits_image_t *image,
2357 int x, int y, int width,
2358 const uint32_t *values)
2360 uint32_t *bits = image->bits + image->rowstride * y;
2363 for (i = 0; i < width; ++i) {
2367 pixel = (((b >> 4) & 0x8) |
2370 Store4(image, bits, i + x, pixel);
2375 fbStore_a1r1g1b1 (bits_image_t *image,
2376 int x, int y, int width,
2377 const uint32_t *values)
2379 uint32_t *bits = image->bits + image->rowstride * y;
2382 for (i = 0; i < width; ++i) {
2385 pixel = (((a >> 4) & 0x8) |
2389 Store4(image, bits, i + x, pixel);
2394 fbStore_a1b1g1r1 (bits_image_t *image,
2395 int x, int y, int width,
2396 const uint32_t *values)
2398 uint32_t *bits = image->bits + image->rowstride * y;
2401 for (i = 0; i < width; ++i) {
2404 pixel = (((a >> 4) & 0x8) |
2408 Store4(image, bits, i + x, pixel);
2413 fbStore_c4 (bits_image_t *image,
2414 int x, int y, int width,
2415 const uint32_t *values)
2417 uint32_t *bits = image->bits + image->rowstride * y;
2418 const pixman_indexed_t *indexed = image->indexed;
2421 for (i = 0; i < width; ++i) {
2424 pixel = miIndexToEnt24(indexed, values[i]);
2425 Store4(image, bits, i + x, pixel);
2430 fbStore_a1 (bits_image_t *image,
2431 int x, int y, int width,
2432 const uint32_t *values)
2434 uint32_t *bits = image->bits + image->rowstride * y;
2437 for (i = 0; i < width; ++i)
2439 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2441 #ifdef WORDS_BIGENDIAN
2442 mask = 1 << (0x1f - ((i+x) & 0x1f));
2444 mask = 1 << ((i+x) & 0x1f);
2446 v = values[i] & 0x80000000 ? mask : 0;
2447 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2452 fbStore_g1 (bits_image_t *image,
2453 int x, int y, int width,
2454 const uint32_t *values)
2456 uint32_t *bits = image->bits + image->rowstride * y;
2457 const pixman_indexed_t *indexed = image->indexed;
2460 for (i = 0; i < width; ++i)
2462 uint32_t *pixel = ((uint32_t *) bits) + ((i+x) >> 5);
2464 #ifdef WORDS_BIGENDIAN
2465 mask = 1 << (0x1f - ((i+x) & 0x1f));
2467 mask = 1 << ((i + x) & 0x1f);
2469 v = miIndexToEntY24 (indexed, values[i]) ? mask : 0;
2470 WRITE(image, pixel, (READ(image, pixel) & ~mask) | v);
2475 * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2476 * store proc. Despite the type, this function expects a uint64_t buffer.
2479 fbStore64_generic (bits_image_t *image, int x, int y, int width, const uint32_t *values)
2481 uint32_t *argb8Pixels;
2483 assert(image->common.type == BITS);
2485 argb8Pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2489 /* Contract the scanline. We could do this in place if values weren't
2492 pixman_contract(argb8Pixels, (uint64_t *)values, width);
2494 image->store_scanline_raw_32 (image, x, y, width, argb8Pixels);
2499 /* Despite the type, this function expects both buffer and mask to be uint64_t */
2501 fbFetch64_generic (pixman_image_t *image, int x, int y, int width, uint32_t *buffer,
2502 const uint32_t *mask, uint32_t mask_bits)
2504 /* Fetch the pixels into the first half of buffer and then expand them in
2507 image->bits.fetch_scanline_raw_32 (image, x, y, width, buffer, NULL, 0);
2509 pixman_expand ((uint64_t *)buffer, buffer, image->bits.format, width);
2512 /* Despite the type, this function expects a uint64_t *buffer */
2514 fbFetchPixel64_generic (bits_image_t *pict, uint32_t *buffer, int n_pixels)
2516 pict->fetch_pixels_raw_32 (pict, buffer, n_pixels);
2518 pixman_expand ((uint64_t *)buffer, buffer, pict->format, n_pixels);
2522 * XXX: The transformed fetch path only works at 32-bpp so far. When all paths
2523 * have wide versions, this can be removed.
2525 * WARNING: This function loses precision!
2528 fbFetchPixel32_generic_lossy (bits_image_t *pict, uint32_t *buffer, int n_pixels)
2530 /* Since buffer contains n_pixels coordinate pairs, it also has enough room for
2531 * n_pixels 64 bit pixels.
2533 pict->fetch_pixels_raw_64 (pict, buffer, n_pixels);
2535 pixman_contract (buffer, (uint64_t *)buffer, n_pixels);
2540 pixman_format_code_t format;
2541 fetch_scanline_t fetch_scanline_raw_32;
2542 fetch_scanline_t fetch_scanline_raw_64;
2543 fetch_pixels_t fetch_pixels_raw_32;
2544 fetch_pixels_t fetch_pixels_raw_64;
2545 store_scanline_t store_scanline_raw_32;
2546 store_scanline_t store_scanline_raw_64;
2549 #define FORMAT_INFO(format) \
2552 fbFetch_##format, fbFetch64_generic, \
2553 fbFetchPixel_##format, fbFetchPixel64_generic, \
2554 fbStore_##format, fbStore64_generic \
2557 static const format_info_t accessors[] =
2559 /* 32 bpp formats */
2560 FORMAT_INFO (a8r8g8b8),
2561 FORMAT_INFO (x8r8g8b8),
2562 FORMAT_INFO (a8b8g8r8),
2563 FORMAT_INFO (x8b8g8r8),
2564 FORMAT_INFO (b8g8r8a8),
2565 FORMAT_INFO (b8g8r8x8),
2568 FORMAT_INFO (r8g8b8),
2569 FORMAT_INFO (b8g8r8),
2572 FORMAT_INFO (r5g6b5),
2573 FORMAT_INFO (b5g6r5),
2575 FORMAT_INFO (a1r5g5b5),
2576 FORMAT_INFO (x1r5g5b5),
2577 FORMAT_INFO (a1b5g5r5),
2578 FORMAT_INFO (x1b5g5r5),
2579 FORMAT_INFO (a4r4g4b4),
2580 FORMAT_INFO (x4r4g4b4),
2581 FORMAT_INFO (a4b4g4r4),
2582 FORMAT_INFO (x4b4g4r4),
2586 FORMAT_INFO (r3g3b2),
2587 FORMAT_INFO (b2g3r3),
2588 FORMAT_INFO (a2r2g2b2),
2589 FORMAT_INFO (a2b2g2r2),
2593 #define fbFetch_g8 fbFetch_c8
2594 #define fbFetchPixel_g8 fbFetchPixel_c8
2595 #define fbStore_g8 fbStore_c8
2597 #define fbFetch_x4c4 fbFetch_c8
2598 #define fbFetchPixel_x4c4 fbFetchPixel_c8
2599 #define fbStore_x4c4 fbStore_c8
2601 #define fbFetch_x4g4 fbFetch_c8
2602 #define fbFetchPixel_x4g4 fbFetchPixel_c8
2603 #define fbStore_x4g4 fbStore_c8
2610 FORMAT_INFO (r1g2b1),
2611 FORMAT_INFO (b1g2r1),
2612 FORMAT_INFO (a1r1g1b1),
2613 FORMAT_INFO (a1b1g1r1),
2616 #define fbFetch_g4 fbFetch_c4
2617 #define fbFetchPixel_g4 fbFetchPixel_c4
2618 #define fbStore_g4 fbStore_c4
2627 { PIXMAN_a2b10g10r10,
2628 NULL, fbFetch_a2b10g10r10,
2629 fbFetchPixel32_generic_lossy, fbFetchPixel_a2b10g10r10_64,
2630 NULL, fbStore_a2b10g10r10 },
2632 { PIXMAN_x2b10g10r10,
2633 NULL, fbFetch_x2b10g10r10,
2634 fbFetchPixel32_generic_lossy, fbFetchPixel_x2b10g10r10_64,
2635 NULL, fbStore_x2b10g10r10 },
2639 fbFetch_yuy2, fbFetch64_generic,
2640 fbFetchPixel_yuy2, fbFetchPixel64_generic,
2644 fbFetch_yv12, fbFetch64_generic,
2645 fbFetchPixel_yv12, fbFetchPixel64_generic,
2652 setup_accessors (bits_image_t *image)
2654 const format_info_t *info = accessors;
2656 while (info->format != PIXMAN_null)
2658 if (info->format == image->format)
2660 image->fetch_scanline_raw_32 = info->fetch_scanline_raw_32;
2661 image->fetch_scanline_raw_64 = info->fetch_scanline_raw_64;
2662 image->fetch_pixels_raw_32 = info->fetch_pixels_raw_32;
2663 image->fetch_pixels_raw_64 = info->fetch_pixels_raw_64;
2664 image->store_scanline_raw_32 = info->store_scanline_raw_32;
2665 image->store_scanline_raw_64 = info->store_scanline_raw_64;
2674 #ifndef PIXMAN_FB_ACCESSORS
2676 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image);
2679 _pixman_bits_image_setup_raw_accessors (bits_image_t *image)
2681 if (image->common.read_func || image->common.write_func)
2682 _pixman_bits_image_setup_raw_accessors_accessors (image);
2684 setup_accessors (image);
2690 _pixman_bits_image_setup_raw_accessors_accessors (bits_image_t *image)
2692 setup_accessors (image);