1 : /*
2 : *
3 : * Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
4 : * 2005 Lars Knoll & Zack Rusin, Trolltech
5 : * 2008 Aaron Plattner, NVIDIA Corporation
6 : *
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.
16 : *
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
24 : * SOFTWARE.
25 : */
26 :
27 : #ifdef HAVE_CONFIG_H
28 : #include <config.h>
29 : #endif
30 :
31 : #include <stdlib.h>
32 : #include <string.h>
33 : #include <assert.h>
34 :
35 : #include "pixman-private.h"
36 : #include "pixman-accessor.h"
37 :
38 : #define CONVERT_RGB24_TO_Y15(s) \
39 : (((((s) >> 16) & 0xff) * 153 + \
40 : (((s) >> 8) & 0xff) * 301 + \
41 : (((s) ) & 0xff) * 58) >> 2)
42 :
43 : #define CONVERT_RGB24_TO_RGB15(s) \
44 : ((((s) >> 3) & 0x001f) | \
45 : (((s) >> 6) & 0x03e0) | \
46 : (((s) >> 9) & 0x7c00))
47 :
48 : #define RGB15_TO_ENTRY(mif,rgb15) \
49 : ((mif)->ent[rgb15])
50 :
51 : #define RGB24_TO_ENTRY(mif,rgb24) \
52 : RGB15_TO_ENTRY (mif,CONVERT_RGB24_TO_RGB15 (rgb24))
53 :
54 : #define RGB24_TO_ENTRY_Y(mif,rgb24) \
55 : ((mif)->ent[CONVERT_RGB24_TO_Y15 (rgb24)])
56 :
57 : /*
58 : * YV12 setup and access macros
59 : */
60 :
61 : #define YV12_SETUP(image) \
62 : bits_image_t *__bits_image = (bits_image_t *)image; \
63 : uint32_t *bits = __bits_image->bits; \
64 : int stride = __bits_image->rowstride; \
65 : int offset0 = stride < 0 ? \
66 : ((-stride) >> 1) * ((__bits_image->height - 1) >> 1) - stride : \
67 : stride * __bits_image->height; \
68 : int offset1 = stride < 0 ? \
69 : offset0 + ((-stride) >> 1) * ((__bits_image->height) >> 1) : \
70 : offset0 + (offset0 >> 2)
71 :
72 : /* Note no trailing semicolon on the above macro; if it's there, then
73 : * the typical usage of YV12_SETUP(image); will have an extra trailing ;
74 : * that some compilers will interpret as a statement -- and then any further
75 : * variable declarations will cause an error.
76 : */
77 :
78 : #define YV12_Y(line) \
79 : ((uint8_t *) ((bits) + (stride) * (line)))
80 :
81 : #define YV12_U(line) \
82 : ((uint8_t *) ((bits) + offset1 + \
83 : ((stride) >> 1) * ((line) >> 1)))
84 :
85 : #define YV12_V(line) \
86 : ((uint8_t *) ((bits) + offset0 + \
87 : ((stride) >> 1) * ((line) >> 1)))
88 :
89 : /********************************** Fetch ************************************/
90 :
91 : static void
92 0 : fetch_scanline_a8r8g8b8 (pixman_image_t *image,
93 : int x,
94 : int y,
95 : int width,
96 : uint32_t * buffer,
97 : const uint32_t *mask)
98 : {
99 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
100 :
101 0 : MEMCPY_WRAPPED (image,
102 : buffer, (const uint32_t *)bits + x,
103 : width * sizeof(uint32_t));
104 0 : }
105 :
106 : static void
107 0 : fetch_scanline_x8r8g8b8 (pixman_image_t *image,
108 : int x,
109 : int y,
110 : int width,
111 : uint32_t * buffer,
112 : const uint32_t *mask)
113 : {
114 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
115 0 : const uint32_t *pixel = (const uint32_t *)bits + x;
116 0 : const uint32_t *end = pixel + width;
117 :
118 0 : while (pixel < end)
119 0 : *buffer++ = READ (image, pixel++) | 0xff000000;
120 0 : }
121 :
122 : static void
123 0 : fetch_scanline_a8b8g8r8 (pixman_image_t *image,
124 : int x,
125 : int y,
126 : int width,
127 : uint32_t * buffer,
128 : const uint32_t *mask)
129 : {
130 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
131 0 : const uint32_t *pixel = (uint32_t *)bits + x;
132 0 : const uint32_t *end = pixel + width;
133 :
134 0 : while (pixel < end)
135 : {
136 0 : uint32_t p = READ (image, pixel++);
137 :
138 0 : *buffer++ = (p & 0xff00ff00) |
139 0 : ((p >> 16) & 0xff) |
140 0 : ((p & 0xff) << 16);
141 : }
142 0 : }
143 :
144 : static void
145 0 : fetch_scanline_x8b8g8r8 (pixman_image_t *image,
146 : int x,
147 : int y,
148 : int width,
149 : uint32_t * buffer,
150 : const uint32_t *mask)
151 : {
152 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
153 0 : const uint32_t *pixel = (uint32_t *)bits + x;
154 0 : const uint32_t *end = pixel + width;
155 :
156 0 : while (pixel < end)
157 : {
158 0 : uint32_t p = READ (image, pixel++);
159 :
160 0 : *buffer++ = 0xff000000 |
161 0 : (p & 0x0000ff00) |
162 0 : ((p >> 16) & 0xff) |
163 0 : ((p & 0xff) << 16);
164 : }
165 0 : }
166 :
167 : static void
168 0 : fetch_scanline_b8g8r8a8 (pixman_image_t *image,
169 : int x,
170 : int y,
171 : int width,
172 : uint32_t * buffer,
173 : const uint32_t *mask)
174 : {
175 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
176 0 : const uint32_t *pixel = (uint32_t *)bits + x;
177 0 : const uint32_t *end = pixel + width;
178 :
179 0 : while (pixel < end)
180 : {
181 0 : uint32_t p = READ (image, pixel++);
182 :
183 0 : *buffer++ = (((p & 0xff000000) >> 24) |
184 0 : ((p & 0x00ff0000) >> 8) |
185 0 : ((p & 0x0000ff00) << 8) |
186 0 : ((p & 0x000000ff) << 24));
187 : }
188 0 : }
189 :
190 : static void
191 0 : fetch_scanline_b8g8r8x8 (pixman_image_t *image,
192 : int x,
193 : int y,
194 : int width,
195 : uint32_t * buffer,
196 : const uint32_t *mask)
197 : {
198 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
199 0 : const uint32_t *pixel = (uint32_t *)bits + x;
200 0 : const uint32_t *end = pixel + width;
201 :
202 0 : while (pixel < end)
203 : {
204 0 : uint32_t p = READ (image, pixel++);
205 :
206 0 : *buffer++ = (0xff000000 |
207 0 : ((p & 0xff000000) >> 24) |
208 0 : ((p & 0x00ff0000) >> 8) |
209 0 : ((p & 0x0000ff00) << 8));
210 : }
211 0 : }
212 :
213 : static void
214 0 : fetch_scanline_r8g8b8a8 (pixman_image_t *image,
215 : int x,
216 : int y,
217 : int width,
218 : uint32_t * buffer,
219 : const uint32_t *mask)
220 : {
221 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
222 0 : const uint32_t *pixel = (uint32_t *)bits + x;
223 0 : const uint32_t *end = pixel + width;
224 :
225 0 : while (pixel < end)
226 : {
227 0 : uint32_t p = READ (image, pixel++);
228 :
229 0 : *buffer++ = (((p & 0x000000ff) << 24) | (p >> 8));
230 : }
231 0 : }
232 :
233 : static void
234 0 : fetch_scanline_r8g8b8x8 (pixman_image_t *image,
235 : int x,
236 : int y,
237 : int width,
238 : uint32_t * buffer,
239 : const uint32_t *mask)
240 : {
241 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
242 0 : const uint32_t *pixel = (uint32_t *)bits + x;
243 0 : const uint32_t *end = pixel + width;
244 :
245 0 : while (pixel < end)
246 : {
247 0 : uint32_t p = READ (image, pixel++);
248 :
249 0 : *buffer++ = (0xff000000 | (p >> 8));
250 : }
251 0 : }
252 :
253 : static void
254 0 : fetch_scanline_x14r6g6b6 (pixman_image_t *image,
255 : int x,
256 : int y,
257 : int width,
258 : uint32_t * buffer,
259 : const uint32_t *mask)
260 : {
261 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
262 0 : const uint32_t *pixel = (const uint32_t *)bits + x;
263 0 : const uint32_t *end = pixel + width;
264 :
265 0 : while (pixel < end)
266 : {
267 0 : uint32_t p = READ (image, pixel++);
268 : uint32_t r, g, b;
269 :
270 0 : r = ((p & 0x3f000) << 6) | ((p & 0x30000));
271 0 : g = ((p & 0x00fc0) << 4) | ((p & 0x00c00) >> 2);
272 0 : b = ((p & 0x0003f) << 2) | ((p & 0x00030) >> 4);
273 :
274 0 : *buffer++ = 0xff000000 | r | g | b;
275 : }
276 0 : }
277 :
278 : /* Expects a uint64_t buffer */
279 : static void
280 0 : fetch_scanline_a2r10g10b10 (pixman_image_t *image,
281 : int x,
282 : int y,
283 : int width,
284 : uint32_t * b,
285 : const uint32_t *mask)
286 : {
287 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
288 0 : const uint32_t *pixel = bits + x;
289 0 : const uint32_t *end = pixel + width;
290 0 : uint64_t *buffer = (uint64_t *)b;
291 :
292 0 : while (pixel < end)
293 : {
294 0 : uint32_t p = READ (image, pixel++);
295 0 : uint64_t a = p >> 30;
296 0 : uint64_t r = (p >> 20) & 0x3ff;
297 0 : uint64_t g = (p >> 10) & 0x3ff;
298 0 : uint64_t b = p & 0x3ff;
299 :
300 0 : r = r << 6 | r >> 4;
301 0 : g = g << 6 | g >> 4;
302 0 : b = b << 6 | b >> 4;
303 :
304 0 : a <<= 14;
305 0 : a |= a >> 2;
306 0 : a |= a >> 4;
307 0 : a |= a >> 8;
308 :
309 0 : *buffer++ = a << 48 | r << 32 | g << 16 | b;
310 : }
311 0 : }
312 :
313 : /* Expects a uint64_t buffer */
314 : static void
315 0 : fetch_scanline_x2r10g10b10 (pixman_image_t *image,
316 : int x,
317 : int y,
318 : int width,
319 : uint32_t * b,
320 : const uint32_t *mask)
321 : {
322 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
323 0 : const uint32_t *pixel = (uint32_t *)bits + x;
324 0 : const uint32_t *end = pixel + width;
325 0 : uint64_t *buffer = (uint64_t *)b;
326 :
327 0 : while (pixel < end)
328 : {
329 0 : uint32_t p = READ (image, pixel++);
330 0 : uint64_t r = (p >> 20) & 0x3ff;
331 0 : uint64_t g = (p >> 10) & 0x3ff;
332 0 : uint64_t b = p & 0x3ff;
333 :
334 0 : r = r << 6 | r >> 4;
335 0 : g = g << 6 | g >> 4;
336 0 : b = b << 6 | b >> 4;
337 :
338 0 : *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
339 : }
340 0 : }
341 :
342 : /* Expects a uint64_t buffer */
343 : static void
344 0 : fetch_scanline_a2b10g10r10 (pixman_image_t *image,
345 : int x,
346 : int y,
347 : int width,
348 : uint32_t * b,
349 : const uint32_t *mask)
350 : {
351 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
352 0 : const uint32_t *pixel = bits + x;
353 0 : const uint32_t *end = pixel + width;
354 0 : uint64_t *buffer = (uint64_t *)b;
355 :
356 0 : while (pixel < end)
357 : {
358 0 : uint32_t p = READ (image, pixel++);
359 0 : uint64_t a = p >> 30;
360 0 : uint64_t b = (p >> 20) & 0x3ff;
361 0 : uint64_t g = (p >> 10) & 0x3ff;
362 0 : uint64_t r = p & 0x3ff;
363 :
364 0 : r = r << 6 | r >> 4;
365 0 : g = g << 6 | g >> 4;
366 0 : b = b << 6 | b >> 4;
367 :
368 0 : a <<= 14;
369 0 : a |= a >> 2;
370 0 : a |= a >> 4;
371 0 : a |= a >> 8;
372 :
373 0 : *buffer++ = a << 48 | r << 32 | g << 16 | b;
374 : }
375 0 : }
376 :
377 : /* Expects a uint64_t buffer */
378 : static void
379 0 : fetch_scanline_x2b10g10r10 (pixman_image_t *image,
380 : int x,
381 : int y,
382 : int width,
383 : uint32_t * b,
384 : const uint32_t *mask)
385 : {
386 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
387 0 : const uint32_t *pixel = (uint32_t *)bits + x;
388 0 : const uint32_t *end = pixel + width;
389 0 : uint64_t *buffer = (uint64_t *)b;
390 :
391 0 : while (pixel < end)
392 : {
393 0 : uint32_t p = READ (image, pixel++);
394 0 : uint64_t b = (p >> 20) & 0x3ff;
395 0 : uint64_t g = (p >> 10) & 0x3ff;
396 0 : uint64_t r = p & 0x3ff;
397 :
398 0 : r = r << 6 | r >> 4;
399 0 : g = g << 6 | g >> 4;
400 0 : b = b << 6 | b >> 4;
401 :
402 0 : *buffer++ = 0xffffULL << 48 | r << 32 | g << 16 | b;
403 : }
404 0 : }
405 :
406 : static void
407 0 : fetch_scanline_r8g8b8 (pixman_image_t *image,
408 : int x,
409 : int y,
410 : int width,
411 : uint32_t * buffer,
412 : const uint32_t *mask)
413 : {
414 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
415 0 : const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
416 0 : const uint8_t *end = pixel + 3 * width;
417 :
418 0 : while (pixel < end)
419 : {
420 0 : uint32_t b = 0xff000000;
421 :
422 : #ifdef WORDS_BIGENDIAN
423 : b |= (READ (image, pixel++) << 16);
424 : b |= (READ (image, pixel++) << 8);
425 : b |= (READ (image, pixel++));
426 : #else
427 0 : b |= (READ (image, pixel++));
428 0 : b |= (READ (image, pixel++) << 8);
429 0 : b |= (READ (image, pixel++) << 16);
430 : #endif
431 :
432 0 : *buffer++ = b;
433 : }
434 0 : }
435 :
436 : static void
437 0 : fetch_scanline_b8g8r8 (pixman_image_t *image,
438 : int x,
439 : int y,
440 : int width,
441 : uint32_t * buffer,
442 : const uint32_t *mask)
443 : {
444 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
445 0 : const uint8_t *pixel = (const uint8_t *)bits + 3 * x;
446 0 : const uint8_t *end = pixel + 3 * width;
447 :
448 0 : while (pixel < end)
449 : {
450 0 : uint32_t b = 0xff000000;
451 : #ifdef WORDS_BIGENDIAN
452 : b |= (READ (image, pixel++));
453 : b |= (READ (image, pixel++) << 8);
454 : b |= (READ (image, pixel++) << 16);
455 : #else
456 0 : b |= (READ (image, pixel++) << 16);
457 0 : b |= (READ (image, pixel++) << 8);
458 0 : b |= (READ (image, pixel++));
459 : #endif
460 0 : *buffer++ = b;
461 : }
462 0 : }
463 :
464 : static void
465 0 : fetch_scanline_r5g6b5 (pixman_image_t *image,
466 : int x,
467 : int y,
468 : int width,
469 : uint32_t * buffer,
470 : const uint32_t *mask)
471 : {
472 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
473 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
474 0 : const uint16_t *end = pixel + width;
475 :
476 0 : while (pixel < end)
477 : {
478 0 : uint32_t p = READ (image, pixel++);
479 0 : uint32_t r = (((p) << 3) & 0xf8) |
480 0 : (((p) << 5) & 0xfc00) |
481 0 : (((p) << 8) & 0xf80000);
482 :
483 0 : r |= (r >> 5) & 0x70007;
484 0 : r |= (r >> 6) & 0x300;
485 :
486 0 : *buffer++ = 0xff000000 | r;
487 : }
488 0 : }
489 :
490 : static void
491 0 : fetch_scanline_b5g6r5 (pixman_image_t *image,
492 : int x,
493 : int y,
494 : int width,
495 : uint32_t * buffer,
496 : const uint32_t *mask)
497 : {
498 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
499 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
500 0 : const uint16_t *end = pixel + width;
501 :
502 0 : while (pixel < end)
503 : {
504 0 : uint32_t p = READ (image, pixel++);
505 : uint32_t r, g, b;
506 :
507 0 : b = ((p & 0xf800) | ((p & 0xe000) >> 5)) >> 8;
508 0 : g = ((p & 0x07e0) | ((p & 0x0600) >> 6)) << 5;
509 0 : r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
510 :
511 0 : *buffer++ = 0xff000000 | r | g | b;
512 : }
513 0 : }
514 :
515 : static void
516 0 : fetch_scanline_a1r5g5b5 (pixman_image_t *image,
517 : int x,
518 : int y,
519 : int width,
520 : uint32_t * buffer,
521 : const uint32_t *mask)
522 : {
523 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
524 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
525 0 : const uint16_t *end = pixel + width;
526 :
527 0 : while (pixel < end)
528 : {
529 0 : uint32_t p = READ (image, pixel++);
530 : uint32_t r, g, b, a;
531 :
532 0 : a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
533 0 : r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
534 0 : g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
535 0 : b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
536 :
537 0 : *buffer++ = a | r | g | b;
538 : }
539 0 : }
540 :
541 : static void
542 0 : fetch_scanline_x1r5g5b5 (pixman_image_t *image,
543 : int x,
544 : int y,
545 : int width,
546 : uint32_t * buffer,
547 : const uint32_t *mask)
548 : {
549 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
550 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
551 0 : const uint16_t *end = pixel + width;
552 :
553 0 : while (pixel < end)
554 : {
555 0 : uint32_t p = READ (image, pixel++);
556 : uint32_t r, g, b;
557 :
558 0 : r = ((p & 0x7c00) | ((p & 0x7000) >> 5)) << 9;
559 0 : g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
560 0 : b = ((p & 0x001c) | ((p & 0x001f) << 5)) >> 2;
561 :
562 0 : *buffer++ = 0xff000000 | r | g | b;
563 : }
564 0 : }
565 :
566 : static void
567 0 : fetch_scanline_a1b5g5r5 (pixman_image_t *image,
568 : int x,
569 : int y,
570 : int width,
571 : uint32_t * buffer,
572 : const uint32_t *mask)
573 : {
574 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
575 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
576 0 : const uint16_t *end = pixel + width;
577 : uint32_t r, g, b, a;
578 :
579 0 : while (pixel < end)
580 : {
581 0 : uint32_t p = READ (image, pixel++);
582 :
583 0 : a = (uint32_t) ((uint8_t) (0 - ((p & 0x8000) >> 15))) << 24;
584 0 : b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
585 0 : g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
586 0 : r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
587 :
588 0 : *buffer++ = a | r | g | b;
589 : }
590 0 : }
591 :
592 : static void
593 0 : fetch_scanline_x1b5g5r5 (pixman_image_t *image,
594 : int x,
595 : int y,
596 : int width,
597 : uint32_t * buffer,
598 : const uint32_t *mask)
599 : {
600 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
601 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
602 0 : const uint16_t *end = pixel + width;
603 :
604 0 : while (pixel < end)
605 : {
606 0 : uint32_t p = READ (image, pixel++);
607 : uint32_t r, g, b;
608 :
609 0 : b = ((p & 0x7c00) | ((p & 0x7000) >> 5)) >> 7;
610 0 : g = ((p & 0x03e0) | ((p & 0x0380) >> 5)) << 6;
611 0 : r = ((p & 0x001c) | ((p & 0x001f) << 5)) << 14;
612 :
613 0 : *buffer++ = 0xff000000 | r | g | b;
614 : }
615 0 : }
616 :
617 : static void
618 0 : fetch_scanline_a4r4g4b4 (pixman_image_t *image,
619 : int x,
620 : int y,
621 : int width,
622 : uint32_t * buffer,
623 : const uint32_t *mask)
624 : {
625 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
626 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
627 0 : const uint16_t *end = pixel + width;
628 :
629 0 : while (pixel < end)
630 : {
631 0 : uint32_t p = READ (image, pixel++);
632 : uint32_t r, g, b, a;
633 :
634 0 : a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
635 0 : r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
636 0 : g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
637 0 : b = ((p & 0x000f) | ((p & 0x000f) << 4));
638 :
639 0 : *buffer++ = a | r | g | b;
640 : }
641 0 : }
642 :
643 : static void
644 0 : fetch_scanline_x4r4g4b4 (pixman_image_t *image,
645 : int x,
646 : int y,
647 : int width,
648 : uint32_t * buffer,
649 : const uint32_t *mask)
650 : {
651 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
652 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
653 0 : const uint16_t *end = pixel + width;
654 :
655 0 : while (pixel < end)
656 : {
657 0 : uint32_t p = READ (image, pixel++);
658 : uint32_t r, g, b;
659 :
660 0 : r = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) << 12;
661 0 : g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
662 0 : b = ((p & 0x000f) | ((p & 0x000f) << 4));
663 :
664 0 : *buffer++ = 0xff000000 | r | g | b;
665 : }
666 0 : }
667 :
668 : static void
669 0 : fetch_scanline_a4b4g4r4 (pixman_image_t *image,
670 : int x,
671 : int y,
672 : int width,
673 : uint32_t * buffer,
674 : const uint32_t *mask)
675 : {
676 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
677 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
678 0 : const uint16_t *end = pixel + width;
679 :
680 0 : while (pixel < end)
681 : {
682 0 : uint32_t p = READ (image, pixel++);
683 : uint32_t r, g, b, a;
684 :
685 0 : a = ((p & 0xf000) | ((p & 0xf000) >> 4)) << 16;
686 0 : b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
687 0 : g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
688 0 : r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
689 :
690 0 : *buffer++ = a | r | g | b;
691 : }
692 0 : }
693 :
694 : static void
695 0 : fetch_scanline_x4b4g4r4 (pixman_image_t *image,
696 : int x,
697 : int y,
698 : int width,
699 : uint32_t * buffer,
700 : const uint32_t *mask)
701 : {
702 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
703 0 : const uint16_t *pixel = (const uint16_t *)bits + x;
704 0 : const uint16_t *end = pixel + width;
705 :
706 0 : while (pixel < end)
707 : {
708 0 : uint32_t p = READ (image, pixel++);
709 : uint32_t r, g, b;
710 :
711 0 : b = ((p & 0x0f00) | ((p & 0x0f00) >> 4)) >> 4;
712 0 : g = ((p & 0x00f0) | ((p & 0x00f0) >> 4)) << 8;
713 0 : r = ((p & 0x000f) | ((p & 0x000f) << 4)) << 16;
714 :
715 0 : *buffer++ = 0xff000000 | r | g | b;
716 : }
717 0 : }
718 :
719 : static void
720 0 : fetch_scanline_a8 (pixman_image_t *image,
721 : int x,
722 : int y,
723 : int width,
724 : uint32_t * buffer,
725 : const uint32_t *mask)
726 : {
727 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
728 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
729 0 : const uint8_t *end = pixel + width;
730 :
731 0 : while (pixel < end)
732 0 : *buffer++ = READ (image, pixel++) << 24;
733 0 : }
734 :
735 : static void
736 0 : fetch_scanline_r3g3b2 (pixman_image_t *image,
737 : int x,
738 : int y,
739 : int width,
740 : uint32_t * buffer,
741 : const uint32_t *mask)
742 : {
743 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
744 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
745 0 : const uint8_t *end = pixel + width;
746 :
747 0 : while (pixel < end)
748 : {
749 0 : uint32_t p = READ (image, pixel++);
750 : uint32_t r, g, b;
751 :
752 0 : r = ((p & 0xe0) | ((p & 0xe0) >> 3) | ((p & 0xc0) >> 6)) << 16;
753 0 : g = ((p & 0x1c) | ((p & 0x18) >> 3) | ((p & 0x1c) << 3)) << 8;
754 0 : b = (((p & 0x03) ) |
755 0 : ((p & 0x03) << 2) |
756 0 : ((p & 0x03) << 4) |
757 0 : ((p & 0x03) << 6));
758 :
759 0 : *buffer++ = 0xff000000 | r | g | b;
760 : }
761 0 : }
762 :
763 : static void
764 0 : fetch_scanline_b2g3r3 (pixman_image_t *image,
765 : int x,
766 : int y,
767 : int width,
768 : uint32_t * buffer,
769 : const uint32_t *mask)
770 : {
771 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
772 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
773 0 : const uint8_t *end = pixel + width;
774 :
775 0 : while (pixel < end)
776 : {
777 0 : uint32_t p = READ (image, pixel++);
778 : uint32_t r, g, b;
779 :
780 0 : b = p & 0xc0;
781 0 : b |= b >> 2;
782 0 : b |= b >> 4;
783 0 : b &= 0xff;
784 :
785 0 : g = (p & 0x38) << 10;
786 0 : g |= g >> 3;
787 0 : g |= g >> 6;
788 0 : g &= 0xff00;
789 :
790 0 : r = (p & 0x7) << 21;
791 0 : r |= r >> 3;
792 0 : r |= r >> 6;
793 0 : r &= 0xff0000;
794 :
795 0 : *buffer++ = 0xff000000 | r | g | b;
796 : }
797 0 : }
798 :
799 : static void
800 0 : fetch_scanline_a2r2g2b2 (pixman_image_t *image,
801 : int x,
802 : int y,
803 : int width,
804 : uint32_t * buffer,
805 : const uint32_t *mask)
806 : {
807 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
808 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
809 0 : const uint8_t *end = pixel + width;
810 :
811 0 : while (pixel < end)
812 : {
813 0 : uint32_t p = READ (image, pixel++);
814 : uint32_t a, r, g, b;
815 :
816 0 : a = ((p & 0xc0) * 0x55) << 18;
817 0 : r = ((p & 0x30) * 0x55) << 12;
818 0 : g = ((p & 0x0c) * 0x55) << 6;
819 0 : b = ((p & 0x03) * 0x55);
820 :
821 0 : *buffer++ = a | r | g | b;
822 : }
823 0 : }
824 :
825 : static void
826 0 : fetch_scanline_a2b2g2r2 (pixman_image_t *image,
827 : int x,
828 : int y,
829 : int width,
830 : uint32_t * buffer,
831 : const uint32_t *mask)
832 : {
833 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
834 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
835 0 : const uint8_t *end = pixel + width;
836 :
837 0 : while (pixel < end)
838 : {
839 0 : uint32_t p = READ (image, pixel++);
840 : uint32_t a, r, g, b;
841 :
842 0 : a = ((p & 0xc0) * 0x55) << 18;
843 0 : b = ((p & 0x30) * 0x55) >> 4;
844 0 : g = ((p & 0x0c) * 0x55) << 6;
845 0 : r = ((p & 0x03) * 0x55) << 16;
846 :
847 0 : *buffer++ = a | r | g | b;
848 : }
849 0 : }
850 :
851 : static void
852 0 : fetch_scanline_c8 (pixman_image_t *image,
853 : int x,
854 : int y,
855 : int width,
856 : uint32_t * buffer,
857 : const uint32_t *mask)
858 : {
859 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
860 0 : const pixman_indexed_t * indexed = image->bits.indexed;
861 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
862 0 : const uint8_t *end = pixel + width;
863 :
864 0 : while (pixel < end)
865 : {
866 0 : uint32_t p = READ (image, pixel++);
867 :
868 0 : *buffer++ = indexed->rgba[p];
869 : }
870 0 : }
871 :
872 : static void
873 0 : fetch_scanline_x4a4 (pixman_image_t *image,
874 : int x,
875 : int y,
876 : int width,
877 : uint32_t * buffer,
878 : const uint32_t *mask)
879 : {
880 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
881 0 : const uint8_t *pixel = (const uint8_t *)bits + x;
882 0 : const uint8_t *end = pixel + width;
883 :
884 0 : while (pixel < end)
885 : {
886 0 : uint8_t p = READ (image, pixel++) & 0xf;
887 :
888 0 : *buffer++ = (p | (p << 4)) << 24;
889 : }
890 0 : }
891 :
892 : #define FETCH_8(img,l,o) (READ (img, (((uint8_t *)(l)) + ((o) >> 3))))
893 : #ifdef WORDS_BIGENDIAN
894 : #define FETCH_4(img,l,o) \
895 : (((4 * (o)) & 4) ? (FETCH_8 (img,l, 4 * (o)) & 0xf) : (FETCH_8 (img,l,(4 * (o))) >> 4))
896 : #else
897 : #define FETCH_4(img,l,o) \
898 : (((4 * (o)) & 4) ? (FETCH_8 (img, l, 4 * (o)) >> 4) : (FETCH_8 (img, l, (4 * (o))) & 0xf))
899 : #endif
900 :
901 : static void
902 0 : fetch_scanline_a4 (pixman_image_t *image,
903 : int x,
904 : int y,
905 : int width,
906 : uint32_t * buffer,
907 : const uint32_t *mask)
908 : {
909 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
910 : int i;
911 :
912 0 : for (i = 0; i < width; ++i)
913 : {
914 0 : uint32_t p = FETCH_4 (image, bits, i + x);
915 :
916 0 : p |= p << 4;
917 :
918 0 : *buffer++ = p << 24;
919 : }
920 0 : }
921 :
922 : static void
923 0 : fetch_scanline_r1g2b1 (pixman_image_t *image,
924 : int x,
925 : int y,
926 : int width,
927 : uint32_t * buffer,
928 : const uint32_t *mask)
929 : {
930 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
931 : int i;
932 :
933 0 : for (i = 0; i < width; ++i)
934 : {
935 0 : uint32_t p = FETCH_4 (image, bits, i + x);
936 : uint32_t r, g, b;
937 :
938 0 : r = ((p & 0x8) * 0xff) << 13;
939 0 : g = ((p & 0x6) * 0x55) << 7;
940 0 : b = ((p & 0x1) * 0xff);
941 :
942 0 : *buffer++ = 0xff000000 | r | g | b;
943 : }
944 0 : }
945 :
946 : static void
947 0 : fetch_scanline_b1g2r1 (pixman_image_t *image,
948 : int x,
949 : int y,
950 : int width,
951 : uint32_t * buffer,
952 : const uint32_t *mask)
953 : {
954 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
955 : int i;
956 :
957 0 : for (i = 0; i < width; ++i)
958 : {
959 0 : uint32_t p = FETCH_4 (image, bits, i + x);
960 : uint32_t r, g, b;
961 :
962 0 : b = ((p & 0x8) * 0xff) >> 3;
963 0 : g = ((p & 0x6) * 0x55) << 7;
964 0 : r = ((p & 0x1) * 0xff) << 16;
965 :
966 0 : *buffer++ = 0xff000000 | r | g | b;
967 : }
968 0 : }
969 :
970 : static void
971 0 : fetch_scanline_a1r1g1b1 (pixman_image_t *image,
972 : int x,
973 : int y,
974 : int width,
975 : uint32_t * buffer,
976 : const uint32_t *mask)
977 : {
978 : uint32_t a, r, g, b;
979 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
980 : int i;
981 :
982 0 : for (i = 0; i < width; ++i)
983 : {
984 0 : uint32_t p = FETCH_4 (image, bits, i + x);
985 :
986 0 : a = ((p & 0x8) * 0xff) << 21;
987 0 : r = ((p & 0x4) * 0xff) << 14;
988 0 : g = ((p & 0x2) * 0xff) << 7;
989 0 : b = ((p & 0x1) * 0xff);
990 :
991 0 : *buffer++ = a | r | g | b;
992 : }
993 0 : }
994 :
995 : static void
996 0 : fetch_scanline_a1b1g1r1 (pixman_image_t *image,
997 : int x,
998 : int y,
999 : int width,
1000 : uint32_t * buffer,
1001 : const uint32_t *mask)
1002 : {
1003 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1004 : int i;
1005 :
1006 0 : for (i = 0; i < width; ++i)
1007 : {
1008 0 : uint32_t p = FETCH_4 (image, bits, i + x);
1009 : uint32_t a, r, g, b;
1010 :
1011 0 : a = ((p & 0x8) * 0xff) << 21;
1012 0 : b = ((p & 0x4) * 0xff) >> 2;
1013 0 : g = ((p & 0x2) * 0xff) << 7;
1014 0 : r = ((p & 0x1) * 0xff) << 16;
1015 :
1016 0 : *buffer++ = a | r | g | b;
1017 : }
1018 0 : }
1019 :
1020 : static void
1021 0 : fetch_scanline_c4 (pixman_image_t *image,
1022 : int x,
1023 : int y,
1024 : int width,
1025 : uint32_t * buffer,
1026 : const uint32_t *mask)
1027 : {
1028 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1029 0 : const pixman_indexed_t * indexed = image->bits.indexed;
1030 : int i;
1031 :
1032 0 : for (i = 0; i < width; ++i)
1033 : {
1034 0 : uint32_t p = FETCH_4 (image, bits, i + x);
1035 :
1036 0 : *buffer++ = indexed->rgba[p];
1037 : }
1038 0 : }
1039 :
1040 : static void
1041 0 : fetch_scanline_a1 (pixman_image_t *image,
1042 : int x,
1043 : int y,
1044 : int width,
1045 : uint32_t * buffer,
1046 : const uint32_t *mask)
1047 : {
1048 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1049 : int i;
1050 :
1051 0 : for (i = 0; i < width; ++i)
1052 : {
1053 0 : uint32_t p = READ (image, bits + ((i + x) >> 5));
1054 : uint32_t a;
1055 :
1056 : #ifdef WORDS_BIGENDIAN
1057 : a = p >> (0x1f - ((i + x) & 0x1f));
1058 : #else
1059 0 : a = p >> ((i + x) & 0x1f);
1060 : #endif
1061 0 : a = a & 1;
1062 0 : a |= a << 1;
1063 0 : a |= a << 2;
1064 0 : a |= a << 4;
1065 :
1066 0 : *buffer++ = a << 24;
1067 : }
1068 0 : }
1069 :
1070 : static void
1071 0 : fetch_scanline_g1 (pixman_image_t *image,
1072 : int x,
1073 : int y,
1074 : int width,
1075 : uint32_t * buffer,
1076 : const uint32_t *mask)
1077 : {
1078 0 : const uint32_t *bits = image->bits.bits + y * image->bits.rowstride;
1079 0 : const pixman_indexed_t * indexed = image->bits.indexed;
1080 : int i;
1081 :
1082 0 : for (i = 0; i < width; ++i)
1083 : {
1084 0 : uint32_t p = READ (image, bits + ((i + x) >> 5));
1085 : uint32_t a;
1086 :
1087 : #ifdef WORDS_BIGENDIAN
1088 : a = p >> (0x1f - ((i + x) & 0x1f));
1089 : #else
1090 0 : a = p >> ((i + x) & 0x1f);
1091 : #endif
1092 0 : a = a & 1;
1093 :
1094 0 : *buffer++ = indexed->rgba[a];
1095 : }
1096 0 : }
1097 :
1098 : static void
1099 0 : fetch_scanline_yuy2 (pixman_image_t *image,
1100 : int x,
1101 : int line,
1102 : int width,
1103 : uint32_t * buffer,
1104 : const uint32_t *mask)
1105 : {
1106 0 : const uint32_t *bits = image->bits.bits + image->bits.rowstride * line;
1107 : int i;
1108 :
1109 0 : for (i = 0; i < width; i++)
1110 : {
1111 : int16_t y, u, v;
1112 : int32_t r, g, b;
1113 :
1114 0 : y = ((uint8_t *) bits)[(x + i) << 1] - 16;
1115 0 : u = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 1] - 128;
1116 0 : v = ((uint8_t *) bits)[(((x + i) << 1) & - 4) + 3] - 128;
1117 :
1118 : /* R = 1.164(Y - 16) + 1.596(V - 128) */
1119 0 : r = 0x012b27 * y + 0x019a2e * v;
1120 : /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1121 0 : g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1122 : /* B = 1.164(Y - 16) + 2.018(U - 128) */
1123 0 : b = 0x012b27 * y + 0x0206a2 * u;
1124 :
1125 0 : *buffer++ = 0xff000000 |
1126 0 : (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1127 0 : (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1128 0 : (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1129 : }
1130 0 : }
1131 :
1132 : static void
1133 0 : fetch_scanline_yv12 (pixman_image_t *image,
1134 : int x,
1135 : int line,
1136 : int width,
1137 : uint32_t * buffer,
1138 : const uint32_t *mask)
1139 : {
1140 0 : YV12_SETUP (image);
1141 0 : uint8_t *y_line = YV12_Y (line);
1142 0 : uint8_t *u_line = YV12_U (line);
1143 0 : uint8_t *v_line = YV12_V (line);
1144 : int i;
1145 :
1146 0 : for (i = 0; i < width; i++)
1147 : {
1148 : int16_t y, u, v;
1149 : int32_t r, g, b;
1150 :
1151 0 : y = y_line[x + i] - 16;
1152 0 : u = u_line[(x + i) >> 1] - 128;
1153 0 : v = v_line[(x + i) >> 1] - 128;
1154 :
1155 : /* R = 1.164(Y - 16) + 1.596(V - 128) */
1156 0 : r = 0x012b27 * y + 0x019a2e * v;
1157 : /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1158 0 : g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1159 : /* B = 1.164(Y - 16) + 2.018(U - 128) */
1160 0 : b = 0x012b27 * y + 0x0206a2 * u;
1161 :
1162 0 : *buffer++ = 0xff000000 |
1163 0 : (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1164 0 : (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1165 0 : (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1166 : }
1167 0 : }
1168 :
1169 : /**************************** Pixel wise fetching *****************************/
1170 :
1171 : /* Despite the type, expects a uint64_t buffer */
1172 : static uint64_t
1173 0 : fetch_pixel_a2r10g10b10 (bits_image_t *image,
1174 : int offset,
1175 : int line)
1176 : {
1177 0 : uint32_t *bits = image->bits + line * image->rowstride;
1178 0 : uint32_t p = READ (image, bits + offset);
1179 0 : uint64_t a = p >> 30;
1180 0 : uint64_t r = (p >> 20) & 0x3ff;
1181 0 : uint64_t g = (p >> 10) & 0x3ff;
1182 0 : uint64_t b = p & 0x3ff;
1183 :
1184 0 : r = r << 6 | r >> 4;
1185 0 : g = g << 6 | g >> 4;
1186 0 : b = b << 6 | b >> 4;
1187 :
1188 0 : a <<= 14;
1189 0 : a |= a >> 2;
1190 0 : a |= a >> 4;
1191 0 : a |= a >> 8;
1192 :
1193 0 : return a << 48 | r << 32 | g << 16 | b;
1194 : }
1195 :
1196 : /* Despite the type, this function expects a uint64_t buffer */
1197 : static uint64_t
1198 0 : fetch_pixel_x2r10g10b10 (bits_image_t *image,
1199 : int offset,
1200 : int line)
1201 : {
1202 0 : uint32_t *bits = image->bits + line * image->rowstride;
1203 0 : uint32_t p = READ (image, bits + offset);
1204 0 : uint64_t r = (p >> 20) & 0x3ff;
1205 0 : uint64_t g = (p >> 10) & 0x3ff;
1206 0 : uint64_t b = p & 0x3ff;
1207 :
1208 0 : r = r << 6 | r >> 4;
1209 0 : g = g << 6 | g >> 4;
1210 0 : b = b << 6 | b >> 4;
1211 :
1212 0 : return 0xffffULL << 48 | r << 32 | g << 16 | b;
1213 : }
1214 :
1215 : /* Despite the type, expects a uint64_t buffer */
1216 : static uint64_t
1217 0 : fetch_pixel_a2b10g10r10 (bits_image_t *image,
1218 : int offset,
1219 : int line)
1220 : {
1221 0 : uint32_t *bits = image->bits + line * image->rowstride;
1222 0 : uint32_t p = READ (image, bits + offset);
1223 0 : uint64_t a = p >> 30;
1224 0 : uint64_t b = (p >> 20) & 0x3ff;
1225 0 : uint64_t g = (p >> 10) & 0x3ff;
1226 0 : uint64_t r = p & 0x3ff;
1227 :
1228 0 : r = r << 6 | r >> 4;
1229 0 : g = g << 6 | g >> 4;
1230 0 : b = b << 6 | b >> 4;
1231 :
1232 0 : a <<= 14;
1233 0 : a |= a >> 2;
1234 0 : a |= a >> 4;
1235 0 : a |= a >> 8;
1236 :
1237 0 : return a << 48 | r << 32 | g << 16 | b;
1238 : }
1239 :
1240 : /* Despite the type, this function expects a uint64_t buffer */
1241 : static uint64_t
1242 0 : fetch_pixel_x2b10g10r10 (bits_image_t *image,
1243 : int offset,
1244 : int line)
1245 : {
1246 0 : uint32_t *bits = image->bits + line * image->rowstride;
1247 0 : uint32_t p = READ (image, bits + offset);
1248 0 : uint64_t b = (p >> 20) & 0x3ff;
1249 0 : uint64_t g = (p >> 10) & 0x3ff;
1250 0 : uint64_t r = p & 0x3ff;
1251 :
1252 0 : r = r << 6 | r >> 4;
1253 0 : g = g << 6 | g >> 4;
1254 0 : b = b << 6 | b >> 4;
1255 :
1256 0 : return 0xffffULL << 48 | r << 32 | g << 16 | b;
1257 : }
1258 :
1259 : static uint32_t
1260 0 : fetch_pixel_a8r8g8b8 (bits_image_t *image,
1261 : int offset,
1262 : int line)
1263 : {
1264 0 : uint32_t *bits = image->bits + line * image->rowstride;
1265 0 : return READ (image, (uint32_t *)bits + offset);
1266 : }
1267 :
1268 : static uint32_t
1269 0 : fetch_pixel_x8r8g8b8 (bits_image_t *image,
1270 : int offset,
1271 : int line)
1272 : {
1273 0 : uint32_t *bits = image->bits + line * image->rowstride;
1274 :
1275 0 : return READ (image, (uint32_t *)bits + offset) | 0xff000000;
1276 : }
1277 :
1278 : static uint32_t
1279 0 : fetch_pixel_a8b8g8r8 (bits_image_t *image,
1280 : int offset,
1281 : int line)
1282 : {
1283 0 : uint32_t *bits = image->bits + line * image->rowstride;
1284 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1285 :
1286 0 : return ((pixel & 0xff000000) |
1287 0 : ((pixel >> 16) & 0xff) |
1288 0 : (pixel & 0x0000ff00) |
1289 0 : ((pixel & 0xff) << 16));
1290 : }
1291 :
1292 : static uint32_t
1293 0 : fetch_pixel_x8b8g8r8 (bits_image_t *image,
1294 : int offset,
1295 : int line)
1296 : {
1297 0 : uint32_t *bits = image->bits + line * image->rowstride;
1298 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1299 :
1300 0 : return ((0xff000000) |
1301 0 : ((pixel >> 16) & 0xff) |
1302 0 : (pixel & 0x0000ff00) |
1303 0 : ((pixel & 0xff) << 16));
1304 : }
1305 :
1306 : static uint32_t
1307 0 : fetch_pixel_b8g8r8a8 (bits_image_t *image,
1308 : int offset,
1309 : int line)
1310 : {
1311 0 : uint32_t *bits = image->bits + line * image->rowstride;
1312 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1313 :
1314 0 : return ((pixel & 0xff000000) >> 24 |
1315 0 : (pixel & 0x00ff0000) >> 8 |
1316 0 : (pixel & 0x0000ff00) << 8 |
1317 0 : (pixel & 0x000000ff) << 24);
1318 : }
1319 :
1320 : static uint32_t
1321 0 : fetch_pixel_b8g8r8x8 (bits_image_t *image,
1322 : int offset,
1323 : int line)
1324 : {
1325 0 : uint32_t *bits = image->bits + line * image->rowstride;
1326 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1327 :
1328 0 : return ((0xff000000) |
1329 0 : (pixel & 0xff000000) >> 24 |
1330 0 : (pixel & 0x00ff0000) >> 8 |
1331 0 : (pixel & 0x0000ff00) << 8);
1332 : }
1333 :
1334 : static uint32_t
1335 0 : fetch_pixel_r8g8b8a8 (bits_image_t *image,
1336 : int offset,
1337 : int line)
1338 : {
1339 0 : uint32_t *bits = image->bits + line * image->rowstride;
1340 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1341 :
1342 0 : return (((pixel & 0x000000ff) << 24) | (pixel >> 8));
1343 : }
1344 :
1345 : static uint32_t
1346 0 : fetch_pixel_r8g8b8x8 (bits_image_t *image,
1347 : int offset,
1348 : int line)
1349 : {
1350 0 : uint32_t *bits = image->bits + line * image->rowstride;
1351 0 : uint32_t pixel = READ (image, (uint32_t *)bits + offset);
1352 :
1353 0 : return (0xff000000 | (pixel >> 8));
1354 : }
1355 :
1356 : static uint32_t
1357 0 : fetch_pixel_x14r6g6b6 (bits_image_t *image,
1358 : int offset,
1359 : int line)
1360 : {
1361 0 : uint32_t *bits = image->bits + line * image->rowstride;
1362 0 : uint32_t pixel = READ (image, (uint32_t *) bits + offset);
1363 : uint32_t r, g, b;
1364 :
1365 0 : r = ((pixel & 0x3f000) << 6) | ((pixel & 0x30000));
1366 0 : g = ((pixel & 0x00fc0) << 4) | ((pixel & 0x00c00) >> 2);
1367 0 : b = ((pixel & 0x0003f) << 2) | ((pixel & 0x00030) >> 4);
1368 :
1369 0 : return 0xff000000 | r | g | b;
1370 : }
1371 :
1372 : static uint32_t
1373 0 : fetch_pixel_r8g8b8 (bits_image_t *image,
1374 : int offset,
1375 : int line)
1376 : {
1377 0 : uint32_t *bits = image->bits + line * image->rowstride;
1378 0 : uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1379 :
1380 : #ifdef WORDS_BIGENDIAN
1381 : return (0xff000000 |
1382 : (READ (image, pixel + 0) << 16) |
1383 : (READ (image, pixel + 1) << 8) |
1384 : (READ (image, pixel + 2)));
1385 : #else
1386 0 : return (0xff000000 |
1387 0 : (READ (image, pixel + 2) << 16) |
1388 0 : (READ (image, pixel + 1) << 8) |
1389 0 : (READ (image, pixel + 0)));
1390 : #endif
1391 : }
1392 :
1393 : static uint32_t
1394 0 : fetch_pixel_b8g8r8 (bits_image_t *image,
1395 : int offset,
1396 : int line)
1397 : {
1398 0 : uint32_t *bits = image->bits + line * image->rowstride;
1399 0 : uint8_t *pixel = ((uint8_t *) bits) + (offset * 3);
1400 : #ifdef WORDS_BIGENDIAN
1401 : return (0xff000000 |
1402 : (READ (image, pixel + 2) << 16) |
1403 : (READ (image, pixel + 1) << 8) |
1404 : (READ (image, pixel + 0)));
1405 : #else
1406 0 : return (0xff000000 |
1407 0 : (READ (image, pixel + 0) << 16) |
1408 0 : (READ (image, pixel + 1) << 8) |
1409 0 : (READ (image, pixel + 2)));
1410 : #endif
1411 : }
1412 :
1413 : static uint32_t
1414 0 : fetch_pixel_r5g6b5 (bits_image_t *image,
1415 : int offset,
1416 : int line)
1417 : {
1418 0 : uint32_t *bits = image->bits + line * image->rowstride;
1419 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1420 : uint32_t r, g, b;
1421 :
1422 0 : r = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) << 8;
1423 0 : g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1424 0 : b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1425 :
1426 0 : return (0xff000000 | r | g | b);
1427 : }
1428 :
1429 : static uint32_t
1430 0 : fetch_pixel_b5g6r5 (bits_image_t *image,
1431 : int offset,
1432 : int line)
1433 : {
1434 : uint32_t r, g, b;
1435 0 : uint32_t *bits = image->bits + line * image->rowstride;
1436 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1437 :
1438 0 : b = ((pixel & 0xf800) | ((pixel & 0xe000) >> 5)) >> 8;
1439 0 : g = ((pixel & 0x07e0) | ((pixel & 0x0600) >> 6)) << 5;
1440 0 : r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1441 :
1442 0 : return (0xff000000 | r | g | b);
1443 : }
1444 :
1445 : static uint32_t
1446 0 : fetch_pixel_a1r5g5b5 (bits_image_t *image,
1447 : int offset,
1448 : int line)
1449 : {
1450 0 : uint32_t *bits = image->bits + line * image->rowstride;
1451 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1452 : uint32_t a, r, g, b;
1453 :
1454 0 : a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1455 0 : r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1456 0 : g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1457 0 : b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1458 :
1459 0 : return (a | r | g | b);
1460 : }
1461 :
1462 : static uint32_t
1463 0 : fetch_pixel_x1r5g5b5 (bits_image_t *image,
1464 : int offset,
1465 : int line)
1466 : {
1467 0 : uint32_t *bits = image->bits + line * image->rowstride;
1468 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1469 : uint32_t r, g, b;
1470 :
1471 0 : r = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) << 9;
1472 0 : g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1473 0 : b = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) >> 2;
1474 :
1475 0 : return (0xff000000 | r | g | b);
1476 : }
1477 :
1478 : static uint32_t
1479 0 : fetch_pixel_a1b5g5r5 (bits_image_t *image,
1480 : int offset,
1481 : int line)
1482 : {
1483 0 : uint32_t *bits = image->bits + line * image->rowstride;
1484 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1485 : uint32_t a, r, g, b;
1486 :
1487 0 : a = (uint32_t) ((uint8_t) (0 - ((pixel & 0x8000) >> 15))) << 24;
1488 0 : b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1489 0 : g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1490 0 : r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1491 :
1492 0 : return (a | r | g | b);
1493 : }
1494 :
1495 : static uint32_t
1496 0 : fetch_pixel_x1b5g5r5 (bits_image_t *image,
1497 : int offset,
1498 : int line)
1499 : {
1500 0 : uint32_t *bits = image->bits + line * image->rowstride;
1501 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1502 : uint32_t r, g, b;
1503 :
1504 0 : b = ((pixel & 0x7c00) | ((pixel & 0x7000) >> 5)) >> 7;
1505 0 : g = ((pixel & 0x03e0) | ((pixel & 0x0380) >> 5)) << 6;
1506 0 : r = ((pixel & 0x001c) | ((pixel & 0x001f) << 5)) << 14;
1507 :
1508 0 : return (0xff000000 | r | g | b);
1509 : }
1510 :
1511 : static uint32_t
1512 0 : fetch_pixel_a4r4g4b4 (bits_image_t *image,
1513 : int offset,
1514 : int line)
1515 : {
1516 0 : uint32_t *bits = image->bits + line * image->rowstride;
1517 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1518 : uint32_t a, r, g, b;
1519 :
1520 0 : a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1521 0 : r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1522 0 : g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1523 0 : b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1524 :
1525 0 : return (a | r | g | b);
1526 : }
1527 :
1528 : static uint32_t
1529 0 : fetch_pixel_x4r4g4b4 (bits_image_t *image,
1530 : int offset,
1531 : int line)
1532 : {
1533 0 : uint32_t *bits = image->bits + line * image->rowstride;
1534 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1535 : uint32_t r, g, b;
1536 :
1537 0 : r = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) << 12;
1538 0 : g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1539 0 : b = ((pixel & 0x000f) | ((pixel & 0x000f) << 4));
1540 :
1541 0 : return (0xff000000 | r | g | b);
1542 : }
1543 :
1544 : static uint32_t
1545 0 : fetch_pixel_a4b4g4r4 (bits_image_t *image,
1546 : int offset,
1547 : int line)
1548 : {
1549 0 : uint32_t *bits = image->bits + line * image->rowstride;
1550 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1551 : uint32_t a, r, g, b;
1552 :
1553 0 : a = ((pixel & 0xf000) | ((pixel & 0xf000) >> 4)) << 16;
1554 0 : b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1555 0 : g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1556 0 : r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1557 :
1558 0 : return (a | r | g | b);
1559 : }
1560 :
1561 : static uint32_t
1562 0 : fetch_pixel_x4b4g4r4 (bits_image_t *image,
1563 : int offset,
1564 : int line)
1565 : {
1566 0 : uint32_t *bits = image->bits + line * image->rowstride;
1567 0 : uint32_t pixel = READ (image, (uint16_t *) bits + offset);
1568 : uint32_t r, g, b;
1569 :
1570 0 : b = ((pixel & 0x0f00) | ((pixel & 0x0f00) >> 4)) >> 4;
1571 0 : g = ((pixel & 0x00f0) | ((pixel & 0x00f0) >> 4)) << 8;
1572 0 : r = ((pixel & 0x000f) | ((pixel & 0x000f) << 4)) << 16;
1573 :
1574 0 : return (0xff000000 | r | g | b);
1575 : }
1576 :
1577 : static uint32_t
1578 0 : fetch_pixel_a8 (bits_image_t *image,
1579 : int offset,
1580 : int line)
1581 : {
1582 0 : uint32_t *bits = image->bits + line * image->rowstride;
1583 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1584 :
1585 0 : return pixel << 24;
1586 : }
1587 :
1588 : static uint32_t
1589 0 : fetch_pixel_r3g3b2 (bits_image_t *image,
1590 : int offset,
1591 : int line)
1592 : {
1593 0 : uint32_t *bits = image->bits + line * image->rowstride;
1594 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1595 : uint32_t r, g, b;
1596 :
1597 0 : r = ((pixel & 0xe0) |
1598 0 : ((pixel & 0xe0) >> 3) |
1599 0 : ((pixel & 0xc0) >> 6)) << 16;
1600 :
1601 0 : g = ((pixel & 0x1c) |
1602 0 : ((pixel & 0x18) >> 3) |
1603 0 : ((pixel & 0x1c) << 3)) << 8;
1604 :
1605 0 : b = (((pixel & 0x03) ) |
1606 0 : ((pixel & 0x03) << 2) |
1607 0 : ((pixel & 0x03) << 4) |
1608 0 : ((pixel & 0x03) << 6));
1609 :
1610 0 : return (0xff000000 | r | g | b);
1611 : }
1612 :
1613 : static uint32_t
1614 0 : fetch_pixel_b2g3r3 (bits_image_t *image,
1615 : int offset,
1616 : int line)
1617 : {
1618 0 : uint32_t *bits = image->bits + line * image->rowstride;
1619 0 : uint32_t p = READ (image, (uint8_t *) bits + offset);
1620 : uint32_t r, g, b;
1621 :
1622 0 : b = p & 0xc0;
1623 0 : b |= b >> 2;
1624 0 : b |= b >> 4;
1625 0 : b &= 0xff;
1626 :
1627 0 : g = (p & 0x38) << 10;
1628 0 : g |= g >> 3;
1629 0 : g |= g >> 6;
1630 0 : g &= 0xff00;
1631 :
1632 0 : r = (p & 0x7) << 21;
1633 0 : r |= r >> 3;
1634 0 : r |= r >> 6;
1635 0 : r &= 0xff0000;
1636 :
1637 0 : return 0xff000000 | r | g | b;
1638 : }
1639 :
1640 : static uint32_t
1641 0 : fetch_pixel_a2r2g2b2 (bits_image_t *image,
1642 : int offset,
1643 : int line)
1644 : {
1645 0 : uint32_t *bits = image->bits + line * image->rowstride;
1646 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1647 : uint32_t a, r, g, b;
1648 :
1649 0 : a = ((pixel & 0xc0) * 0x55) << 18;
1650 0 : r = ((pixel & 0x30) * 0x55) << 12;
1651 0 : g = ((pixel & 0x0c) * 0x55) << 6;
1652 0 : b = ((pixel & 0x03) * 0x55);
1653 :
1654 0 : return a | r | g | b;
1655 : }
1656 :
1657 : static uint32_t
1658 0 : fetch_pixel_a2b2g2r2 (bits_image_t *image,
1659 : int offset,
1660 : int line)
1661 : {
1662 0 : uint32_t *bits = image->bits + line * image->rowstride;
1663 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1664 : uint32_t a, r, g, b;
1665 :
1666 0 : a = ((pixel & 0xc0) * 0x55) << 18;
1667 0 : b = ((pixel & 0x30) * 0x55) >> 4;
1668 0 : g = ((pixel & 0x0c) * 0x55) << 6;
1669 0 : r = ((pixel & 0x03) * 0x55) << 16;
1670 :
1671 0 : return a | r | g | b;
1672 : }
1673 :
1674 : static uint32_t
1675 0 : fetch_pixel_c8 (bits_image_t *image,
1676 : int offset,
1677 : int line)
1678 : {
1679 0 : uint32_t *bits = image->bits + line * image->rowstride;
1680 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1681 0 : const pixman_indexed_t * indexed = image->indexed;
1682 :
1683 0 : return indexed->rgba[pixel];
1684 : }
1685 :
1686 : static uint32_t
1687 0 : fetch_pixel_x4a4 (bits_image_t *image,
1688 : int offset,
1689 : int line)
1690 : {
1691 0 : uint32_t *bits = image->bits + line * image->rowstride;
1692 0 : uint32_t pixel = READ (image, (uint8_t *) bits + offset);
1693 :
1694 0 : return ((pixel & 0xf) | ((pixel & 0xf) << 4)) << 24;
1695 : }
1696 :
1697 : static uint32_t
1698 0 : fetch_pixel_a4 (bits_image_t *image,
1699 : int offset,
1700 : int line)
1701 : {
1702 0 : uint32_t *bits = image->bits + line * image->rowstride;
1703 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1704 :
1705 0 : pixel |= pixel << 4;
1706 0 : return pixel << 24;
1707 : }
1708 :
1709 : static uint32_t
1710 0 : fetch_pixel_r1g2b1 (bits_image_t *image,
1711 : int offset,
1712 : int line)
1713 : {
1714 0 : uint32_t *bits = image->bits + line * image->rowstride;
1715 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1716 : uint32_t r, g, b;
1717 :
1718 0 : r = ((pixel & 0x8) * 0xff) << 13;
1719 0 : g = ((pixel & 0x6) * 0x55) << 7;
1720 0 : b = ((pixel & 0x1) * 0xff);
1721 :
1722 0 : return 0xff000000 | r | g | b;
1723 : }
1724 :
1725 : static uint32_t
1726 0 : fetch_pixel_b1g2r1 (bits_image_t *image,
1727 : int offset,
1728 : int line)
1729 : {
1730 0 : uint32_t *bits = image->bits + line * image->rowstride;
1731 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1732 : uint32_t r, g, b;
1733 :
1734 0 : b = ((pixel & 0x8) * 0xff) >> 3;
1735 0 : g = ((pixel & 0x6) * 0x55) << 7;
1736 0 : r = ((pixel & 0x1) * 0xff) << 16;
1737 :
1738 0 : return 0xff000000 | r | g | b;
1739 : }
1740 :
1741 : static uint32_t
1742 0 : fetch_pixel_a1r1g1b1 (bits_image_t *image,
1743 : int offset,
1744 : int line)
1745 : {
1746 0 : uint32_t *bits = image->bits + line * image->rowstride;
1747 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1748 : uint32_t a, r, g, b;
1749 :
1750 0 : a = ((pixel & 0x8) * 0xff) << 21;
1751 0 : r = ((pixel & 0x4) * 0xff) << 14;
1752 0 : g = ((pixel & 0x2) * 0xff) << 7;
1753 0 : b = ((pixel & 0x1) * 0xff);
1754 :
1755 0 : return a | r | g | b;
1756 : }
1757 :
1758 : static uint32_t
1759 0 : fetch_pixel_a1b1g1r1 (bits_image_t *image,
1760 : int offset,
1761 : int line)
1762 : {
1763 0 : uint32_t *bits = image->bits + line * image->rowstride;
1764 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1765 : uint32_t a, r, g, b;
1766 :
1767 0 : a = ((pixel & 0x8) * 0xff) << 21;
1768 0 : b = ((pixel & 0x4) * 0xff) >> 2;
1769 0 : g = ((pixel & 0x2) * 0xff) << 7;
1770 0 : r = ((pixel & 0x1) * 0xff) << 16;
1771 :
1772 0 : return a | r | g | b;
1773 : }
1774 :
1775 : static uint32_t
1776 0 : fetch_pixel_c4 (bits_image_t *image,
1777 : int offset,
1778 : int line)
1779 : {
1780 0 : uint32_t *bits = image->bits + line * image->rowstride;
1781 0 : uint32_t pixel = FETCH_4 (image, bits, offset);
1782 0 : const pixman_indexed_t * indexed = image->indexed;
1783 :
1784 0 : return indexed->rgba[pixel];
1785 : }
1786 :
1787 : static uint32_t
1788 0 : fetch_pixel_a1 (bits_image_t *image,
1789 : int offset,
1790 : int line)
1791 : {
1792 0 : uint32_t *bits = image->bits + line * image->rowstride;
1793 0 : uint32_t pixel = READ (image, bits + (offset >> 5));
1794 : uint32_t a;
1795 :
1796 : #ifdef WORDS_BIGENDIAN
1797 : a = pixel >> (0x1f - (offset & 0x1f));
1798 : #else
1799 0 : a = pixel >> (offset & 0x1f);
1800 : #endif
1801 0 : a = a & 1;
1802 0 : a |= a << 1;
1803 0 : a |= a << 2;
1804 0 : a |= a << 4;
1805 :
1806 0 : return a << 24;
1807 : }
1808 :
1809 : static uint32_t
1810 0 : fetch_pixel_g1 (bits_image_t *image,
1811 : int offset,
1812 : int line)
1813 : {
1814 0 : uint32_t *bits = image->bits + line * image->rowstride;
1815 0 : uint32_t pixel = READ (image, bits + (offset >> 5));
1816 0 : const pixman_indexed_t * indexed = image->indexed;
1817 : uint32_t a;
1818 :
1819 : #ifdef WORDS_BIGENDIAN
1820 : a = pixel >> (0x1f - (offset & 0x1f));
1821 : #else
1822 0 : a = pixel >> (offset & 0x1f);
1823 : #endif
1824 0 : a = a & 1;
1825 :
1826 0 : return indexed->rgba[a];
1827 : }
1828 :
1829 : static uint32_t
1830 0 : fetch_pixel_yuy2 (bits_image_t *image,
1831 : int offset,
1832 : int line)
1833 : {
1834 0 : const uint32_t *bits = image->bits + image->rowstride * line;
1835 :
1836 : int16_t y, u, v;
1837 : int32_t r, g, b;
1838 :
1839 0 : y = ((uint8_t *) bits)[offset << 1] - 16;
1840 0 : u = ((uint8_t *) bits)[((offset << 1) & - 4) + 1] - 128;
1841 0 : v = ((uint8_t *) bits)[((offset << 1) & - 4) + 3] - 128;
1842 :
1843 : /* R = 1.164(Y - 16) + 1.596(V - 128) */
1844 0 : r = 0x012b27 * y + 0x019a2e * v;
1845 :
1846 : /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1847 0 : g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1848 :
1849 : /* B = 1.164(Y - 16) + 2.018(U - 128) */
1850 0 : b = 0x012b27 * y + 0x0206a2 * u;
1851 :
1852 0 : return 0xff000000 |
1853 0 : (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1854 0 : (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1855 0 : (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1856 : }
1857 :
1858 : static uint32_t
1859 0 : fetch_pixel_yv12 (bits_image_t *image,
1860 : int offset,
1861 : int line)
1862 : {
1863 0 : YV12_SETUP (image);
1864 0 : int16_t y = YV12_Y (line)[offset] - 16;
1865 0 : int16_t u = YV12_U (line)[offset >> 1] - 128;
1866 0 : int16_t v = YV12_V (line)[offset >> 1] - 128;
1867 : int32_t r, g, b;
1868 :
1869 : /* R = 1.164(Y - 16) + 1.596(V - 128) */
1870 0 : r = 0x012b27 * y + 0x019a2e * v;
1871 :
1872 : /* G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) */
1873 0 : g = 0x012b27 * y - 0x00d0f2 * v - 0x00647e * u;
1874 :
1875 : /* B = 1.164(Y - 16) + 2.018(U - 128) */
1876 0 : b = 0x012b27 * y + 0x0206a2 * u;
1877 :
1878 0 : return 0xff000000 |
1879 0 : (r >= 0 ? r < 0x1000000 ? r & 0xff0000 : 0xff0000 : 0) |
1880 0 : (g >= 0 ? g < 0x1000000 ? (g >> 8) & 0x00ff00 : 0x00ff00 : 0) |
1881 0 : (b >= 0 ? b < 0x1000000 ? (b >> 16) & 0x0000ff : 0x0000ff : 0);
1882 : }
1883 :
1884 : /*********************************** Store ************************************/
1885 :
1886 : #define SPLIT_A(v) \
1887 : uint32_t a = ((v) >> 24), \
1888 : r = ((v) >> 16) & 0xff, \
1889 : g = ((v) >> 8) & 0xff, \
1890 : b = (v) & 0xff
1891 :
1892 : #define SPLIT(v) \
1893 : uint32_t r = ((v) >> 16) & 0xff, \
1894 : g = ((v) >> 8) & 0xff, \
1895 : b = (v) & 0xff
1896 :
1897 : static void
1898 0 : store_scanline_a2r10g10b10 (bits_image_t * image,
1899 : int x,
1900 : int y,
1901 : int width,
1902 : const uint32_t *v)
1903 : {
1904 0 : uint32_t *bits = image->bits + image->rowstride * y;
1905 0 : uint32_t *pixel = bits + x;
1906 0 : uint64_t *values = (uint64_t *)v;
1907 : int i;
1908 :
1909 0 : for (i = 0; i < width; ++i)
1910 : {
1911 0 : WRITE (image, pixel++,
1912 : ((values[i] >> 32) & 0xc0000000) |
1913 : ((values[i] >> 18) & 0x3ff00000) |
1914 : ((values[i] >> 12) & 0xffc00) |
1915 : ((values[i] >> 6) & 0x3ff));
1916 : }
1917 0 : }
1918 :
1919 : static void
1920 0 : store_scanline_x2r10g10b10 (bits_image_t * image,
1921 : int x,
1922 : int y,
1923 : int width,
1924 : const uint32_t *v)
1925 : {
1926 0 : uint32_t *bits = image->bits + image->rowstride * y;
1927 0 : uint64_t *values = (uint64_t *)v;
1928 0 : uint32_t *pixel = bits + x;
1929 : int i;
1930 :
1931 0 : for (i = 0; i < width; ++i)
1932 : {
1933 0 : WRITE (image, pixel++,
1934 : ((values[i] >> 18) & 0x3ff00000) |
1935 : ((values[i] >> 12) & 0xffc00) |
1936 : ((values[i] >> 6) & 0x3ff));
1937 : }
1938 0 : }
1939 :
1940 : static void
1941 0 : store_scanline_a2b10g10r10 (bits_image_t * image,
1942 : int x,
1943 : int y,
1944 : int width,
1945 : const uint32_t *v)
1946 : {
1947 0 : uint32_t *bits = image->bits + image->rowstride * y;
1948 0 : uint32_t *pixel = bits + x;
1949 0 : uint64_t *values = (uint64_t *)v;
1950 : int i;
1951 :
1952 0 : for (i = 0; i < width; ++i)
1953 : {
1954 0 : WRITE (image, pixel++,
1955 : ((values[i] >> 32) & 0xc0000000) |
1956 : ((values[i] >> 38) & 0x3ff) |
1957 : ((values[i] >> 12) & 0xffc00) |
1958 : ((values[i] << 14) & 0x3ff00000));
1959 : }
1960 0 : }
1961 :
1962 : static void
1963 0 : store_scanline_x2b10g10r10 (bits_image_t * image,
1964 : int x,
1965 : int y,
1966 : int width,
1967 : const uint32_t *v)
1968 : {
1969 0 : uint32_t *bits = image->bits + image->rowstride * y;
1970 0 : uint64_t *values = (uint64_t *)v;
1971 0 : uint32_t *pixel = bits + x;
1972 : int i;
1973 :
1974 0 : for (i = 0; i < width; ++i)
1975 : {
1976 0 : WRITE (image, pixel++,
1977 : ((values[i] >> 38) & 0x3ff) |
1978 : ((values[i] >> 12) & 0xffc00) |
1979 : ((values[i] << 14) & 0x3ff00000));
1980 : }
1981 0 : }
1982 :
1983 : static void
1984 0 : store_scanline_a8r8g8b8 (bits_image_t * image,
1985 : int x,
1986 : int y,
1987 : int width,
1988 : const uint32_t *values)
1989 : {
1990 0 : uint32_t *bits = image->bits + image->rowstride * y;
1991 :
1992 0 : MEMCPY_WRAPPED (image, ((uint32_t *)bits) + x, values,
1993 : width * sizeof(uint32_t));
1994 0 : }
1995 :
1996 : static void
1997 0 : store_scanline_x8r8g8b8 (bits_image_t * image,
1998 : int x,
1999 : int y,
2000 : int width,
2001 : const uint32_t *values)
2002 : {
2003 0 : uint32_t *bits = image->bits + image->rowstride * y;
2004 0 : uint32_t *pixel = (uint32_t *)bits + x;
2005 : int i;
2006 :
2007 0 : for (i = 0; i < width; ++i)
2008 0 : WRITE (image, pixel++, values[i] & 0xffffff);
2009 0 : }
2010 :
2011 : static void
2012 0 : store_scanline_a8b8g8r8 (bits_image_t * image,
2013 : int x,
2014 : int y,
2015 : int width,
2016 : const uint32_t *values)
2017 : {
2018 0 : uint32_t *bits = image->bits + image->rowstride * y;
2019 0 : uint32_t *pixel = (uint32_t *)bits + x;
2020 : int i;
2021 :
2022 0 : for (i = 0; i < width; ++i)
2023 : {
2024 0 : WRITE (image, pixel++,
2025 : (values[i] & 0xff00ff00) |
2026 : ((values[i] >> 16) & 0xff) |
2027 : ((values[i] & 0xff) << 16));
2028 : }
2029 0 : }
2030 :
2031 : static void
2032 0 : store_scanline_x8b8g8r8 (bits_image_t * image,
2033 : int x,
2034 : int y,
2035 : int width,
2036 : const uint32_t *values)
2037 : {
2038 0 : uint32_t *bits = image->bits + image->rowstride * y;
2039 0 : uint32_t *pixel = (uint32_t *)bits + x;
2040 : int i;
2041 :
2042 0 : for (i = 0; i < width; ++i)
2043 : {
2044 0 : WRITE (image, pixel++,
2045 : (values[i] & 0x0000ff00) |
2046 : ((values[i] >> 16) & 0xff) |
2047 : ((values[i] & 0xff) << 16));
2048 : }
2049 0 : }
2050 :
2051 : static void
2052 0 : store_scanline_b8g8r8a8 (bits_image_t * image,
2053 : int x,
2054 : int y,
2055 : int width,
2056 : const uint32_t *values)
2057 : {
2058 0 : uint32_t *bits = image->bits + image->rowstride * y;
2059 0 : uint32_t *pixel = (uint32_t *)bits + x;
2060 : int i;
2061 :
2062 0 : for (i = 0; i < width; ++i)
2063 : {
2064 0 : WRITE (image, pixel++,
2065 : ((values[i] >> 24) & 0x000000ff) |
2066 : ((values[i] >> 8) & 0x0000ff00) |
2067 : ((values[i] << 8) & 0x00ff0000) |
2068 : ((values[i] << 24) & 0xff000000));
2069 : }
2070 0 : }
2071 :
2072 : static void
2073 0 : store_scanline_b8g8r8x8 (bits_image_t * image,
2074 : int x,
2075 : int y,
2076 : int width,
2077 : const uint32_t *values)
2078 : {
2079 0 : uint32_t *bits = image->bits + image->rowstride * y;
2080 0 : uint32_t *pixel = (uint32_t *)bits + x;
2081 : int i;
2082 :
2083 0 : for (i = 0; i < width; ++i)
2084 : {
2085 0 : WRITE (image, pixel++,
2086 : ((values[i] >> 8) & 0x0000ff00) |
2087 : ((values[i] << 8) & 0x00ff0000) |
2088 : ((values[i] << 24) & 0xff000000));
2089 : }
2090 0 : }
2091 :
2092 : static void
2093 0 : store_scanline_r8g8b8a8 (bits_image_t * image,
2094 : int x,
2095 : int y,
2096 : int width,
2097 : const uint32_t *values)
2098 : {
2099 0 : uint32_t *bits = image->bits + image->rowstride * y;
2100 0 : uint32_t *pixel = (uint32_t *)bits + x;
2101 : int i;
2102 :
2103 0 : for (i = 0; i < width; ++i)
2104 : {
2105 0 : WRITE (image, pixel++,
2106 : ((values[i] >> 24) & 0x000000ff) | (values[i] << 8));
2107 : }
2108 0 : }
2109 :
2110 : static void
2111 0 : store_scanline_r8g8b8x8 (bits_image_t * image,
2112 : int x,
2113 : int y,
2114 : int width,
2115 : const uint32_t *values)
2116 : {
2117 0 : uint32_t *bits = image->bits + image->rowstride * y;
2118 0 : uint32_t *pixel = (uint32_t *)bits + x;
2119 : int i;
2120 :
2121 0 : for (i = 0; i < width; ++i)
2122 0 : WRITE (image, pixel++, (values[i] << 8));
2123 0 : }
2124 :
2125 : static void
2126 0 : store_scanline_x14r6g6b6 (bits_image_t * image,
2127 : int x,
2128 : int y,
2129 : int width,
2130 : const uint32_t *values)
2131 : {
2132 0 : uint32_t *bits = image->bits + image->rowstride * y;
2133 0 : uint32_t *pixel = ((uint32_t *) bits) + x;
2134 : int i;
2135 :
2136 0 : for (i = 0; i < width; ++i)
2137 : {
2138 0 : uint32_t s = values[i];
2139 : uint32_t r, g, b;
2140 :
2141 0 : r = (s & 0xfc0000) >> 6;
2142 0 : g = (s & 0x00fc00) >> 4;
2143 0 : b = (s & 0x0000fc) >> 2;
2144 :
2145 0 : WRITE (image, pixel++, r | g | b);
2146 : }
2147 0 : }
2148 :
2149 : static void
2150 0 : store_scanline_r8g8b8 (bits_image_t * image,
2151 : int x,
2152 : int y,
2153 : int width,
2154 : const uint32_t *values)
2155 : {
2156 0 : uint32_t *bits = image->bits + image->rowstride * y;
2157 0 : uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2158 : int i;
2159 :
2160 0 : for (i = 0; i < width; ++i)
2161 : {
2162 0 : uint32_t val = values[i];
2163 :
2164 : #ifdef WORDS_BIGENDIAN
2165 : WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2166 : WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2167 : WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2168 : #else
2169 0 : WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2170 0 : WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2171 0 : WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2172 : #endif
2173 : }
2174 0 : }
2175 :
2176 : static void
2177 0 : store_scanline_b8g8r8 (bits_image_t * image,
2178 : int x,
2179 : int y,
2180 : int width,
2181 : const uint32_t *values)
2182 : {
2183 0 : uint32_t *bits = image->bits + image->rowstride * y;
2184 0 : uint8_t *pixel = ((uint8_t *) bits) + 3 * x;
2185 : int i;
2186 :
2187 0 : for (i = 0; i < width; ++i)
2188 : {
2189 0 : uint32_t val = values[i];
2190 :
2191 : #ifdef WORDS_BIGENDIAN
2192 : WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2193 : WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2194 : WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2195 : #else
2196 0 : WRITE (image, pixel++, (val & 0x00ff0000) >> 16);
2197 0 : WRITE (image, pixel++, (val & 0x0000ff00) >> 8);
2198 0 : WRITE (image, pixel++, (val & 0x000000ff) >> 0);
2199 : #endif
2200 : }
2201 0 : }
2202 :
2203 : static void
2204 0 : store_scanline_r5g6b5 (bits_image_t * image,
2205 : int x,
2206 : int y,
2207 : int width,
2208 : const uint32_t *values)
2209 : {
2210 0 : uint32_t *bits = image->bits + image->rowstride * y;
2211 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2212 : int i;
2213 :
2214 0 : for (i = 0; i < width; ++i)
2215 : {
2216 0 : uint32_t s = values[i];
2217 :
2218 0 : WRITE (image, pixel++,
2219 : ((s >> 3) & 0x001f) |
2220 : ((s >> 5) & 0x07e0) |
2221 : ((s >> 8) & 0xf800));
2222 : }
2223 0 : }
2224 :
2225 : static void
2226 0 : store_scanline_b5g6r5 (bits_image_t * image,
2227 : int x,
2228 : int y,
2229 : int width,
2230 : const uint32_t *values)
2231 : {
2232 0 : uint32_t *bits = image->bits + image->rowstride * y;
2233 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2234 : int i;
2235 :
2236 0 : for (i = 0; i < width; ++i)
2237 : {
2238 0 : SPLIT (values[i]);
2239 :
2240 0 : WRITE (image, pixel++,
2241 : ((b << 8) & 0xf800) |
2242 : ((g << 3) & 0x07e0) |
2243 : ((r >> 3) ));
2244 : }
2245 0 : }
2246 :
2247 : static void
2248 0 : store_scanline_a1r5g5b5 (bits_image_t * image,
2249 : int x,
2250 : int y,
2251 : int width,
2252 : const uint32_t *values)
2253 : {
2254 0 : uint32_t *bits = image->bits + image->rowstride * y;
2255 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2256 : int i;
2257 :
2258 0 : for (i = 0; i < width; ++i)
2259 : {
2260 0 : SPLIT_A (values[i]);
2261 :
2262 0 : WRITE (image, pixel++,
2263 : ((a << 8) & 0x8000) |
2264 : ((r << 7) & 0x7c00) |
2265 : ((g << 2) & 0x03e0) |
2266 : ((b >> 3) ));
2267 : }
2268 0 : }
2269 :
2270 : static void
2271 0 : store_scanline_x1r5g5b5 (bits_image_t * image,
2272 : int x,
2273 : int y,
2274 : int width,
2275 : const uint32_t *values)
2276 : {
2277 0 : uint32_t *bits = image->bits + image->rowstride * y;
2278 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2279 : int i;
2280 :
2281 0 : for (i = 0; i < width; ++i)
2282 : {
2283 0 : SPLIT (values[i]);
2284 :
2285 0 : WRITE (image, pixel++,
2286 : ((r << 7) & 0x7c00) |
2287 : ((g << 2) & 0x03e0) |
2288 : ((b >> 3) ));
2289 : }
2290 0 : }
2291 :
2292 : static void
2293 0 : store_scanline_a1b5g5r5 (bits_image_t * image,
2294 : int x,
2295 : int y,
2296 : int width,
2297 : const uint32_t *values)
2298 : {
2299 0 : uint32_t *bits = image->bits + image->rowstride * y;
2300 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2301 : int i;
2302 :
2303 0 : for (i = 0; i < width; ++i)
2304 : {
2305 0 : SPLIT_A (values[i]);
2306 :
2307 0 : WRITE (image, pixel++,
2308 : ((a << 8) & 0x8000) |
2309 : ((b << 7) & 0x7c00) |
2310 : ((g << 2) & 0x03e0) |
2311 : ((r >> 3) ));
2312 : }
2313 0 : }
2314 :
2315 : static void
2316 0 : store_scanline_x1b5g5r5 (bits_image_t * image,
2317 : int x,
2318 : int y,
2319 : int width,
2320 : const uint32_t *values)
2321 : {
2322 0 : uint32_t *bits = image->bits + image->rowstride * y;
2323 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2324 : int i;
2325 :
2326 0 : for (i = 0; i < width; ++i)
2327 : {
2328 0 : SPLIT (values[i]);
2329 :
2330 0 : WRITE (image, pixel++, ((b << 7) & 0x7c00) |
2331 : ((g << 2) & 0x03e0) |
2332 : ((r >> 3) ));
2333 : }
2334 0 : }
2335 :
2336 : static void
2337 0 : store_scanline_a4r4g4b4 (bits_image_t * image,
2338 : int x,
2339 : int y,
2340 : int width,
2341 : const uint32_t *values)
2342 : {
2343 0 : uint32_t *bits = image->bits + image->rowstride * y;
2344 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2345 : int i;
2346 :
2347 0 : for (i = 0; i < width; ++i)
2348 : {
2349 0 : SPLIT_A (values[i]);
2350 :
2351 0 : WRITE (image, pixel++,
2352 : ((a << 8) & 0xf000) |
2353 : ((r << 4) & 0x0f00) |
2354 : ((g ) & 0x00f0) |
2355 : ((b >> 4) ));
2356 : }
2357 0 : }
2358 :
2359 : static void
2360 0 : store_scanline_x4r4g4b4 (bits_image_t * image,
2361 : int x,
2362 : int y,
2363 : int width,
2364 : const uint32_t *values)
2365 : {
2366 0 : uint32_t *bits = image->bits + image->rowstride * y;
2367 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2368 : int i;
2369 :
2370 0 : for (i = 0; i < width; ++i)
2371 : {
2372 0 : SPLIT (values[i]);
2373 :
2374 0 : WRITE (image, pixel++,
2375 : ((r << 4) & 0x0f00) |
2376 : ((g ) & 0x00f0) |
2377 : ((b >> 4) ));
2378 : }
2379 0 : }
2380 :
2381 : static void
2382 0 : store_scanline_a4b4g4r4 (bits_image_t * image,
2383 : int x,
2384 : int y,
2385 : int width,
2386 : const uint32_t *values)
2387 : {
2388 0 : uint32_t *bits = image->bits + image->rowstride * y;
2389 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2390 : int i;
2391 :
2392 0 : for (i = 0; i < width; ++i)
2393 : {
2394 0 : SPLIT_A (values[i]);
2395 0 : WRITE (image, pixel++, ((a << 8) & 0xf000) |
2396 : ((b << 4) & 0x0f00) |
2397 : ((g ) & 0x00f0) |
2398 : ((r >> 4) ));
2399 : }
2400 0 : }
2401 :
2402 : static void
2403 0 : store_scanline_x4b4g4r4 (bits_image_t * image,
2404 : int x,
2405 : int y,
2406 : int width,
2407 : const uint32_t *values)
2408 : {
2409 0 : uint32_t *bits = image->bits + image->rowstride * y;
2410 0 : uint16_t *pixel = ((uint16_t *) bits) + x;
2411 : int i;
2412 :
2413 0 : for (i = 0; i < width; ++i)
2414 : {
2415 0 : SPLIT (values[i]);
2416 :
2417 0 : WRITE (image, pixel++,
2418 : ((b << 4) & 0x0f00) |
2419 : ((g ) & 0x00f0) |
2420 : ((r >> 4) ));
2421 : }
2422 0 : }
2423 :
2424 : static void
2425 0 : store_scanline_a8 (bits_image_t * image,
2426 : int x,
2427 : int y,
2428 : int width,
2429 : const uint32_t *values)
2430 : {
2431 0 : uint32_t *bits = image->bits + image->rowstride * y;
2432 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2433 : int i;
2434 :
2435 0 : for (i = 0; i < width; ++i)
2436 : {
2437 0 : WRITE (image, pixel++, values[i] >> 24);
2438 : }
2439 0 : }
2440 :
2441 : static void
2442 0 : store_scanline_r3g3b2 (bits_image_t * image,
2443 : int x,
2444 : int y,
2445 : int width,
2446 : const uint32_t *values)
2447 : {
2448 0 : uint32_t *bits = image->bits + image->rowstride * y;
2449 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2450 : int i;
2451 :
2452 0 : for (i = 0; i < width; ++i)
2453 : {
2454 0 : SPLIT (values[i]);
2455 :
2456 0 : WRITE (image, pixel++,
2457 : ((r ) & 0xe0) |
2458 : ((g >> 3) & 0x1c) |
2459 : ((b >> 6) ));
2460 : }
2461 0 : }
2462 :
2463 : static void
2464 0 : store_scanline_b2g3r3 (bits_image_t * image,
2465 : int x,
2466 : int y,
2467 : int width,
2468 : const uint32_t *values)
2469 : {
2470 0 : uint32_t *bits = image->bits + image->rowstride * y;
2471 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2472 : int i;
2473 :
2474 0 : for (i = 0; i < width; ++i)
2475 : {
2476 0 : SPLIT (values[i]);
2477 :
2478 0 : WRITE (image, pixel++,
2479 : ((b ) & 0xc0) |
2480 : ((g >> 2) & 0x38) |
2481 : ((r >> 5) ));
2482 : }
2483 0 : }
2484 :
2485 : static void
2486 0 : store_scanline_a2r2g2b2 (bits_image_t * image,
2487 : int x,
2488 : int y,
2489 : int width,
2490 : const uint32_t *values)
2491 : {
2492 0 : uint32_t *bits = image->bits + image->rowstride * y;
2493 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2494 : int i;
2495 :
2496 0 : for (i = 0; i < width; ++i)
2497 : {
2498 0 : SPLIT_A (values[i]);
2499 :
2500 0 : WRITE (image, pixel++,
2501 : ((a ) & 0xc0) |
2502 : ((r >> 2) & 0x30) |
2503 : ((g >> 4) & 0x0c) |
2504 : ((b >> 6) ));
2505 : }
2506 0 : }
2507 :
2508 : static void
2509 0 : store_scanline_a2b2g2r2 (bits_image_t * image,
2510 : int x,
2511 : int y,
2512 : int width,
2513 : const uint32_t *values)
2514 : {
2515 0 : uint32_t *bits = image->bits + image->rowstride * y;
2516 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2517 : int i;
2518 :
2519 0 : for (i = 0; i < width; ++i)
2520 : {
2521 0 : SPLIT_A (values[i]);
2522 :
2523 0 : WRITE (image, pixel++,
2524 : ((a ) & 0xc0) |
2525 : ((b >> 2) & 0x30) |
2526 : ((g >> 4) & 0x0c) |
2527 : ((r >> 6) ));
2528 : }
2529 0 : }
2530 :
2531 : static void
2532 0 : store_scanline_c8 (bits_image_t * image,
2533 : int x,
2534 : int y,
2535 : int width,
2536 : const uint32_t *values)
2537 : {
2538 0 : uint32_t *bits = image->bits + image->rowstride * y;
2539 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2540 0 : const pixman_indexed_t *indexed = image->indexed;
2541 : int i;
2542 :
2543 0 : for (i = 0; i < width; ++i)
2544 0 : WRITE (image, pixel++, RGB24_TO_ENTRY (indexed,values[i]));
2545 0 : }
2546 :
2547 : static void
2548 0 : store_scanline_g8 (bits_image_t * image,
2549 : int x,
2550 : int y,
2551 : int width,
2552 : const uint32_t *values)
2553 : {
2554 0 : uint32_t *bits = image->bits + image->rowstride * y;
2555 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2556 0 : const pixman_indexed_t *indexed = image->indexed;
2557 : int i;
2558 :
2559 0 : for (i = 0; i < width; ++i)
2560 0 : WRITE (image, pixel++, RGB24_TO_ENTRY_Y (indexed,values[i]));
2561 0 : }
2562 :
2563 : static void
2564 0 : store_scanline_x4a4 (bits_image_t * image,
2565 : int x,
2566 : int y,
2567 : int width,
2568 : const uint32_t *values)
2569 : {
2570 0 : uint32_t *bits = image->bits + image->rowstride * y;
2571 0 : uint8_t *pixel = ((uint8_t *) bits) + x;
2572 : int i;
2573 :
2574 0 : for (i = 0; i < width; ++i)
2575 0 : WRITE (image, pixel++, values[i] >> 28);
2576 0 : }
2577 :
2578 : #define STORE_8(img,l,o,v) (WRITE (img, (uint8_t *)(l) + ((o) >> 3), (v)))
2579 : #ifdef WORDS_BIGENDIAN
2580 :
2581 : #define STORE_4(img,l,o,v) \
2582 : do \
2583 : { \
2584 : int bo = 4 * (o); \
2585 : int v4 = (v) & 0x0f; \
2586 : \
2587 : STORE_8 (img, l, bo, ( \
2588 : bo & 4 ? \
2589 : (FETCH_8 (img, l, bo) & 0xf0) | (v4) : \
2590 : (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4))); \
2591 : } while (0)
2592 : #else
2593 :
2594 : #define STORE_4(img,l,o,v) \
2595 : do \
2596 : { \
2597 : int bo = 4 * (o); \
2598 : int v4 = (v) & 0x0f; \
2599 : \
2600 : STORE_8 (img, l, bo, ( \
2601 : bo & 4 ? \
2602 : (FETCH_8 (img, l, bo) & 0x0f) | (v4 << 4) : \
2603 : (FETCH_8 (img, l, bo) & 0xf0) | (v4))); \
2604 : } while (0)
2605 : #endif
2606 :
2607 : static void
2608 0 : store_scanline_a4 (bits_image_t * image,
2609 : int x,
2610 : int y,
2611 : int width,
2612 : const uint32_t *values)
2613 : {
2614 0 : uint32_t *bits = image->bits + image->rowstride * y;
2615 : int i;
2616 :
2617 0 : for (i = 0; i < width; ++i)
2618 0 : STORE_4 (image, bits, i + x, values[i] >> 28);
2619 0 : }
2620 :
2621 : static void
2622 0 : store_scanline_r1g2b1 (bits_image_t * image,
2623 : int x,
2624 : int y,
2625 : int width,
2626 : const uint32_t *values)
2627 : {
2628 0 : uint32_t *bits = image->bits + image->rowstride * y;
2629 : int i;
2630 :
2631 0 : for (i = 0; i < width; ++i)
2632 : {
2633 : uint32_t pixel;
2634 :
2635 0 : SPLIT (values[i]);
2636 0 : pixel = (((r >> 4) & 0x8) |
2637 0 : ((g >> 5) & 0x6) |
2638 0 : ((b >> 7) ));
2639 0 : STORE_4 (image, bits, i + x, pixel);
2640 : }
2641 0 : }
2642 :
2643 : static void
2644 0 : store_scanline_b1g2r1 (bits_image_t * image,
2645 : int x,
2646 : int y,
2647 : int width,
2648 : const uint32_t *values)
2649 : {
2650 0 : uint32_t *bits = image->bits + image->rowstride * y;
2651 : int i;
2652 :
2653 0 : for (i = 0; i < width; ++i)
2654 : {
2655 : uint32_t pixel;
2656 :
2657 0 : SPLIT (values[i]);
2658 0 : pixel = (((b >> 4) & 0x8) |
2659 0 : ((g >> 5) & 0x6) |
2660 0 : ((r >> 7) ));
2661 0 : STORE_4 (image, bits, i + x, pixel);
2662 : }
2663 0 : }
2664 :
2665 : static void
2666 0 : store_scanline_a1r1g1b1 (bits_image_t * image,
2667 : int x,
2668 : int y,
2669 : int width,
2670 : const uint32_t *values)
2671 : {
2672 0 : uint32_t *bits = image->bits + image->rowstride * y;
2673 : int i;
2674 :
2675 0 : for (i = 0; i < width; ++i)
2676 : {
2677 : uint32_t pixel;
2678 :
2679 0 : SPLIT_A (values[i]);
2680 0 : pixel = (((a >> 4) & 0x8) |
2681 0 : ((r >> 5) & 0x4) |
2682 0 : ((g >> 6) & 0x2) |
2683 0 : ((b >> 7) ));
2684 :
2685 0 : STORE_4 (image, bits, i + x, pixel);
2686 : }
2687 0 : }
2688 :
2689 : static void
2690 0 : store_scanline_a1b1g1r1 (bits_image_t * image,
2691 : int x,
2692 : int y,
2693 : int width,
2694 : const uint32_t *values)
2695 : {
2696 0 : uint32_t *bits = image->bits + image->rowstride * y;
2697 : int i;
2698 :
2699 0 : for (i = 0; i < width; ++i)
2700 : {
2701 : uint32_t pixel;
2702 :
2703 0 : SPLIT_A (values[i]);
2704 0 : pixel = (((a >> 4) & 0x8) |
2705 0 : ((b >> 5) & 0x4) |
2706 0 : ((g >> 6) & 0x2) |
2707 0 : ((r >> 7) ));
2708 :
2709 0 : STORE_4 (image, bits, i + x, pixel);
2710 : }
2711 0 : }
2712 :
2713 : static void
2714 0 : store_scanline_c4 (bits_image_t * image,
2715 : int x,
2716 : int y,
2717 : int width,
2718 : const uint32_t *values)
2719 : {
2720 0 : uint32_t *bits = image->bits + image->rowstride * y;
2721 0 : const pixman_indexed_t *indexed = image->indexed;
2722 : int i;
2723 :
2724 0 : for (i = 0; i < width; ++i)
2725 : {
2726 : uint32_t pixel;
2727 :
2728 0 : pixel = RGB24_TO_ENTRY (indexed, values[i]);
2729 0 : STORE_4 (image, bits, i + x, pixel);
2730 : }
2731 0 : }
2732 :
2733 : static void
2734 0 : store_scanline_g4 (bits_image_t * image,
2735 : int x,
2736 : int y,
2737 : int width,
2738 : const uint32_t *values)
2739 : {
2740 0 : uint32_t *bits = image->bits + image->rowstride * y;
2741 0 : const pixman_indexed_t *indexed = image->indexed;
2742 : int i;
2743 :
2744 0 : for (i = 0; i < width; ++i)
2745 : {
2746 : uint32_t pixel;
2747 :
2748 0 : pixel = RGB24_TO_ENTRY_Y (indexed, values[i]);
2749 0 : STORE_4 (image, bits, i + x, pixel);
2750 : }
2751 0 : }
2752 :
2753 : static void
2754 0 : store_scanline_a1 (bits_image_t * image,
2755 : int x,
2756 : int y,
2757 : int width,
2758 : const uint32_t *values)
2759 : {
2760 0 : uint32_t *bits = image->bits + image->rowstride * y;
2761 : int i;
2762 :
2763 0 : for (i = 0; i < width; ++i)
2764 : {
2765 0 : uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
2766 : uint32_t mask, v;
2767 :
2768 : #ifdef WORDS_BIGENDIAN
2769 : mask = 1 << (0x1f - ((i + x) & 0x1f));
2770 : #else
2771 0 : mask = 1 << ((i + x) & 0x1f);
2772 : #endif
2773 0 : v = values[i] & 0x80000000 ? mask : 0;
2774 :
2775 0 : WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
2776 : }
2777 0 : }
2778 :
2779 : static void
2780 0 : store_scanline_g1 (bits_image_t * image,
2781 : int x,
2782 : int y,
2783 : int width,
2784 : const uint32_t *values)
2785 : {
2786 0 : uint32_t *bits = image->bits + image->rowstride * y;
2787 0 : const pixman_indexed_t *indexed = image->indexed;
2788 : int i;
2789 :
2790 0 : for (i = 0; i < width; ++i)
2791 : {
2792 0 : uint32_t *pixel = ((uint32_t *) bits) + ((i + x) >> 5);
2793 : uint32_t mask, v;
2794 :
2795 : #ifdef WORDS_BIGENDIAN
2796 : mask = 1 << (0x1f - ((i + x) & 0x1f));
2797 : #else
2798 0 : mask = 1 << ((i + x) & 0x1f);
2799 : #endif
2800 0 : v = RGB24_TO_ENTRY_Y (indexed, values[i]) & 0x1 ? mask : 0;
2801 :
2802 0 : WRITE (image, pixel, (READ (image, pixel) & ~mask) | v);
2803 : }
2804 0 : }
2805 :
2806 : /*
2807 : * Contracts a 64bpp image to 32bpp and then stores it using a regular 32-bit
2808 : * store proc. Despite the type, this function expects a uint64_t buffer.
2809 : */
2810 : static void
2811 0 : store_scanline_generic_64 (bits_image_t * image,
2812 : int x,
2813 : int y,
2814 : int width,
2815 : const uint32_t *values)
2816 : {
2817 : uint32_t *argb8_pixels;
2818 :
2819 0 : assert (image->common.type == BITS);
2820 :
2821 0 : argb8_pixels = pixman_malloc_ab (width, sizeof(uint32_t));
2822 0 : if (!argb8_pixels)
2823 0 : return;
2824 :
2825 : /* Contract the scanline. We could do this in place if values weren't
2826 : * const.
2827 : */
2828 0 : pixman_contract (argb8_pixels, (uint64_t *)values, width);
2829 :
2830 0 : image->store_scanline_32 (image, x, y, width, argb8_pixels);
2831 :
2832 0 : free (argb8_pixels);
2833 : }
2834 :
2835 : /* Despite the type, this function expects both buffer
2836 : * and mask to be uint64_t
2837 : */
2838 : static void
2839 0 : fetch_scanline_generic_64 (pixman_image_t *image,
2840 : int x,
2841 : int y,
2842 : int width,
2843 : uint32_t * buffer,
2844 : const uint32_t *mask)
2845 : {
2846 : pixman_format_code_t format;
2847 :
2848 : /* Fetch the pixels into the first half of buffer and then expand them in
2849 : * place.
2850 : */
2851 0 : image->bits.fetch_scanline_32 (image, x, y, width, buffer, NULL);
2852 :
2853 0 : format = image->bits.format;
2854 0 : if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_COLOR ||
2855 0 : PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_GRAY)
2856 : {
2857 : /* Indexed formats are mapped to a8r8g8b8 with full
2858 : * precision, so when expanding we shouldn't correct
2859 : * for the width of the channels
2860 : */
2861 :
2862 0 : format = PIXMAN_a8r8g8b8;
2863 : }
2864 :
2865 0 : pixman_expand ((uint64_t *)buffer, buffer, format, width);
2866 0 : }
2867 :
2868 : /* Despite the type, this function expects a uint64_t *buffer */
2869 : static uint64_t
2870 0 : fetch_pixel_generic_64 (bits_image_t *image,
2871 : int offset,
2872 : int line)
2873 : {
2874 0 : uint32_t pixel32 = image->fetch_pixel_32 (image, offset, line);
2875 : uint64_t result;
2876 : pixman_format_code_t format;
2877 :
2878 0 : format = image->format;
2879 0 : if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_COLOR ||
2880 0 : PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_GRAY)
2881 : {
2882 : /* Indexed formats are mapped to a8r8g8b8 with full
2883 : * precision, so when expanding we shouldn't correct
2884 : * for the width of the channels
2885 : */
2886 :
2887 0 : format = PIXMAN_a8r8g8b8;
2888 : }
2889 :
2890 0 : pixman_expand ((uint64_t *)&result, &pixel32, format, 1);
2891 :
2892 0 : return result;
2893 : }
2894 :
2895 : /*
2896 : * XXX: The transformed fetch path only works at 32-bpp so far. When all
2897 : * paths have wide versions, this can be removed.
2898 : *
2899 : * WARNING: This function loses precision!
2900 : */
2901 : static uint32_t
2902 0 : fetch_pixel_generic_lossy_32 (bits_image_t *image,
2903 : int offset,
2904 : int line)
2905 : {
2906 0 : uint64_t pixel64 = image->fetch_pixel_64 (image, offset, line);
2907 : uint32_t result;
2908 :
2909 0 : pixman_contract (&result, &pixel64, 1);
2910 :
2911 0 : return result;
2912 : }
2913 :
2914 : typedef struct
2915 : {
2916 : pixman_format_code_t format;
2917 : fetch_scanline_t fetch_scanline_32;
2918 : fetch_scanline_t fetch_scanline_64;
2919 : fetch_pixel_32_t fetch_pixel_32;
2920 : fetch_pixel_64_t fetch_pixel_64;
2921 : store_scanline_t store_scanline_32;
2922 : store_scanline_t store_scanline_64;
2923 : } format_info_t;
2924 :
2925 : #define FORMAT_INFO(format) \
2926 : { \
2927 : PIXMAN_ ## format, \
2928 : fetch_scanline_ ## format, \
2929 : fetch_scanline_generic_64, \
2930 : fetch_pixel_ ## format, fetch_pixel_generic_64, \
2931 : store_scanline_ ## format, store_scanline_generic_64 \
2932 : }
2933 :
2934 : static const format_info_t accessors[] =
2935 : {
2936 : /* 32 bpp formats */
2937 : FORMAT_INFO (a8r8g8b8),
2938 : FORMAT_INFO (x8r8g8b8),
2939 : FORMAT_INFO (a8b8g8r8),
2940 : FORMAT_INFO (x8b8g8r8),
2941 : FORMAT_INFO (b8g8r8a8),
2942 : FORMAT_INFO (b8g8r8x8),
2943 : FORMAT_INFO (r8g8b8a8),
2944 : FORMAT_INFO (r8g8b8x8),
2945 : FORMAT_INFO (x14r6g6b6),
2946 :
2947 : /* 24bpp formats */
2948 : FORMAT_INFO (r8g8b8),
2949 : FORMAT_INFO (b8g8r8),
2950 :
2951 : /* 16bpp formats */
2952 : FORMAT_INFO (r5g6b5),
2953 : FORMAT_INFO (b5g6r5),
2954 :
2955 : FORMAT_INFO (a1r5g5b5),
2956 : FORMAT_INFO (x1r5g5b5),
2957 : FORMAT_INFO (a1b5g5r5),
2958 : FORMAT_INFO (x1b5g5r5),
2959 : FORMAT_INFO (a4r4g4b4),
2960 : FORMAT_INFO (x4r4g4b4),
2961 : FORMAT_INFO (a4b4g4r4),
2962 : FORMAT_INFO (x4b4g4r4),
2963 :
2964 : /* 8bpp formats */
2965 : FORMAT_INFO (a8),
2966 : FORMAT_INFO (r3g3b2),
2967 : FORMAT_INFO (b2g3r3),
2968 : FORMAT_INFO (a2r2g2b2),
2969 : FORMAT_INFO (a2b2g2r2),
2970 :
2971 : FORMAT_INFO (c8),
2972 :
2973 : #define fetch_scanline_g8 fetch_scanline_c8
2974 : #define fetch_pixel_g8 fetch_pixel_c8
2975 : FORMAT_INFO (g8),
2976 :
2977 : #define fetch_scanline_x4c4 fetch_scanline_c8
2978 : #define fetch_pixel_x4c4 fetch_pixel_c8
2979 : #define store_scanline_x4c4 store_scanline_c8
2980 : FORMAT_INFO (x4c4),
2981 :
2982 : #define fetch_scanline_x4g4 fetch_scanline_c8
2983 : #define fetch_pixel_x4g4 fetch_pixel_c8
2984 : #define store_scanline_x4g4 store_scanline_g8
2985 : FORMAT_INFO (x4g4),
2986 :
2987 : FORMAT_INFO (x4a4),
2988 :
2989 : /* 4bpp formats */
2990 : FORMAT_INFO (a4),
2991 : FORMAT_INFO (r1g2b1),
2992 : FORMAT_INFO (b1g2r1),
2993 : FORMAT_INFO (a1r1g1b1),
2994 : FORMAT_INFO (a1b1g1r1),
2995 :
2996 : FORMAT_INFO (c4),
2997 :
2998 : #define fetch_scanline_g4 fetch_scanline_c4
2999 : #define fetch_pixel_g4 fetch_pixel_c4
3000 : FORMAT_INFO (g4),
3001 :
3002 : /* 1bpp formats */
3003 : FORMAT_INFO (a1),
3004 : FORMAT_INFO (g1),
3005 :
3006 : /* Wide formats */
3007 :
3008 : { PIXMAN_a2r10g10b10,
3009 : NULL, fetch_scanline_a2r10g10b10,
3010 : fetch_pixel_generic_lossy_32, fetch_pixel_a2r10g10b10,
3011 : NULL, store_scanline_a2r10g10b10 },
3012 :
3013 : { PIXMAN_x2r10g10b10,
3014 : NULL, fetch_scanline_x2r10g10b10,
3015 : fetch_pixel_generic_lossy_32, fetch_pixel_x2r10g10b10,
3016 : NULL, store_scanline_x2r10g10b10 },
3017 :
3018 : { PIXMAN_a2b10g10r10,
3019 : NULL, fetch_scanline_a2b10g10r10,
3020 : fetch_pixel_generic_lossy_32, fetch_pixel_a2b10g10r10,
3021 : NULL, store_scanline_a2b10g10r10 },
3022 :
3023 : { PIXMAN_x2b10g10r10,
3024 : NULL, fetch_scanline_x2b10g10r10,
3025 : fetch_pixel_generic_lossy_32, fetch_pixel_x2b10g10r10,
3026 : NULL, store_scanline_x2b10g10r10 },
3027 :
3028 : /* YUV formats */
3029 : { PIXMAN_yuy2,
3030 : fetch_scanline_yuy2, fetch_scanline_generic_64,
3031 : fetch_pixel_yuy2, fetch_pixel_generic_64,
3032 : NULL, NULL },
3033 :
3034 : { PIXMAN_yv12,
3035 : fetch_scanline_yv12, fetch_scanline_generic_64,
3036 : fetch_pixel_yv12, fetch_pixel_generic_64,
3037 : NULL, NULL },
3038 :
3039 : { PIXMAN_null },
3040 : };
3041 :
3042 : static void
3043 72 : setup_accessors (bits_image_t *image)
3044 : {
3045 72 : const format_info_t *info = accessors;
3046 :
3047 158 : while (info->format != PIXMAN_null)
3048 : {
3049 86 : if (info->format == image->format)
3050 : {
3051 72 : image->fetch_scanline_32 = info->fetch_scanline_32;
3052 72 : image->fetch_scanline_64 = info->fetch_scanline_64;
3053 72 : image->fetch_pixel_32 = info->fetch_pixel_32;
3054 72 : image->fetch_pixel_64 = info->fetch_pixel_64;
3055 72 : image->store_scanline_32 = info->store_scanline_32;
3056 72 : image->store_scanline_64 = info->store_scanline_64;
3057 :
3058 72 : return;
3059 : }
3060 :
3061 14 : info++;
3062 : }
3063 : }
3064 :
3065 : #ifndef PIXMAN_FB_ACCESSORS
3066 : void
3067 : _pixman_bits_image_setup_accessors_accessors (bits_image_t *image);
3068 :
3069 : void
3070 72 : _pixman_bits_image_setup_accessors (bits_image_t *image)
3071 : {
3072 72 : if (image->read_func || image->write_func)
3073 0 : _pixman_bits_image_setup_accessors_accessors (image);
3074 : else
3075 72 : setup_accessors (image);
3076 72 : }
3077 :
3078 : #else
3079 :
3080 : void
3081 0 : _pixman_bits_image_setup_accessors_accessors (bits_image_t *image)
3082 : {
3083 0 : setup_accessors (image);
3084 0 : }
3085 :
3086 : #endif
|