2 * Copyright © 2000 SuSE, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of SuSE not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. SuSE makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
14 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Author: Keith Packard, SuSE, Inc.
30 #include "pixman-private.h"
33 * Compute the smallest value no less than y which is on a
37 PIXMAN_EXPORT pixman_fixed_t
38 pixman_sample_ceil_y (pixman_fixed_t y, int n)
40 pixman_fixed_t f = pixman_fixed_frac(y);
41 pixman_fixed_t i = pixman_fixed_floor(y);
43 f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
44 if (f > Y_FRAC_LAST(n))
46 if (pixman_fixed_to_int(i) == 0x7fff)
48 f = 0xffff; /* saturate */
57 #define _div(a,b) ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b)))
60 * Compute the largest value no greater than y which is on a
63 PIXMAN_EXPORT pixman_fixed_t
64 pixman_sample_floor_y (pixman_fixed_t y, int n)
66 pixman_fixed_t f = pixman_fixed_frac(y);
67 pixman_fixed_t i = pixman_fixed_floor (y);
69 f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n);
70 if (f < Y_FRAC_FIRST(n))
72 if (pixman_fixed_to_int(i) == 0x8000)
84 * Step an edge by any amount (including negative values)
87 pixman_edge_step (pixman_edge_t *e, int n)
89 pixman_fixed_48_16_t ne;
93 ne = e->e + n * (pixman_fixed_48_16_t) e->dx;
99 int nx = (ne + e->dy - 1) / e->dy;
100 e->e = ne - nx * (pixman_fixed_48_16_t) e->dy;
101 e->x += nx * e->signdx;
108 int nx = (-ne) / e->dy;
109 e->e = ne + nx * (pixman_fixed_48_16_t) e->dy;
110 e->x -= nx * e->signdx;
116 * A private routine to initialize the multi-step
117 * elements of an edge structure
120 _pixman_edge_multi_init (pixman_edge_t *e, int n, pixman_fixed_t *stepx_p, pixman_fixed_t *dx_p)
122 pixman_fixed_t stepx;
123 pixman_fixed_48_16_t ne;
125 ne = n * (pixman_fixed_48_16_t) e->dx;
126 stepx = n * e->stepx;
131 stepx += nx * e->signdx;
138 * Initialize one edge structure given the line endpoints and a
142 pixman_edge_init (pixman_edge_t *e,
144 pixman_fixed_t y_start,
145 pixman_fixed_t x_top,
146 pixman_fixed_t y_top,
147 pixman_fixed_t x_bot,
148 pixman_fixed_t y_bot)
150 pixman_fixed_t dx, dy;
170 e->stepx = -(-dx / dy);
175 _pixman_edge_multi_init (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small);
176 _pixman_edge_multi_init (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big);
178 pixman_edge_step (e, y_start - y_top);
182 * Initialize one edge structure given a line, starting y value
183 * and a pixel offset for the line
186 pixman_line_fixed_edge_init (pixman_edge_t *e,
189 const pixman_line_fixed_t *line,
193 pixman_fixed_t x_off_fixed = pixman_int_to_fixed(x_off);
194 pixman_fixed_t y_off_fixed = pixman_int_to_fixed(y_off);
195 const pixman_point_fixed_t *top, *bot;
197 if (line->p1.y <= line->p2.y)
207 pixman_edge_init (e, n, y,
208 top->x + x_off_fixed,
209 top->y + y_off_fixed,
210 bot->x + x_off_fixed,
211 bot->y + y_off_fixed);
215 pixman_multiply_overflows_int (unsigned int a,
218 return a >= INT32_MAX / b;
222 pixman_addition_overflows_int (unsigned int a,
225 return a > INT32_MAX - b;
229 pixman_malloc_ab(unsigned int a,
232 if (a >= INT32_MAX / b)
235 return malloc (a * b);
239 pixman_malloc_abc (unsigned int a,
243 if (a >= INT32_MAX / b)
245 else if (a * b >= INT32_MAX / c)
248 return malloc (a * b * c);
255 * Returns the version of the pixman library encoded in a single
256 * integer as per %PIXMAN_VERSION_ENCODE. The encoding ensures that
257 * later versions compare greater than earlier versions.
259 * A run-time comparison to check that pixman's version is greater than
260 * or equal to version X.Y.Z could be performed as follows:
262 * <informalexample><programlisting>
263 * if (pixman_version() >= PIXMAN_VERSION_ENCODE(X,Y,Z)) {...}
264 * </programlisting></informalexample>
266 * See also pixman_version_string() as well as the compile-time
267 * equivalents %PIXMAN_VERSION and %PIXMAN_VERSION_STRING.
269 * Return value: the encoded version.
272 pixman_version (void)
274 return PIXMAN_VERSION;
278 * pixman_version_string:
280 * Returns the version of the pixman library as a human-readable string
281 * of the form "X.Y.Z".
283 * See also pixman_version() as well as the compile-time equivalents
284 * %PIXMAN_VERSION_STRING and %PIXMAN_VERSION.
286 * Return value: a string containing the version.
288 PIXMAN_EXPORT const char*
289 pixman_version_string (void)
291 return PIXMAN_VERSION_STRING;
295 * pixman_format_supported_destination:
296 * @format: A pixman_format_code_t format
298 * Return value: whether the provided format code is a supported
299 * format for a pixman surface used as a destination in
302 * Currently, all pixman_format_code_t values are supported
303 * except for the YUV formats.
305 PIXMAN_EXPORT pixman_bool_t
306 pixman_format_supported_destination (pixman_format_code_t format)
310 case PIXMAN_a2b10g10r10:
311 case PIXMAN_x2b10g10r10:
312 case PIXMAN_a8r8g8b8:
313 case PIXMAN_x8r8g8b8:
314 case PIXMAN_a8b8g8r8:
315 case PIXMAN_x8b8g8r8:
316 case PIXMAN_b8g8r8a8:
317 case PIXMAN_b8g8r8x8:
323 case PIXMAN_a1r5g5b5:
324 case PIXMAN_x1r5g5b5:
325 case PIXMAN_a1b5g5r5:
326 case PIXMAN_x1b5g5r5:
327 case PIXMAN_a4r4g4b4:
328 case PIXMAN_x4r4g4b4:
329 case PIXMAN_a4b4g4r4:
330 case PIXMAN_x4b4g4r4:
335 case PIXMAN_a2r2g2b2:
336 case PIXMAN_a2b2g2r2:
340 /* Collides with PIXMAN_c8
343 /* Collides with PIXMAN_g8
350 case PIXMAN_a1r1g1b1:
351 case PIXMAN_a1b1g1r1:
368 * pixman_format_supported_source:
369 * @format: A pixman_format_code_t format
371 * Return value: whether the provided format code is a supported
372 * format for a pixman surface used as a source in
375 * Currently, all pixman_format_code_t values are supported.
377 PIXMAN_EXPORT pixman_bool_t
378 pixman_format_supported_source (pixman_format_code_t format)
382 case PIXMAN_a2b10g10r10:
383 case PIXMAN_x2b10g10r10:
384 case PIXMAN_a8r8g8b8:
385 case PIXMAN_x8r8g8b8:
386 case PIXMAN_a8b8g8r8:
387 case PIXMAN_x8b8g8r8:
388 case PIXMAN_b8g8r8a8:
389 case PIXMAN_b8g8r8x8:
395 case PIXMAN_a1r5g5b5:
396 case PIXMAN_x1r5g5b5:
397 case PIXMAN_a1b5g5r5:
398 case PIXMAN_x1b5g5r5:
399 case PIXMAN_a4r4g4b4:
400 case PIXMAN_x4r4g4b4:
401 case PIXMAN_a4b4g4r4:
402 case PIXMAN_x4b4g4r4:
407 case PIXMAN_a2r2g2b2:
408 case PIXMAN_a2b2g2r2:
412 /* Collides with PIXMAN_c8
415 /* Collides with PIXMAN_g8
422 case PIXMAN_a1r1g1b1:
423 case PIXMAN_a1b1g1r1:
440 _pixman_walk_composite_region (pixman_implementation_t *imp,
442 pixman_image_t * pSrc,
443 pixman_image_t * pMask,
444 pixman_image_t * pDst,
453 pixman_bool_t srcRepeat,
454 pixman_bool_t maskRepeat,
455 pixman_composite_func_t compositeRect)
458 const pixman_box32_t *pbox;
459 int w, h, w_this, h_this;
460 int x_msk, y_msk, x_src, y_src, x_dst, y_dst;
461 pixman_region32_t reg;
462 pixman_region32_t *region;
464 pixman_region32_init (®);
465 if (!pixman_compute_composite_region32 (®, pSrc, pMask, pDst,
466 xSrc, ySrc, xMask, yMask, xDst, yDst, width, height))
473 pbox = pixman_region32_rectangles (region, &n);
476 h = pbox->y2 - pbox->y1;
477 y_src = pbox->y1 - yDst + ySrc;
478 y_msk = pbox->y1 - yDst + yMask;
483 w = pbox->x2 - pbox->x1;
484 x_src = pbox->x1 - xDst + xSrc;
485 x_msk = pbox->x1 - xDst + xMask;
489 y_msk = MOD (y_msk, pMask->bits.height);
490 if (h_this > pMask->bits.height - y_msk)
491 h_this = pMask->bits.height - y_msk;
495 y_src = MOD (y_src, pSrc->bits.height);
496 if (h_this > pSrc->bits.height - y_src)
497 h_this = pSrc->bits.height - y_src;
504 x_msk = MOD (x_msk, pMask->bits.width);
505 if (w_this > pMask->bits.width - x_msk)
506 w_this = pMask->bits.width - x_msk;
510 x_src = MOD (x_src, pSrc->bits.width);
511 if (w_this > pSrc->bits.width - x_src)
512 w_this = pSrc->bits.width - x_src;
514 (*compositeRect) (imp,
515 op, pSrc, pMask, pDst,
516 x_src, y_src, x_msk, y_msk, x_dst, y_dst,
530 pixman_region32_fini (®);
534 mask_is_solid (pixman_image_t *mask)
536 if (mask->type == SOLID)
539 if (mask->type == BITS &&
540 mask->common.repeat == PIXMAN_REPEAT_NORMAL &&
541 mask->bits.width == 1 &&
542 mask->bits.height == 1)
550 static const FastPathInfo *
551 get_fast_path (const FastPathInfo *fast_paths,
553 pixman_image_t *pSrc,
554 pixman_image_t *pMask,
555 pixman_image_t *pDst,
556 pixman_bool_t is_pixbuf)
558 const FastPathInfo *info;
560 for (info = fast_paths; info->op != PIXMAN_OP_NONE; info++)
562 pixman_bool_t valid_src = FALSE;
563 pixman_bool_t valid_mask = FALSE;
568 if ((info->src_format == PIXMAN_solid && pixman_image_can_get_solid (pSrc)) ||
569 (pSrc->type == BITS && info->src_format == pSrc->bits.format))
577 if ((info->mask_format == PIXMAN_null && !pMask) ||
578 (pMask && pMask->type == BITS && info->mask_format == pMask->bits.format))
582 if (info->flags & NEED_SOLID_MASK)
584 if (!pMask || !mask_is_solid (pMask))
588 if (info->flags & NEED_COMPONENT_ALPHA)
590 if (!pMask || !pMask->common.component_alpha)
598 if (info->dest_format != pDst->bits.format)
601 if ((info->flags & NEED_PIXBUF) && !is_pixbuf)
611 _pixman_run_fast_path (const FastPathInfo *paths,
612 pixman_implementation_t *imp,
615 pixman_image_t *mask,
616 pixman_image_t *dest,
626 pixman_composite_func_t func = NULL;
627 pixman_bool_t src_repeat = src->common.repeat == PIXMAN_REPEAT_NORMAL;
628 pixman_bool_t mask_repeat = mask && mask->common.repeat == PIXMAN_REPEAT_NORMAL;
630 if ((src->type == BITS || pixman_image_can_get_solid (src)) &&
631 (!mask || mask->type == BITS)
632 && !src->common.transform && !(mask && mask->common.transform)
633 && !(mask && mask->common.alpha_map) && !src->common.alpha_map && !dest->common.alpha_map
634 && (src->common.filter != PIXMAN_FILTER_CONVOLUTION)
635 && (src->common.repeat != PIXMAN_REPEAT_PAD)
636 && (src->common.repeat != PIXMAN_REPEAT_REFLECT)
637 && (!mask || (mask->common.filter != PIXMAN_FILTER_CONVOLUTION &&
638 mask->common.repeat != PIXMAN_REPEAT_PAD &&
639 mask->common.repeat != PIXMAN_REPEAT_REFLECT))
640 && !src->common.read_func && !src->common.write_func
641 && !(mask && mask->common.read_func)
642 && !(mask && mask->common.write_func)
643 && !dest->common.read_func
644 && !dest->common.write_func)
646 const FastPathInfo *info;
647 pixman_bool_t pixbuf;
650 src && src->type == BITS &&
651 mask && mask->type == BITS &&
652 src->bits.bits == mask->bits.bits &&
655 !mask->common.component_alpha &&
658 info = get_fast_path (paths, op, src, mask, dest, pixbuf);
664 if (info->src_format == PIXMAN_solid)
667 if (info->mask_format == PIXMAN_solid || info->flags & NEED_SOLID_MASK)
671 src->bits.width == 1 &&
672 src->bits.height == 1) ||
674 mask->bits.width == 1 &&
675 mask->bits.height == 1))
677 /* If src or mask are repeating 1x1 images and src_repeat or
678 * mask_repeat are still TRUE, it means the fast path we
679 * selected does not actually handle repeating images.
681 * So rather than call the "fast path" with a zillion
682 * 1x1 requests, we just fall back to the general code (which
683 * does do something sensible with 1x1 repeating images).
692 _pixman_walk_composite_region (imp, op,
694 src_x, src_y, mask_x, mask_y,
697 src_repeat, mask_repeat,