Delete simple repeat code
[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 #include "pixman-combine32.h"
34
35 pixman_bool_t
36 _pixman_init_gradient (gradient_t *                  gradient,
37                        const pixman_gradient_stop_t *stops,
38                        int                           n_stops)
39 {
40     return_val_if_fail (n_stops > 0, FALSE);
41
42     gradient->stops = pixman_malloc_ab (n_stops, sizeof (pixman_gradient_stop_t));
43     if (!gradient->stops)
44         return FALSE;
45
46     memcpy (gradient->stops, stops, n_stops * sizeof (pixman_gradient_stop_t));
47
48     gradient->n_stops = n_stops;
49
50     gradient->stop_range = 0xffff;
51     gradient->common.class = SOURCE_IMAGE_CLASS_UNKNOWN;
52
53     return TRUE;
54 }
55
56 /*
57  * By default, just evaluate the image at 32bpp and expand.  Individual image
58  * types can plug in a better scanline getter if they want to. For example
59  * we  could produce smoother gradients by evaluating them at higher color
60  * depth, but that's a project for the future.
61  */
62 void
63 _pixman_image_get_scanline_generic_64 (pixman_image_t * image,
64                                        int              x,
65                                        int              y,
66                                        int              width,
67                                        uint32_t *       buffer,
68                                        const uint32_t * mask)
69 {
70     uint32_t *mask8 = NULL;
71
72     /* Contract the mask image, if one exists, so that the 32-bit fetch
73      * function can use it.
74      */
75     if (mask)
76     {
77         mask8 = pixman_malloc_ab (width, sizeof(uint32_t));
78         if (!mask8)
79             return;
80
81         pixman_contract (mask8, (uint64_t *)mask, width);
82     }
83
84     /* Fetch the source image into the first half of buffer. */
85     _pixman_image_get_scanline_32 (image, x, y, width, (uint32_t*)buffer, mask8);
86
87     /* Expand from 32bpp to 64bpp in place. */
88     pixman_expand ((uint64_t *)buffer, buffer, PIXMAN_a8r8g8b8, width);
89
90     free (mask8);
91 }
92
93 pixman_image_t *
94 _pixman_image_allocate (void)
95 {
96     pixman_image_t *image = malloc (sizeof (pixman_image_t));
97
98     if (image)
99     {
100         image_common_t *common = &image->common;
101
102         pixman_region32_init (&common->clip_region);
103
104         common->alpha_count = 0;
105         common->have_clip_region = FALSE;
106         common->clip_sources = FALSE;
107         common->transform = NULL;
108         common->repeat = PIXMAN_REPEAT_NONE;
109         common->filter = PIXMAN_FILTER_NEAREST;
110         common->filter_params = NULL;
111         common->n_filter_params = 0;
112         common->alpha_map = NULL;
113         common->component_alpha = FALSE;
114         common->ref_count = 1;
115         common->classify = NULL;
116         common->client_clip = FALSE;
117         common->destroy_func = NULL;
118         common->destroy_data = NULL;
119         common->dirty = TRUE;
120     }
121
122     return image;
123 }
124
125 source_image_class_t
126 _pixman_image_classify (pixman_image_t *image,
127                         int             x,
128                         int             y,
129                         int             width,
130                         int             height)
131 {
132     if (image->common.classify)
133         return image->common.classify (image, x, y, width, height);
134     else
135         return SOURCE_IMAGE_CLASS_UNKNOWN;
136 }
137
138 void
139 _pixman_image_get_scanline_32 (pixman_image_t *image,
140                                int             x,
141                                int             y,
142                                int             width,
143                                uint32_t *      buffer,
144                                const uint32_t *mask)
145 {
146     image->common.get_scanline_32 (image, x, y, width, buffer, mask);
147 }
148
149 /* Even thought the type of buffer is uint32_t *, the function actually expects
150  * a uint64_t *buffer.
151  */
152 void
153 _pixman_image_get_scanline_64 (pixman_image_t *image,
154                                int             x,
155                                int             y,
156                                int             width,
157                                uint32_t *      buffer,
158                                const uint32_t *unused)
159 {
160     image->common.get_scanline_64 (image, x, y, width, buffer, unused);
161 }
162
163 static void
164 image_property_changed (pixman_image_t *image)
165 {
166     image->common.dirty = TRUE;
167 }
168
169 /* Ref Counting */
170 PIXMAN_EXPORT pixman_image_t *
171 pixman_image_ref (pixman_image_t *image)
172 {
173     image->common.ref_count++;
174
175     return image;
176 }
177
178 /* returns TRUE when the image is freed */
179 PIXMAN_EXPORT pixman_bool_t
180 pixman_image_unref (pixman_image_t *image)
181 {
182     image_common_t *common = (image_common_t *)image;
183
184     common->ref_count--;
185
186     if (common->ref_count == 0)
187     {
188         if (image->common.destroy_func)
189             image->common.destroy_func (image, image->common.destroy_data);
190
191         pixman_region32_fini (&common->clip_region);
192
193         if (common->transform)
194             free (common->transform);
195
196         if (common->filter_params)
197             free (common->filter_params);
198
199         if (common->alpha_map)
200             pixman_image_unref ((pixman_image_t *)common->alpha_map);
201
202         if (image->type == LINEAR ||
203             image->type == RADIAL ||
204             image->type == CONICAL)
205         {
206             if (image->gradient.stops)
207                 free (image->gradient.stops);
208         }
209
210         if (image->type == BITS && image->bits.free_me)
211             free (image->bits.free_me);
212
213         free (image);
214
215         return TRUE;
216     }
217
218     return FALSE;
219 }
220
221 PIXMAN_EXPORT void
222 pixman_image_set_destroy_function (pixman_image_t *            image,
223                                    pixman_image_destroy_func_t func,
224                                    void *                      data)
225 {
226     image->common.destroy_func = func;
227     image->common.destroy_data = data;
228 }
229
230 PIXMAN_EXPORT void *
231 pixman_image_get_destroy_data (pixman_image_t *image)
232 {
233   return image->common.destroy_data;
234 }
235
236 void
237 _pixman_image_reset_clip_region (pixman_image_t *image)
238 {
239     image->common.have_clip_region = FALSE;
240 }
241
242 static pixman_bool_t out_of_bounds_workaround = TRUE;
243
244 /* Old X servers rely on out-of-bounds accesses when they are asked
245  * to composite with a window as the source. They create a pixman image
246  * pointing to some bogus position in memory, but then they set a clip
247  * region to the position where the actual bits are.
248  *
249  * Due to a bug in old versions of pixman, where it would not clip
250  * against the image bounds when a clip region was set, this would
251  * actually work. So by default we allow certain out-of-bound access
252  * to happen unless explicitly disabled.
253  *
254  * Fixed X servers should call this function to disable the workaround.
255  */
256 PIXMAN_EXPORT void
257 pixman_disable_out_of_bounds_workaround (void)
258 {
259     out_of_bounds_workaround = FALSE;
260 }
261
262 static pixman_bool_t
263 source_image_needs_out_of_bounds_workaround (bits_image_t *image)
264 {
265     if (image->common.clip_sources                      &&
266         image->common.repeat == PIXMAN_REPEAT_NONE      &&
267         image->common.have_clip_region                  &&
268         out_of_bounds_workaround)
269     {
270         if (!image->common.client_clip)
271         {
272             /* There is no client clip, so if the clip region extends beyond the
273              * drawable geometry, it must be because the X server generated the
274              * bogus clip region.
275              */
276             const pixman_box32_t *extents =
277                 pixman_region32_extents (&image->common.clip_region);
278
279             if (extents->x1 >= 0 && extents->x2 <= image->width &&
280                 extents->y1 >= 0 && extents->y2 <= image->height)
281             {
282                 return FALSE;
283             }
284         }
285
286         return TRUE;
287     }
288
289     return FALSE;
290 }
291
292 static void
293 compute_image_info (pixman_image_t *image)
294 {
295     pixman_format_code_t code;
296     uint32_t flags = 0;
297
298     /* Transform */
299     if (!image->common.transform)
300     {
301         flags |= (FAST_PATH_ID_TRANSFORM        |
302                   FAST_PATH_X_UNIT_POSITIVE     |
303                   FAST_PATH_Y_UNIT_ZERO         |
304                   FAST_PATH_AFFINE_TRANSFORM);
305     }
306     else
307     {
308         flags |= FAST_PATH_HAS_TRANSFORM;
309
310         if (image->common.transform->matrix[2][0] == 0                  &&
311             image->common.transform->matrix[2][1] == 0                  &&
312             image->common.transform->matrix[2][2] == pixman_fixed_1)
313         {
314             flags |= FAST_PATH_AFFINE_TRANSFORM;
315
316             if (image->common.transform->matrix[0][1] == 0 &&
317                 image->common.transform->matrix[1][0] == 0)
318             {
319                 flags |= FAST_PATH_SCALE_TRANSFORM;
320             }
321         }
322
323         if (image->common.transform->matrix[0][0] > 0)
324             flags |= FAST_PATH_X_UNIT_POSITIVE;
325
326         if (image->common.transform->matrix[1][0] == 0)
327             flags |= FAST_PATH_Y_UNIT_ZERO;
328     }
329
330     /* Filter */
331     switch (image->common.filter)
332     {
333     case PIXMAN_FILTER_NEAREST:
334     case PIXMAN_FILTER_FAST:
335         flags |= (FAST_PATH_NEAREST_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
336         break;
337
338     case PIXMAN_FILTER_BILINEAR:
339     case PIXMAN_FILTER_GOOD:
340     case PIXMAN_FILTER_BEST:
341         flags |= (FAST_PATH_BILINEAR_FILTER | FAST_PATH_NO_CONVOLUTION_FILTER);
342         break;
343
344     case PIXMAN_FILTER_CONVOLUTION:
345         break;
346
347     default:
348         flags |= FAST_PATH_NO_CONVOLUTION_FILTER;
349         break;
350     }
351
352     /* Repeat mode */
353     switch (image->common.repeat)
354     {
355     case PIXMAN_REPEAT_NONE:
356         flags |=
357             FAST_PATH_NO_REFLECT_REPEAT         |
358             FAST_PATH_NO_PAD_REPEAT             |
359             FAST_PATH_NO_NORMAL_REPEAT;
360         break;
361
362     case PIXMAN_REPEAT_REFLECT:
363         flags |=
364             FAST_PATH_NO_PAD_REPEAT             |
365             FAST_PATH_NO_NONE_REPEAT            |
366             FAST_PATH_NO_NORMAL_REPEAT;
367         break;
368
369     case PIXMAN_REPEAT_PAD:
370         flags |=
371             FAST_PATH_NO_REFLECT_REPEAT         |
372             FAST_PATH_NO_NONE_REPEAT            |
373             FAST_PATH_NO_NORMAL_REPEAT;
374         break;
375
376     default:
377         flags |=
378             FAST_PATH_NO_REFLECT_REPEAT         |
379             FAST_PATH_NO_PAD_REPEAT             |
380             FAST_PATH_NO_NONE_REPEAT;
381         break;
382     }
383
384     /* Component alpha */
385     if (image->common.component_alpha)
386         flags |= FAST_PATH_COMPONENT_ALPHA;
387     else
388         flags |= FAST_PATH_UNIFIED_ALPHA;
389
390     flags |= (FAST_PATH_NO_ACCESSORS | FAST_PATH_NARROW_FORMAT);
391
392     /* Type specific checks */
393     switch (image->type)
394     {
395     case SOLID:
396         code = PIXMAN_solid;
397
398         if (image->solid.color.alpha == 0xffff)
399             flags |= FAST_PATH_IS_OPAQUE;
400         break;
401
402     case BITS:
403         if (image->bits.width == 1      &&
404             image->bits.height == 1     &&
405             image->common.repeat != PIXMAN_REPEAT_NONE)
406         {
407             code = PIXMAN_solid;
408         }
409         else
410         {
411             code = image->bits.format;
412         }
413
414         if (!PIXMAN_FORMAT_A (image->bits.format)                               &&
415             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_GRAY         &&
416             PIXMAN_FORMAT_TYPE (image->bits.format) != PIXMAN_TYPE_COLOR)
417         {
418             flags |= FAST_PATH_SAMPLES_OPAQUE;
419
420             if (image->common.repeat != PIXMAN_REPEAT_NONE)
421                 flags |= FAST_PATH_IS_OPAQUE;
422         }
423
424         if (source_image_needs_out_of_bounds_workaround (&image->bits))
425             flags |= FAST_PATH_NEEDS_WORKAROUND;
426
427         if (image->bits.read_func || image->bits.write_func)
428             flags &= ~FAST_PATH_NO_ACCESSORS;
429
430         if (PIXMAN_FORMAT_IS_WIDE (image->bits.format))
431             flags &= ~FAST_PATH_NARROW_FORMAT;
432         break;
433
434     case LINEAR:
435     case RADIAL:
436         code = PIXMAN_unknown;
437
438         if (image->common.repeat != PIXMAN_REPEAT_NONE)
439         {
440             int i;
441
442             flags |= FAST_PATH_IS_OPAQUE;
443             for (i = 0; i < image->gradient.n_stops; ++i)
444             {
445                 if (image->gradient.stops[i].color.alpha != 0xffff)
446                 {
447                     flags &= ~FAST_PATH_IS_OPAQUE;
448                     break;
449                 }
450             }
451         }
452         break;
453
454     default:
455         code = PIXMAN_unknown;
456         break;
457     }
458
459     /* Alpha map */
460     if (!image->common.alpha_map)
461     {
462         flags |= FAST_PATH_NO_ALPHA_MAP;
463     }
464     else
465     {
466         if (PIXMAN_FORMAT_IS_WIDE (image->common.alpha_map->format))
467             flags &= ~FAST_PATH_NARROW_FORMAT;
468     }
469
470     /* Both alpha maps and convolution filters can introduce
471      * non-opaqueness in otherwise opaque images. Also
472      * an image with component alpha turned on is only opaque
473      * if all channels are opaque, so we simply turn it off
474      * unconditionally for those images.
475      */
476     if (image->common.alpha_map                                 ||
477         image->common.filter == PIXMAN_FILTER_CONVOLUTION       ||
478         image->common.component_alpha)
479     {
480         flags &= ~(FAST_PATH_IS_OPAQUE | FAST_PATH_SAMPLES_OPAQUE);
481     }
482
483     image->common.flags = flags;
484     image->common.extended_format_code = code;
485 }
486
487 void
488 _pixman_image_validate (pixman_image_t *image)
489 {
490     if (image->common.dirty)
491     {
492         compute_image_info (image);
493
494         /* It is important that property_changed is
495          * called *after* compute_image_info() because
496          * property_changed() can make use of the flags
497          * to set up accessors etc.
498          */
499         image->common.property_changed (image);
500
501         image->common.dirty = FALSE;
502     }
503
504     if (image->common.alpha_map)
505         _pixman_image_validate ((pixman_image_t *)image->common.alpha_map);
506 }
507
508 PIXMAN_EXPORT pixman_bool_t
509 pixman_image_set_clip_region32 (pixman_image_t *   image,
510                                 pixman_region32_t *region)
511 {
512     image_common_t *common = (image_common_t *)image;
513     pixman_bool_t result;
514
515     if (region)
516     {
517         if ((result = pixman_region32_copy (&common->clip_region, region)))
518             image->common.have_clip_region = TRUE;
519     }
520     else
521     {
522         _pixman_image_reset_clip_region (image);
523
524         result = TRUE;
525     }
526
527     image_property_changed (image);
528
529     return result;
530 }
531
532 PIXMAN_EXPORT pixman_bool_t
533 pixman_image_set_clip_region (pixman_image_t *   image,
534                               pixman_region16_t *region)
535 {
536     image_common_t *common = (image_common_t *)image;
537     pixman_bool_t result;
538
539     if (region)
540     {
541         if ((result = pixman_region32_copy_from_region16 (&common->clip_region, region)))
542             image->common.have_clip_region = TRUE;
543     }
544     else
545     {
546         _pixman_image_reset_clip_region (image);
547
548         result = TRUE;
549     }
550
551     image_property_changed (image);
552
553     return result;
554 }
555
556 PIXMAN_EXPORT void
557 pixman_image_set_has_client_clip (pixman_image_t *image,
558                                   pixman_bool_t   client_clip)
559 {
560     image->common.client_clip = client_clip;
561 }
562
563 PIXMAN_EXPORT pixman_bool_t
564 pixman_image_set_transform (pixman_image_t *          image,
565                             const pixman_transform_t *transform)
566 {
567     static const pixman_transform_t id =
568     {
569         { { pixman_fixed_1, 0, 0 },
570           { 0, pixman_fixed_1, 0 },
571           { 0, 0, pixman_fixed_1 } }
572     };
573
574     image_common_t *common = (image_common_t *)image;
575     pixman_bool_t result;
576
577     if (common->transform == transform)
578         return TRUE;
579
580     if (memcmp (&id, transform, sizeof (pixman_transform_t)) == 0)
581     {
582         free (common->transform);
583         common->transform = NULL;
584         result = TRUE;
585
586         goto out;
587     }
588
589     if (common->transform == NULL)
590         common->transform = malloc (sizeof (pixman_transform_t));
591
592     if (common->transform == NULL)
593     {
594         result = FALSE;
595
596         goto out;
597     }
598
599     memcpy (common->transform, transform, sizeof(pixman_transform_t));
600
601     result = TRUE;
602
603 out:
604     image_property_changed (image);
605
606     return result;
607 }
608
609 PIXMAN_EXPORT void
610 pixman_image_set_repeat (pixman_image_t *image,
611                          pixman_repeat_t repeat)
612 {
613     image->common.repeat = repeat;
614
615     image_property_changed (image);
616 }
617
618 PIXMAN_EXPORT pixman_bool_t
619 pixman_image_set_filter (pixman_image_t *      image,
620                          pixman_filter_t       filter,
621                          const pixman_fixed_t *params,
622                          int                   n_params)
623 {
624     image_common_t *common = (image_common_t *)image;
625     pixman_fixed_t *new_params;
626
627     if (params == common->filter_params && filter == common->filter)
628         return TRUE;
629
630     new_params = NULL;
631     if (params)
632     {
633         new_params = pixman_malloc_ab (n_params, sizeof (pixman_fixed_t));
634         if (!new_params)
635             return FALSE;
636
637         memcpy (new_params,
638                 params, n_params * sizeof (pixman_fixed_t));
639     }
640
641     common->filter = filter;
642
643     if (common->filter_params)
644         free (common->filter_params);
645
646     common->filter_params = new_params;
647     common->n_filter_params = n_params;
648
649     image_property_changed (image);
650     return TRUE;
651 }
652
653 PIXMAN_EXPORT void
654 pixman_image_set_source_clipping (pixman_image_t *image,
655                                   pixman_bool_t   clip_sources)
656 {
657     image->common.clip_sources = clip_sources;
658
659     image_property_changed (image);
660 }
661
662 /* Unlike all the other property setters, this function does not
663  * copy the content of indexed. Doing this copying is simply
664  * way, way too expensive.
665  */
666 PIXMAN_EXPORT void
667 pixman_image_set_indexed (pixman_image_t *        image,
668                           const pixman_indexed_t *indexed)
669 {
670     bits_image_t *bits = (bits_image_t *)image;
671
672     bits->indexed = indexed;
673
674     image_property_changed (image);
675 }
676
677 PIXMAN_EXPORT void
678 pixman_image_set_alpha_map (pixman_image_t *image,
679                             pixman_image_t *alpha_map,
680                             int16_t         x,
681                             int16_t         y)
682 {
683     image_common_t *common = (image_common_t *)image;
684
685     return_if_fail (!alpha_map || alpha_map->type == BITS);
686
687     if (alpha_map && common->alpha_count > 0)
688     {
689         /* If this image is being used as an alpha map itself,
690          * then you can't give it an alpha map of its own.
691          */
692         return;
693     }
694
695     if (alpha_map && alpha_map->common.alpha_map)
696     {
697         /* If the image has an alpha map of its own,
698          * then it can't be used as an alpha map itself
699          */
700         return;
701     }
702
703     if (common->alpha_map != (bits_image_t *)alpha_map)
704     {
705         if (common->alpha_map)
706         {
707             common->alpha_map->common.alpha_count--;
708
709             pixman_image_unref ((pixman_image_t *)common->alpha_map);
710         }
711
712         if (alpha_map)
713         {
714             common->alpha_map = (bits_image_t *)pixman_image_ref (alpha_map);
715
716             common->alpha_map->common.alpha_count++;
717         }
718         else
719         {
720             common->alpha_map = NULL;
721         }
722     }
723
724     common->alpha_origin_x = x;
725     common->alpha_origin_y = y;
726
727     image_property_changed (image);
728 }
729
730 PIXMAN_EXPORT void
731 pixman_image_set_component_alpha   (pixman_image_t *image,
732                                     pixman_bool_t   component_alpha)
733 {
734     image->common.component_alpha = component_alpha;
735
736     image_property_changed (image);
737 }
738
739 PIXMAN_EXPORT pixman_bool_t
740 pixman_image_get_component_alpha   (pixman_image_t       *image)
741 {
742     return image->common.component_alpha;
743 }
744
745 PIXMAN_EXPORT void
746 pixman_image_set_accessors (pixman_image_t *           image,
747                             pixman_read_memory_func_t  read_func,
748                             pixman_write_memory_func_t write_func)
749 {
750     return_if_fail (image != NULL);
751
752     if (image->type == BITS)
753     {
754         image->bits.read_func = read_func;
755         image->bits.write_func = write_func;
756
757         image_property_changed (image);
758     }
759 }
760
761 PIXMAN_EXPORT uint32_t *
762 pixman_image_get_data (pixman_image_t *image)
763 {
764     if (image->type == BITS)
765         return image->bits.bits;
766
767     return NULL;
768 }
769
770 PIXMAN_EXPORT int
771 pixman_image_get_width (pixman_image_t *image)
772 {
773     if (image->type == BITS)
774         return image->bits.width;
775
776     return 0;
777 }
778
779 PIXMAN_EXPORT int
780 pixman_image_get_height (pixman_image_t *image)
781 {
782     if (image->type == BITS)
783         return image->bits.height;
784
785     return 0;
786 }
787
788 PIXMAN_EXPORT int
789 pixman_image_get_stride (pixman_image_t *image)
790 {
791     if (image->type == BITS)
792         return image->bits.rowstride * (int) sizeof (uint32_t);
793
794     return 0;
795 }
796
797 PIXMAN_EXPORT int
798 pixman_image_get_depth (pixman_image_t *image)
799 {
800     if (image->type == BITS)
801         return PIXMAN_FORMAT_DEPTH (image->bits.format);
802
803     return 0;
804 }
805
806 PIXMAN_EXPORT pixman_format_code_t
807 pixman_image_get_format (pixman_image_t *image)
808 {
809     if (image->type == BITS)
810         return image->bits.format;
811
812     return 0;
813 }
814
815 uint32_t
816 _pixman_image_get_solid (pixman_image_t *     image,
817                          pixman_format_code_t format)
818 {
819     uint32_t result;
820
821     _pixman_image_get_scanline_32 (image, 0, 0, 1, &result, NULL);
822
823     /* If necessary, convert RGB <--> BGR. */
824     if (PIXMAN_FORMAT_TYPE (format) != PIXMAN_TYPE_ARGB)
825     {
826         result = (((result & 0xff000000) >>  0) |
827                   ((result & 0x00ff0000) >> 16) |
828                   ((result & 0x0000ff00) >>  0) |
829                   ((result & 0x000000ff) << 16));
830     }
831
832     return result;
833 }