[gthumb] added _cairo_image_surface_create()
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] added _cairo_image_surface_create()
- Date: Sun, 30 Jun 2013 08:41:03 +0000 (UTC)
commit 3d273152e516effa52f8a790346b3a2fdf344167
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Jun 28 16:44:21 2013 +0200
added _cairo_image_surface_create()
similar to cairo_image_surface_create but returns NULL on error.
extensions/cairo_io/cairo-image-surface-jpeg.c | 10 +--
gthumb/cairo-utils.c | 73 ++++++++----------------
gthumb/cairo-utils.h | 3 +
3 files changed, 31 insertions(+), 55 deletions(-)
---
diff --git a/extensions/cairo_io/cairo-image-surface-jpeg.c b/extensions/cairo_io/cairo-image-surface-jpeg.c
index 9c794e4..616ef92 100644
--- a/extensions/cairo_io/cairo-image-surface-jpeg.c
+++ b/extensions/cairo_io/cairo-image-surface-jpeg.c
@@ -247,16 +247,14 @@ _cairo_image_surface_create_from_jpeg (GInputStream *istream,
destination_height);
#endif
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, destination_width, destination_height);
- if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) {
- /* g_warning ("%s", cairo_status_to_string (cairo_surface_status (surface))); */
-
- jpeg_destroy ((j_common_ptr) &srcinfo);
- cairo_surface_destroy (surface);
+ surface = _cairo_image_surface_create (CAIRO_FORMAT_ARGB32, destination_width, destination_height);
+ if (surface == NULL) {
+ jpeg_destroy_decompress (&srcinfo);
g_free (in_buffer);
return image;
}
+
metadata = _cairo_image_surface_get_metadata (surface);
metadata->has_alpha = FALSE;
diff --git a/gthumb/cairo-utils.c b/gthumb/cairo-utils.c
index 651c72e..43eceb9 100644
--- a/gthumb/cairo-utils.c
+++ b/gthumb/cairo-utils.c
@@ -35,7 +35,6 @@ const unsigned char cairo_channel[4] = { CAIRO_RED, CAIRO_GREEN, CAIRO_BLUE, CAI
static cairo_user_data_key_t surface_metadata_key;
-static cairo_user_data_key_t surface_pixels_key;
static void
@@ -46,13 +45,6 @@ surface_metadata_free (void *data)
}
-static void
-surface_pixels_free (void *data)
-{
- g_free (data);
-}
-
-
inline int
_cairo_multiply_alpha (int color,
int alpha)
@@ -160,61 +152,44 @@ _cairo_image_surface_get_has_alpha (cairo_surface_t *surface)
cairo_surface_t *
-_cairo_image_surface_copy (cairo_surface_t *source)
+_cairo_image_surface_create (cairo_format_t format,
+ int width,
+ int height)
{
cairo_surface_t *result;
- cairo_format_t format;
- int width;
- int height;
- int stride;
- unsigned char *pixels;
cairo_status_t status;
- int source_stride;
- int destination_stride;
- unsigned char *p_source;
- unsigned char *p_destination;
- int row_size;
-
- if (source == NULL)
- return NULL;
- format = cairo_image_surface_get_format (source);
- width = cairo_image_surface_get_width (source);
- height = cairo_image_surface_get_height (source);
- stride = cairo_format_stride_for_width (format, width);
- pixels = g_try_malloc (stride * height);
- if (pixels == NULL)
- return NULL;
-
- result = cairo_image_surface_create_for_data (pixels, format, width, height, stride);
+ result = cairo_image_surface_create (format, width, height);
status = cairo_surface_status (result);
if (status != CAIRO_STATUS_SUCCESS) {
- g_warning ("_cairo_image_surface_copy: could not create the surface: %s",
cairo_status_to_string (status));
+ g_warning ("_cairo_image_surface_create: could not create the surface: %s",
cairo_status_to_string (status));
cairo_surface_destroy (result);
return NULL;
}
- status = cairo_surface_set_user_data (result, &surface_pixels_key, pixels, surface_pixels_free);
- if (status != CAIRO_STATUS_SUCCESS) {
- g_warning ("_cairo_image_surface_copy: could not set the user data: %s",
cairo_status_to_string (status));
- cairo_surface_destroy (result);
- return NULL;
- }
+ return result;
+}
- cairo_surface_flush (result);
- source_stride = cairo_image_surface_get_stride (source);
- destination_stride = cairo_image_surface_get_stride (result);
- p_source = cairo_image_surface_get_data (source);
- p_destination = cairo_image_surface_get_data (result);
- row_size = width * 4;
- while (height-- > 0) {
- memcpy (p_destination, p_source, row_size);
+cairo_surface_t *
+_cairo_image_surface_copy (cairo_surface_t *source)
+{
+ cairo_surface_t *result;
+ unsigned char *p_source;
+ unsigned char *p_destination;
- p_source += source_stride;
- p_destination += destination_stride;
- }
+ if (source == NULL)
+ return NULL;
+
+ result = _cairo_image_surface_create (cairo_image_surface_get_format (source),
+ cairo_image_surface_get_width (source),
+ cairo_image_surface_get_height (source));
+ if (result == NULL)
+ return NULL;
+ p_source = _cairo_image_surface_flush_and_get_data (source);
+ p_destination = _cairo_image_surface_flush_and_get_data (result);
+ memcpy (p_destination, p_source, cairo_image_surface_get_stride (source) *
cairo_image_surface_get_height (source));
cairo_surface_mark_dirty (result);
return result;
diff --git a/gthumb/cairo-utils.h b/gthumb/cairo-utils.h
index 82c1d2d..05e10e5 100644
--- a/gthumb/cairo-utils.h
+++ b/gthumb/cairo-utils.h
@@ -160,6 +160,9 @@ unsigned char * _cairo_image_surface_flush_and_get_data (cairo_surface_t
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_create (cairo_format_t format,
+ int width,
+ int height);
cairo_surface_t * _cairo_image_surface_copy (cairo_surface_t *surface);
cairo_surface_t * _cairo_image_surface_copy_subsurface (cairo_surface_t *surface,
int src_x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]