[gimp/wip/animation: 139/197] plug-ins: add a file chooser to choose animation file name.



commit b614e8e8e67c65519d59f2889f353fb24836b338
Author: Jehan <jehan girinstud io>
Date:   Mon May 22 13:09:27 2017 +0200

    plug-ins: add a file chooser to choose animation file name.
    
    Also move the code to a separate file and add some filter.
    Right now it still only export video files, but I should soon be able to
    export image sequences as well.

 plug-ins/animation-play/Makefile.am                |    2 +
 plug-ins/animation-play/core/animation-playback.c  |   40 ------
 plug-ins/animation-play/core/animation-playback.h  |    1 -
 .../widgets/animation-dialog-export.c              |  137 ++++++++++++++++++++
 .../widgets/animation-dialog-export.h              |   29 ++++
 plug-ins/animation-play/widgets/animation-dialog.c |    3 +-
 6 files changed, 170 insertions(+), 42 deletions(-)
---
diff --git a/plug-ins/animation-play/Makefile.am b/plug-ins/animation-play/Makefile.am
index b47a8f1..74b0fc2 100644
--- a/plug-ins/animation-play/Makefile.am
+++ b/plug-ins/animation-play/Makefile.am
@@ -57,6 +57,8 @@ animation_play_SOURCES = \
        core/animation-renderer.c               \
        widgets/animation-dialog.h              \
        widgets/animation-dialog.c              \
+       widgets/animation-dialog-export.h       \
+       widgets/animation-dialog-export.c       \
        widgets/animation-keyframe-view.h       \
        widgets/animation-keyframe-view.c       \
        widgets/animation-layer-view.h  \
diff --git a/plug-ins/animation-play/core/animation-playback.c 
b/plug-ins/animation-play/core/animation-playback.c
index 37e44a4..b4b2da3 100644
--- a/plug-ins/animation-play/core/animation-playback.c
+++ b/plug-ins/animation-play/core/animation-playback.c
@@ -548,46 +548,6 @@ animation_playback_get_stop (AnimationPlayback *playback)
   return playback->priv->stop;
 }
 
-void
-animation_playback_export (AnimationPlayback *playback)
-{
-  AnimationRenderer *renderer;
-  GeglNode          *graph;
-  GeglNode          *export;
-  GeglNode          *input;
-  gint               duration;
-  gint               i;
-
-  renderer = ANIMATION_RENDERER (playback->priv->renderer);
-  duration = animation_get_duration (playback->priv->animation);
-  graph  = gegl_node_new ();
-  export = gegl_node_new_child (graph,
-                                "operation", "gegl:ff-save",
-                                "path", "bla.ogv",
-                                NULL);
-  input = gegl_node_new_child (graph,
-                               "operation", "gegl:buffer-source",
-                               NULL);
-  gegl_node_set (export, "frame-rate", 24.0, NULL);
-  gegl_node_set (export, "video-bufsize", 0, NULL);
-  gegl_node_set (export, "video-bit-rate", 0, NULL);
-  gegl_node_link_many (input, export, NULL);
-
-  for (i = 0; i < duration; i++)
-    {
-      GeglBuffer *buffer;
-
-      g_signal_emit_by_name (playback->priv->animation, "loading",
-                             (gdouble) i / ((gdouble) duration - 0.999));
-      buffer = animation_renderer_get_buffer (renderer, i);
-      gegl_node_set (input, "buffer", buffer, NULL);
-      gegl_node_process (export);
-      g_object_unref (buffer);
-    }
-  g_object_unref (graph);
-  g_signal_emit_by_name (playback->priv->animation, "loaded");
-}
-
 /************ Private Functions ****************/
 
 static void
diff --git a/plug-ins/animation-play/core/animation-playback.h 
b/plug-ins/animation-play/core/animation-playback.h
index e257c26..145ac57 100644
--- a/plug-ins/animation-play/core/animation-playback.h
+++ b/plug-ins/animation-play/core/animation-playback.h
@@ -87,5 +87,4 @@ void          animation_playback_set_stop      (AnimationPlayback   *playback,
                                                 gint                 index);
 gint          animation_playback_get_stop      (AnimationPlayback   *playback);
 
-void          animation_playback_export        (AnimationPlayback   *playback);
 #endif  /*  __ANIMATION_PLAYBACK_H__  */
diff --git a/plug-ins/animation-play/widgets/animation-dialog-export.c 
b/plug-ins/animation-play/widgets/animation-dialog-export.c
new file mode 100644
index 0000000..1012610
--- /dev/null
+++ b/plug-ins/animation-play/widgets/animation-dialog-export.c
@@ -0,0 +1,137 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * animation-dialog-export.c
+ * Copyright (C) 2017 Jehan <jehan gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+#include <libgimp/gimp.h>
+#undef GDK_DISABLE_DEPRECATED
+#include <libgimp/gimpui.h>
+#include "libgimp/stdplugins-intl.h"
+
+#include "core/animation.h"
+#include "core/animation-playback.h"
+
+#include "animation-dialog.h"
+#include "animation-dialog-export.h"
+
+static void animation_dialog_export_video (AnimationPlayback *playback,
+                                           gchar             *filename);
+
+void
+animation_dialog_export (GtkWindow         *main_dialog,
+                         AnimationPlayback *playback)
+{
+  GtkWidget     *dialog;
+  GtkFileFilter *all;
+  GtkFileFilter *videos;
+  gchar         *filename = NULL;
+
+  dialog = gtk_file_chooser_dialog_new (_("Export animation"),
+                                        main_dialog,
+                                        GTK_FILE_CHOOSER_ACTION_SAVE,
+                                        _("_Cancel"), GTK_RESPONSE_CANCEL,
+                                        _("_Export"), GTK_RESPONSE_ACCEPT,
+                                        NULL);
+  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+  /*gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
+                                         default_folder_for_saving);*/
+  /*gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
+                                       "Untitled document");*/
+
+  /* Add filters. */
+  all = gtk_file_filter_new ();
+  gtk_file_filter_set_name (all, _("All files"));
+  gtk_file_filter_add_pattern (all, "*");
+  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), all);
+
+  videos = gtk_file_filter_new ();
+  gtk_file_filter_set_name (videos, _("Video Files"));
+  gtk_file_filter_add_pattern (videos, "*.[oO][gG][vV]");
+  gtk_file_filter_add_mime_type (videos, "video/x-theora+ogg");
+  gtk_file_filter_add_mime_type (videos, "video/ogg");
+  gtk_file_filter_add_pattern (videos, "*.[aA][vV][iI]");
+  gtk_file_filter_add_pattern (videos, "*.[mM][oO][vV]");
+  gtk_file_filter_add_pattern (videos, "*.[mM][pP][gG]");
+  gtk_file_filter_add_pattern (videos, "*.[mM][pP]4");
+  gtk_file_filter_add_mime_type (videos, "video/x-msvideo");
+  gtk_file_filter_add_mime_type (videos, "video/quicktime");
+  gtk_file_filter_add_mime_type (videos, "video/mpeg");
+  gtk_file_filter_add_mime_type (videos, "video/mp4");
+  gtk_file_filter_add_mime_type (videos, "video/x-matroska");
+  gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), videos);
+
+  gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), videos);
+
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+    {
+      filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+    }
+  gtk_widget_destroy (dialog);
+  if (filename)
+    {
+      animation_dialog_export_video (playback, filename);
+      g_free (filename);
+    }
+}
+
+static void
+animation_dialog_export_video (AnimationPlayback *playback,
+                               gchar             *filename)
+{
+  Animation *animation;
+  GeglNode  *graph;
+  GeglNode  *export;
+  GeglNode  *input;
+  gint       duration;
+  gint       i;
+
+  animation = animation_playback_get_animation (playback);
+  duration = animation_get_duration (animation);
+  graph  = gegl_node_new ();
+  export = gegl_node_new_child (graph,
+                                "operation", "gegl:ff-save",
+                                "path", filename,
+                                NULL);
+  input = gegl_node_new_child (graph,
+                               "operation", "gegl:buffer-source",
+                               NULL);
+  gegl_node_set (export, "frame-rate", 24.0, NULL);
+  gegl_node_set (export, "video-bufsize", 0, NULL);
+  gegl_node_set (export, "video-bit-rate", 0, NULL);
+  gegl_node_link_many (input, export, NULL);
+
+  for (i = 0; i < duration; i++)
+    {
+      GeglBuffer *buffer;
+
+      g_signal_emit_by_name (animation, "loading",
+                             (gdouble) i / ((gdouble) duration - 0.999));
+      buffer = animation_playback_get_buffer (playback, i);
+      gegl_node_set (input, "buffer", buffer, NULL);
+      gegl_node_process (export);
+      g_object_unref (buffer);
+    }
+  g_object_unref (graph);
+  g_signal_emit_by_name (animation, "loaded");
+}
diff --git a/plug-ins/animation-play/widgets/animation-dialog-export.h 
b/plug-ins/animation-play/widgets/animation-dialog-export.h
new file mode 100644
index 0000000..ccf8e9b
--- /dev/null
+++ b/plug-ins/animation-play/widgets/animation-dialog-export.h
@@ -0,0 +1,29 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * animation-dialog-export.h
+ * Copyright (C) 2017 Jehan <jehan gimp org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ANIMATION_DIALOG_EXPORT_H__
+#define __ANIMATION_DIALOG_EXPORT_H__
+
+#include <gtk/gtk.h>
+
+void         animation_dialog_export              (GtkWindow         *main_dialog,
+                                                   AnimationPlayback *playback);
+
+#endif  /*  __ANIMATION_DIALOG_EXPORT_H__  */
diff --git a/plug-ins/animation-play/widgets/animation-dialog.c 
b/plug-ins/animation-play/widgets/animation-dialog.c
index f954456..b5d9be8 100755
--- a/plug-ins/animation-play/widgets/animation-dialog.c
+++ b/plug-ins/animation-play/widgets/animation-dialog.c
@@ -35,6 +35,7 @@
 #include "core/animation-playback.h"
 
 #include "animation-dialog.h"
+#include "animation-dialog-export.h"
 #include "animation-keyframe-view.h"
 #include "animation-layer-view.h"
 #include "animation-storyboard.h"
@@ -1476,7 +1477,7 @@ export_callback (GtkAction       *action,
 {
   AnimationDialogPrivate *priv = GET_PRIVATE (dialog);
 
-  animation_playback_export (priv->playback);
+  animation_dialog_export (GTK_WINDOW (dialog), priv->playback);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]