summaryrefslogtreecommitdiff
path: root/src/cairo-image-surface.c
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2008-02-16 22:13:43 +1030
committerAdrian Johnson <ajohnson@redneon.com>2008-03-10 17:02:31 +1030
commit7eb8f497d8ac8ee76809f958170f1e5370744ba8 (patch)
treec8edb51ad9d4b72914c8ddf3c7cf4e1d9deed20f /src/cairo-image-surface.c
parent00091d50a6187acd0fd35aef16a4fa5fab3c8aa9 (diff)
Move analyze_image_transparency in to cairo-image-surface.c
Diffstat (limited to 'src/cairo-image-surface.c')
-rw-r--r--src/cairo-image-surface.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c
index 28e3ce223..9ea274c68 100644
--- a/src/cairo-image-surface.c
+++ b/src/cairo-image-surface.c
@@ -1337,3 +1337,32 @@ _cairo_image_surface_clone (cairo_image_surface_t *surface,
return clone;
}
+
+cairo_image_transparency_t
+_cairo_image_analyze_transparency (cairo_image_surface_t *image)
+{
+ int x, y;
+ cairo_image_transparency_t transparency;
+
+ if (image->format == CAIRO_FORMAT_RGB24)
+ return CAIRO_IMAGE_IS_OPAQUE;
+
+ if (image->format != CAIRO_FORMAT_ARGB32)
+ return CAIRO_IMAGE_HAS_ALPHA;
+
+ transparency = CAIRO_IMAGE_IS_OPAQUE;
+ for (y = 0; y < image->height; y++) {
+ uint32_t *pixel = (uint32_t *) (image->data + y * image->stride);
+
+ for (x = 0; x < image->width; x++, pixel++) {
+ int a = (*pixel & 0xff000000) >> 24;
+ if (a > 0 && a < 255) {
+ return CAIRO_IMAGE_HAS_ALPHA;
+ } else if (a == 0) {
+ transparency = CAIRO_IMAGE_HAS_BILEVEL_ALPHA;
+ }
+ }
+ }
+
+ return transparency;
+}