[gegl/next-API: 2/7] transform-core: use the GeglSamplerType instead of a string



commit 7b84cda4666982edeb94891afddfc01e81edda88
Author: Michael Murà <mure michael gmail com>
Date:   Sun May 27 14:46:06 2012 +0900

    transform-core: use the GeglSamplerType instead of a string

 docs/gallery/clones.xml                    |   10 ++--
 operations/transform/transform-core.c      |   93 ++++++++++------------------
 operations/transform/transform-core.h      |    2 +-
 tests/compositions/clones.xml              |   10 ++--
 tests/compositions/composite-transform.xml |    2 +-
 tests/compositions/simple-scale.xml        |    2 +-
 tests/compositions/transform.xml           |    2 +-
 7 files changed, 47 insertions(+), 74 deletions(-)
---
diff --git a/docs/gallery/clones.xml b/docs/gallery/clones.xml
index 9ff1806..b8ca67c 100644
--- a/docs/gallery/clones.xml
+++ b/docs/gallery/clones.xml
@@ -11,7 +11,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -43,7 +43,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -63,7 +63,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -86,7 +86,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -154,7 +154,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.500000</param>
             <param name='y'>0.500000</param>
           </params>
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index 55547d4..95fb77d 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -47,10 +47,9 @@ enum
 {
   PROP_ORIGIN_X = 1,
   PROP_ORIGIN_Y,
-  PROP_FILTER,
+  PROP_SAMPLER,
 };
 
-static void          gegl_transform_finalize                  (GObject              *object);
 static void          gegl_transform_get_property              (GObject              *object,
                                                                guint                 prop_id,
                                                                GValue               *value,
@@ -141,28 +140,6 @@ op_transform_get_type (void)
   return g_define_type_id;
 }
 
-#if 0
-static void
-op_affine_sampler_init (OpTransform *self)
-{
-  GType                 desired_type;
-  GeglInterpolation     interpolation;
-
-  interpolation = gegl_buffer_interpolation_from_string (self->filter);
-  desired_type = gegl_sampler_type_from_interpolation (interpolation);
-
-  if (self->sampler != NULL &&
-      !G_TYPE_CHECK_INSTANCE_TYPE (self->sampler, desired_type))
-    {
-      self->sampler->buffer=NULL;
-      g_object_unref(self->sampler);
-      self->sampler = NULL;
-    }
-
-  self->sampler = op_affine_sampler (self);
-}
-#endif
-
 static void
 gegl_transform_prepare (GeglOperation *operation)
 {
@@ -179,7 +156,6 @@ op_transform_class_init (OpTransformClass *klass)
 
   gobject_class->set_property         = gegl_transform_set_property;
   gobject_class->get_property         = gegl_transform_get_property;
-  gobject_class->finalize             = gegl_transform_finalize;
 
   op_class->get_invalidated_by_change = gegl_transform_get_invalidated_by_change;
   op_class->get_bounding_box          = gegl_transform_get_bounding_box;
@@ -209,23 +185,17 @@ op_transform_class_init (OpTransformClass *klass)
                                      -G_MAXDOUBLE, G_MAXDOUBLE,
                                      0.,
                                      G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
-  g_object_class_install_property (gobject_class, PROP_FILTER,
-                                   g_param_spec_string (
-                                     "filter",
-                                     _("Filter"),
-                                     _("Filter type (nearest, linear, lanczos, cubic, lohalo)"),
-                                     "linear",
+  g_object_class_install_property (gobject_class, PROP_SAMPLER,
+                                   g_param_spec_enum (
+                                     "sampler",
+                                     _("Sampler"),
+                                     _("Sampler used internally"),
+                                     gegl_sampler_type_get_type (),
+                                     GEGL_SAMPLER_LINEAR,
                                      G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
 }
 
 static void
-gegl_transform_finalize (GObject *object)
-{
-  g_free (OP_TRANSFORM (object)->filter);
-  G_OBJECT_CLASS (op_transform_parent_class)->finalize (object);
-}
-
-static void
 op_transform_init (OpTransform *self)
 {
 }
@@ -246,8 +216,8 @@ gegl_transform_get_property (GObject    *object,
     case PROP_ORIGIN_Y:
       g_value_set_double (value, self->origin_y);
       break;
-    case PROP_FILTER:
-      g_value_set_string (value, self->filter);
+    case PROP_SAMPLER:
+      g_value_set_enum (value, self->sampler);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -271,9 +241,8 @@ gegl_transform_set_property (GObject      *object,
     case PROP_ORIGIN_Y:
       self->origin_y = g_value_get_double (value);
       break;
-    case PROP_FILTER:
-      g_free (self->filter);
-      self->filter = g_value_dup_string (value);
+    case PROP_SAMPLER:
+      self->sampler = g_value_get_enum (value);
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -365,8 +334,7 @@ gegl_transform_is_intermediate_node (OpTransform *transform)
 
       sink = gegl_connection_get_sink_node (connections->data)->operation;
 
-      if (! IS_OP_TRANSFORM (sink) ||
-          strcmp (transform->filter, OP_TRANSFORM (sink)->filter))
+      if (! IS_OP_TRANSFORM (sink) || transform->sampler != OP_TRANSFORM (sink)->sampler)
         return FALSE;
     }
   while ((connections = g_slist_next (connections)));
@@ -388,8 +356,7 @@ gegl_transform_is_composite_node (OpTransform *transform)
 
   source = gegl_connection_get_source_node (connections->data)->operation;
 
-  return (IS_OP_TRANSFORM (source) &&
-          ! strcmp (transform->filter, OP_TRANSFORM (source)->filter));
+  return (IS_OP_TRANSFORM (source) && transform->sampler == OP_TRANSFORM (source)->sampler);
 }
 
 static void
@@ -424,8 +391,9 @@ gegl_transform_get_bounding_box (GeglOperation *op)
   GeglRectangle  context_rect;
   GeglSampler   *sampler;
 
-  sampler = gegl_buffer_sampler_new (NULL, babl_format("RaGaBaA float"),
-      gegl_sampler_type_from_string (transform->filter));
+  sampler = gegl_buffer_sampler_new (NULL,
+                                     babl_format("RaGaBaA float"),
+                                     transform->sampler);
   context_rect = *gegl_sampler_get_context_rect (sampler);
   g_object_unref (sampler);
 
@@ -514,8 +482,9 @@ gegl_transform_get_required_for_output (GeglOperation       *op,
   gint           i;
 
   requested_rect = *region;
-  sampler = gegl_buffer_sampler_new (NULL, babl_format("RaGaBaA float"),
-      gegl_sampler_type_from_string (transform->filter));
+  sampler = gegl_buffer_sampler_new (NULL,
+                                     babl_format("RaGaBaA float"),
+                                     transform->sampler);
   context_rect = *gegl_sampler_get_context_rect (sampler);
   g_object_unref (sampler);
 
@@ -566,8 +535,9 @@ gegl_transform_get_invalidated_by_change (GeglOperation       *op,
   gint               i;
   GeglRectangle      region = *input_region;
 
-  sampler = gegl_buffer_sampler_new (NULL, babl_format("RaGaBaA float"),
-      gegl_sampler_type_from_string (transform->filter));
+  sampler = gegl_buffer_sampler_new (NULL,
+                                     babl_format("RaGaBaA float"),
+                                     transform->sampler);
   context_rect = *gegl_sampler_get_context_rect (sampler);
   g_object_unref (sampler);
 
@@ -941,7 +911,7 @@ gegl_transform_process (GeglOperation        *operation,
     }
   else if (gegl_transform_matrix3_allow_fast_translate (&matrix) ||
            (gegl_matrix3_is_translate (&matrix) &&
-            ! strcmp (transform->filter, "nearest")))
+            transform->sampler == GEGL_SAMPLER_NEAREST))
     {
       /* doing a buffer shifting trick, (enhanced nop) */
       input  = gegl_operation_context_get_source (context, "input");
@@ -981,8 +951,9 @@ gegl_transform_process (GeglOperation        *operation,
       src_rect = gegl_operation_get_required_for_output (operation, "output", result);
       src_rect.y += 1;
 
-      sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"),
-          gegl_sampler_type_from_string (transform->filter));
+      sampler = gegl_buffer_sampler_new (input,
+                                         babl_format("RaGaBaA float"),
+                                         transform->sampler);
       context_rect = *gegl_sampler_get_context_rect (sampler);
 
       src_rect.width -= context_rect.width;
@@ -1012,8 +983,9 @@ gegl_transform_process (GeglOperation        *operation,
       src_rect = gegl_operation_get_required_for_output (operation, "output", result);
       src_rect.x += 1;
 
-      sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"),
-          gegl_sampler_type_from_string (transform->filter));
+      sampler = gegl_buffer_sampler_new (input,
+                                         babl_format("RaGaBaA float"),
+                                         transform->sampler);
       context_rect = *gegl_sampler_get_context_rect (sampler);
 
       src_rect.width -= context_rect.width;
@@ -1033,8 +1005,9 @@ gegl_transform_process (GeglOperation        *operation,
       input  = gegl_operation_context_get_source (context, "input");
       output = gegl_operation_context_get_target (context, "output");
 
-      sampler = gegl_buffer_sampler_new (input, babl_format("RaGaBaA float"),
-          gegl_sampler_type_from_string (transform->filter));
+      sampler = gegl_buffer_sampler_new (input,
+                                         babl_format("RaGaBaA float"),
+                                         transform->sampler);
 
       if (gegl_matrix3_is_affine (&matrix))
         {
diff --git a/operations/transform/transform-core.h b/operations/transform/transform-core.h
index b2bf995..a1782c8 100644
--- a/operations/transform/transform-core.h
+++ b/operations/transform/transform-core.h
@@ -20,7 +20,7 @@ struct _OpTransform
   GeglOperationFilter parent_instance;
   gdouble             origin_x;
   gdouble             origin_y;
-  gchar              *filter;
+  GeglSamplerType     sampler;
 };
 
 typedef struct _OpTransformClass OpTransformClass;
diff --git a/tests/compositions/clones.xml b/tests/compositions/clones.xml
index 5ce40fb..7aa378e 100644
--- a/tests/compositions/clones.xml
+++ b/tests/compositions/clones.xml
@@ -11,7 +11,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -43,7 +43,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -63,7 +63,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -86,7 +86,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.200000</param>
             <param name='y'>0.200000</param>
           </params>
@@ -156,7 +156,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.500000</param>
             <param name='y'>0.500000</param>
           </params>
diff --git a/tests/compositions/composite-transform.xml b/tests/compositions/composite-transform.xml
index 25b97a4..43c92d6 100644
--- a/tests/compositions/composite-transform.xml
+++ b/tests/compositions/composite-transform.xml
@@ -13,7 +13,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.500000</param>
             <param name='y'>0.500000</param>
         </params>
diff --git a/tests/compositions/simple-scale.xml b/tests/compositions/simple-scale.xml
index 246310c..dfff358 100644
--- a/tests/compositions/simple-scale.xml
+++ b/tests/compositions/simple-scale.xml
@@ -2,7 +2,7 @@
 <gegl>
   <node operation='gegl:scale'>
     <params>
-      <param name='filter'>cubic</param>
+      <param name='sampler'>cubic</param>
       <param name='x'>0.5</param>
       <param name='y'>0.5</param>
     </params>
diff --git a/tests/compositions/transform.xml b/tests/compositions/transform.xml
index 23b28dd..7191099 100644
--- a/tests/compositions/transform.xml
+++ b/tests/compositions/transform.xml
@@ -5,7 +5,7 @@
           <params>
             <param name='origin-x'>0.000000</param>
             <param name='origin-y'>0.000000</param>
-            <param name='filter'>linear</param>
+            <param name='sampler'>linear</param>
             <param name='x'>0.500000</param>
             <param name='y'>0.500000</param>
         </params>



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