[shotwell/wip/optimize: 1/6] Create commandline utility to apply transformations
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/optimize: 1/6] Create commandline utility to apply transformations
- Date: Wed, 15 Mar 2017 23:15:01 +0000 (UTC)
commit 9df84ac29b883ed68f792fbe3d9099bf10883d72
Author: Jens Georg <mail jensge org>
Date: Tue Mar 14 23:09:53 2017 +0100
Create commandline utility to apply transformations
Signed-off-by: Jens Georg <mail jensge org>
Makefile.am | 1 +
pipeline.am | 41 +++++++++++++++++++
shotwell.am | 10 +++--
src/ColorTransformation.vala | 2 +-
src/graphics-processor.vala | 88 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 137 insertions(+), 5 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 93b929b..5d9e9c8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -128,6 +128,7 @@ dist_noinst_DATA = $(NULL)
MOSTLYCLEANFILES = $(NULL)
include $(top_srcdir)/common.am
+include $(top_srcdir)/pipeline.am
include $(top_srcdir)/shotwell.am
include $(top_srcdir)/thumbnailer.am
diff --git a/pipeline.am b/pipeline.am
new file mode 100644
index 0000000..559cecf
--- /dev/null
+++ b/pipeline.am
@@ -0,0 +1,41 @@
+src/shotwell-graphics-processor.vapi src/shotwell-graphics-processor.h: \
+ src_libgraphics_processor_la_vala.stamp
+
+noinst_LTLIBRARIES += \
+ src/libgraphics-processor.la
+
+src_libgraphics_processor_la_SOURCES = \
+ src/ColorTransformation.vala \
+ src/util/KeyValueMap.vala
+
+src_libgraphics_processor_la_VALAFLAGS = \
+ $(COMMON_VALAFLAGS) \
+ --pkg gio-2.0 \
+ --pkg gdk-3.0 \
+ --pkg gee-0.8 \
+ --pkg gdk-pixbuf-2.0 \
+ --vapi=src/shotwell-graphics-processor.vapi \
+ --header=src/shotwell-graphics-processor.h
+
+src_libgraphics_processor_la_CFLAGS = $(SHOTWELL_CFLAGS) $(COMMON_CFLAGS)
+
+
+noinst_PROGRAMS = \
+ src/shotwell-graphics-processor
+
+src_shotwell_graphics_processor_SOURCES = \
+ src/graphics-processor.vala \
+ src/shotwell-graphics-processor.vapi
+
+src_shotwell_graphics_processor_VALAFLAGS = \
+ $(COMMON_VALAFLAGS) \
+ --pkg gio-2.0 \
+ --pkg gdk-3.0 \
+ --pkg gee-0.8 \
+ --pkg gdk-pixbuf-2.0
+
+src_shotwell_graphics_processor_CFLAGS = $(SHOTWELL_CFLAGS) $(COMMON_CFLAGS)
+
+src_shotwell_graphics_processor_LDADD = \
+ src/libgraphics-processor.la \
+ $(SHOTWELL_LIBS)
diff --git a/shotwell.am b/shotwell.am
index bb2c53b..91b6d35 100644
--- a/shotwell.am
+++ b/shotwell.am
@@ -4,12 +4,15 @@ shotwell_CFLAGS = \
$(UNITY_CFLAGS) \
$(COMMON_CFLAGS) \
-I$(top_builddir)/plugins \
- -I$(abs_top_srcdir)/plugins
+ -I$(abs_top_srcdir)/plugins \
+ -I$(abs_top_srcdir)/src
shotwell_LDADD = \
src/plugins/libplugin.la \
+ src/libgraphics-processor.la \
$(SHOTWELL_LIBS) \
$(UNITY_LIBS)
+
shotwell_VALAFLAGS = $(COMMON_VALAFLAGS) \
--pkg gio-2.0 --pkg gtk+-3.0 --pkg gee-0.8 \
--pkg gio-unix-2.0 --pkg sqlite3 --pkg gmodule-2.0 \
@@ -44,7 +47,6 @@ shotwell_SOURCES = \
src/util/misc.vala \
src/util/string.vala \
src/util/system.vala \
- src/util/KeyValueMap.vala \
src/util/ui.vala \
src/threads/Threads.vala \
src/threads/Workers.vala \
@@ -171,7 +173,6 @@ shotwell_SOURCES = \
src/Dialogs.vala \
src/Resources.vala \
src/Debug.vala \
- src/ColorTransformation.vala \
src/Properties.vala \
src/CustomComponents.vala \
src/Event.vala \
@@ -228,4 +229,5 @@ shotwell_SOURCES = \
src/.unitize/_FoldersInternals.vala \
src/.unitize/_Library_unitize_entry.vala \
src/.unitize/_Direct_unitize_entry.vala \
- plugins/shotwell-plugin-dev-1.0.vapi
+ plugins/shotwell-plugin-dev-1.0.vapi \
+ src/shotwell-graphics-processor.vapi
diff --git a/src/ColorTransformation.vala b/src/ColorTransformation.vala
index 435d3f4..5fab75c 100644
--- a/src/ColorTransformation.vala
+++ b/src/ColorTransformation.vala
@@ -955,7 +955,7 @@ public class PixelTransformer {
}
}
-class RGBHistogram {
+public class RGBHistogram {
private const uchar MARKED_BACKGROUND = 30;
private const uchar MARKED_FOREGROUND = 210;
private const uchar UNMARKED_BACKGROUND = 120;
diff --git a/src/graphics-processor.vala b/src/graphics-processor.vala
new file mode 100644
index 0000000..28968a7
--- /dev/null
+++ b/src/graphics-processor.vala
@@ -0,0 +1,88 @@
+static string input_file;
+static string output_file;
+static string pipeline;
+static bool auto_enhance;
+
+const GLib.OptionEntry[] options = {
+ { "input", 'i', 0, GLib.OptionArg.FILENAME, ref input_file, "FILE to process", "FILE" },
+ { "output", 'o', 0, GLib.OptionArg.FILENAME, ref output_file, "destination FILE", "FILE" },
+ { "pipeline", 'p', 0, GLib.OptionArg.FILENAME, ref pipeline, "graphics PIPELINE to run", "PIPELINE" },
+ { "auto-enance", 'a', 0, GLib.OptionArg.NONE, ref auto_enhance, "run auto-enhance on input file", null },
+ { null, 0, 0, GLib.OptionArg.NONE, null, null, null }
+};
+
+Gee.HashMap<string, KeyValueMap>? marshall_all_transformations(string filename) {
+ try {
+ var keyfile = new KeyFile();
+ keyfile.load_from_file(filename, KeyFileFlags.NONE);
+ var map = new Gee.HashMap<string, KeyValueMap>();
+
+ var objects = keyfile.get_groups();
+ foreach (var object in objects) {
+ var keys = keyfile.get_keys(object);
+ if (keys == null || keys.length == 0) {
+ continue;
+ }
+
+ var key_map = new KeyValueMap(object);
+ foreach (var key in keys) {
+ key_map.set_string(key, keyfile.get_string(object, key));
+ }
+ map.set(object, key_map);
+ }
+
+ return map;
+ } catch (Error err) {
+ error("%s", err.message);
+ }
+}
+
+int main(string[] args)
+{
+ var ctx = new OptionContext("- Apply shotwell transformations on commandline");
+ ctx.set_help_enabled(true);
+ ctx.set_ignore_unknown_options(true);
+ ctx.add_main_entries(options, null);
+
+ try {
+ ctx.parse(ref args);
+ } catch (Error error) {
+ print(ctx.get_help(true, null));
+
+ return 1;
+ }
+
+ Gdk.Pixbuf? src = null;
+ try {
+ src = new Gdk.Pixbuf.from_file(input_file);
+ } catch (Error err) {
+ error ("%s", err.message);
+ }
+
+ var output = src.copy();
+
+ var transformations = marshall_all_transformations(pipeline);
+
+ var adjustments = new PixelTransformationBundle();
+ var map = transformations.get("adjustments");
+ if (map == null) {
+ adjustments.set_to_identity();
+ } else {
+ adjustments.load(map);
+ }
+
+ var transformer = adjustments.generate_transformer();
+ var timer = new Timer();
+ transformer.transform_to_other_pixbuf(src, output, null);
+ var elapsed = timer.elapsed();
+
+ print("Transformation took %f\n", elapsed);
+
+ try {
+ output.save(output_file, "jpeg", "quality", "100", null);
+ } catch (Error err) {
+ error("%s", err.message);
+ }
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]