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