[gimp] app: half-sane aspect ratio implementation



commit 452819143a7ef9af446e5df30a468730cadf0949
Author: Alexia Death <alexiadeath gmail com>
Date:   Tue Jan 25 23:27:23 2011 +0200

    app: half-sane aspect ratio implementation

 app/core/gimpbrush-transform.c   |   12 ++++----
 app/core/gimpbrush.c             |   14 +++------
 app/core/gimpbrushgenerated.c    |   16 +++++------
 app/core/gimpdynamicsoutput.c    |   53 ++++++++++++++++++++------------------
 app/paint/gimpbrushcore.c        |   43 ++++++++++++++++++++----------
 app/paint/gimppaintoptions.c     |    4 +-
 app/tools/gimppaintoptions-gui.c |    2 +-
 7 files changed, 77 insertions(+), 67 deletions(-)
---
diff --git a/app/core/gimpbrush-transform.c b/app/core/gimpbrush-transform.c
index 7083ccb..ccd900c 100644
--- a/app/core/gimpbrush-transform.c
+++ b/app/core/gimpbrush-transform.c
@@ -652,18 +652,18 @@ gimp_brush_transform_matrix (gdouble      width,
 {
   const gdouble center_x = width  / 2;
   const gdouble center_y = height / 2;
-  gdouble scale_x;
-  gdouble scale_y;
+  gdouble scale_x = scale;
+  gdouble scale_y = scale;
 
-  if (aspect_ratio < 1.0)
+  if (aspect_ratio < 0.0)
     {
-        scale_x = scale * aspect_ratio;
+        scale_x = scale * (1.0 - (fabs (aspect_ratio) / 20.0));
         scale_y = scale;
     }
-  else
+  else if (aspect_ratio > 0.0)
     {
       scale_x = scale;
-      scale_y = scale / aspect_ratio;
+      scale_y = scale * (1.0 - (aspect_ratio  / 20.0));
     }
 
   gimp_matrix3_identity (matrix);
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index 5cae9b6..e99ff26 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -277,13 +277,13 @@ gimp_brush_get_new_preview (GimpViewable *viewable,
 
       if (scale != 1.0)
         {
-          mask_buf = gimp_brush_transform_mask (brush, scale, 1.0, 0.0, 1.0);
+          mask_buf = gimp_brush_transform_mask (brush, scale, 0.0, 0.0, 1.0);
 
           if (! mask_buf)
             mask_buf = temp_buf_new (1, 1, 1, 0, 0, transp);
 
           if (pixmap_buf)
-            pixmap_buf = gimp_brush_transform_pixmap (brush, scale, 1.0, 0.0, 1.0);
+            pixmap_buf = gimp_brush_transform_pixmap (brush, scale, 0.0, 0.0, 1.0);
 
           mask_width  = mask_buf->width;
           mask_height = mask_buf->height;
@@ -466,11 +466,10 @@ gimp_brush_transform_size (GimpBrush     *brush,
 {
   g_return_if_fail (GIMP_IS_BRUSH (brush));
   g_return_if_fail (scale > 0.0);
-  g_return_if_fail (aspect_ratio > 0.0);
   g_return_if_fail (width != NULL);
   g_return_if_fail (height != NULL);
 
-  if ((scale == 1.0) && ( aspect_ratio == 1.0) && ((angle == 0.0) || (angle == 0.5) || (angle == 1.0)))
+  if ((scale == 1.0) && ( aspect_ratio == 0.0) && ((angle == 0.0) || (angle == 0.5) || (angle == 1.0)))
     {
       *width  = brush->mask->width;
       *height = brush->mask->height;
@@ -490,9 +489,8 @@ gimp_brush_transform_mask (GimpBrush *brush,
 {
   g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
   g_return_val_if_fail (scale > 0.0, NULL);
-  g_return_val_if_fail (aspect_ratio > 0.0, NULL);
 
-  if ((scale == 1.0) && (aspect_ratio == 1.0) && (angle == 0.0) && (hardness == 1.0))
+  if ((scale == 1.0) && (aspect_ratio == 0.0) && (angle == 0.0) && (hardness == 1.0))
     return temp_buf_copy (brush->mask, NULL);
 
   return GIMP_BRUSH_GET_CLASS (brush)->transform_mask (brush, scale, aspect_ratio, angle, hardness);
@@ -508,10 +506,8 @@ gimp_brush_transform_pixmap (GimpBrush *brush,
   g_return_val_if_fail (GIMP_IS_BRUSH (brush), NULL);
   g_return_val_if_fail (brush->pixmap != NULL, NULL);
   g_return_val_if_fail (scale > 0.0, NULL);
-  g_return_val_if_fail (aspect_ratio > 0.0, NULL);
 
-
-  if ((scale == 1.0) && (aspect_ratio == 1.0) && (angle == 0.0) && (hardness == 1.0))
+  if ((scale == 1.0) && (aspect_ratio == 0.0) && (angle == 0.0) && (hardness == 1.0))
     return temp_buf_copy (brush->pixmap, NULL);
 
   return GIMP_BRUSH_GET_CLASS (brush)->transform_pixmap (brush, scale, aspect_ratio, angle, hardness);
diff --git a/app/core/gimpbrushgenerated.c b/app/core/gimpbrushgenerated.c
index 65b3ffa..05c9c2f 100644
--- a/app/core/gimpbrushgenerated.c
+++ b/app/core/gimpbrushgenerated.c
@@ -302,20 +302,19 @@ gimp_brush_generated_transform_size (GimpBrush *gbrush,
   gint                half_height;
   gdouble             ratio;
 
-  if (aspect_ratio == 1.0)
+  if (aspect_ratio == 0.0)
     {
       ratio = brush->aspect_ratio;
     }
   else
     {
-      ratio = MIN (aspect_ratio, 20);
+      ratio = MIN (fabs (aspect_ratio) + 1, 20);
       /* Since generated brushes are symmetric the dont have input
        * for aspect ratios  < 1.0. its same as rotate by 90 degrees and
        * 1 / ratio. So we fix the input up for this case.   */
 
-      if (ratio < 1.0)
+      if (aspect_ratio < 0.0)
         {
-          ratio = MIN (1.0 / ratio, 20);
           angle = angle + 0.25;
         }
     }
@@ -347,23 +346,22 @@ gimp_brush_generated_transform_mask (GimpBrush *gbrush,
   GimpBrushGenerated *brush  = GIMP_BRUSH_GENERATED (gbrush);
   gdouble             ratio;
 
-  if (aspect_ratio == 1.0)
+  if (aspect_ratio == 0.0)
     {
       ratio = brush->aspect_ratio;
     }
   else
     {
-      ratio = MIN (aspect_ratio, 20);
+      ratio = MIN (fabs (aspect_ratio) + 1, 20);
       /* Since generated brushes are symmetric the dont have input
        * for aspect ratios  < 1.0. its same as rotate by 90 degrees and
        * 1 / ratio. So we fix the input up for this case.   */
 
-      if (ratio < 1.0)
+      if (aspect_ratio < 0.0)
         {
-          ratio = MIN (1.0 / ratio, 20);
           angle = angle + 0.25;
         }
-    }
+   }
 
 
   return gimp_brush_generated_calc (brush,
diff --git a/app/core/gimpdynamicsoutput.c b/app/core/gimpdynamicsoutput.c
index 3549147..f6f022a 100644
--- a/app/core/gimpdynamicsoutput.c
+++ b/app/core/gimpdynamicsoutput.c
@@ -586,18 +586,19 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
                                        gdouble             fade_point)
 {
   gdouble total   = 0.0;
-  gdouble result  = 1.0;
   gint    factors = 0;
+  gdouble sign    = 1.0;
+  gdouble result  = 1.0;
 
   if (output->use_pressure)
     {
-      total += 2 * gimp_curve_map_value (output->pressure_curve, coords->pressure);
+      total += gimp_curve_map_value (output->pressure_curve, coords->pressure);
       factors++;
     }
 
   if (output->use_velocity)
     {
-      total +=  2 * gimp_curve_map_value (output->velocity_curve, coords->velocity);
+      total += gimp_curve_map_value (output->velocity_curve, coords->velocity);
       factors++;
     }
 
@@ -605,26 +606,24 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
     {
       gdouble direction = gimp_curve_map_value (output->direction_curve, coords->direction);
 
-      direction = fmod (1 + direction, 0.5) / 0.25;
-
-      if ((coords->direction > 0.0) && (coords->direction < 0.5))
-        direction = 1 / direction;
+      if (((direction > 0.875) && (direction < 0.0)) ||
+          ((direction > 0.0) && (direction < 0.125)) ||
+          ((direction > 0.375) && (direction < 0.625)))
+        sign = -1.0;
 
-      total += direction;
+      total += 1.0;
       factors++;
     }
 
   if (output->use_tilt)
     {
-      gdouble tilt_value =  MIN ((1 - fabs (coords->xtilt)) /
-                                 (1 - fabs (coords->ytilt)), 20);
+      gdouble tilt_value =  MAX (fabs (coords->xtilt), fabs (coords->ytilt));
 
-      if (tilt_value <= 1.0)
-        tilt_value = gimp_curve_map_value (output->tilt_curve,
-                                           tilt_value);
-      else
-        tilt_value = (1 - gimp_curve_map_value (output->tilt_curve,
-                                                (1.0 - (tilt_value - 1.0) / 19.0))) * 19.0 + 1.0 ;
+      tilt_value = gimp_curve_map_value (output->tilt_curve,
+                                         tilt_value);
+
+      if (fabs (coords->xtilt) > fabs (coords->ytilt))
+        sign = -1.0;
 
       total += tilt_value;
 
@@ -633,8 +632,16 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
 
   if (output->use_wheel)
     {
-      total += 2 * gimp_curve_map_value (output->wheel_curve, coords->wheel);
+      gdouble wheel = gimp_curve_map_value (output->wheel_curve, coords->wheel);
+
+      if (((wheel > 0.875) && (wheel < 0.0)) ||
+          ((wheel > 0.0) && (wheel < 0.125)) ||
+          ((wheel > 0.375) && (wheel < 0.625)))
+        sign = -1.0;
+
+      total += 1.0;
       factors++;
+
     }
 
   if (output->use_random)
@@ -642,11 +649,6 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
       gdouble random = gimp_curve_map_value (output->random_curve,
                                              g_random_double_range (0.0, 1.0));
 
-      if (random <= 0.5)
-        random = 1 / (random / 0.5 * (2.0 - 1.0) + 1.0);
-      else
-        random = (random - 0.5) / (1.0 - 0.5) * (2.0 - 1.0) + 1.0;
-
       total += random;
       factors++;
     }
@@ -661,11 +663,12 @@ gimp_dynamics_output_get_aspect_value (GimpDynamicsOutput *output,
   if (factors > 0)
     result = total / factors;
 
+
 #if 0
-  g_printerr ("Dynamics queried(aspect). Result: %f, factors: %d, total: %f\n",
-              result, factors, total);
+  g_printerr ("Dynamics queried(aspect). Result: %f, factors: %d, total: %f sign: %f\n",
+              result, factors, total, sign);
 #endif
-  result = CLAMP (result, 0.05, 20.0);
+  result = CLAMP (result * sign, -1.0, 1.0);
 
   return result;
 }
diff --git a/app/paint/gimpbrushcore.c b/app/paint/gimpbrushcore.c
index 50aa11b..295d72e 100644
--- a/app/paint/gimpbrushcore.c
+++ b/app/paint/gimpbrushcore.c
@@ -953,7 +953,7 @@ gimp_brush_core_create_boundary (GimpBrushCore    *core,
           MAX (core->main_brush->mask->width,
                core->main_brush->mask->height);
 
-  if (scale > 0.0)
+  if ((scale > 0.0) && (paint_options->brush_aspect_ratio != 0.0))
     {
       scale = gimp_brush_clamp_scale (core->main_brush, scale);
 
@@ -974,7 +974,7 @@ gimp_brush_core_create_boundary (GimpBrushCore    *core,
           gimp_brush_generated_set_aspect_ratio (generated_brush, 1.0);
 
           mask = gimp_brush_transform_mask (core->main_brush,
-                                            1.0, 1.0, 0.0, 1.0);
+                                            1.0, 0.0, 0.0, 1.0);
 
           gimp_brush_generated_set_aspect_ratio (generated_brush, ratio);
 
@@ -985,7 +985,7 @@ gimp_brush_core_create_boundary (GimpBrushCore    *core,
       else
         {
           mask = gimp_brush_transform_mask (core->main_brush,
-                                            1.0, 1.0, 0.0, 1.0);
+                                            1.0, 0.0, 0.0, 1.0);
         }
     }
 
@@ -1023,8 +1023,8 @@ gimp_brush_core_get_transform (GimpBrushCore *core,
   gdouble aspect_ratio;
   gdouble height;
   gdouble width;
-  gdouble scale_x;
-  gdouble scale_y;
+  gdouble scale_x = core->scale;
+  gdouble scale_y = core->scale;
 
   g_return_val_if_fail (GIMP_IS_BRUSH_CORE (core), FALSE);
   g_return_val_if_fail (matrix != 0, FALSE);
@@ -1049,25 +1049,25 @@ gimp_brush_core_get_transform (GimpBrushCore *core,
 
       angle = angle + base_angle / 360;
 
-      if (aspect_ratio == 1.0)
+      if (aspect_ratio == 0.0)
         aspect_ratio = gimp_brush_generated_get_aspect_ratio (generated_brush);
     }
 
   height = core->brush_bound_width;
   width  = core->brush_bound_height;
 
-  if (aspect_ratio < 1.0)
+  if (aspect_ratio < 0.0)
     {
-      scale_x = scale * aspect_ratio;
+      scale_x = scale / fabs (aspect_ratio);
       scale_y = scale;
     }
-  else
+  else  if (aspect_ratio > 0.0)
     {
       scale_x = scale;
       scale_y = scale / aspect_ratio;
     }
 
-  if ((scale > 0.0) && (aspect_ratio > 0.0))
+  if (scale > 0.0)
     {
       scale = gimp_brush_clamp_scale (core->main_brush, scale);
 
@@ -1544,7 +1544,7 @@ gimp_brush_core_transform_mask (GimpBrushCore *core,
   if ((core->scale == 1.0) &&
       (core->angle == 0.0) &&
       (core->hardness == 1.0) &&
-      (core->aspect_ratio == 1.0))
+      (core->aspect_ratio == 0.0))
     return brush->mask;
 
   gimp_brush_transform_size (brush,
@@ -1600,7 +1600,7 @@ gimp_brush_core_transform_pixmap (GimpBrushCore *core,
   if ((core->scale        == 1.0) &&
       (core->angle        == 0.0) &&
       (core->hardness     == 1.0) &&
-      (core->aspect_ratio == 1.0))
+      (core->aspect_ratio == 0.0))
     return brush->pixmap;
 
   gimp_brush_transform_size (brush,
@@ -1688,8 +1688,8 @@ gimp_brush_core_eval_transform_dynamics (GimpPaintCore     *paint_core,
                                          GimpPaintOptions  *paint_options,
                                          const GimpCoords  *coords)
 {
-  GimpBrushCore *core = GIMP_BRUSH_CORE (paint_core);
-  gdouble    fade_point = 1.0;
+  GimpBrushCore      *core                = GIMP_BRUSH_CORE (paint_core);
+  gdouble             fade_point          = 1.0;
 
   if (core->main_brush)
     core->scale = paint_options->brush_size /
@@ -1706,6 +1706,7 @@ gimp_brush_core_eval_transform_dynamics (GimpPaintCore     *paint_core,
 
   if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_dynamic_transforming_brush)
     {
+      gdouble dyn_aspect_ratio = 0.0;
       if (drawable)
         {
           GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
@@ -1732,11 +1733,23 @@ gimp_brush_core_eval_transform_dynamics (GimpPaintCore     *paint_core,
                                                paint_options,
                                                fade_point);
 
-      core->aspect_ratio *=
+      dyn_aspect_ratio =
         gimp_dynamics_output_get_aspect_value (core->dynamics->aspect_ratio_output,
                                                coords,
                                                paint_options,
                                                fade_point);
+
+      /* Zero aspect ratio is special cased to half of all ar range,
+       * to force dynamics to have any effect . Forcing to full results
+       * in disapearing stamp if applied to maximum.
+       */
+      if (gimp_dynamics_output_is_enabled (core->dynamics->aspect_ratio_output))
+        {
+          if (core->aspect_ratio == 0.0)
+            core->aspect_ratio = 10.0 * dyn_aspect_ratio;
+          else
+            core->aspect_ratio *= dyn_aspect_ratio;
+        }
     }
 }
 
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 7d33b87..14d51c4 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -38,7 +38,7 @@
 
 
 #define DEFAULT_BRUSH_SIZE             20.0
-#define DEFAULT_BRUSH_ASPECT_RATIO     1.0
+#define DEFAULT_BRUSH_ASPECT_RATIO     0.0
 #define DEFAULT_BRUSH_ANGLE            0.0
 
 #define DEFAULT_APPLICATION_MODE       GIMP_PAINT_CONSTANT
@@ -148,7 +148,7 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,
                                    "brush-aspect-ratio", _("Brush Aspect Ratio"),
-                                   0.01, 10.0, DEFAULT_BRUSH_ASPECT_RATIO,
+                                   -20.0, 20.0, DEFAULT_BRUSH_ASPECT_RATIO,
                                    GIMP_PARAM_STATIC_STRINGS);
   GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ANGLE,
                                    "brush-angle", _("Brush Angle"),
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 8801152..95285f2 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -409,7 +409,7 @@ gimp_paint_options_gui_reset_aspect_ratio (GtkWidget        *button,
 {
 
    g_object_set (paint_options,
-                 "brush-aspect-ratio", 1.0,
+                 "brush-aspect-ratio", 0.0,
                  NULL);
 }
 



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