[gegl] filmic: add ACES based filmic HDR to SDR proofing filter



commit 18db3c27ea38e837a84f3e5796d150c54235e50a
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jul 17 15:46:50 2018 +0200

    filmic: add ACES based filmic HDR to SDR proofing filter

 operations/workshop/Makefile.am |  1 +
 operations/workshop/filmic.c    | 91 +++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in                  |  1 +
 3 files changed, 93 insertions(+)
---
diff --git a/operations/workshop/Makefile.am b/operations/workshop/Makefile.am
index 06e7922a3..297b3eb5d 100644
--- a/operations/workshop/Makefile.am
+++ b/operations/workshop/Makefile.am
@@ -19,6 +19,7 @@ op_LTLIBRARIES = \
        gradient-map.la \
        hstack.la \
        enlarge.la \
+       filmic.la \
        inpaint.la \
        integral-image.la \
        linear-sinusoid.la \
diff --git a/operations/workshop/filmic.c b/operations/workshop/filmic.c
new file mode 100644
index 000000000..402857661
--- /dev/null
+++ b/operations/workshop/filmic.c
@@ -0,0 +1,91 @@
+/* This file is an image processing operation for GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
+ *
+ * Copyright 2018 Øyvind Kolås <pippin gimp org>
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+
+#ifdef GEGL_PROPERTIES
+
+   /* no properties */
+
+#else
+
+#define GEGL_OP_POINT_FILTER
+#define GEGL_OP_NAME     filmic
+#define GEGL_OP_C_SOURCE filmic.c
+
+#include "gegl-op.h"
+
+static inline float aces_filmic (float x)
+{
+ /* source of approximation:
+
+    https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/
+    https://github.com/TheRealMJP/BakingLab/blob/master/BakingLab/ACES.hlsl
+  */
+ float a = x * (x + 0.0245786f) - 0.000090537f;
+ float b = x * (0.983729f * x + 0.4329510f) + 0.238081f;
+ return a / b;
+}
+
+static gboolean
+process (GeglOperation       *op,
+         void                *in_buf,
+         void                *out_buf,
+         glong                samples,
+         const GeglRectangle *roi,
+         gint                 level)
+{
+  gfloat *in  = in_buf;
+  gfloat *out = out_buf;
+
+  while (samples--)
+    {
+      out[0] = aces_filmic (in[0]);
+      out[1] = aces_filmic (in[1]);
+      out[2] = aces_filmic (in[2]);
+      out[3] = in[3];
+
+      in += 4;
+      out+= 4;
+    }
+  return TRUE;
+}
+
+static void
+gegl_op_class_init (GeglOpClass *klass)
+{
+  GeglOperationClass            *operation_class;
+  GeglOperationPointFilterClass *point_filter_class;
+
+  operation_class    = GEGL_OPERATION_CLASS (klass);
+  point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
+
+  point_filter_class->process  = process;
+
+  gegl_operation_class_set_keys (operation_class,
+    "name",        "gegl:filmic",
+    "title",       _("ACES Filmic"),
+    "categories" , "color:tonemapping",
+    "description",
+       _("HDR to SDR proofing filter/mapping curve that is an approximation of the ACES filmic curve, useful 
for consistent previewing of content in near HDR range.").
+    NULL);
+}
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 27da9d92e..c88e1fb39 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -253,6 +253,7 @@ operations/workshop/external/gluas.c
 operations/workshop/external/lens-correct.c
 operations/workshop/external/line-profile.c
 operations/workshop/external/v4l2.c
+operations/workshop/filmic.c
 operations/workshop/generated/average.c
 operations/workshop/generated/blend-reflect.c
 operations/workshop/generated/negation.c


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