ad5996b83b01d225ff7717576e926879df2ecf81
[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 #include <assert.h>
31
32 #include "pixman-private.h"
33
34 static const pixman_color_t transparent_black = { 0, 0, 0, 0 };
35
36 static void
37 gradient_property_changed (pixman_image_t *image)
38 {
39     gradient_t *gradient = &image->gradient;
40     int n = gradient->n_stops;
41     pixman_gradient_stop_t *stops = gradient->stops;
42     pixman_gradient_stop_t *begin = &(gradient->stops[-1]);
43     pixman_gradient_stop_t *end = &(gradient->stops[n]);
44
45     switch (gradient->common.repeat)
46     {
47     default:
48     case PIXMAN_REPEAT_NONE:
49         begin->x = INT32_MIN;
50         begin->color = transparent_black;
51         end->x = INT32_MAX;
52         end->color = transparent_black;
53         break;
54
55     case PIXMAN_REPEAT_NORMAL:
56         begin->x = stops[n - 1].x - pixman_fixed_1;
57         begin->color = stops[n - 1].color;
58         end->x = stops[0].x + pixman_fixed_1;
59         end->color = stops[0].color;
60         break;
61
62     case PIXMAN_REPEAT_REFLECT:
63         begin->x = - stops[0].x;
64         begin->color = stops[0].color;
65         end->x = pixman_int_to_fixed (2) - stops[n - 1].x;
66         end->color = stops[n - 1].color;
67         break;
68
69     case PIXMAN_REPEAT_PAD:
70         begin->x = INT32_MIN;
71         begin->color = stops[0].color;
72         end->x = INT32_MAX;
73         end->color = stops[n - 1].color;
74         break;
75     }
76 }
77
78 pixman_bool_t
79 _pixman_init_gradient (gradient_t *                  gradient,
80                        const pixman_gradient_stop_t *stops,
81                        int                           n_stops)
82 {
83     return_val_if_fail (n_stops > 0, FALSE);
84
85     /* We allocate two extra stops, one before the beginning of the stop list,
86      * and one after the end. These stops are initialized to whatever color
87      * would be used for positions outside the range of the stop list.
88      *
89      * This saves a bit of computation in the gradient walker.
90      *
91      * The pointer we store in the gradient_t struct still points to the
92      * first user-supplied struct, so when freeing, we will have to
93      * subtract one.
94      */
95     gradient->stops =
96         pixman_malloc_ab (n_stops + 2, sizeof (pixman_gradient_stop_t));
97     if (!gradient->stops)
98         return FALSE;
99
100     gradient->stops += 1;
101     memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
102     gradient->n_stops = n_stops;
103
104     gradient->common.property_changed = gradient_property_changed;
105
106     return TRUE;
107 }
108
109 void
110 _pixman_image_init (pixman_image_t *image)
111 {
112     image_common_t *common = &image->common;
113
114     pixman_region32_init (&common->clip_region);
115
116     common->alpha_count = 0;
117     common->have_clip_region = FALSE;
118     common->clip_sources = FALSE;
119     common->transform = NULL;
120     common->repeat = PIXMAN_REPEAT_NONE;
121     common->filter = PIXMAN_FILTER_NEAREST;
122     common->filter_params = NULL;
123     common->n_filter_params = 0;
124     common->alpha_map = NULL;
125     common->component_alpha = FALSE;
126     common->ref_count = 1;
127     common->property_changed = NULL;
128     common->client_clip = FALSE;
129     common->destroy_func = NULL;
130     common->destroy_data = NULL;
131     common->dirty = TRUE;
132 }
133
134 pixman_bool_t
135 _pixman_image_fini (pixman_image_t *image)
136 {
137     image_common_t *common = (image_common_t *)image;
138
139     common->ref_count--;
140
141     if (common->ref_count == 0)
142     {
143         if (image->common.destroy_func)
144             image->common.destroy_func (image, image->common.destroy_data);
145
146         pixman_region32_fini (&common->clip_region);
147
148         free (common->transform);
149         free (common->filter_params);
150
151         if (common->alpha_map)
152             pixman_image_unref ((pixman_image_t *)common->alpha_map);
153
154         if (image->type == LINEAR ||
155             image->type == RADIAL ||
156             image->type == CONICAL)
157         {
158             if (image->gradient.stops)
159             {
160                 /* See _pixman_init_gradient() for an explanation of the - 1 */
161                 free (image->gradient.stops - 1);
162             }
163
164             /* This will trigger if someone adds a property_changed
165              * method to the linear/radial/conical gradient overwriting
166              * the general one.
167              */
168             assert (
169                 image->common.property_changed == gradient_property_changed);
170         }
171
172         if (image->type == BITS && image->bits.free_me)
173             free (image->bits.free_me);
174
175         return TRUE;
176     }
177
178     return FALSE;
179 }
180
181 pixman_image_t *
182 _pixman_image_allocate (void)
183 {
184     pixman_image_t *image = malloc (sizeof (pixman_image_t));
185
186     if (image)
187         _pixman_image_init (image);
188
189     return image;
190 }
191
192 static void
193 image_property_changed (pixman_image_t *image)
194 {
195     image->common.dirty = TRUE;
196 }
197
198 /* Ref Counting */
199 PIXMAN_EXPORT pixman_image_t *
200 pixman_image_ref (pixman_image_t *image)
201 {
202     image->common.ref_count++;
203
204     return image;
205 }
206
207 /* returns TRUE when the image is freed */
208 PIXMAN_EXPORT pixman_bool_t
209 pixman_image_unref (pixman_image_t *image)
210 {
211     if (_pixman_image_fini (image))
212     {
213         free (image);
214         return TRUE;
215     }
216
217     return FALSE;
218 }
219
220 PIXMAN_EXPORT void
221 pixman_image_set_destroy_function (pixman_image_t *            image,
222                                    pixman_image_destroy_func_t func,
223                                    void *                      data)
224 {
225     image->common.destroy_func = func;
226     image->common.destroy_data = data;
227 }
228
229 PIXMAN_EXPORT void *
230 pixman_image_get_destroy_data (pixman_image_t *image)
231 {
232   return image->common.destroy_data;
233 }
234
235 void
236 _pixman_image_reset_clip_region (pixman_image_t *image)
237 {
238     image->common.have_clip_region = FALSE;
239 }
240
241 /* Executive Summary: This function is a no-op that only exists
242  * for historical reasons.
243  *
244  * There used to be a bug in the X server where it would rely on
245  * out-of-bounds accesses when it was asked to composite with a
246  * window as the source. It would create a pixman image pointing
247  * to some bogus position in memory, but then set a clip region
248  * to the position where the actual bits were.
249  *
250  * Due to a bug in old versions of pixman, where it would not clip
251  * against the image bounds when a clip region was set, this would
252  * actually work. So when the pixman bug was fixed, a workaround was
253  * added to allow certain out-of-bound accesses. This function disabled
254  * those workarounds.
255  *
256  * Since 0.21.2, pixman doesn't do these workarounds anymore, so now
257  * this function is a no-op.
258  */
259 PIXMAN_EXPORT void
260 pixman_disable_out_of_bounds_workaround (void)
261 {
262 }
263
264 static void
265 compute_image_info (pixman_image_t *image)
266 {
267     pixman_format_code_t code;
268     uint32_t flags = 0;
269
270     /* Transform */
271     if (!image->common.transform)
272     {
273         flags |= (FAST_PATH_ID_TRANSFORM        |
274                   FAST_PATH_X_UNIT_POSITIVE     |
275                   FAST_PATH_Y_UNIT_ZERO         |
276                   FAST_PATH_AFFINE_TRANSFORM);
277     }
278     else
279     {
280         flags |= FAST_PATH_HAS_TRANSFORM;
281
282         if (image->common.transform->matrix[2][0] == 0                  &&
283             image->common.transform->matrix[2][1] == 0                  &&
284             image->common.transform->matrix[2][2] == pixman_fixed_1)
285         {
286             flags |= FAST_PATH_AFFINE_TRANSFORM;
287
288             if (image->common.transform->matrix[0][1] == 0 &&
289                 image->common.transform->matrix[1][0] == 0)
290             {
291                 if (image->common.transform->matrix[0][0] == -pixman_fixed_1 &&
292                     image->common.transform->matrix[1][1] == -pixman_fixed_1)
293                 {
294                     flags |= FAST_PATH_ROTATE_180_TRANSFORM;
295                 }
296                 flags |= FAST_PATH_SCALE_TRANSFORM;
297             }
298             else if (image->common.transform->matrix[0][0] == 0 &&
299                      image->common.transform->matrix[1][1] == 0)
300             {
301                 pixman_fixed_t m01 = image->common.transform->matrix[0][1];
302                 if (m01 == -image->common.transform->matrix[1][0])
303                 {
304                         if (m01 == -pixman_fixed_1)
305                             flags |= FAST_PATH_ROTATE_90_TRANSFORM;
306                         else if (m01 == pixman_fixed_1)
307                             flags |= FAST_PATH_ROTATE_270_TRANSFORM;
308                 }
309             }
310         }
311
312         if (image->common.transform->matrix[0][0] > 0)
313             flags |= FAST_PATH_X_UNIT_POSITIVE;
314
315         if (image->common.transform->matrix[1][0] == 0)
316             flags |= FAST_PATH_Y_UNIT_ZERO;
317     }
318
319     /* Filter */
320     switch (image->common.filter)
321     {
322     case PIXMAN_FILTER_NEAREST:
323     case PIXMAN_FILTER_FAST:
324         flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
325         break;
326
327     case PIXMAN_FILTER_BILINEAR:
328     case PIXMAN_FILTER_GOOD:
329     case PIXMAN_FILTER_BEST:
330         flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
331
332         /* Here we have a chance to optimize BILINEAR filter to NEAREST if
333          * they are equivalent for the currently used transformation matrix.
334          */
335         if (flags & FAST_PATH_ID_TRANSFORM)
336         {
337             flags |= FAST_PATH_NEAREST_FILTER;
338         }
339         else if (
340             /* affine and integer translation components in matrix ... */
341             ((flags & FAST_PATH_AFFINE_TRANSFORM) &&
342              !pixman_fixed_frac (image->common.transform->matrix[0][2] |
343                                  image->common.transform->matrix[1][2])) &&
344             (
345                 /* ... combined with a simple rotation */
346                 (flags & (FAST_PATH_ROTATE_90_TRANSFORM |
347                           FAST_PATH_ROTATE_180_TRANSFORM |
348                           FAST_PATH_ROTATE_270_TRANSFORM)) ||
349                 /* ... or combined with a simple non-rotated translation */
350                 (image->common.transform->matrix[0][0] == pixman_fixed_1 &&
351                  image->common.transform->matrix[1][1] == pixman_fixed_1 &&
352                  image->common.transform->matrix[0][1] == 0 &&
353                  image->common.transform->matrix[1][0] == 0)
354                 )
355             )
356         {
357             /* FIXME: there are some affine-test failures, showing that
358              * handling of BILINEAR and NEAREST filter is not quite
359              * equivalent when getting close to 32K for the translation
360              * components of the matrix. That's likely some bug, but for
361              * now just skip BILINEAR->NEAREST optimization in this case.
362              */
363             pixman_fixed_t magic_limit = pixman_int_to_fixed (30000);
364             if (image->common.transform->matrix[0][2] <= magic_limit  &&
365                 image->common.transform->matrix[1][2] <= magic_limit  &&
366                 image->common.transform->matrix[0][2] >= -magic_limit &&
367                 image->common.transform->matrix[1][2] >= -magic_limit)
368             {
369                 flags |= FAST_PATH_NEAREST_FILTER;
370             }
371         }
372         break;
373
374     case PIXMAN_FILTER_CONVOLUTION:
375         break;
376
377     default:
378         flags |= FAST_PATH_NO_CONVOLUTION_FILTER;
379         break;
380     }
381
382     /* Repeat mode */
383     switch (image->common.repeat)
384     {
385     case PIXMAN_REPEAT_NONE:
386         flags |=
387             FAST_PATH_NO_REFLECT_REPEAT         |
388             FAST_PATH_NO_PAD_REPEAT             |
389             FAST_PATH_NO_NORMAL_REPEAT;
390         break;
391
392     case PIXMAN_REPEAT_REFLECT:
393         flags |=
394             FAST_PATH_NO_PAD_REPEAT             |
395             FAST_PATH_NO_NONE_REPEAT            |
396             FAST_PATH_NO_NORMAL_REPEAT;
397         break;
398
399     case PIXMAN_REPEAT_PAD:
400         flags |=
401             FAST_PATH_NO_REFLECT_REPEAT         |
402             FAST_PATH_NO_NONE_REPEAT            |
403             FAST_PATH_NO_NORMAL_REPEAT;
404         break;
405
406     default:
407         flags |=
408             FAST_PATH_NO_REFLECT_REPEAT         |
409             FAST_PATH_NO_PAD_REPEAT             |
410             FAST_PATH_NO_NONE_REPEAT;
411         break;
412     }
413
414     /* Component alpha */
415     if (image->common.component_alpha)
416         flags |= FAST_PATH_COMPONENT_ALPHA;
417     else
418         flags |= FAST_PATH_UNIFIED_ALPHA;
419
420     flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
421
422     /* Type specific checks */
423     switch (image->type)
424     {
425     case SOLID:
426         code = PIXMAN_solid;
427
428         if (image->solid.color.alpha == 0xffff)
429             flags |= FAST_PATH_IS_OPAQUE;
430         break;
431
432     case BITS:
433         if (image->bits.width == 1      &&
434             image->bits.height == 1     &&
435             image->common.repeat != PIXMAN_REPEAT_NONE)
436         {
437             code = PIXMAN_solid;
438         }
439         else
440         {
441             code = image->bits.format;
442             flags |= FAST_PATH_BITS_IMAGE;
443         }
444
445         if (!PIXMAN_FORMAT_A (image->bits.format)                               &&
446             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_GRAY         &&
447             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_COLOR)
448         {
449             flags |= FAST_PATH_SAMPLES_OPAQUE;
450
451             if (image->common.repeat != PIXMAN_REPEAT_NONE)
452                 flags |= FAST_PATH_IS_OPAQUE;
453         }
454
455         if (image->bits.read_func || image->bits.write_func)
456             flags &= ~FAST_PATH_NO_ACCESSORS;
457
458         if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
459             flags &= ~FAST_PATH_NARROW_FORMAT;
460         break;
461
462     case RADIAL:
463         code = PIXMAN_unknown;
464
465         /*
466          * As explained in pixman-radial-gradient.c, every point of
467          * the plane has a valid associated radius (and thus will be
468          * colored) if and only if a is negative (i.e. one of the two
469          * circles contains the other one).
470          */
471
472         if (image->radial.a >= 0)
473             break;
474
475         /* Fall through */
476
477     case CONICAL:
478     case LINEAR:
479         code = PIXMAN_unknown;
480
481         if (image->common.repeat != PIXMAN_REPEAT_NONE)
482         {
483             int i;
484
485             flags |= FAST_PATH_IS_OPAQUE;
486             for (i = 0; i < image->gradient.n_stops; ++i)
487             {
488                 if (image->gradient.stops[i].color.alpha != 0xffff)
489                 {
490                     flags &= ~FAST_PATH_IS_OPAQUE;
491                     break;
492                 }
493             }
494         }
495         break;
496
497     default:
498         code = PIXMAN_unknown;
499         break;
500     }
501
502     /* Alpha map */
503     if (!image->common.alpha_map)
504     {
505         flags |= FAST_PATH_NO_ALPHA_MAP;
506     }
507     else
508     {
509         if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
510             flags &= ~FAST_PATH_NARROW_FORMAT;
511     }
512
513     /* Both alpha maps and convolution filters can introduce
514      * non-opaqueness in otherwise opaque images. Also
515      * an image with component alpha turned on is only opaque
516      * if all channels are opaque, so we simply turn it off
517      * unconditionally for those images.
518      */
519     if (image->common.alpha_map                                 ||
520         image->common.filter == PIXMAN_FILTER_CONVOLUTION       ||
521         image->common.component_alpha)
522     {
523         flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
524     }
525
526     image->common.flags = flags;
527     image->common.extended_format_code = code;
528 }
529
530 void
531 _pixman_image_validate (pixman_image_t *image)
532 {
533     if (image->common.dirty)
534     {
535         compute_image_info (image);
536
537         /* It is important that property_changed is
538          * called *after* compute_image_info() because
539          * property_changed() can make use of the flags
540          * to set up accessors etc.
541          */
542         if (image->common.property_changed)
543             image->common.property_changed (image);
544
545         image->common.dirty = FALSE;
546     }
547
548     if (image->common.alpha_map)
549         _pixman_image_validate ((pixman_image_t *)image->common.alpha_map);
550 }
551
552 PIXMAN_EXPORT pixman_bool_t
553 pixman_image_set_clip_region32 (pixman_image_t *   image,
554                                 pixman_region32_t *region)
555 {
556     image_common_t *common = (image_common_t *)image;
557     pixman_bool_t result;
558
559     if (region)
560     {
561         if ((result = pixman_region32_copy (&common->clip_region, region)))
562             image->common.have_clip_region = TRUE;
563     }
564     else
565     {
566         _pixman_image_reset_clip_region (image);
567
568         result = TRUE;
569     }
570
571     image_property_changed (image);
572
573     return result;
574 }
575
576 PIXMAN_EXPORT pixman_bool_t
577 pixman_image_set_clip_region (pixman_image_t *   image,
578                               pixman_region16_t *region)
579 {
580     image_common_t *common = (image_common_t *)image;
581     pixman_bool_t result;
582
583     if (region)
584     {
585         if ((result = pixman_region32_copy_from_region16 (&common->clip_region, region)))
586             image->common.have_clip_region = TRUE;
587     }
588     else
589     {
590         _pixman_image_reset_clip_region (image);
591
592         result = TRUE;
593     }
594
595     image_property_changed (image);
596
597     return result;
598 }
599
600 PIXMAN_EXPORT void
601 pixman_image_set_has_client_clip (pixman_image_t *image,
602                                   pixman_bool_t   client_clip)
603 {
604     image->common.client_clip = client_clip;
605 }
606
607 PIXMAN_EXPORT pixman_bool_t
608 pixman_image_set_transform (pixman_image_t *          image,
609                             const pixman_transform_t *transform)
610 {
611     static const pixman_transform_t id =
612     {
613         { { pixman_fixed_1, 0, 0 },
614           { 0, pixman_fixed_1, 0 },
615           { 0, 0, pixman_fixed_1 } }
616     };
617
618     image_common_t *common = (image_common_t *)image;
619     pixman_bool_t result;
620
621     if (common->transform == transform)
622         return TRUE;
623
624     if (!transform || memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
625     {
626         free (common->transform);
627         common->transform = NULL;
628         result = TRUE;
629
630         goto out;
631     }
632
633     if (common->transform &&
634         memcmp (common->transform, transform, sizeof (pixman_transform_t)) == 0)
635     {
636         return TRUE;
637     }
638
639     if (common->transform == NULL)
640         common->transform = malloc (sizeof (pixman_transform_t));
641
642     if (common->transform == NULL)
643     {
644         result = FALSE;
645
646         goto out;
647     }
648
649     memcpy (common->transform, transform, sizeof(pixman_transform_t));
650
651     result = TRUE;
652
653 out:
654     image_property_changed (image);
655
656     return result;
657 }
658
659 PIXMAN_EXPORT void
660 pixman_image_set_repeat (pixman_image_t *image,
661                          pixman_repeat_t repeat)
662 {
663     if (image->common.repeat == repeat)
664         return;
665
666     image->common.repeat = repeat;
667
668     image_property_changed (image);
669 }
670
671 PIXMAN_EXPORT pixman_bool_t
672 pixman_image_set_filter (pixman_image_t *      image,
673                          pixman_filter_t       filter,
674                          const pixman_fixed_t *params,
675                          int                   n_params)
676 {
677     image_common_t *common = (image_common_t *)image;
678     pixman_fixed_t *new_params;
679
680     if (params == common->filter_params && filter == common->filter)
681         return TRUE;
682
683     new_params = NULL;
684     if (params)
685     {
686         new_params = pixman_malloc_ab (n_params, sizeof (pixman_fixed_t));
687         if (!new_params)
688             return FALSE;
689
690         memcpy (new_params,
691                 params, n_params * sizeof (pixman_fixed_t));
692     }
693
694     common->filter = filter;
695
696     if (common->filter_params)
697         free (common->filter_params);
698
699     common->filter_params = new_params;
700     common->n_filter_params = n_params;
701
702     image_property_changed (image);
703     return TRUE;
704 }
705
706 PIXMAN_EXPORT void
707 pixman_image_set_source_clipping (pixman_image_t *image,
708                                   pixman_bool_t   clip_sources)
709 {
710     if (image->common.clip_sources == clip_sources)
711         return;
712
713     image->common.clip_sources = clip_sources;
714
715     image_property_changed (image);
716 }
717
718 /* Unlike all the other property setters, this function does not
719  * copy the content of indexed. Doing this copying is simply
720  * way, way too expensive.
721  */
722 PIXMAN_EXPORT void
723 pixman_image_set_indexed (pixman_image_t *        image,
724                           const pixman_indexed_t *indexed)
725 {
726     bits_image_t *bits = (bits_image_t *)image;
727
728     if (bits->indexed == indexed)
729         return;
730
731     bits->indexed = indexed;
732
733     image_property_changed (image);
734 }
735
736 PIXMAN_EXPORT void
737 pixman_image_set_alpha_map (pixman_image_t *image,
738                             pixman_image_t *alpha_map,
739                             int16_t         x,
740                             int16_t         y)
741 {
742     image_common_t *common = (image_common_t *)image;
743
744     return_if_fail (!alpha_map || alpha_map->type == BITS);
745
746     if (alpha_map && common->alpha_count > 0)
747     {
748         /* If this image is being used as an alpha map itself,
749          * then you can't give it an alpha map of its own.
750          */
751         return;
752     }
753
754     if (alpha_map && alpha_map->common.alpha_map)
755     {
756         /* If the image has an alpha map of its own,
757          * then it can't be used as an alpha map itself
758          */
759         return;
760     }
761
762     if (common->alpha_map != (bits_image_t *)alpha_map)
763     {
764         if (common->alpha_map)
765         {
766             common->alpha_map->common.alpha_count--;
767
768             pixman_image_unref ((pixman_image_t *)common->alpha_map);
769         }
770
771         if (alpha_map)
772         {
773             common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
774
775             common->alpha_map->common.alpha_count++;
776         }
777         else
778         {
779             common->alpha_map = NULL;
780         }
781     }
782
783     common->alpha_origin_x = x;
784     common->alpha_origin_y = y;
785
786     image_property_changed (image);
787 }
788
789 PIXMAN_EXPORT void
790 pixman_image_set_component_alpha   (pixman_image_t *image,
791                                     pixman_bool_t   component_alpha)
792 {
793     if (image->common.component_alpha == component_alpha)
794         return;
795
796     image->common.component_alpha = component_alpha;
797
798     image_property_changed (image);
799 }
800
801 PIXMAN_EXPORT pixman_bool_t
802 pixman_image_get_component_alpha   (pixman_image_t       *image)
803 {
804     return image->common.component_alpha;
805 }
806
807 PIXMAN_EXPORT void
808 pixman_image_set_accessors (pixman_image_t *           image,
809                             pixman_read_memory_func_t  read_func,
810                             pixman_write_memory_func_t write_func)
811 {
812     return_if_fail (image != NULL);
813
814     if (image->type == BITS)
815     {
816         image->bits.read_func = read_func;
817         image->bits.write_func = write_func;
818
819         image_property_changed (image);
820     }
821 }
822
823 PIXMAN_EXPORT uint32_t *
824 pixman_image_get_data (pixman_image_t *image)
825 {
826     if (image->type == BITS)
827         return image->bits.bits;
828
829     return NULL;
830 }
831
832 PIXMAN_EXPORT int
833 pixman_image_get_width (pixman_image_t *image)
834 {
835     if (image->type == BITS)
836         return image->bits.width;
837
838     return 0;
839 }
840
841 PIXMAN_EXPORT int
842 pixman_image_get_height (pixman_image_t *image)
843 {
844     if (image->type == BITS)
845         return image->bits.height;
846
847     return 0;
848 }
849
850 PIXMAN_EXPORT int
851 pixman_image_get_stride (pixman_image_t *image)
852 {
853     if (image->type == BITS)
854         return image->bits.rowstride * (int) sizeof (uint32_t);
855
856     return 0;
857 }
858
859 PIXMAN_EXPORT int
860 pixman_image_get_depth (pixman_image_t *image)
861 {
862     if (image->type == BITS)
863         return PIXMAN_FORMAT_DEPTH (image->bits.format);
864
865     return 0;
866 }
867
868 PIXMAN_EXPORT pixman_format_code_t
869 pixman_image_get_format (pixman_image_t *image)
870 {
871     if (image->type == BITS)
872         return image->bits.format;
873
874     return 0;
875 }
876
877 uint32_t
878 _pixman_image_get_solid (pixman_implementation_t *imp,
879                          pixman_image_t *         image,
880                          pixman_format_code_t     format)
881 {
882     uint32_t result;
883     pixman_iter_t iter;
884
885     _pixman_implementation_src_iter_init (
886         imp, &iter, image, 0, 0, 1, 1,
887         (uint8_t *)&result, ITER_NARROW);
888
889     result = *iter.get_scanline (&iter, NULL);
890
891     /* If necessary, convert RGB <--> BGR. */
892     if (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB)
893     {
894         result = (((result & 0xff000000) >>  0) |
895                   ((result & 0x00ff0000) >> 16) |
896                   ((result & 0x0000ff00) >>  0) |
897                   ((result & 0x000000ff) << 16));
898     }
899
900     return result;
901 }