[gthumb: 16/129] image history: store images using cairo_surface_t instead of GdkPixbuf
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 16/129] image history: store images using cairo_surface_t instead of GdkPixbuf
- Date: Wed, 27 Apr 2011 20:51:43 +0000 (UTC)
commit 3ae9ba0e51a3053302a4f823ae92ad9023e8b1ab
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Apr 15 12:58:01 2011 +0200
image history: store images using cairo_surface_t instead of GdkPixbuf
extensions/image_viewer/gth-image-viewer-page.c | 63 ++++++++++++++---------
extensions/image_viewer/gth-image-viewer-page.h | 4 ++
gthumb/gth-image-history.c | 28 +++++-----
gthumb/gth-image-history.h | 13 +++--
gthumb/gth-image-viewer.h | 2 +-
5 files changed, 65 insertions(+), 45 deletions(-)
---
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 056cd18..ef12435 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -294,8 +294,6 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
GError *error,
GthImageViewerPage *self)
{
- GdkPixbuf *pixbuf;
-
if (! _g_file_equal (requested->file, self->priv->file_data->file))
return;
@@ -312,11 +310,10 @@ image_preloader_requested_ready_cb (GthImagePreloader *preloader,
if (self->priv->shrink_wrap)
gth_image_viewer_page_shrink_wrap (self, TRUE);
gth_image_history_clear (self->priv->history);
- pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer));
- gth_image_history_add_image (self->priv->history, pixbuf, FALSE);
+ gth_image_history_add_image (self->priv->history,
+ gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer)),
+ FALSE);
gth_image_viewer_page_file_loaded (self, TRUE);
-
- _g_object_unref (pixbuf);
}
@@ -329,8 +326,6 @@ image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
GError *error,
GthImageViewerPage *self)
{
- GdkPixbuf *pixbuf;
-
if (! _g_file_equal (requested->file, self->priv->file_data->file))
return;
@@ -342,10 +337,9 @@ image_preloader_original_size_ready_cb (GthImagePreloader *preloader,
original_width,
original_height);
gth_image_history_clear (self->priv->history);
- pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer));
- gth_image_history_add_image (self->priv->history, pixbuf, FALSE);
-
- _g_object_unref (pixbuf);
+ gth_image_history_add_image (self->priv->history,
+ gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer)),
+ FALSE);
}
@@ -1169,23 +1163,23 @@ gth_image_viewer_page_real_save_as (GthViewerPage *base,
static void
-_gth_image_viewer_page_set_pixbuf (GthImageViewerPage *self,
- GdkPixbuf *pixbuf,
- gboolean modified)
+_gth_image_viewer_page_set_image (GthImageViewerPage *self,
+ cairo_surface_t *image,
+ gboolean modified)
{
GthFileData *file_data;
int width;
int height;
char *size;
- gth_image_viewer_set_pixbuf (GTH_IMAGE_VIEWER (self->priv->viewer), pixbuf, -1, -1);
+ gth_image_viewer_set_image (GTH_IMAGE_VIEWER (self->priv->viewer), image, -1, -1);
file_data = gth_browser_get_current_file (GTH_BROWSER (self->priv->browser));
g_file_info_set_attribute_boolean (file_data->info, "gth::file::is-modified", modified);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
+ width = cairo_image_surface_get_width (image);
+ height = cairo_image_surface_get_height (image);
g_file_info_set_attribute_int32 (file_data->info, "image::width", width);
g_file_info_set_attribute_int32 (file_data->info, "image::height", height);
@@ -1206,7 +1200,7 @@ gth_image_viewer_page_real_revert (GthViewerPage *base)
idata = gth_image_history_revert (self->priv->history);
if (idata != NULL) {
- _gth_image_viewer_page_set_pixbuf (self, idata->image, idata->unsaved);
+ _gth_image_viewer_page_set_image (self, idata->image, idata->unsaved);
gth_image_data_unref (idata);
}
}
@@ -1350,9 +1344,30 @@ gth_image_viewer_page_set_pixbuf (GthImageViewerPage *self,
GdkPixbuf *pixbuf,
gboolean add_to_history)
{
+ cairo_surface_t *image;
+
+ image = _cairo_image_surface_create_from_pixbuf (pixbuf);
+ gth_image_viewer_page_set_image (self, image, add_to_history);
+
+ cairo_surface_destroy (image);
+}
+
+
+cairo_surface_t *
+gth_image_viewer_page_get_image (GthImageViewerPage *self)
+{
+ return gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer));
+}
+
+
+void
+gth_image_viewer_page_set_image (GthImageViewerPage *self,
+ cairo_surface_t *image,
+ gboolean add_to_history)
+{
if (add_to_history)
- gth_image_history_add_image (self->priv->history, pixbuf, TRUE);
- _gth_image_viewer_page_set_pixbuf (self, pixbuf, TRUE);
+ gth_image_history_add_image (self->priv->history, image, TRUE);
+ _gth_image_viewer_page_set_image (self, image, TRUE);
self->priv->pixbuf_changed = TRUE;
}
@@ -1364,7 +1379,7 @@ gth_image_viewer_page_undo (GthImageViewerPage *self)
idata = gth_image_history_undo (self->priv->history);
if (idata != NULL)
- _gth_image_viewer_page_set_pixbuf (self, idata->image, idata->unsaved);
+ _gth_image_viewer_page_set_image (self, idata->image, idata->unsaved);
}
@@ -1375,7 +1390,7 @@ gth_image_viewer_page_redo (GthImageViewerPage *self)
idata = gth_image_history_redo (self->priv->history);
if (idata != NULL)
- _gth_image_viewer_page_set_pixbuf (self, idata->image, idata->unsaved);
+ _gth_image_viewer_page_set_image (self, idata->image, idata->unsaved);
}
@@ -1395,7 +1410,7 @@ gth_image_viewer_page_reset (GthImageViewerPage *self)
if (last_image == NULL)
return;
- _gth_image_viewer_page_set_pixbuf (self, last_image->image, last_image->unsaved);
+ _gth_image_viewer_page_set_image (self, last_image->image, last_image->unsaved);
}
diff --git a/extensions/image_viewer/gth-image-viewer-page.h b/extensions/image_viewer/gth-image-viewer-page.h
index 2e1f83a..730cb10 100644
--- a/extensions/image_viewer/gth-image-viewer-page.h
+++ b/extensions/image_viewer/gth-image-viewer-page.h
@@ -52,6 +52,10 @@ GdkPixbuf * gth_image_viewer_page_get_pixbuf (GthImageViewerPage *
void gth_image_viewer_page_set_pixbuf (GthImageViewerPage *page,
GdkPixbuf *pixbuf,
gboolean add_to_history);
+cairo_surface_t * gth_image_viewer_page_get_image (GthImageViewerPage *page);
+void gth_image_viewer_page_set_image (GthImageViewerPage *page,
+ cairo_surface_t *image,
+ gboolean add_to_history);
void gth_image_viewer_page_undo (GthImageViewerPage *page);
void gth_image_viewer_page_redo (GthImageViewerPage *page);
GthImageHistory * gth_image_viewer_page_get_history (GthImageViewerPage *self);
diff --git a/gthumb/gth-image-history.c b/gthumb/gth-image-history.c
index 914eb5e..2e6d635 100644
--- a/gthumb/gth-image-history.c
+++ b/gthumb/gth-image-history.c
@@ -30,8 +30,8 @@
GthImageData *
-gth_image_data_new (GdkPixbuf *image,
- gboolean unsaved)
+gth_image_data_new (cairo_surface_t *image,
+ gboolean unsaved)
{
GthImageData *idata;
@@ -40,7 +40,7 @@ gth_image_data_new (GdkPixbuf *image,
idata = g_new0 (GthImageData, 1);
idata->ref = 1;
- idata->image = g_object_ref (image);
+ idata->image = cairo_surface_reference (image);
idata->unsaved = unsaved;
return idata;
@@ -63,7 +63,7 @@ gth_image_data_unref (GthImageData *idata)
idata->ref--;
if (idata->ref == 0) {
- g_object_unref (idata->image);
+ cairo_surface_destroy (idata->image);
g_free (idata);
}
}
@@ -198,9 +198,9 @@ remove_first_image (GList **list)
static GList*
-add_image_to_list (GList *list,
- GdkPixbuf *pixbuf,
- gboolean unsaved)
+add_image_to_list (GList *list,
+ cairo_surface_t *image,
+ gboolean unsaved)
{
if (g_list_length (list) > MAX_UNDO_HISTORY_LEN) {
GList *last;
@@ -212,38 +212,38 @@ add_image_to_list (GList *list,
}
}
- if (pixbuf == NULL)
+ if (image == NULL)
return list;
- return g_list_prepend (list, gth_image_data_new (pixbuf, unsaved));
+ return g_list_prepend (list, gth_image_data_new (image, unsaved));
}
static void
add_image_to_undo_history (GthImageHistory *history,
- GdkPixbuf *pixbuf,
+ cairo_surface_t *image,
gboolean unsaved)
{
history->priv->undo_history = add_image_to_list (history->priv->undo_history,
- pixbuf,
+ image,
unsaved);
}
static void
add_image_to_redo_history (GthImageHistory *history,
- GdkPixbuf *pixbuf,
+ cairo_surface_t *image,
gboolean unsaved)
{
history->priv->redo_history = add_image_to_list (history->priv->redo_history,
- pixbuf,
+ image,
unsaved);
}
void
gth_image_history_add_image (GthImageHistory *history,
- GdkPixbuf *image,
+ cairo_surface_t *image,
gboolean unsaved)
{
add_image_to_undo_history (history, image, unsaved);
diff --git a/gthumb/gth-image-history.h b/gthumb/gth-image-history.h
index 67b3d9c..e52e5a7 100644
--- a/gthumb/gth-image-history.h
+++ b/gthumb/gth-image-history.h
@@ -23,7 +23,8 @@
#define GTH_IMAGE_HISTORY_H
#include <glib.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <glib-object.h>
+#include <cairo.h>
G_BEGIN_DECLS
@@ -39,9 +40,9 @@ typedef struct _GthImageHistoryPrivate GthImageHistoryPrivate;
typedef struct _GthImageHistoryClass GthImageHistoryClass;
typedef struct {
- int ref;
- GdkPixbuf *image;
- gboolean unsaved;
+ int ref;
+ cairo_surface_t *image;
+ gboolean unsaved;
} GthImageData;
struct _GthImageHistory {
@@ -57,7 +58,7 @@ struct _GthImageHistoryClass {
void (*changed) (GthImageHistory *image_history);
};
-GthImageData * gth_image_data_new (GdkPixbuf *image,
+GthImageData * gth_image_data_new (cairo_surface_t *image,
gboolean unsaved);
GthImageData * gth_image_data_ref (GthImageData *idata);
void gth_image_data_unref (GthImageData *idata);
@@ -66,7 +67,7 @@ void gth_image_data_list_free (GList *list);
GType gth_image_history_get_type (void);
GthImageHistory * gth_image_history_new (void);
void gth_image_history_add_image (GthImageHistory *history,
- GdkPixbuf *image,
+ cairo_surface_t *image,
gboolean unsaved);
GthImageData * gth_image_history_undo (GthImageHistory *history);
GthImageData * gth_image_history_redo (GthImageHistory *history);
diff --git a/gthumb/gth-image-viewer.h b/gthumb/gth-image-viewer.h
index 45251e1..2c6e765 100644
--- a/gthumb/gth-image-viewer.h
+++ b/gthumb/gth-image-viewer.h
@@ -188,7 +188,7 @@ int gth_image_viewer_get_image_height (GthImageViewer *vi
gboolean gth_image_viewer_get_has_alpha (GthImageViewer *viewer);
GdkPixbuf * gth_image_viewer_get_current_pixbuf (GthImageViewer *viewer);
cairo_surface_t *
- gth_image_viewer_get_current_image (GthImageViewer *viewer);
+ gth_image_viewer_get_current_image (GthImageViewer *viewer);
void gth_image_viewer_get_original_size (GthImageViewer *viewer,
int *width,
int *height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]