[gegl] Bug 794414: new GeglDistanceMetric enum type.



commit f8020a25dc762bd0822c00904f93369c70063e8f
Author: Jehan <jehan girinstud io>
Date:   Fri Mar 16 23:12:30 2018 +0100

    Bug 794414: new GeglDistanceMetric enum type.
    
    Makes using the distance "metric" property (used in distance-transform)
    more robust to changes, rather than having to recreate the enum in third
    party applications, like GIMP.
    As discussed, "chessboard" distance has been renamed to "Chebyshev"
    which seems more standard and less confusing since some pieces in chess
    count their distance in Chebyshev whereas other count it in Manhattan.

 gegl/gegl-enums.c                      |   27 ++++++++++++++++++++++++
 gegl/gegl-enums.h                      |   10 ++++++++
 operations/common/distance-transform.c |   36 +++++++++++++------------------
 3 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/gegl/gegl-enums.c b/gegl/gegl-enums.c
index d3086d7..00e5da1 100644
--- a/gegl/gegl-enums.c
+++ b/gegl/gegl-enums.c
@@ -113,6 +113,33 @@ gegl_dither_method_get_type (void)
 }
 
 GType
+gegl_distance_metric_get_type (void)
+{
+  static GType etype = 0;
+
+  if (etype == 0)
+    {
+      static GEnumValue values[] = {
+        { GEGL_DISTANCE_EUCLIDEAN, N_("Euclidean"), "euclidean"  },
+        { GEGL_DISTANCE_MANHATTAN, N_("Manhattan"), "manhattan"  },
+        { GEGL_DISTANCE_CHEBYSHEV, N_("Chebyshev"), "chebyshev" },
+
+        { 0, NULL, NULL }
+      };
+      gint i;
+
+      for (i = 0; i < G_N_ELEMENTS (values); i++)
+        if (values[i].value_name)
+          values[i].value_name =
+            dgettext (GETTEXT_PACKAGE, values[i].value_name);
+
+      etype = g_enum_register_static ("GeglDistanceMetric", values);
+    }
+
+  return etype;
+}
+
+GType
 gegl_orientation_get_type (void)
 {
   static GType etype = 0;
diff --git a/gegl/gegl-enums.h b/gegl/gegl-enums.h
index ddd026d..54b5c2a 100644
--- a/gegl/gegl-enums.h
+++ b/gegl/gegl-enums.h
@@ -92,6 +92,16 @@ GType gegl_dither_method_get_type (void) G_GNUC_CONST;
 
 #define GEGL_TYPE_DITHER_METHOD (gegl_dither_method_get_type ())
 
+typedef enum {
+  GEGL_DISTANCE_EUCLIDEAN,
+  GEGL_DISTANCE_MANHATTAN,
+  GEGL_DISTANCE_CHEBYSHEV
+} GeglDistanceMetric;
+
+GType gegl_distance_metric_get_type (void) G_GNUC_CONST;
+
+#define GEGL_TYPE_DISTANCE_METRIC (gegl_distance_metric_get_type ())
+
 
 typedef enum {
   GEGL_ORIENTATION_HORIZONTAL,
diff --git a/operations/common/distance-transform.c b/operations/common/distance-transform.c
index 5572d02..6734cd1 100644
--- a/operations/common/distance-transform.c
+++ b/operations/common/distance-transform.c
@@ -27,14 +27,8 @@
 
 #ifdef GEGL_PROPERTIES
 
-enum_start (gegl_dt_metric)
-  enum_value (GEGL_DT_METRIC_EUCLIDEAN,  "euclidean",  N_("Euclidean"))
-  enum_value (GEGL_DT_METRIC_MANHATTAN,  "manhattan",  N_("Manhattan"))
-  enum_value (GEGL_DT_METRIC_CHESSBOARD, "chessboard", N_("Chessboard"))
-enum_end (GeglDTMetric)
-
 property_enum (metric, _("Metric"),
-    GeglDTMetric, gegl_dt_metric, GEGL_DT_METRIC_EUCLIDEAN)
+               GeglDistanceMetric, gegl_distance_metric, GEGL_DISTANCE_EUCLIDEAN)
     description (_("Metric to use for the distance calculation"))
 
 property_double (threshold_lo, _("Threshold low"), 0.0001)
@@ -147,13 +141,13 @@ cdt_sep (gint i, gint u, gfloat g_i, gfloat g_u)
 
 
 static void
-binary_dt_2nd_pass (GeglOperation *operation,
-                    gint           width,
-                    gint           height,
-                    gfloat         thres_lo,
-                    GeglDTMetric   metric,
-                    gfloat        *src,
-                    gfloat        *dest)
+binary_dt_2nd_pass (GeglOperation      *operation,
+                    gint                width,
+                    gint                height,
+                    gfloat              thres_lo,
+                    GeglDistanceMetric  metric,
+                    gfloat             *src,
+                    gfloat             *dest)
 {
   gint u, y;
   gint q, w, *t, *s;
@@ -164,15 +158,15 @@ binary_dt_2nd_pass (GeglOperation *operation,
 
   switch (metric)
     {
-      case GEGL_DT_METRIC_CHESSBOARD:
+      case GEGL_DISTANCE_CHEBYSHEV:
         dt_f   = cdt_f;
         dt_sep = cdt_sep;
         break;
-      case GEGL_DT_METRIC_MANHATTAN:
+      case GEGL_DISTANCE_MANHATTAN:
         dt_f   = mdt_f;
         dt_sep = mdt_sep;
         break;
-      default: /* GEGL_DT_METRIC_EUCLIDEAN */
+      default: /* GEGL_DISTANCE_EUCLIDEAN */
         dt_f   = edt_f;
         dt_sep = edt_sep;
         break;
@@ -305,10 +299,10 @@ process (GeglOperation       *operation,
   const Babl  *input_format = babl_format ("Y float");
   const int bytes_per_pixel = babl_format_get_bytes_per_pixel (input_format);
 
-  GeglDTMetric metric;
-  gint     width, height, averaging, i;
-  gfloat   threshold_lo, threshold_hi, maxval, *src_buf, *dst_buf;
-  gboolean normalize;
+  GeglDistanceMetric metric;
+  gint               width, height, averaging, i;
+  gfloat             threshold_lo, threshold_hi, maxval, *src_buf, *dst_buf;
+  gboolean           normalize;
 
   width  = result->width;
   height = result->height;


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