[recipes] Also undo image rotations when the recipe isn't saved
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Also undo image rotations when the recipe isn't saved
- Date: Sun, 19 Feb 2017 01:11:40 +0000 (UTC)
commit b9882b77a2f4a79ed0b83d9bf8d534a42d3b37a8
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 18 19:10:25 2017 -0500
Also undo image rotations when the recipe isn't saved
This simply requires us to write the rotated image out to
a separate file, and use the same deferred removal mechanism
we already have in place.
src/gr-image-viewer.c | 10 +++++++++-
src/gr-utils.c | 20 ++++++++++++--------
src/gr-utils.h | 2 +-
3 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/src/gr-image-viewer.c b/src/gr-image-viewer.c
index 2722c1a..4f773e5 100644
--- a/src/gr-image-viewer.c
+++ b/src/gr-image-viewer.c
@@ -657,12 +657,20 @@ gr_image_viewer_rotate_image (GrImageViewer *viewer,
int angle)
{
GrRotatedImage *ri;
+ char *path;
g_assert (angle == 0 || angle == 90 || angle == 180 || angle == 270);
ri = &g_array_index (viewer->images, GrRotatedImage, viewer->index);
- rotate_image (ri->path, angle);
+ path = rotate_image (ri->path, angle);
+ g_ptr_array_add (viewer->removals, g_strdup (ri->path));
+
+ g_free (ri->path);
+ ri->path = path;
+
+ g_ptr_array_add (viewer->additions, g_strdup (ri->path));
+
populate_preview (viewer);
set_current_image (viewer);
diff --git a/src/gr-utils.c b/src/gr-utils.c
index 4db7d5c..739d040 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -678,13 +678,13 @@ import_image (const char *path)
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_autoptr(GdkPixbuf) oriented = NULL;
g_autoptr(GError) error = NULL;
- char *imported;
+ g_autofree char *imported = NULL;
GdkPixbufFormat *format;
g_autofree char *format_name = NULL;
// FIXME: this could be much more efficient
pixbuf = gdk_pixbuf_new_from_file (path, &error);
- if (pixbuf== NULL) {
+ if (pixbuf == NULL) {
g_message ("Failed to load image '%s': %s", path, error->message);
return NULL;
}
@@ -704,25 +704,27 @@ import_image (const char *path)
return NULL;
}
- return imported;
+ return g_strdup (imported);
}
-void
+char *
rotate_image (const char *path,
int angle)
{
g_autoptr(GdkPixbuf) pixbuf = NULL;
g_autoptr(GdkPixbuf) oriented = NULL;
g_autoptr(GError) error = NULL;
+ g_autofree char *imported = NULL;
GdkPixbufFormat *format;
g_autofree char *format_name = NULL;
pixbuf = gdk_pixbuf_new_from_file (path, &error);
- if (pixbuf== NULL) {
+ if (pixbuf == NULL) {
g_message ("Failed to load image '%s': %s", path, error->message);
- return;
+ return NULL;
}
+ imported = get_import_name (path);
format = gdk_pixbuf_get_file_info (path, NULL, NULL);
if (gdk_pixbuf_format_is_writable (format))
format_name = gdk_pixbuf_format_get_name (format);
@@ -731,10 +733,12 @@ rotate_image (const char *path,
oriented = gdk_pixbuf_rotate_simple (pixbuf, angle);
- if (!gdk_pixbuf_save (oriented, path, format_name, &error, NULL)) {
+ if (!gdk_pixbuf_save (oriented, imported, format_name, &error, NULL)) {
g_message ("Failed to save rotated image: %s", error->message);
- return;
+ return NULL;
}
+
+ return g_strdup (imported);
}
void
diff --git a/src/gr-utils.h b/src/gr-utils.h
index 882b091..5ff7ab3 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -81,6 +81,6 @@ void
window_unexport_handle (GtkWindow *window);
char *import_image (const char *path);
-void rotate_image (const char *path,
+char *rotate_image (const char *path,
int angle);
void remove_image (const char *path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]