[gthumb: 15/129] implemented _cairo_image_surface_has_alpha
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 15/129] implemented _cairo_image_surface_has_alpha
- Date: Wed, 27 Apr 2011 20:51:38 +0000 (UTC)
commit fff270609b34250ed589cae45764058c671da0b6
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Apr 15 12:09:37 2011 +0200
implemented _cairo_image_surface_has_alpha
attach the has_alpha info to the cairo surface
gthumb/cairo-utils.c | 55 +++++++++++++++++++++++++++++++++++++-------
gthumb/cairo-utils.h | 1 +
gthumb/gth-image-viewer.c | 4 +-
gthumb/pixbuf-utils.c | 5 ++-
4 files changed, 52 insertions(+), 13 deletions(-)
---
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index 21410e2..7a16d54 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -24,6 +24,22 @@
#include "cairo-utils.h"
+typedef struct {
+ gboolean has_alpha;
+} cairo_surface_metadata_t;
+
+
+static cairo_user_data_key_t surface_metadata_key;
+
+
+static void
+surface_metadata_free (void *data)
+{
+ cairo_surface_metadata_t *metadata = data;
+ g_free (metadata);
+}
+
+
void
_gdk_color_to_cairo_color (GdkColor *g_color,
cairo_color_t *c_color)
@@ -113,18 +129,35 @@ _cairo_clear_surface (cairo_surface_t **surface)
}
+gboolean
+_cairo_image_surface_has_alpha (cairo_surface_t *surface)
+{
+ cairo_surface_metadata_t *metadata;
+
+ if (surface == NULL)
+ return FALSE;
+
+ metadata = cairo_surface_get_user_data (surface, &surface_metadata_key);
+ if (metadata != NULL)
+ return metadata->has_alpha;
+
+ return cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32;
+}
+
+
cairo_surface_t *
_cairo_image_surface_create_from_pixbuf (GdkPixbuf *pixbuf)
{
- cairo_surface_t *surface;
- int width;
- int height;
- int p_stride;
- int p_n_channels;
- guchar *p_pixels;
- int s_stride;
- unsigned char *s_pixels;
- int h, w;
+ cairo_surface_t *surface;
+ cairo_surface_metadata_t *metadata;
+ int width;
+ int height;
+ int p_stride;
+ int p_n_channels;
+ guchar *p_pixels;
+ int s_stride;
+ unsigned char *s_pixels;
+ int h, w;
if (pixbuf == NULL)
return NULL;
@@ -140,6 +173,10 @@ _cairo_image_surface_create_from_pixbuf (GdkPixbuf *pixbuf)
s_stride = cairo_image_surface_get_stride (surface);
s_pixels = cairo_image_surface_get_data (surface);
+ metadata = g_new0 (cairo_surface_metadata_t, 1);
+ metadata->has_alpha = (p_n_channels == 4);
+ cairo_surface_set_user_data (surface, &surface_metadata_key, metadata, surface_metadata_free);
+
if (p_n_channels == 4) {
guchar *s_iter;
guchar *p_iter;
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index 6decc5c..ea78fbb 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -87,6 +87,7 @@ void _cairo_paint_full_gradient (cairo_surface_t *surface,
GdkColor *v_color1,
GdkColor *v_color2);
void _cairo_clear_surface (cairo_surface_t **surface);
+gboolean _cairo_image_surface_has_alpha (cairo_surface_t *surface);
cairo_surface_t *
_cairo_image_surface_create_from_pixbuf
(GdkPixbuf *pixbuf);
diff --git a/gthumb/gth-image-viewer.c b/gthumb/gth-image-viewer.c
index 739b3e8..a60d5c2 100644
--- a/gthumb/gth-image-viewer.c
+++ b/gthumb/gth-image-viewer.c
@@ -1845,7 +1845,7 @@ gth_image_viewer_get_original_size (GthImageViewer *self,
gboolean
gth_image_viewer_get_has_alpha (GthImageViewer *self)
{
- return TRUE; /* FIXME */
+ return _cairo_image_surface_has_alpha (self->priv->surface);
}
@@ -2591,7 +2591,7 @@ gth_image_viewer_paint_background (GthImageViewer *self,
cairo_stroke (cr);
}
- if (TRUE /* FIXME gth_image_viewer_get_has_alpha (self) */) {
+ if (gth_image_viewer_get_has_alpha (self)) {
/* Draw the background for the transparency */
diff --git a/gthumb/pixbuf-utils.c b/gthumb/pixbuf-utils.c
index 1382f55..52479c4 100644
--- a/gthumb/pixbuf-utils.c
+++ b/gthumb/pixbuf-utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include "cairo-utils.h"
#include "pixbuf-utils.h"
@@ -65,7 +66,7 @@ _gdk_pixbuf_new_from_cairo_context (cairo_t *cr)
}
-/* Taken from http://www.gtkforums.com/about5204.html
+/* Started from from http://www.gtkforums.com/about5204.html
* Author: tadeboro */
GdkPixbuf *
_gdk_pixbuf_new_from_cairo_surface (cairo_surface_t *surface)
@@ -87,7 +88,7 @@ _gdk_pixbuf_new_from_cairo_surface (cairo_surface_t *surface)
s_stride = cairo_image_surface_get_stride (surface);
s_pixels = cairo_image_surface_get_data (surface);
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, _cairo_image_surface_has_alpha (surface), 8, width, height);
p_stride = gdk_pixbuf_get_rowstride (pixbuf);
p_pixels = gdk_pixbuf_get_pixels (pixbuf);
p_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]