[gegl] Bug 698468 - Add abyss-policy property to scale operations



commit bff1364593a3aa9541c49ed76b6a940aef22d34f
Author: Ell <ell_se yahoo com>
Date:   Thu Mar 22 16:12:56 2018 -0400

    Bug 698468 - Add abyss-policy property to scale operations
    
    Add an OpScale subclass of OpTransform, and use it as a base class
    for the scale ops: scale-ratio, scale-size, and scale-size-
    keepaspect.
    
    OpScale provides an abyss-policy property, and overrides
    OpTransform::get_abyss_policy() to return its value.  The point is
    that we want to be able to control the abyss policy of scale ops
    (in particular, to avoid "leaking transparency" into the image when
    upscaling the entire image), while not providing this option for
    other transform ops, for which it makes little sense, at least for
    now.

 operations/transform/Makefile.am             |    2 +
 operations/transform/scale-ratio.c           |    6 +-
 operations/transform/scale-size-keepaspect.c |    6 +-
 operations/transform/scale-size.c            |    6 +-
 operations/transform/scale.c                 |  156 ++++++++++++++++++++++++++
 operations/transform/scale.h                 |   35 ++++++
 po/POTFILES.in                               |    1 +
 7 files changed, 203 insertions(+), 9 deletions(-)
---
diff --git a/operations/transform/Makefile.am b/operations/transform/Makefile.am
index cebc804..8b1ec8a 100644
--- a/operations/transform/Makefile.am
+++ b/operations/transform/Makefile.am
@@ -14,6 +14,8 @@ transformops_la_SOURCES = \
        reflect.c       \
        rotate.c        \
        rotate-on-center.c      \
+       scale.c \
+       scale.h \
        scale-ratio.c \
        scale-size.c \
        scale-size-keepaspect.c \
diff --git a/operations/transform/scale-ratio.c b/operations/transform/scale-ratio.c
index 29bdf07..56fc7d4 100644
--- a/operations/transform/scale-ratio.c
+++ b/operations/transform/scale-ratio.c
@@ -35,10 +35,10 @@ property_double (y, _("Y"), 0.0)
 #else
 
 #include "gegl-operation-filter.h"
-#include "transform-core.h"
+#include "scale.h"
 #define GEGL_OP_NO_SOURCE
-#define GEGL_OP_Parent  OpTransform
-#define GEGL_OP_PARENT  TYPE_OP_TRANSFORM
+#define GEGL_OP_Parent  OpScale
+#define GEGL_OP_PARENT  TYPE_OP_SCALE
 #define GEGL_OP_NAME    scale_ratio
 #define GEGL_OP_BUNDLE
 #define GEGL_OP_C_FILE  "scale-ratio.c"
diff --git a/operations/transform/scale-size-keepaspect.c b/operations/transform/scale-size-keepaspect.c
index c9c1882..0b1024b 100644
--- a/operations/transform/scale-size-keepaspect.c
+++ b/operations/transform/scale-size-keepaspect.c
@@ -35,10 +35,10 @@ property_double (y, _("Y"), -1.0)
 #else
 
 #include "gegl-operation-filter.h"
-#include "transform-core.h"
+#include "scale.h"
 #define GEGL_OP_NO_SOURCE
-#define GEGL_OP_Parent  OpTransform
-#define GEGL_OP_PARENT  TYPE_OP_TRANSFORM
+#define GEGL_OP_Parent  OpScale
+#define GEGL_OP_PARENT  TYPE_OP_SCALE
 #define GEGL_OP_NAME    scale_size_keepaspect
 #define GEGL_OP_BUNDLE
 #define GEGL_OP_C_FILE  "scale-size-keepaspect.c"
diff --git a/operations/transform/scale-size.c b/operations/transform/scale-size.c
index 2b148d1..92cbd5c 100644
--- a/operations/transform/scale-size.c
+++ b/operations/transform/scale-size.c
@@ -35,10 +35,10 @@ property_double (y, _("Y"), 100.0)
 #else
 
 #include "gegl-operation-filter.h"
-#include "transform-core.h"
+#include "scale.h"
 #define GEGL_OP_NO_SOURCE
-#define GEGL_OP_Parent  OpTransform
-#define GEGL_OP_PARENT  TYPE_OP_TRANSFORM
+#define GEGL_OP_Parent  OpScale
+#define GEGL_OP_PARENT  TYPE_OP_SCALE
 #define GEGL_OP_NAME    scale_size
 #define GEGL_OP_BUNDLE
 #define GEGL_OP_C_FILE  "scale-size.c"
diff --git a/operations/transform/scale.c b/operations/transform/scale.c
new file mode 100644
index 0000000..7aaa94a
--- /dev/null
+++ b/operations/transform/scale.c
@@ -0,0 +1,156 @@
+/* This file is part of 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 <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2018 Ell
+ */
+
+#include "config.h"
+#include <glib/gi18n-lib.h>
+
+#include <gegl.h>
+#include <gegl-plugin.h>
+
+#include "gegl-config.h"
+
+#include "scale.h"
+#include "module.h"
+
+enum
+{
+  PROP_ABYSS_POLICY = 1
+};
+
+static void              gegl_scale_get_property     (GObject      *object,
+                                                      guint         prop_id,
+                                                      GValue       *value,
+                                                      GParamSpec   *pspec);
+static void              gegl_scale_set_property     (GObject      *object,
+                                                      guint         prop_id,
+                                                      const GValue *value,
+                                                      GParamSpec   *pspec);
+
+static GeglAbyssPolicy   gegl_scale_get_abyss_policy (OpTransform  *transform);
+
+/* ************************* */
+
+static void              op_scale_init               (OpScale      *self);
+static void              op_scale_class_init         (OpScaleClass *klass);
+static gpointer          op_scale_parent_class = NULL;
+
+static void
+op_scale_class_intern_init (gpointer klass)
+{
+  op_scale_parent_class = g_type_class_peek_parent (klass);
+  op_scale_class_init ((OpScaleClass *) klass);
+}
+
+GType
+op_scale_get_type (void)
+{
+  static GType g_define_type_id = 0;
+  if (G_UNLIKELY (g_define_type_id == 0))
+    {
+      static const GTypeInfo g_define_type_info =
+        {
+          sizeof (OpScaleClass),
+          (GBaseInitFunc) NULL,
+          (GBaseFinalizeFunc) NULL,
+          (GClassInitFunc) op_scale_class_intern_init,
+          (GClassFinalizeFunc) NULL,
+          NULL,   /* class_data */
+          sizeof (OpScale),
+          0,      /* n_preallocs */
+          (GInstanceInitFunc) op_scale_init,
+          NULL    /* value_table */
+        };
+
+      g_define_type_id =
+        gegl_module_register_type (transform_module_get_module (),
+                                   TYPE_OP_TRANSFORM,
+                                   "GeglOpPlugIn-scale-core",
+                                   &g_define_type_info, 0);
+    }
+  return g_define_type_id;
+}
+
+static void
+op_scale_class_init (OpScaleClass *klass)
+{
+  GObjectClass     *gobject_class   = G_OBJECT_CLASS (klass);
+  OpTransformClass *transform_class = OP_TRANSFORM_CLASS (klass);
+
+  gobject_class->set_property       = gegl_scale_set_property;
+  gobject_class->get_property       = gegl_scale_get_property;
+
+  transform_class->get_abyss_policy = gegl_scale_get_abyss_policy;
+
+  g_object_class_install_property (gobject_class, PROP_ABYSS_POLICY,
+                                   g_param_spec_enum (
+                                     "abyss-policy",
+                                     _("Abyss policy"),
+                                     _("How image edges are handled"),
+                                     GEGL_TYPE_ABYSS_POLICY,
+                                     GEGL_ABYSS_NONE,
+                                     G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+}
+
+static void
+op_scale_init (OpScale *self)
+{
+}
+
+static void
+gegl_scale_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  OpScale *self = OP_SCALE (object);
+
+  switch (prop_id)
+    {
+    case PROP_ABYSS_POLICY:
+      g_value_set_enum (value, self->abyss_policy);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gegl_scale_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  OpScale *self = OP_SCALE (object);
+
+  switch (prop_id)
+    {
+    case PROP_ABYSS_POLICY:
+      self->abyss_policy = g_value_get_enum (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static GeglAbyssPolicy
+gegl_scale_get_abyss_policy (OpTransform *transform)
+{
+  return OP_SCALE (transform)->abyss_policy;
+}
diff --git a/operations/transform/scale.h b/operations/transform/scale.h
new file mode 100644
index 0000000..00a6252
--- /dev/null
+++ b/operations/transform/scale.h
@@ -0,0 +1,35 @@
+#ifndef __OP_SCALE_H__
+#define __OP_SCALE_H__
+
+#include "transform-core.h"
+
+G_BEGIN_DECLS
+
+#define TYPE_OP_SCALE            (op_scale_get_type ())
+#define OP_SCALE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_OP_SCALE, OpScale))
+#define OP_SCALE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  TYPE_OP_SCALE, OpScaleClass))
+#define IS_OP_SCALE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_OP_SCALE))
+#define IS_OP_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  TYPE_OP_SCALE))
+#define OP_SCALE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  TYPE_OP_SCALE, OpScaleClass))
+
+typedef struct _OpScale OpScale;
+
+struct _OpScale
+{
+  OpTransform     parent_instance;
+
+  GeglAbyssPolicy abyss_policy;
+};
+
+typedef struct _OpScaleClass OpScaleClass;
+
+struct _OpScaleClass
+{
+  OpTransformClass parent_class;
+};
+
+GType op_scale_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 7bc3d36..c43e8f1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -227,6 +227,7 @@ operations/seamless-clone/seamless-clone-compose.c
 operations/transform/reflect.c
 operations/transform/rotate.c
 operations/transform/rotate-on-center.c
+operations/transform/scale.c
 operations/transform/scale-ratio.c
 operations/transform/scale-size.c
 operations/transform/scale-size-keepaspect.c


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