Commit 2a44f1f1 authored by Paolo Bacchilega's avatar Paolo Bacchilega

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

parent 13eb08db
......@@ -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;
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment