Code

patch 1591723 for extra tracing parameters
authorbuliabyak <buliabyak@users.sourceforge.net>
Tue, 14 Nov 2006 00:43:28 +0000 (00:43 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Tue, 14 Nov 2006 00:43:28 +0000 (00:43 +0000)
src/trace/potrace/inkscape-potrace.cpp
src/trace/potrace/inkscape-potrace.h
src/ui/dialog/tracedialog.cpp

index 404d25d3a18c87f16bedfc5877c84edd13b47255..e36673e4fe55216b0b65d1391f0d8ae8da6e9325 100644 (file)
@@ -3,8 +3,9 @@
  *
  * Authors:
  *   Bob Jamison <rjamison@titan.com>
+ *   Stéphane Gimenez <dev@gim.name>
  *
- * Copyright (C) 2004 Bob Jamison
+ * Copyright (C) 2004-2006 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  *
@@ -70,18 +71,23 @@ namespace Potrace {
  */
 PotraceTracingEngine::PotraceTracingEngine()
 {
+    /* get default parameters */
+    potraceParams = potrace_param_default();
+    potraceParams->progress.callback = potraceStatusCallback;
+    potraceParams->progress.data = (void *)this;
 
     //##### Our defaults
     invert    = false;
     traceType = TRACE_BRIGHTNESS;
-
     quantizationNrColors = 8;
-
     brightnessThreshold  = 0.45;
-
     cannyHighThreshold   = 0.65;
 
+}
 
+PotraceTracingEngine::~PotraceTracingEngine()
+{
+    potrace_param_free(potraceParams);
 }
 
 
@@ -366,13 +372,6 @@ PotraceTracingEngine::preview(Glib::RefPtr<Gdk::Pixbuf> thePixbuf)
 std::string
 PotraceTracingEngine::grayMapToPath(GrayMap *grayMap, long *nodeCount)
 {
-
-    /* get default parameters */
-    potrace_param_t *potraceParams = potrace_param_default();
-
-    potraceParams->progress.callback = potraceStatusCallback;
-    potraceParams->progress.data     = (void *)this;
-
     potrace_bitmap_t *potraceBitmap = bm_new(grayMap->width, grayMap->height);
     bm_clear(potraceBitmap, 0);
 
@@ -410,7 +409,6 @@ PotraceTracingEngine::grayMapToPath(GrayMap *grayMap, long *nodeCount)
         {
         g_warning("aborted");
         potrace_state_free(potraceState);
-        potrace_param_free(potraceParams);
         return "";
         }
 
@@ -424,7 +422,6 @@ PotraceTracingEngine::grayMapToPath(GrayMap *grayMap, long *nodeCount)
 
     /* free a potrace items */
     potrace_state_free(potraceState);
-    potrace_param_free(potraceParams);
 
     if (!keepGoing)
         return "";
index f3459159f3b79c358448bce1064b6813f7de6132..838a1363af86dd667314eb386e3c87e1b2504480 100644 (file)
@@ -3,8 +3,9 @@
  *
  * Authors:
  *   Bob Jamison <rjamison@titan.com>
+ *   Stéphane Gimenez <dev@gim.name>
  *
- * Copyright (C) 2004 Bob Jamison
+ * Copyright (C) 2004-2006 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  *
@@ -20,6 +21,8 @@
 #include <trace/trace.h>
 #include <trace/imagemap.h>
 
+#include "potracelib.h"
+
 namespace Inkscape {
 
 namespace Trace {
@@ -50,8 +53,47 @@ class PotraceTracingEngine : public TracingEngine
     /**
      *
      */
-    virtual ~PotraceTracingEngine()
-        {}
+    ~PotraceTracingEngine();
+
+
+    /**
+     * Sets/gets potrace parameters
+     */
+    void setParamsTurdSize(int val)
+        {
+        potraceParams->turdsize = val;
+        }
+    int getParamsTurdSize()
+        {
+        return potraceParams->turdsize;
+        }
+
+    void setParamsAlphaMax(double val)
+        {
+        potraceParams->alphamax = val;
+        }
+    double getParamsAlphaMax()
+        {
+        return potraceParams->alphamax;
+        }
+
+    void setParamsOptiCurve(bool val)
+        {
+        potraceParams->opticurve = val;
+        }
+    bool getParamsOptiCurve()
+        {
+        return potraceParams->opticurve;
+        }
+
+    void setParamsOptTolerance(double val)
+        {
+        potraceParams->opttolerance = val;
+        }
+    double getParamsOptTolerance()
+        {
+        return potraceParams->opttolerance;
+        }
 
     void setTraceType(TraceType val)
         {
@@ -199,6 +241,7 @@ class PotraceTracingEngine : public TracingEngine
 
     private:
 
+    potrace_param_t *potraceParams;
     TraceType traceType;
 
     //## do i invert at the end?
index 6182954f6e090c783b05e171dc8728b5e6a62580..645ce885f24c1a9e45538aced354dacfd8da4327 100644 (file)
@@ -3,10 +3,11 @@
  * bitmap <image> into an svg <path>
  *
  * Authors:
- *   Bob Jamison
+ *   Bob Jamison <rjamison@titan.com>
+ *   Stéphane Gimenez <dev@gim.name>
  *   Other dudes from The Inkscape Organization
  *
- * Copyright (C) 2004, 2005 Authors
+ * Copyright (C) 2004-2006 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -98,6 +99,22 @@ class TraceDialogImpl : public TraceDialog
     Gtk::Button           *potraceOkButton;
     Gtk::Button           *potraceCancelButton;
 
+    //params
+    Gtk::Frame            potraceParamsFrame;
+    Gtk::VBox             potraceParamsVBox;
+    Gtk::HBox             potraceParamsSpecklesBox;
+    Gtk::CheckButton      potraceParamsSpecklesButton;
+    Gtk::Label            potraceParamsSpecklesSizeLabel;
+    Gtk::SpinButton       potraceParamsSpecklesSizeSpinner;
+    Gtk::HBox             potraceParamsCornersBox;
+    Gtk::CheckButton      potraceParamsCornersButton;
+    Gtk::Label            potraceParamsCornersThresholdLabel;
+    Gtk::SpinButton       potraceParamsCornersThresholdSpinner;
+    Gtk::HBox             potraceParamsOptimBox;
+    Gtk::CheckButton      potraceParamsOptimButton;
+    Gtk::Label            potraceParamsOptimToleranceLabel;
+    Gtk::SpinButton       potraceParamsOptimToleranceSpinner;
+
     //brightness
     Gtk::Frame            potraceBrightnessFrame;
     Gtk::VBox             potraceBrightnessVBox;
@@ -211,7 +228,24 @@ void TraceDialogImpl::potraceProcess(bool do_i_trace)
         pte.setInvert(false);
         }
 
+    /* params */
+    int paramsSpecklesSize =
+      potraceParamsSpecklesButton.get_active() ?
+      potraceParamsSpecklesSizeSpinner.get_value_as_int() :
+      0;
+    pte.setParamsTurdSize(paramsSpecklesSize);
+    double paramsCornersThreshold =
+      potraceParamsCornersButton.get_active() ?
+      potraceParamsCornersThresholdSpinner.get_value() :
+      0.;
+    pte.setParamsAlphaMax(paramsCornersThreshold);
+    bool paramsOptim = potraceParamsOptimButton.get_active();
+    pte.setParamsOptiCurve(paramsOptim);
+    double paramsOptimTolerance = potraceParamsOptimToleranceSpinner.get_value();
+    pte.setParamsOptTolerance(paramsOptimTolerance);
+
     //##### Get the single-scan settings
+
     /* brightness */
     double brightnessThreshold = potraceBrightnessSpinner.get_value();
     pte.setBrightnessThreshold(brightnessThreshold);
@@ -357,6 +391,57 @@ TraceDialogImpl::TraceDialogImpl()
 
     //##Set up the Potrace panel
 
+    /*#### params ####*/
+    potraceParamsSpecklesButton.set_label(_("Speckles Filtering"));
+    potraceParamsSpecklesButton.set_active(true);
+    //tips.set_tip(potraceParamsSpecklesButton, _(""));
+    potraceParamsSpecklesBox.pack_start(potraceParamsSpecklesButton, false, false, MARGIN);
+    potraceParamsSpecklesSizeSpinner.set_digits(0);
+    potraceParamsSpecklesSizeSpinner.set_increments(1, 10);
+    potraceParamsSpecklesSizeSpinner.set_range(0, 1000);
+    potraceParamsSpecklesSizeSpinner.set_value(2);
+    tips.set_tip(potraceParamsSpecklesSizeSpinner,
+                _("Suppress speckles of up to this many pixels"));
+    potraceParamsSpecklesBox.pack_end(potraceParamsSpecklesSizeSpinner, false, false, MARGIN);
+    potraceParamsSpecklesSizeLabel.set_label(_("Size:"));
+    potraceParamsSpecklesBox.pack_end(potraceParamsSpecklesSizeLabel, false, false, MARGIN);
+
+    potraceParamsCornersButton.set_label(_("Corner Smoothing"));
+    potraceParamsCornersButton.set_active(true);
+    //tips.set_tip(potraceParamsCornersButton, _(""));
+    potraceParamsCornersBox.pack_start(potraceParamsCornersButton, false, false, MARGIN);
+    potraceParamsCornersThresholdSpinner.set_digits(2);
+    potraceParamsCornersThresholdSpinner.set_increments(0.01, 0.1);
+    potraceParamsCornersThresholdSpinner.set_range(0.0, 1.34);
+    potraceParamsCornersThresholdSpinner.set_value(1.0);
+    potraceParamsCornersBox.pack_end(potraceParamsCornersThresholdSpinner, false, false, MARGIN);
+    tips.set_tip(potraceParamsCornersThresholdSpinner,
+                _("The higher this value, the smoother corners will be produced"));
+    potraceParamsCornersThresholdLabel.set_label(_("Threshold:"));
+    potraceParamsCornersBox.pack_end(potraceParamsCornersThresholdLabel, false, false, MARGIN);
+
+    potraceParamsOptimButton.set_label(_("Curve Optimization"));
+    potraceParamsOptimButton.set_active(true);
+    tips.set_tip(potraceParamsOptimButton,
+                _("Try to join adjacent Bezier curve segments"));
+    potraceParamsOptimBox.pack_start(potraceParamsOptimButton, false, false, MARGIN);
+    potraceParamsOptimToleranceSpinner.set_digits(2);
+    potraceParamsOptimToleranceSpinner.set_increments(0.05, 0.25);
+    potraceParamsOptimToleranceSpinner.set_range(0.0, 5.0);
+    potraceParamsOptimToleranceSpinner.set_value(0.2);
+    potraceParamsOptimBox.pack_end(potraceParamsOptimToleranceSpinner, false, false, MARGIN);
+    tips.set_tip(potraceParamsOptimToleranceSpinner,
+                _("Set the curve optimization tolerance"));
+    potraceParamsOptimToleranceLabel.set_label(_("Tolerance:"));
+    potraceParamsOptimBox.pack_end(potraceParamsOptimToleranceLabel, false, false, MARGIN);
+
+    potraceParamsVBox.pack_start(potraceParamsSpecklesBox, false, false, MARGIN);
+    potraceParamsVBox.pack_start(potraceParamsCornersBox, false, false, MARGIN);
+    potraceParamsVBox.pack_start(potraceParamsOptimBox, false, false, MARGIN);
+    potraceParamsFrame.set_label(_("Parameters"));
+    potraceParamsFrame.add(potraceParamsVBox);
+    potraceBox.pack_start(potraceParamsFrame, false, false, 0);
+
     /*#### brightness ####*/
     potraceBrightnessRadioButton.set_label(_("Brightness"));
     potraceGroup = potraceBrightnessRadioButton.get_group();