tracedialog.cpp revision 77dae8b0ae204855f29e1acb5105295dcacd710e
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * @brief Bitmap tracing settings dialog - implementation
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Bob Jamison <rjamison@titan.com>
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Stéphane Gimenez <dev@gim.name>
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Other dudes from The Inkscape Organization
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Copyright (C) 2004-2006 Authors
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Released under GNU GPL, read the file 'COPYING' for more information
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński#include <gtk/gtk.h> //for GTK_RESPONSE* types
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński#include "trace/potrace/inkscape-potrace.h"
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//## I M P L E M E N T A T I O N
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * A dialog for adjusting bitmap->vector tracing parameters
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskiclass TraceDialogImpl : public TraceDialog
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Callback from OK or Cancel
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * This is the big almighty McGuffin
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński * This does potrace processing
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Only preview if do_i_trace is false
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Abort processing
827bc501341bcc5c344c0422f13422bc368151b4Krzysztof Kosiński //############ General items
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //######## Left pannel
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //#### Notebook
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //# Single scan mode
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński Gtk::RadioButton modeBrightnessRadioButton;
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński Inkscape::UI::Widget::SpinButton modeBrightnessSpinner;
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński //edge detection
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński //Gtk::HSeparator modeCannySeparator;
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński //Gtk::Label modeCannyLoSpinnerLabel;
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński //Inkscape::UI::Widget::SpinButton modeCannyLoSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton modeCannyHiSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //quantization
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton modeQuantNrColorSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //# Multiple path scanning mode
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::RadioButton modeMultiScanBrightnessRadioButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton modeMultiScanNrColorSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::RadioButton modeMultiScanColorRadioButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::RadioButton modeMultiScanMonoRadioButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::CheckButton modeMultiScanStackButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::CheckButton modeMultiScanSmoothButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Gtk::CheckButton modeMultiScanBackgroundButton;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński // potrace parameters
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton optionsSpecklesSizeSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton optionsCornersThresholdSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::UI::Widget::SpinButton optionsOptimToleranceSpinner;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //#### Credits
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //######## Right pannel
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //#### SIOX selection
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //#### Preview
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//## E V E N T S
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński//#########################################################################
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński * This does potrace processing
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosiński * Only preview if do_i_trace is false
ef494f75ca77f36881ad59e94263a07c146c3649Krzysztof Kosińskivoid TraceDialogImpl::potraceProcess(bool do_i_trace)
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Get the tracer and engine
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Inkscape::Trace::Potrace::PotraceTracingEngine pte;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* inversion */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński bool invert = modeInvertButton.get_active();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Get the preprocessor settings
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* siox -- performed by Tracer, and before any of the others */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* one of the following */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński if (modeBrightnessRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_BRIGHTNESS);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (modeMultiScanBrightnessRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_BRIGHTNESS_MULTI);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (modeCannyRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_CANNY);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (modeQuantRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_QUANT);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (modeMultiScanColorRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_QUANT_COLOR);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (modeMultiScanMonoRadioButton.get_active())
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setTraceType(Inkscape::Trace::Potrace::TRACE_QUANT_MONO);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński optionsSpecklesSizeSpinner.get_value_as_int() :
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setParamsTurdSize(paramsSpecklesSize);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński optionsCornersThresholdSpinner.get_value() :
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setParamsAlphaMax(paramsCornersThreshold);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński bool paramsOptim = optionsOptimButton.get_active();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński double paramsOptimTolerance = optionsOptimToleranceSpinner.get_value();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setParamsOptTolerance(paramsOptimTolerance);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Get the single-scan settings
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* brightness */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński double brightnessThreshold = modeBrightnessSpinner.get_value();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setBrightnessThreshold(brightnessThreshold);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński double cannyHighThreshold = modeCannyHiSpinner.get_value();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setCannyHighThreshold(cannyHighThreshold);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński /* quantization */
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński int quantNrColors = modeQuantNrColorSpinner.get_value_as_int();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setQuantizationNrColors(quantNrColors);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Get multiple-scan settings
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński int multiScanNrColors = modeMultiScanNrColorSpinner.get_value_as_int();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setMultiScanNrColors(multiScanNrColors);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński bool do_i_stack = modeMultiScanStackButton.get_active();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński bool do_i_smooth = modeMultiScanSmoothButton.get_active();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński bool do_i_remove_background = modeMultiScanBackgroundButton.get_active();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński pte.setMultiScanRemoveBackground(do_i_remove_background);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Get intermediate bitmap image
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Glib::RefPtr<Gdk::Pixbuf> pixbuf = tracer.getSelectedImage();
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Glib::RefPtr<Gdk::Pixbuf> preview = pte.preview(pixbuf);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński double scaleFactor = scaleFX > scaleFY ? scaleFY : scaleFX;
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński int newWidth = (int) (((double)width) * scaleFactor);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński int newHeight = (int) (((double)height) * scaleFactor);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński Glib::RefPtr<Gdk::Pixbuf> scaledPreview =
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński preview->scale_simple(newWidth, newHeight,
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //g_object_unref(preview);
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //##### Convert
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Abort processing
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński //### Make the abort() call to the tracer
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//## E V E N T S
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Callback from the Preview button. Can be called from elsewhere.
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński * Default response from the dialog. Let's intercept it
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosińskivoid TraceDialogImpl::responseCallback(int response_id)
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński // for now, we assume potrace, as it's the only one we have
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński else if (response_id == GTK_RESPONSE_CANCEL)
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//## C O N S T R U C T O R / D E S T R U C T O R
40742313779ee5e43be93a9191f1c86412cf183bKrzysztof Kosiński//#########################################################################
modeCannyLoSpinnerLabel.set_label(_("Low"));
modeCannyLoSpinner.set_digits(5);
modeCannyLoSpinner.set_increments(0.01, 0);
modeCannyLoSpinner.set_range(0.0, 1.0);
modeCannyLoSpinner.set_value(0.1);
tips.set_tip(modeMultiScanStackButton, _("Stack scans on top of one another (no gaps) instead of tiling (usually with gaps)"));
//modeQuantFrame.set_shadow_type(Gtk::SHADOW_NONE);
potraceCreditsLabel.set_text(_("Inkscape bitmap tracing\nis based on Potrace,\ncreated by Peter Selinger\n\nhttp://potrace.sourceforge.net"));
//previewImage.set_alignment (Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER);
//previewFrame.set_shadow_type(Gtk::SHADOW_NONE);
if (mainCancelButton) {
return *dialog;