[gthumb] cairio-io: set the has_alpha flag when loading a jpeg or png image



commit 2a44f1f14a750c3ca744be0f2829b6e416307dee
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun May 15 12:09:47 2011 +0200

    cairio-io: set the has_alpha flag when loading a jpeg or png image

 extensions/cairo_io/cairo-io-jpeg.c          |    3 +++
 extensions/cairo_io/cairo-io-png.c           |   20 ++++++++++++--------
 extensions/file_tools/gth-file-tool-rotate.c |    2 +-
 gthumb/cairo-utils.c                         |   23 ++++++++++++++++-------
 gthumb/cairo-utils.h                         |    5 +++++
 5 files changed, 37 insertions(+), 16 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-io-jpeg.c b/extensions/cairo_io/cairo-io-jpeg.c
index 9eeb6e9..3e47fb7 100644
--- a/extensions/cairo_io/cairo-io-jpeg.c
+++ b/extensions/cairo_io/cairo-io-jpeg.c
@@ -156,6 +156,7 @@ _cairo_image_surface_create_from_jpeg (GthFileData   *file_data,
 	struct error_handler_data      jsrcerr;
 	struct jpeg_decompress_struct  srcinfo;
 	cairo_surface_t               *surface;
+	cairo_surface_metadata_t      *metadata;
 	unsigned char                 *surface_row;
 	JSAMPARRAY                     buffer;
 	int                            buffer_stride;
@@ -246,6 +247,8 @@ _cairo_image_surface_create_from_jpeg (GthFileData   *file_data,
 
 		return image;
 	}
+	metadata = _cairo_image_surface_get_metadata (surface);
+	metadata->has_alpha = FALSE;
 	cairo_surface_flush (surface);
 	surface_row = cairo_image_surface_get_data (surface) + line_start;
 
diff --git a/extensions/cairo_io/cairo-io-png.c b/extensions/cairo_io/cairo-io-png.c
index 84e2de9..146754b 100644
--- a/extensions/cairo_io/cairo-io-png.c
+++ b/extensions/cairo_io/cairo-io-png.c
@@ -126,14 +126,15 @@ _cairo_image_surface_create_from_png (GthFileData   *file_data,
 				      GCancellable  *cancellable,
 				      GError       **error)
 {
-	GthImage      *image;
-	CairoPngData  *cairo_png_data;
-	png_uint_32    width, height;
-	int            bit_depth, color_type, interlace_type;
-	unsigned char *surface_row;
-	int            rowstride;
-	png_bytep     *row_pointers;
-	int            row;
+	GthImage                 *image;
+	CairoPngData             *cairo_png_data;
+	png_uint_32               width, height;
+	int                       bit_depth, color_type, interlace_type;
+	cairo_surface_metadata_t *metadata;
+	unsigned char            *surface_row;
+	int                       rowstride;
+	png_bytep                *row_pointers;
+	int                       row;
 
 	image = gth_image_new ();
 
@@ -185,6 +186,9 @@ _cairo_image_surface_create_from_png (GthFileData   *file_data,
 	        return image;
 	}
 
+	metadata = _cairo_image_surface_get_metadata (cairo_png_data->surface);
+	metadata->has_alpha = (color_type & PNG_COLOR_MASK_ALPHA);
+
 	/* Set the data transformations */
 
 	png_set_strip_16 (cairo_png_data->png_ptr);
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index 8f13764..ea35b2f 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -495,7 +495,7 @@ gth_file_tool_rotate_get_options (GthFileTool *base)
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->background_transparent), TRUE);
 	}
 	else {
-		gtk_widget_set_sensitive (GET_WIDGET ("background_transparent"), FALSE);
+		gtk_widget_set_sensitive (self->priv->background_transparent, FALSE);
 		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->background_transparent), FALSE);
 	}
 
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index f5ed20f..0f4360c 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -28,11 +28,6 @@
 const unsigned char cairo_channel[4] = { CAIRO_RED, CAIRO_GREEN, CAIRO_BLUE, CAIRO_ALPHA };
 
 
-typedef struct {
-	gboolean has_alpha;
-} cairo_surface_metadata_t;
-
-
 static cairo_user_data_key_t surface_metadata_key;
 static cairo_user_data_key_t surface_pixels_key;
 
@@ -91,6 +86,21 @@ _cairo_clear_surface (cairo_surface_t  **surface)
 }
 
 
+cairo_surface_metadata_t *
+_cairo_image_surface_get_metadata (cairo_surface_t *surface)
+{
+	cairo_surface_metadata_t *metadata;
+
+	metadata = cairo_surface_get_user_data (surface, &surface_metadata_key);
+	if (metadata == NULL) {
+		metadata = g_new0 (cairo_surface_metadata_t, 1);
+		cairo_surface_set_user_data (surface, &surface_metadata_key, metadata, surface_metadata_free);
+	}
+
+	return metadata;
+}
+
+
 gboolean
 _cairo_image_surface_get_has_alpha (cairo_surface_t *surface)
 {
@@ -247,9 +257,8 @@ _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 = _cairo_image_surface_get_metadata (surface);
 	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;
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index 46ffa9d..3921f70 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -124,6 +124,9 @@ typedef struct {
 	guchar a;
 } cairo_color_255_t;
 
+typedef struct {
+	gboolean has_alpha;
+} cairo_surface_metadata_t;
 
 extern const unsigned char cairo_channel[4];
 
@@ -143,6 +146,8 @@ void               _gdk_color_to_cairo_color_255            (GdkColor          *
 /* surface */
 
 void               _cairo_clear_surface                     (cairo_surface_t  **surface);
+cairo_surface_metadata_t *
+		   _cairo_image_surface_get_metadata       (cairo_surface_t   *surface);
 gboolean           _cairo_image_surface_get_has_alpha       (cairo_surface_t   *surface);
 cairo_surface_t *  _cairo_image_surface_copy                (cairo_surface_t   *surface);
 cairo_surface_t *  _cairo_image_surface_copy_subsurface     (cairo_surface_t   *surface,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]