Move calls of the classification out of the if statements.
[profile/ivi/pixman.git] / pixman / pixman-image.c
1 /*
2  * Copyright © 2000 SuSE, Inc.
3  * Copyright © 2007 Red Hat, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and its
6  * documentation for any purpose is hereby granted without fee, provided that
7  * the above copyright notice appear in all copies and that both that
8  * copyright notice and this permission notice appear in supporting
9  * documentation, and that the name of SuSE not be used in advertising or
10  * publicity pertaining to distribution of the software without specific,
11  * written prior permission.  SuSE makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as is"
13  * without express or implied warranty.
14  *
15  * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
17  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
19  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include "pixman-private.h"
32
33 #define Alpha(x) ((x) >> 24)
34
35 static source_pict_class_t
36 SourcePictureClassify (pixman_image_t *image,
37                        int             x,
38                        int             y,
39                        int             width,
40                        int             height)
41 {
42     source_image_t *pict = &image->source;
43     
44     if (pict->class != SOURCE_IMAGE_CLASS_UNKNOWN)
45         return pict->class;
46
47     pict->class = SOURCE_IMAGE_CLASS_NEITHER;
48     
49     if (pict->common.type == SOLID)
50     {
51         pict->class = SOURCE_IMAGE_CLASS_HORIZONTAL;
52     }
53     else if (pict->common.type == LINEAR)
54     {
55         linear_gradient_t *linear = (linear_gradient_t *)pict;
56         pixman_vector_t   v;
57         pixman_fixed_32_32_t l;
58         pixman_fixed_48_16_t dx, dy, a, b, off;
59         pixman_fixed_48_16_t factors[4];
60         int          i;
61
62         dx = linear->p2.x - linear->p1.x;
63         dy = linear->p2.y - linear->p1.y;
64         l = dx * dx + dy * dy;
65         if (l)
66         {
67             a = (dx << 32) / l;
68             b = (dy << 32) / l;
69         }
70         else
71         {
72             a = b = 0;
73         }
74
75         off = (-a * linear->p1.x
76                -b * linear->p1.y) >> 16;
77
78         for (i = 0; i < 3; i++)
79         {
80             v.vector[0] = pixman_int_to_fixed ((i % 2) * (width  - 1) + x);
81             v.vector[1] = pixman_int_to_fixed ((i / 2) * (height - 1) + y);
82             v.vector[2] = pixman_fixed_1;
83
84             if (pict->common.transform)
85             {
86                 if (!pixman_transform_point_3d (pict->common.transform, &v))
87                     return SOURCE_IMAGE_CLASS_UNKNOWN;
88             }
89
90             factors[i] = ((a * v.vector[0] + b * v.vector[1]) >> 16) + off;
91         }
92
93         if (factors[2] == factors[0])
94             pict->class = SOURCE_IMAGE_CLASS_HORIZONTAL;
95         else if (factors[1] == factors[0])
96             pict->class = SOURCE_IMAGE_CLASS_VERTICAL;
97     }
98
99     return pict->class;
100 }
101
102 static void
103 init_source_image (source_image_t *image)
104 {
105     image->class = SOURCE_IMAGE_CLASS_UNKNOWN;
106     image->common.classify = SourcePictureClassify;
107 }
108
109 static pixman_bool_t
110 init_gradient (gradient_t     *gradient,
111                const pixman_gradient_stop_t *stops,
112                int             n_stops)
113 {
114     return_val_if_fail (n_stops > 0, FALSE);
115
116     init_source_image (&gradient->common);
117
118     gradient->stops = pixman_malloc_ab (n_stops, sizeof (pixman_gradient_stop_t));
119     if (!gradient->stops)
120         return FALSE;
121
122     memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
123
124     gradient->n_stops = n_stops;
125
126     gradient->stop_range = 0xffff;
127     gradient->color_table = NULL;
128     gradient->color_table_size = 0;
129
130     return TRUE;
131 }
132
133 static uint32_t
134 color_to_uint32 (const pixman_color_t *color)
135 {
136     return
137         (color->alpha >> 8 << 24) |
138         (color->red >> 8 << 16) |
139         (color->green & 0xff00) |
140         (color->blue >> 8);
141 }
142
143 static pixman_image_t *
144 allocate_image (void)
145 {
146     pixman_image_t *image = malloc (sizeof (pixman_image_t));
147
148     if (image)
149     {
150         image_common_t *common = &image->common;
151
152         pixman_region32_init (&common->full_region);
153         pixman_region32_init (&common->clip_region);
154         common->src_clip = &common->full_region;
155         common->has_client_clip = FALSE;
156         common->transform = NULL;
157         common->repeat = PIXMAN_REPEAT_NONE;
158         common->filter = PIXMAN_FILTER_NEAREST;
159         common->filter_params = NULL;
160         common->n_filter_params = 0;
161         common->alpha_map = NULL;
162         common->component_alpha = FALSE;
163         common->ref_count = 1;
164         common->read_func = NULL;
165         common->write_func = NULL;
166         common->classify = NULL;
167     }
168
169     return image;
170 }
171
172 source_pict_class_t
173 _pixman_image_classify (pixman_image_t *image,
174                         int             x,
175                         int             y,
176                         int             width,
177                         int             height)
178 {
179     if (image->common.classify)
180         return image->common.classify (image, x, y, width, height);
181     else
182         return SOURCE_IMAGE_CLASS_NEITHER;
183 }
184
185 /* Ref Counting */
186 PIXMAN_EXPORT pixman_image_t *
187 pixman_image_ref (pixman_image_t *image)
188 {
189     image->common.ref_count++;
190
191     return image;
192 }
193
194 /* returns TRUE when the image is freed */
195 PIXMAN_EXPORT pixman_bool_t
196 pixman_image_unref (pixman_image_t *image)
197 {
198     image_common_t *common = (image_common_t *)image;
199
200     common->ref_count--;
201
202     if (common->ref_count == 0)
203     {
204         pixman_region32_fini (&common->clip_region);
205         pixman_region32_fini (&common->full_region);
206
207         if (common->transform)
208             free (common->transform);
209
210         if (common->filter_params)
211             free (common->filter_params);
212
213         if (common->alpha_map)
214             pixman_image_unref ((pixman_image_t *)common->alpha_map);
215
216 #if 0
217         if (image->type == BITS && image->bits.indexed)
218             free (image->bits.indexed);
219 #endif
220
221 #if 0
222         memset (image, 0xaa, sizeof (pixman_image_t));
223 #endif
224         if (image->type == LINEAR || image->type == RADIAL || image->type == CONICAL)
225         {
226             if (image->gradient.stops)
227                 free (image->gradient.stops);
228         }
229
230
231         if (image->type == BITS && image->bits.free_me)
232             free (image->bits.free_me);
233
234         free (image);
235
236         return TRUE;
237     }
238
239     return FALSE;
240 }
241
242 /* Constructors */
243 PIXMAN_EXPORT pixman_image_t *
244 pixman_image_create_solid_fill (pixman_color_t *color)
245 {
246     pixman_image_t *img = allocate_image();
247     if (!img)
248         return NULL;
249
250     init_source_image (&img->solid.common);
251
252     img->type = SOLID;
253     img->solid.color = color_to_uint32 (color);
254
255     return img;
256 }
257
258 PIXMAN_EXPORT pixman_image_t *
259 pixman_image_create_linear_gradient (pixman_point_fixed_t         *p1,
260                                      pixman_point_fixed_t         *p2,
261                                      const pixman_gradient_stop_t *stops,
262                                      int                           n_stops)
263 {
264     pixman_image_t *image;
265     linear_gradient_t *linear;
266
267     return_val_if_fail (n_stops >= 2, NULL);
268
269     image = allocate_image();
270
271     if (!image)
272         return NULL;
273
274     linear = &image->linear;
275
276     if (!init_gradient (&linear->common, stops, n_stops))
277     {
278         free (image);
279         return NULL;
280     }
281
282     linear->p1 = *p1;
283     linear->p2 = *p2;
284
285     image->type = LINEAR;
286
287     return image;
288 }
289
290
291 PIXMAN_EXPORT pixman_image_t *
292 pixman_image_create_radial_gradient (pixman_point_fixed_t         *inner,
293                                      pixman_point_fixed_t         *outer,
294                                      pixman_fixed_t                inner_radius,
295                                      pixman_fixed_t                outer_radius,
296                                      const pixman_gradient_stop_t *stops,
297                                      int                           n_stops)
298 {
299     pixman_image_t *image;
300     radial_gradient_t *radial;
301
302     return_val_if_fail (n_stops >= 2, NULL);
303
304     image = allocate_image();
305
306     if (!image)
307         return NULL;
308
309     radial = &image->radial;
310
311     if (!init_gradient (&radial->common, stops, n_stops))
312     {
313         free (image);
314         return NULL;
315     }
316
317     image->type = RADIAL;
318
319     radial->c1.x = inner->x;
320     radial->c1.y = inner->y;
321     radial->c1.radius = inner_radius;
322     radial->c2.x = outer->x;
323     radial->c2.y = outer->y;
324     radial->c2.radius = outer_radius;
325     radial->cdx = pixman_fixed_to_double (radial->c2.x - radial->c1.x);
326     radial->cdy = pixman_fixed_to_double (radial->c2.y - radial->c1.y);
327     radial->dr = pixman_fixed_to_double (radial->c2.radius - radial->c1.radius);
328     radial->A = (radial->cdx * radial->cdx
329                  + radial->cdy * radial->cdy
330                  - radial->dr  * radial->dr);
331
332     return image;
333 }
334
335 PIXMAN_EXPORT pixman_image_t *
336 pixman_image_create_conical_gradient (pixman_point_fixed_t *center,
337                                       pixman_fixed_t angle,
338                                       const pixman_gradient_stop_t *stops,
339                                       int n_stops)
340 {
341     pixman_image_t *image = allocate_image();
342     conical_gradient_t *conical;
343
344     if (!image)
345         return NULL;
346
347     conical = &image->conical;
348
349     if (!init_gradient (&conical->common, stops, n_stops))
350     {
351         free (image);
352         return NULL;
353     }
354
355     image->type = CONICAL;
356     conical->center = *center;
357     conical->angle = angle;
358
359     return image;
360 }
361
362 static uint32_t *
363 create_bits (pixman_format_code_t format,
364              int                  width,
365              int                  height,
366              int                 *rowstride_bytes)
367 {
368     int stride;
369     int buf_size;
370     int bpp;
371
372     /* what follows is a long-winded way, avoiding any possibility of integer
373      * overflows, of saying:
374      * stride = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (uint32_t);
375      */
376
377     bpp = PIXMAN_FORMAT_BPP (format);
378     if (pixman_multiply_overflows_int (width, bpp))
379         return NULL;
380
381     stride = width * bpp;
382     if (pixman_addition_overflows_int (stride, FB_MASK))
383         return NULL;
384
385     stride += FB_MASK;
386     stride >>= FB_SHIFT;
387
388 #if FB_SHIFT < 2
389     if (pixman_multiply_overflows_int (stride, sizeof (uint32_t)))
390         return NULL;
391 #endif
392     stride *= sizeof (uint32_t);
393
394     if (pixman_multiply_overflows_int (height, stride))
395         return NULL;
396
397     buf_size = height * stride;
398
399     if (rowstride_bytes)
400         *rowstride_bytes = stride;
401
402     return calloc (buf_size, 1);
403 }
404
405 static void
406 reset_clip_region (pixman_image_t *image)
407 {
408     pixman_region32_fini (&image->common.clip_region);
409
410     if (image->type == BITS)
411     {
412         pixman_region32_init_rect (&image->common.clip_region, 0, 0,
413                                    image->bits.width, image->bits.height);
414     }
415     else
416     {
417         pixman_region32_init (&image->common.clip_region);
418     }
419 }
420
421 PIXMAN_EXPORT pixman_image_t *
422 pixman_image_create_bits (pixman_format_code_t  format,
423                           int                   width,
424                           int                   height,
425                           uint32_t             *bits,
426                           int                   rowstride_bytes)
427 {
428     pixman_image_t *image;
429     uint32_t *free_me = NULL;
430
431     /* must be a whole number of uint32_t's
432      */
433     return_val_if_fail (bits == NULL ||
434                         (rowstride_bytes % sizeof (uint32_t)) == 0, NULL);
435
436     if (!bits && width && height)
437     {
438         free_me = bits = create_bits (format, width, height, &rowstride_bytes);
439         if (!bits)
440             return NULL;
441     }
442
443     image = allocate_image();
444
445     if (!image) {
446         if (free_me)
447             free (free_me);
448         return NULL;
449     }
450     
451     image->type = BITS;
452     image->bits.format = format;
453     image->bits.width = width;
454     image->bits.height = height;
455     image->bits.bits = bits;
456     image->bits.free_me = free_me;
457
458     image->bits.rowstride = rowstride_bytes / (int) sizeof (uint32_t); /* we store it in number
459                                                                   * of uint32_t's
460                                                                   */
461     image->bits.indexed = NULL;
462
463     pixman_region32_fini (&image->common.full_region);
464     pixman_region32_init_rect (&image->common.full_region, 0, 0,
465                                image->bits.width, image->bits.height);
466
467     reset_clip_region (image);
468     return image;
469 }
470
471 PIXMAN_EXPORT pixman_bool_t
472 pixman_image_set_clip_region32 (pixman_image_t *image,
473                                 pixman_region32_t *region)
474 {
475     image_common_t *common = (image_common_t *)image;
476
477     if (region)
478     {
479         return pixman_region32_copy (&common->clip_region, region);
480     }
481     else
482     {
483         reset_clip_region (image);
484
485         return TRUE;
486     }
487 }
488
489
490 PIXMAN_EXPORT pixman_bool_t
491 pixman_image_set_clip_region (pixman_image_t    *image,
492                               pixman_region16_t *region)
493 {
494     image_common_t *common = (image_common_t *)image;
495
496     if (region)
497     {
498         return pixman_region32_copy_from_region16 (&common->clip_region, region);
499     }
500     else
501     {
502         reset_clip_region (image);
503
504         return TRUE;
505     }
506 }
507
508 /* Sets whether the clip region includes a clip region set by the client
509  */
510 PIXMAN_EXPORT void
511 pixman_image_set_has_client_clip (pixman_image_t *image,
512                                   pixman_bool_t   client_clip)
513 {
514     image->common.has_client_clip = client_clip;
515 }
516
517 PIXMAN_EXPORT pixman_bool_t
518 pixman_image_set_transform (pixman_image_t           *image,
519                             const pixman_transform_t *transform)
520 {
521     static const pixman_transform_t id =
522     {
523         { { pixman_fixed_1, 0, 0 },
524           { 0, pixman_fixed_1, 0 },
525           { 0, 0, pixman_fixed_1 }
526         }
527     };
528
529     image_common_t *common = (image_common_t *)image;
530
531     if (common->transform == transform)
532         return TRUE;
533
534     if (memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
535     {
536         free(common->transform);
537         common->transform = NULL;
538         return TRUE;
539     }
540
541     if (common->transform == NULL)
542         common->transform = malloc (sizeof (pixman_transform_t));
543     if (common->transform == NULL)
544         return FALSE;
545
546     memcpy(common->transform, transform, sizeof(pixman_transform_t));
547
548     return TRUE;
549 }
550
551 PIXMAN_EXPORT void
552 pixman_image_set_repeat (pixman_image_t  *image,
553                          pixman_repeat_t  repeat)
554 {
555     image->common.repeat = repeat;
556 }
557
558 PIXMAN_EXPORT pixman_bool_t
559 pixman_image_set_filter (pixman_image_t       *image,
560                          pixman_filter_t       filter,
561                          const pixman_fixed_t *params,
562                          int                   n_params)
563 {
564     image_common_t *common = (image_common_t *)image;
565     pixman_fixed_t *new_params;
566
567     if (params == common->filter_params && filter == common->filter)
568         return TRUE;
569
570     new_params = NULL;
571     if (params)
572     {
573         new_params = pixman_malloc_ab (n_params, sizeof (pixman_fixed_t));
574         if (!new_params)
575             return FALSE;
576
577         memcpy (new_params,
578                 params, n_params * sizeof (pixman_fixed_t));
579     }
580
581     common->filter = filter;
582
583     if (common->filter_params)
584         free (common->filter_params);
585
586     common->filter_params = new_params;
587     common->n_filter_params = n_params;
588     return TRUE;
589 }
590
591 PIXMAN_EXPORT void
592 pixman_image_set_source_clipping (pixman_image_t  *image,
593                                   pixman_bool_t    source_clipping)
594 {
595     image_common_t *common = &image->common;
596
597     if (source_clipping)
598         common->src_clip = &common->clip_region;
599     else
600         common->src_clip = &common->full_region;
601 }
602
603 /* Unlike all the other property setters, this function does not
604  * copy the content of indexed. Doing this copying is simply
605  * way, way too expensive.
606  */
607 PIXMAN_EXPORT void
608 pixman_image_set_indexed (pixman_image_t         *image,
609                           const pixman_indexed_t *indexed)
610 {
611     bits_image_t *bits = (bits_image_t *)image;
612
613     bits->indexed = indexed;
614 }
615
616 PIXMAN_EXPORT void
617 pixman_image_set_alpha_map (pixman_image_t *image,
618                             pixman_image_t *alpha_map,
619                             int16_t         x,
620                             int16_t         y)
621 {
622     image_common_t *common = (image_common_t *)image;
623
624     return_if_fail (!alpha_map || alpha_map->type == BITS);
625
626     if (common->alpha_map != (bits_image_t *)alpha_map)
627     {
628         if (common->alpha_map)
629             pixman_image_unref ((pixman_image_t *)common->alpha_map);
630
631         if (alpha_map)
632             common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
633         else
634             common->alpha_map = NULL;
635     }
636
637     common->alpha_origin.x = x;
638     common->alpha_origin.y = y;
639 }
640
641 PIXMAN_EXPORT void
642 pixman_image_set_component_alpha   (pixman_image_t       *image,
643                                     pixman_bool_t         component_alpha)
644 {
645     image->common.component_alpha = component_alpha;
646 }
647
648
649 PIXMAN_EXPORT void
650 pixman_image_set_accessors (pixman_image_t             *image,
651                             pixman_read_memory_func_t   read_func,
652                             pixman_write_memory_func_t  write_func)
653 {
654     return_if_fail (image != NULL);
655
656     image->common.read_func = read_func;
657     image->common.write_func = write_func;
658 }
659
660 PIXMAN_EXPORT uint32_t *
661 pixman_image_get_data (pixman_image_t *image)
662 {
663     if (image->type == BITS)
664         return image->bits.bits;
665
666     return NULL;
667 }
668
669 PIXMAN_EXPORT int
670 pixman_image_get_width (pixman_image_t *image)
671 {
672     if (image->type == BITS)
673         return image->bits.width;
674
675     return 0;
676 }
677
678 PIXMAN_EXPORT int
679 pixman_image_get_height (pixman_image_t *image)
680 {
681     if (image->type == BITS)
682         return image->bits.height;
683
684     return 0;
685 }
686
687 PIXMAN_EXPORT int
688 pixman_image_get_stride (pixman_image_t *image)
689 {
690     if (image->type == BITS)
691         return image->bits.rowstride * (int) sizeof (uint32_t);
692
693     return 0;
694 }
695
696 PIXMAN_EXPORT int
697 pixman_image_get_depth (pixman_image_t *image)
698 {
699     if (image->type == BITS)
700         return PIXMAN_FORMAT_DEPTH (image->bits.format);
701
702     return 0;
703 }
704
705 static pixman_bool_t
706 color_to_pixel (pixman_color_t *color,
707                 uint32_t       *pixel,
708                 pixman_format_code_t format)
709 {
710     uint32_t c = color_to_uint32 (color);
711
712     if (!(format == PIXMAN_a8r8g8b8     ||
713           format == PIXMAN_x8r8g8b8     ||
714           format == PIXMAN_a8b8g8r8     ||
715           format == PIXMAN_x8b8g8r8     ||
716           format == PIXMAN_b8g8r8a8     ||
717           format == PIXMAN_b8g8r8x8     ||
718           format == PIXMAN_r5g6b5       ||
719           format == PIXMAN_b5g6r5       ||
720           format == PIXMAN_a8))
721     {
722         return FALSE;
723     }
724
725     if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_ABGR)
726     {
727         c = ((c & 0xff000000) >>  0) |
728             ((c & 0x00ff0000) >> 16) |
729             ((c & 0x0000ff00) >>  0) |
730             ((c & 0x000000ff) << 16);
731     }
732     if (PIXMAN_FORMAT_TYPE (format) == PIXMAN_TYPE_BGRA)
733     {
734         c = ((c & 0xff000000) >> 24) |
735             ((c & 0x00ff0000) >>  8) |
736             ((c & 0x0000ff00) <<  8) |
737             ((c & 0x000000ff) << 24);
738     }
739
740     if (format == PIXMAN_a8)
741         c = c >> 24;
742     else if (format == PIXMAN_r5g6b5 ||
743              format == PIXMAN_b5g6r5)
744         c = cvt8888to0565 (c);
745
746 #if 0
747     printf ("color: %x %x %x %x\n", color->alpha, color->red, color->green, color->blue);
748     printf ("pixel: %x\n", c);
749 #endif
750
751     *pixel = c;
752     return TRUE;
753 }
754
755 PIXMAN_EXPORT pixman_bool_t
756 pixman_image_fill_rectangles (pixman_op_t                   op,
757                               pixman_image_t               *dest,
758                               pixman_color_t               *color,
759                               int                           n_rects,
760                               const pixman_rectangle16_t   *rects)
761 {
762     pixman_image_t *solid;
763     pixman_color_t c;
764     int i;
765
766     if (color->alpha == 0xffff)
767     {
768         if (op == PIXMAN_OP_OVER)
769             op = PIXMAN_OP_SRC;
770     }
771
772     if (op == PIXMAN_OP_CLEAR)
773     {
774         c.red = 0;
775         c.green = 0;
776         c.blue = 0;
777         c.alpha = 0;
778
779         color = &c;
780
781         op = PIXMAN_OP_SRC;
782     }
783
784     if (op == PIXMAN_OP_SRC)
785     {
786         uint32_t pixel;
787
788         if (color_to_pixel (color, &pixel, dest->bits.format))
789         {
790             for (i = 0; i < n_rects; ++i)
791             {
792                 pixman_region32_t fill_region;
793                 int n_boxes, j;
794                 pixman_box32_t *boxes;
795
796                 pixman_region32_init_rect (&fill_region, rects[i].x, rects[i].y, rects[i].width, rects[i].height);
797                 if (!pixman_region32_intersect (&fill_region,
798                                                 &fill_region,
799                                                 &dest->common.clip_region))
800                     return FALSE;
801
802
803                 boxes = pixman_region32_rectangles (&fill_region, &n_boxes);
804                 for (j = 0; j < n_boxes; ++j)
805                 {
806                     const pixman_box32_t *box = &(boxes[j]);
807                     pixman_fill (dest->bits.bits, dest->bits.rowstride, PIXMAN_FORMAT_BPP (dest->bits.format),
808                                  box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1,
809                                  pixel);
810                 }
811
812                 pixman_region32_fini (&fill_region);
813             }
814             return TRUE;
815         }
816     }
817
818     solid = pixman_image_create_solid_fill (color);
819     if (!solid)
820         return FALSE;
821
822     for (i = 0; i < n_rects; ++i)
823     {
824         const pixman_rectangle16_t *rect = &(rects[i]);
825
826         pixman_image_composite (op, solid, NULL, dest,
827                                 0, 0, 0, 0,
828                                 rect->x, rect->y,
829                                 rect->width, rect->height);
830     }
831
832     pixman_image_unref (solid);
833
834     return TRUE;
835 }
836
837 pixman_bool_t
838 pixman_image_can_get_solid (pixman_image_t *image)
839 {
840     if (image->type == SOLID)
841         return TRUE;
842
843     if (image->type != BITS     ||
844         image->bits.width != 1  ||
845         image->bits.height != 1)
846     {
847         return FALSE;
848     }
849
850     if (image->common.repeat != PIXMAN_REPEAT_NORMAL)
851         return FALSE;
852
853     switch (image->bits.format)
854     {
855     case PIXMAN_a8r8g8b8:
856     case PIXMAN_x8r8g8b8:
857     case PIXMAN_a8b8g8r8:
858     case PIXMAN_x8b8g8r8:
859     case PIXMAN_b8g8r8a8:
860     case PIXMAN_b8g8r8x8:
861     case PIXMAN_r8g8b8:
862     case PIXMAN_b8g8r8:
863     case PIXMAN_r5g6b5:
864     case PIXMAN_b5g6r5:
865         return TRUE;
866     default:
867         return FALSE;
868     }
869 }
870
871 pixman_bool_t
872 pixman_image_is_opaque(pixman_image_t *image)
873 {
874     int i = 0;
875     int gradientNumberOfColors = 0;
876
877     if(image->common.alpha_map)
878         return FALSE;
879
880     switch(image->type)
881     {
882     case BITS:
883         if(PIXMAN_FORMAT_A(image->bits.format))
884             return FALSE;
885         break;
886
887     case LINEAR:
888     case CONICAL:
889     case RADIAL:
890         gradientNumberOfColors = image->gradient.n_stops;
891         i=0;
892         while(i<gradientNumberOfColors)
893         {
894             if(image->gradient.stops[i].color.alpha != 0xffff)
895                 return FALSE;
896             i++;
897         }
898         break;
899
900     case SOLID:
901          if(Alpha(image->solid.color) != 0xff)
902             return FALSE;
903         break;
904     }
905
906     /* Convolution filters can introduce translucency if the sum of the weights
907        is lower than 1. */
908     if (image->common.filter == PIXMAN_FILTER_CONVOLUTION)
909          return FALSE;
910
911     if (image->common.repeat == PIXMAN_REPEAT_NONE)
912     {
913         if (image->common.filter != PIXMAN_FILTER_NEAREST)
914             return FALSE;
915
916         if (image->common.transform)
917             return FALSE;
918
919         /* Gradients do not necessarily cover the entire compositing area */
920         if (image->type == LINEAR || image->type == CONICAL || image->type == RADIAL)
921             return FALSE;
922     }
923
924      return TRUE;
925 }