[gimp] app: apply a cap on brush scaling



commit 5a22fb57992671fc7bebf05b60653dc58f13320f
Author: Alexia Death <alexiadeath gmail com>
Date:   Sat Nov 15 19:38:44 2014 +0200

    app: apply a cap on brush scaling

 app/core/gimpbrush.c         |   16 ++++++++++++++--
 app/core/gimpbrush.h         |    1 +
 app/paint/gimppaintoptions.c |    2 +-
 3 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/app/core/gimpbrush.c b/app/core/gimpbrush.c
index 0ec34aa..4cd356e 100644
--- a/app/core/gimpbrush.c
+++ b/app/core/gimpbrush.c
@@ -580,21 +580,33 @@ gimp_brush_transform_size (GimpBrush     *brush,
                            gint          *width,
                            gint          *height)
 {
+  gdouble tmp_width;
+  gdouble tmp_height;
+ 
   g_return_if_fail (GIMP_IS_BRUSH (brush));
   g_return_if_fail (scale > 0.0);
   g_return_if_fail (width != NULL);
   g_return_if_fail (height != NULL);
 
+  tmp_width = gimp_temp_buf_get_width  (brush->priv->mask);
+  tmp_height = gimp_temp_buf_get_height (brush->priv->mask);
+
   if (scale        == 1.0 &&
       aspect_ratio == 0.0 &&
       ((angle == 0.0) || (angle == 0.5) || (angle == 1.0)))
     {
-      *width  = gimp_temp_buf_get_width  (brush->priv->mask);
-      *height = gimp_temp_buf_get_height (brush->priv->mask);;
+      *width  = tmp_width;
+      *height = tmp_height;
 
       return;
     }
 
+  /*Cap transform result for brushes or OOM can occur*/
+  if (((gdouble) MAX (tmp_width, tmp_height)) > GIMP_BRUSH_MAX_SIZE)
+    {
+      scale = GIMP_BRUSH_MAX_SIZE / (gdouble) MAX (tmp_width, tmp_height);
+    }
+
   GIMP_BRUSH_GET_CLASS (brush)->transform_size (brush,
                                                 scale, aspect_ratio, angle,
                                                 width, height);
diff --git a/app/core/gimpbrush.h b/app/core/gimpbrush.h
index 5c02710..53e2762 100644
--- a/app/core/gimpbrush.h
+++ b/app/core/gimpbrush.h
@@ -21,6 +21,7 @@
 
 #include "gimpdata.h"
 
+#define GIMP_BRUSH_MAX_SIZE 10000.0 /*Max size in either dimension in px*/
 
 #define GIMP_TYPE_BRUSH            (gimp_brush_get_type ())
 #define GIMP_BRUSH(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index a1c2e67..4393719 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -156,7 +156,7 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_SIZE,
                                    "brush-size", _("Brush Size"),
-                                   1.0, 10000.0, DEFAULT_BRUSH_SIZE,
+                                   1.0, GIMP_BRUSH_MAX_SIZE, DEFAULT_BRUSH_SIZE,
                                    GIMP_PARAM_STATIC_STRINGS);
 
   GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,


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