[gthumb] allow to preserve the metadata when saving to a buffer
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] allow to preserve the metadata when saving to a buffer
- Date: Tue, 4 Sep 2012 18:49:00 +0000 (UTC)
commit 37098e3df820770ee0eb9ace868a4c9175a62054
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Sep 4 18:26:57 2012 +0200
allow to preserve the metadata when saving to a buffer
.../contact_sheet/gth-contact-sheet-creator.c | 1 +
extensions/exiv2_tools/exiv2-utils.cpp | 10 +-
extensions/facebook/facebook-service.c | 1 +
gthumb/gth-image-saver.c | 149 ++++++++++++--------
gthumb/gth-image-saver.h | 8 +-
5 files changed, 99 insertions(+), 70 deletions(-)
---
diff --git a/extensions/contact_sheet/gth-contact-sheet-creator.c b/extensions/contact_sheet/gth-contact-sheet-creator.c
index be6fae8..3a4a6ea 100644
--- a/extensions/contact_sheet/gth-contact-sheet-creator.c
+++ b/extensions/contact_sheet/gth-contact-sheet-creator.c
@@ -356,6 +356,7 @@ end_page (GthContactSheetCreator *self,
gth_image_set_cairo_surface (image, cairo_get_target (self->priv->cr));
if (! gth_image_save_to_buffer (image,
self->priv->mime_type,
+ NULL,
&buffer,
&size,
error))
diff --git a/extensions/exiv2_tools/exiv2-utils.cpp b/extensions/exiv2_tools/exiv2-utils.cpp
index c0e52b0..0f8ce0e 100644
--- a/extensions/exiv2_tools/exiv2-utils.cpp
+++ b/extensions/exiv2_tools/exiv2-utils.cpp
@@ -1062,7 +1062,13 @@ exiv2_write_metadata_private (Exiv2::Image::AutoPtr image,
scale_keeping_ratio (&width, &height, 128, 128, FALSE);
thumbnail = _cairo_image_surface_scale (surface, width, height, SCALE_FILTER_BEST, NULL);
thumbnail_data = gth_image_new_for_surface (thumbnail);
- if (gth_image_save_to_buffer (thumbnail_data, "image/jpeg", &buffer, &buffer_size, NULL)) {
+ if (gth_image_save_to_buffer (thumbnail_data,
+ "image/jpeg",
+ NULL,
+ &buffer,
+ &buffer_size,
+ NULL))
+ {
thumb.setJpegThumbnail ((Exiv2::byte *) buffer, buffer_size);
ed["Exif.Thumbnail.XResolution"] = 72;
ed["Exif.Thumbnail.YResolution"] = 72;
@@ -1229,7 +1235,7 @@ extern "C"
gboolean
exiv2_write_metadata (GthImageSaveData *data)
{
- if (exiv2_supports_writes (data->mime_type)) {
+ if (exiv2_supports_writes (data->mime_type) && (data->file_data != NULL)) {
try {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open ((Exiv2::byte*) data->buffer, data->buffer_size);
g_assert (image.get() != 0);
diff --git a/extensions/facebook/facebook-service.c b/extensions/facebook/facebook-service.c
index 1093c8a..8874834 100644
--- a/extensions/facebook/facebook-service.c
+++ b/extensions/facebook/facebook-service.c
@@ -779,6 +779,7 @@ upload_photo_file_buffer_ready_cb (void **buffer,
gth_image_set_cairo_surface (image, surface);
if (! gth_image_save_to_buffer (image,
gth_file_data_get_mime_type (file_data),
+ file_data,
(char **) buffer,
&count,
&error))
diff --git a/gthumb/gth-image-saver.c b/gthumb/gth-image-saver.c
index 6cb807f..967d84d 100644
--- a/gthumb/gth-image-saver.c
+++ b/gthumb/gth-image-saver.c
@@ -163,61 +163,60 @@ gth_image_saver_save_image (GthImageSaver *self,
}
-gboolean
-gth_image_save_to_buffer (GthImage *image,
- const char *mime_type,
- char **buffer,
- gsize *buffer_size,
- GError **p_error)
+static GthImageSaveData *
+_gth_image_save_to_buffer_common (GthImage *image,
+ const char *mime_type,
+ GthFileData *file_data,
+ GError **p_error)
{
- GthImageSaver *saver;
- gboolean result;
- GError *error = NULL;
+ GthImageSaver *saver;
+ char *buffer;
+ gsize buffer_size;
+ GError *error = NULL;
+ GthImageSaveData *save_data = NULL;
saver = gth_main_get_image_saver (mime_type);
if (saver == NULL) {
if (p_error != NULL)
*p_error = g_error_new (GTH_ERROR, GTH_ERROR_GENERIC, _("Could not find a suitable module to save the image as \"%s\""), mime_type);
- return FALSE;
+ return NULL;
}
- result = gth_image_saver_save_image (saver, image, buffer, buffer_size, mime_type, &error);
-
- if (p_error != NULL)
- *p_error = error;
- else
- _g_error_free (error);
+ if (gth_image_saver_save_image (saver,
+ image,
+ &buffer,
+ &buffer_size,
+ mime_type,
+ &error))
+ {
+ save_data = g_new0 (GthImageSaveData, 1);
+ save_data->file_data = _g_object_ref (file_data);
+ save_data->image = gth_image_copy (image);
+ save_data->mime_type = mime_type;
+ save_data->buffer = buffer;
+ save_data->buffer_size = buffer_size;
+ save_data->files = NULL;
+ save_data->error = NULL;
+
+ if (save_data->file_data != NULL)
+ gth_hook_invoke ("save-image", save_data);
+
+ if ((save_data->error != NULL) && (p_error != NULL))
+ *p_error = g_error_copy (*save_data->error);
+ }
+ else {
+ if (p_error != NULL)
+ *p_error = error;
+ else
+ _g_error_free (error);
+ }
g_object_unref (saver);
- return result;
+ return save_data;
}
-/*
-gboolean
-_cairo_image_surface_to_mime_type (cairo_surface_t *image,
- char **buffer,
- gsize *buffer_size,
- const char *mime_type,
- GError **error)
-{
-
-}
-*/
-
-
-/* -- gth_image_save_to_file -- */
-
-
-typedef struct {
- GthImageSaveData *data;
- GthFileDataFunc ready_func;
- gpointer ready_data;
- GList *current;
-} SaveData;
-
-
static void
gth_image_save_file_free (GthImageSaveFile *file)
{
@@ -230,7 +229,7 @@ gth_image_save_file_free (GthImageSaveFile *file)
static void
gth_image_save_data_free (GthImageSaveData *data)
{
- g_object_unref (data->file_data);
+ _g_object_unref (data->file_data);
g_object_unref (data->image);
g_list_foreach (data->files, (GFunc) gth_image_save_file_free, NULL);
g_list_free (data->files);
@@ -238,6 +237,46 @@ gth_image_save_data_free (GthImageSaveData *data)
}
+gboolean
+gth_image_save_to_buffer (GthImage *image,
+ const char *mime_type,
+ GthFileData *file_data,
+ char **buffer,
+ gsize *buffer_size,
+ GError **p_error)
+{
+ GthImageSaveData *save_data;
+
+ g_return_val_if_fail (image != NULL, FALSE);
+
+ save_data = _gth_image_save_to_buffer_common (image,
+ mime_type,
+ file_data,
+ p_error);
+
+ if (save_data != NULL) {
+ *buffer = save_data->buffer;
+ *buffer_size = save_data->buffer_size;
+ gth_image_save_data_free (save_data);
+ return TRUE;
+ }
+
+ return FALSE;
+
+}
+
+
+/* -- gth_image_save_to_file -- */
+
+
+typedef struct {
+ GthImageSaveData *data;
+ GthFileDataFunc ready_func;
+ gpointer ready_data;
+ GList *current;
+} SaveData;
+
+
static void
save_completed (SaveData *save_data)
{
@@ -321,31 +360,20 @@ gth_image_save_to_file (GthImage *image,
GthFileDataFunc ready_func,
gpointer user_data)
{
- void *buffer;
- gsize buffer_size;
- GError *error = NULL;
GthImageSaveData *data;
+ GError *error = NULL;
- if (! gth_image_save_to_buffer (image,
- mime_type,
- (char **) &buffer,
- &buffer_size,
- &error))
- {
+ data = _gth_image_save_to_buffer_common (image,
+ mime_type,
+ file_data,
+ &error);
+
+ if (data == NULL) {
gth_file_data_ready_with_error (file_data, ready_func, user_data, error);
return;
}
- data = g_new0 (GthImageSaveData, 1);
- data->file_data = g_object_ref (file_data);
- data->image = gth_image_copy (image);
- data->mime_type = mime_type;
data->replace = replace;
- data->buffer = buffer;
- data->buffer_size = buffer_size;
- data->files = NULL;
- data->error = NULL;
- gth_hook_invoke ("save-image", data);
if (data->error == NULL) {
GthImageSaveFile *file;
@@ -358,7 +386,6 @@ gth_image_save_to_file (GthImage *image,
}
else {
gth_image_save_data_free (data);
- g_free (buffer);
gth_file_data_ready_with_error (file_data, ready_func, user_data, error);
return;
}
diff --git a/gthumb/gth-image-saver.h b/gthumb/gth-image-saver.h
index 5ba1522..edf417b 100644
--- a/gthumb/gth-image-saver.h
+++ b/gthumb/gth-image-saver.h
@@ -102,16 +102,10 @@ gboolean gth_image_saver_can_save (GthImageSaver *self,
const char *mime_type);
gboolean gth_image_save_to_buffer (GthImage *image,
const char *mime_type,
+ GthFileData *file_data,
char **buffer,
gsize *buffer_size,
GError **error);
-/*
-gboolean _cairo_image_surface_to_mime_type (cairo_surface_t *image,
- char **buffer,
- gsize *buffer_size,
- const char *mime_type,
- GError **error);
-*/
void gth_image_save_to_file (GthImage *image,
const char *mime_type,
GthFileData *file_data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]