[gegl] gcut: add a new c file for utility functions
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] gcut: add a new c file for utility functions
- Date: Sun, 13 Aug 2017 01:01:14 +0000 (UTC)
commit c06ff200da3720abe52aeaa949c421e1f1974396
Author: Øyvind Kolås <pippin gimp org>
Date: Sun Aug 13 01:04:46 2017 +0200
gcut: add a new c file for utility functions
gcut/Makefile.am | 1 +
gcut/gcut-util.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
gcut/gcut.c | 134 +--------------------------------------------------
3 files changed, 144 insertions(+), 132 deletions(-)
---
diff --git a/gcut/Makefile.am b/gcut/Makefile.am
index 770b412..4d1fbc9 100644
--- a/gcut/Makefile.am
+++ b/gcut/Makefile.am
@@ -45,6 +45,7 @@ default.edl.inc: default.edl
gcut_SOURCES = \
gcut.c \
+ gcut-util.c \
default.edl.inc \
gcut.h \
iconographer.c \
diff --git a/gcut/gcut-util.c b/gcut/gcut-util.c
new file mode 100644
index 0000000..a233cff
--- /dev/null
+++ b/gcut/gcut-util.c
@@ -0,0 +1,141 @@
+#include "config.h"
+#include <gegl.h>
+#include <gegl-audio-fragment.h>
+#include "gcut.h"
+#if HAVE_GEXIV2
+#include <gexiv2/gexiv2.h>
+#endif
+
+void gcut_get_video_info (const char *path,
+ int *frames,
+ double *duration,
+ double *fps)
+{
+ GeglNode *gegl = gegl_node_new ();
+ GeglNode *probe = gegl_node_new_child (gegl, "operation",
+ "gegl:ff-load", "path", path, NULL);
+ double r_fps;
+ int r_frames;
+ gegl_node_process (probe);
+
+ gegl_node_get (probe, "frames", &r_frames, NULL);
+ gegl_node_get (probe, "frame-rate", &r_fps, NULL);
+
+ if (frames)
+ *frames = r_frames;
+ if (fps)
+ *fps = r_fps;
+ if (duration)
+ *duration = r_frames / r_fps;
+ g_object_unref (gegl);
+}
+
+
+void
+gegl_meta_set_audio (const char *path,
+ GeglAudioFragment *audio)
+{
+#if HAVE_GEXIV2
+ GError *error = NULL;
+ GExiv2Metadata *e2m = gexiv2_metadata_new ();
+ gexiv2_metadata_open_path (e2m, path, &error);
+ if (error)
+ {
+ g_warning ("%s", error->message);
+ }
+ else
+ {
+ int i, c;
+ GString *str = g_string_new ("");
+ int sample_count = gegl_audio_fragment_get_sample_count (audio);
+ int channels = gegl_audio_fragment_get_channels (audio);
+ if (gexiv2_metadata_has_tag (e2m, "Xmp.xmp.GEGL"))
+ gexiv2_metadata_clear_tag (e2m, "Xmp.xmp.GEGL");
+
+ g_string_append_printf (str, "%i %i %i %i",
+ gegl_audio_fragment_get_sample_rate (audio),
+ gegl_audio_fragment_get_channels (audio),
+ gegl_audio_fragment_get_channel_layout (audio),
+ gegl_audio_fragment_get_sample_count (audio));
+
+ for (i = 0; i < sample_count; i++)
+ for (c = 0; c < channels; c++)
+ g_string_append_printf (str, " %0.5f", audio->data[c][i]);
+
+ gexiv2_metadata_set_tag_string (e2m, "Xmp.xmp.GeglAudio", str->str);
+ gexiv2_metadata_save_file (e2m, path, &error);
+ if (error)
+ g_warning ("%s", error->message);
+ g_string_free (str, TRUE);
+ }
+ g_object_unref (e2m);
+#endif
+}
+
+void
+gegl_meta_get_audio (const char *path,
+ GeglAudioFragment *audio)
+{
+#if HAVE_GEXIV2
+ GError *error = NULL;
+ GExiv2Metadata *e2m = gexiv2_metadata_new ();
+ gexiv2_metadata_open_path (e2m, path, &error);
+ if (!error)
+ {
+ GString *word = g_string_new ("");
+ gchar *p;
+ gchar *ret = gexiv2_metadata_get_tag_string (e2m, "Xmp.xmp.GeglAudio");
+ int element_no = 0;
+ int channels = 2;
+ int max_samples = 2000;
+
+ if (ret)
+ for (p = ret; p==ret || p[-1] != '\0'; p++)
+ {
+ switch (p[0])
+ {
+ case '\0':case ' ':
+ if (word->len > 0)
+ {
+ switch (element_no++)
+ {
+ case 0:
+ gegl_audio_fragment_set_sample_rate (audio, g_strtod (word->str, NULL));
+ break;
+ case 1:
+ channels = g_strtod (word->str, NULL);
+ gegl_audio_fragment_set_channels (audio, channels);
+ break;
+ case 2:
+ gegl_audio_fragment_set_channel_layout (audio, g_strtod (word->str, NULL));
+ break;
+ case 3:
+ gegl_audio_fragment_set_sample_count (audio, g_strtod (word->str, NULL));
+ break;
+ default:
+ {
+ int sample_no = element_no - 4;
+ int channel_no = sample_no % channels;
+ sample_no/=2;
+ if (sample_no < max_samples)
+ audio->data[channel_no][sample_no] = g_strtod (word->str, NULL);
+ }
+ break;
+ }
+ }
+ g_string_assign (word, "");
+ break;
+ default:
+ g_string_append_c (word, p[0]);
+ break;
+ }
+ }
+ g_string_free (word, TRUE);
+ g_free (ret);
+ }
+ else
+ g_warning ("%s", error->message);
+ g_object_unref (e2m);
+#endif
+}
+
diff --git a/gcut/gcut.c b/gcut/gcut.c
index 4178573..43e6435 100644
--- a/gcut/gcut.c
+++ b/gcut/gcut.c
@@ -131,8 +131,8 @@ GeglEDL *gcut_new (void)
edl->audio_samplerate = DEFAULT_audio_samplerate;
edl->framedrop = DEFAULT_framedrop;
edl->frame_pos_ui = 0.0; /* frame-no in ui shell */
- edl->frame = -1; /* frame-no in renderer thread */
- edl->pos = -1.0; /* frame-no in renderer thread */
+ edl->frame = -1; /* frame-no in renderer thread */
+ edl->pos = -1.0; /* frame-no in renderer thread */
edl->scale = 1.0;
edl->buffer = gegl_buffer_new (&roi, babl_format ("R'G'B'A u8"));
@@ -177,7 +177,6 @@ void gcut_free (GeglEDL *edl)
g_free (edl);
}
-
Clip *gcut_get_clip (GeglEDL *edl, double frame_pos, double *clip_frame_pos)
{
GList *l;
@@ -536,27 +535,6 @@ GeglAudioFragment *gcut_get_audio (GeglEDL *edl)
return clip?clip->audio:NULL;
}
-void gcut_get_video_info (const char *path, int *frames, double *duration, double *fps)
-{
- GeglNode *gegl = gegl_node_new ();
- GeglNode *probe = gegl_node_new_child (gegl, "operation",
- "gegl:ff-load", "path", path, NULL);
- double r_fps;
- int r_frames;
- gegl_node_process (probe);
-
- gegl_node_get (probe, "frames", &r_frames, NULL);
- gegl_node_get (probe, "frame-rate", &r_fps, NULL);
-
- if (frames)
- *frames = r_frames;
- if (fps)
- *fps = r_fps;
- if (duration)
- *duration = r_frames / r_fps;
- g_object_unref (gegl);
-}
-
double gcut_get_duration (GeglEDL *edl)
{
double count = 0;
@@ -1574,114 +1552,6 @@ char *gcut_serialize (GeglEDL *edl)
return ret;
}
-void
-gegl_meta_set_audio (const char *path,
- GeglAudioFragment *audio)
-{
-#if HAVE_GEXIV2
- GError *error = NULL;
- GExiv2Metadata *e2m = gexiv2_metadata_new ();
- gexiv2_metadata_open_path (e2m, path, &error);
- if (error)
- {
- g_warning ("%s", error->message);
- }
- else
- {
- int i, c;
- GString *str = g_string_new ("");
- int sample_count = gegl_audio_fragment_get_sample_count (audio);
- int channels = gegl_audio_fragment_get_channels (audio);
- if (gexiv2_metadata_has_tag (e2m, "Xmp.xmp.GEGL"))
- gexiv2_metadata_clear_tag (e2m, "Xmp.xmp.GEGL");
-
- g_string_append_printf (str, "%i %i %i %i",
- gegl_audio_fragment_get_sample_rate (audio),
- gegl_audio_fragment_get_channels (audio),
- gegl_audio_fragment_get_channel_layout (audio),
- gegl_audio_fragment_get_sample_count (audio));
-
- for (i = 0; i < sample_count; i++)
- for (c = 0; c < channels; c++)
- g_string_append_printf (str, " %0.5f", audio->data[c][i]);
-
- gexiv2_metadata_set_tag_string (e2m, "Xmp.xmp.GeglAudio", str->str);
- gexiv2_metadata_save_file (e2m, path, &error);
- if (error)
- g_warning ("%s", error->message);
- g_string_free (str, TRUE);
- }
- g_object_unref (e2m);
-#endif
-}
-
-void
-gegl_meta_get_audio (const char *path,
- GeglAudioFragment *audio)
-{
-#if HAVE_GEXIV2
- GError *error = NULL;
- GExiv2Metadata *e2m = gexiv2_metadata_new ();
- gexiv2_metadata_open_path (e2m, path, &error);
- if (!error)
- {
- GString *word = g_string_new ("");
- gchar *p;
- gchar *ret = gexiv2_metadata_get_tag_string (e2m, "Xmp.xmp.GeglAudio");
- int element_no = 0;
- int channels = 2;
- int max_samples = 2000;
-
- if (ret)
- for (p = ret; p==ret || p[-1] != '\0'; p++)
- {
- switch (p[0])
- {
- case '\0':case ' ':
- if (word->len > 0)
- {
- switch (element_no++)
- {
- case 0:
- gegl_audio_fragment_set_sample_rate (audio, g_strtod (word->str, NULL));
- break;
- case 1:
- channels = g_strtod (word->str, NULL);
- gegl_audio_fragment_set_channels (audio, channels);
- break;
- case 2:
- gegl_audio_fragment_set_channel_layout (audio, g_strtod (word->str, NULL));
- break;
- case 3:
- gegl_audio_fragment_set_sample_count (audio, g_strtod (word->str, NULL));
- break;
- default:
- {
- int sample_no = element_no - 4;
- int channel_no = sample_no % channels;
- sample_no/=2;
- if (sample_no < max_samples)
- audio->data[channel_no][sample_no] = g_strtod (word->str, NULL);
- }
- break;
- }
- }
- g_string_assign (word, "");
- break;
- default:
- g_string_append_c (word, p[0]);
- break;
- }
- }
- g_string_free (word, TRUE);
- g_free (ret);
- }
- else
- g_warning ("%s", error->message);
- g_object_unref (e2m);
-#endif
-}
-
void gcut_set_selection (GeglEDL *edl, double start_frame, double end_frame)
{
edl->selection_start = start_frame;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]