summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2011-07-27 04:55:07 +0000
committerJon A. Cruz <jon@joncruz.org>2011-07-27 04:55:07 +0000
commitadbc8efa025ad921775e3c171c3ce3bd7763d1ca (patch)
tree1f12f5d930e7d7b041a6e7ede8208516dd9d6060 /src
parentupdate to cmake checker and add missing header. (diff)
downloadinkscape-adbc8efa025ad921775e3c171c3ce3bd7763d1ca.tar.gz
inkscape-adbc8efa025ad921775e3c171c3ce3bd7763d1ca.zip
Cleaning up trace methods to aid fixing color inversion.
(bzr r10507)
Diffstat (limited to 'src')
-rw-r--r--src/message-stack.cpp6
-rw-r--r--src/message-stack.h29
-rw-r--r--src/trace/potrace/inkscape-potrace.cpp203
-rw-r--r--src/trace/potrace/inkscape-potrace.h10
4 files changed, 136 insertions, 112 deletions
diff --git a/src/message-stack.cpp b/src/message-stack.cpp
index d2101009e..c1669e3db 100644
--- a/src/message-stack.cpp
+++ b/src/message-stack.cpp
@@ -62,6 +62,12 @@ void MessageStack::cancel(MessageId id) {
}
}
+MessageId MessageStack::flash(MessageType type, Glib::ustring const &message)
+{
+ MessageId id = flash( type, message.c_str() );
+ return id;
+}
+
MessageId MessageStack::flash(MessageType type, gchar const *message) {
switch (type) {
case INFORMATION_MESSAGE: // stay rather long so as to seem permanent, but eventually disappear
diff --git a/src/message-stack.h b/src/message-stack.h
index ae8860965..3b8307761 100644
--- a/src/message-stack.h
+++ b/src/message-stack.h
@@ -5,8 +5,10 @@
/*
* Authors:
* MenTaLguY <mental@rydia.net>
+ * Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2004 MenTaLguY
+ * Copyright (C) 2011 Jon A. Cruz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
@@ -18,6 +20,7 @@
#include <sigc++/sigc++.h>
#include <glib.h>
#include <stdarg.h>
+#include <glibmm/ustring.h>
#include "gc-managed.h"
#include "gc-finalized.h"
#include "gc-anchored.h"
@@ -108,15 +111,27 @@ public:
*/
void cancel(MessageId id);
- /** @brief temporarily pushes a message onto the stack
- *
- * @param type the message type
- * @param message the message text
- *
- * @return the id of the pushed message
- */
+ /**
+ * Temporarily pushes a message onto the stack.
+ *
+ * @param type the message type
+ * @param message the message text
+ *
+ * @return the id of the pushed message
+ */
MessageId flash(MessageType type, gchar const *message);
+ /**
+ * Temporarily pushes a message onto the stack.
+ *
+ * @param type the message type
+ * @param message the message text
+ *
+ * @return the id of the pushed message
+ */
+ MessageId flash(MessageType type, Glib::ustring const &message);
+
+
/** @brief temporarily pushes a message onto the stack using
* printf-like formatting
*
diff --git a/src/trace/potrace/inkscape-potrace.cpp b/src/trace/potrace/inkscape-potrace.cpp
index 2f4dc7a6f..6583fb735 100644
--- a/src/trace/potrace/inkscape-potrace.cpp
+++ b/src/trace/potrace/inkscape-potrace.cpp
@@ -18,6 +18,7 @@
#include <glibmm/i18n.h>
#include <gtkmm.h>
+#include <iomanip>
#include "trace/filterset.h"
#include "trace/quantize.h"
@@ -31,7 +32,7 @@
#include "curve.h"
#include "bitmap.h"
-
+using Glib::ustring;
static void updateGui()
{
@@ -57,6 +58,12 @@ static void potraceStatusCallback(double /*progress*/, void *userData) /* callba
}
+namespace {
+ustring twohex( int value )
+{
+ return ustring::format(std::hex, std::setfill(L'0'), std::setw(2), value);
+}
+} // namespace
//required by potrace
@@ -471,67 +478,56 @@ PotraceTracingEngine::traceGrayMap(GrayMap *grayMap)
/**
* Called for multiple-scanning algorithms
*/
-std::vector<TracingEngineResult>
-PotraceTracingEngine::traceBrightnessMulti(GdkPixbuf * thePixbuf)
+std::vector<TracingEngineResult> PotraceTracingEngine::traceBrightnessMulti(GdkPixbuf * thePixbuf)
{
-
std::vector<TracingEngineResult> results;
- if (!thePixbuf)
- return results;
-
- double low = 0.2; //bottom of range
- double high = 0.9; //top of range
- double delta = (high - low ) / ((double)multiScanNrColors);
-
- brightnessFloor = 0.0; //Set bottom to black
-
- int traceCount = 0;
+ if ( thePixbuf ) {
+ double low = 0.2; //bottom of range
+ double high = 0.9; //top of range
+ double delta = (high - low ) / ((double)multiScanNrColors);
- for ( brightnessThreshold = low ;
- brightnessThreshold <= high ;
- brightnessThreshold += delta)
+ brightnessFloor = 0.0; //Set bottom to black
- {
-
- GrayMap *grayMap = filter(*this, thePixbuf);
- if (!grayMap)
- return results;
-
- long nodeCount;
- std::string d = grayMapToPath(grayMap, &nodeCount);
+ int traceCount = 0;
- grayMap->destroy(grayMap);
+ for ( brightnessThreshold = low ;
+ brightnessThreshold <= high ;
+ brightnessThreshold += delta) {
+ GrayMap *grayMap = filter(*this, thePixbuf);
+ if ( grayMap ) {
+ long nodeCount;
+ std::string d = grayMapToPath(grayMap, &nodeCount);
- if (d.size() == 0)
- return results;
+ grayMap->destroy(grayMap);
- int grayVal = (int)(256.0 * brightnessThreshold);
- char style[31];
- sprintf(style, "fill-opacity:1.0;fill:#%02x%02x%02x",
- grayVal, grayVal, grayVal);
+ if ( !d.empty() ) {
+ //### get style info
+ int grayVal = (int)(256.0 * brightnessThreshold);
+ ustring style = ustring::compose("fill-opacity:1.0;fill:%1%2%3", twohex(grayVal), twohex(grayVal), twohex(grayVal) );
- //g_message("### GOT '%s' \n", d);
- TracingEngineResult result(style, d, nodeCount);
- results.push_back(result);
+ //g_message("### GOT '%s' \n", style.c_str());
+ TracingEngineResult result(style, d, nodeCount);
+ results.push_back(result);
- if (!multiScanStack)
- brightnessFloor = brightnessThreshold;
+ if (!multiScanStack) {
+ brightnessFloor = brightnessThreshold;
+ }
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (desktop)
- {
- gchar *msg = g_strdup_printf(_("Trace: %d. %ld nodes"), traceCount++, nodeCount);
- sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg);
- g_free(msg);
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop) {
+ ustring msg = ustring::compose(_("Trace: %1. %2 nodes"), traceCount++, nodeCount);
+ sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg);
+ }
+ }
}
}
- //# Remove the bottom-most scan, if requested
- if (results.size() > 1 && multiScanRemoveBackground)
- {
- results.erase(results.end() - 1);
+ //# Remove the bottom-most scan, if requested
+ if (results.size() > 1 && multiScanRemoveBackground) {
+ results.erase(results.end() - 1);
}
+ }
return results;
}
@@ -540,77 +536,64 @@ PotraceTracingEngine::traceBrightnessMulti(GdkPixbuf * thePixbuf)
/**
* Quantization
*/
-std::vector<TracingEngineResult>
-PotraceTracingEngine::traceQuant(GdkPixbuf * thePixbuf)
+std::vector<TracingEngineResult> PotraceTracingEngine::traceQuant(GdkPixbuf * thePixbuf)
{
-
std::vector<TracingEngineResult> results;
- if (!thePixbuf)
- return results;
-
- IndexedMap *iMap = filterIndexed(*this, thePixbuf);
- if (!iMap)
- return results;
-
- //Create and clear a gray map
- GrayMap *gm = GrayMapCreate(iMap->width, iMap->height);
- for (int row=0 ; row<gm->height ; row++)
- for (int col=0 ; col<gm->width ; col++)
- gm->setPixel(gm, col, row, GRAYMAP_WHITE);
-
-
- for (int colorIndex=0 ; colorIndex<iMap->nrColors ; colorIndex++)
- {
-
- /*Make a gray map for each color index */
- for (int row=0 ; row<iMap->height ; row++)
- {
- for (int col=0 ; col<iMap->width ; col++)
- {
- int indx = (int) iMap->getPixel(iMap, col, row);
- if (indx == colorIndex)
- gm->setPixel(gm, col, row, GRAYMAP_BLACK); //black
- else if (!multiScanStack)
- gm->setPixel(gm, col, row, GRAYMAP_WHITE); //white
+ if (thePixbuf) {
+ IndexedMap *iMap = filterIndexed(*this, thePixbuf);
+ if ( iMap ) {
+ //Create and clear a gray map
+ GrayMap *gm = GrayMapCreate(iMap->width, iMap->height);
+ for (int row=0 ; row<gm->height ; row++) {
+ for (int col=0 ; col<gm->width ; col++) {
+ gm->setPixel(gm, col, row, GRAYMAP_WHITE);
}
}
- //## Now we have a traceable graymap
- long nodeCount;
- std::string d = grayMapToPath(gm, &nodeCount);
-
- if (d.size() == 0)
- return results;
+ for (int colorIndex=0 ; colorIndex<iMap->nrColors ; colorIndex++) {
+ // Make a gray map for each color index
+ for (int row=0 ; row<iMap->height ; row++) {
+ for (int col=0 ; col<iMap->width ; col++) {
+ int indx = (int) iMap->getPixel(iMap, col, row);
+ if (indx == colorIndex) {
+ gm->setPixel(gm, col, row, GRAYMAP_BLACK); //black
+ } else if (!multiScanStack) {
+ gm->setPixel(gm, col, row, GRAYMAP_WHITE); //white
+ }
+ }
+ }
- //### get style info
- char style[13];
- RGB rgb = iMap->clut[colorIndex];
- sprintf(style, "fill:#%02x%02x%02x", rgb.r, rgb.g, rgb.b);
+ //## Now we have a traceable graymap
+ long nodeCount;
+ std::string d = grayMapToPath(gm, &nodeCount);
- //g_message("### GOT '%s' \n", d);
- TracingEngineResult result(style, d, nodeCount);
- results.push_back(result);
+ if ( !d.empty() ) {
+ //### get style info
+ RGB rgb = iMap->clut[colorIndex];
+ ustring style = ustring::compose("fill:#%1%2%3", twohex(rgb.r), twohex(rgb.g), twohex(rgb.b) );
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (desktop)
- {
- gchar *msg = g_strdup_printf(_("Trace: %d. %ld nodes"), colorIndex, nodeCount);
- sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg);
- g_free(msg);
- }
+ //g_message("### GOT '%s' \n", style.c_str());
+ TracingEngineResult result(style, d, nodeCount);
+ results.push_back(result);
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop) {
+ ustring msg = ustring::compose(_("Trace: %1. %2 nodes"), colorIndex, nodeCount);
+ sp_desktop_message_stack(desktop)->flash(Inkscape::NORMAL_MESSAGE, msg);
+ }
+ }
+ }// for colorIndex
- }// for colorIndex
-
- gm->destroy(gm);
- iMap->destroy(iMap);
+ gm->destroy(gm);
+ iMap->destroy(iMap);
+ }
- //# Remove the bottom-most scan, if requested
- if (results.size() > 1 && multiScanRemoveBackground)
- {
- results.erase(results.end() - 1);
+ //# Remove the bottom-most scan, if requested
+ if (results.size() > 1 && multiScanRemoveBackground) {
+ results.erase(results.end() - 1);
}
+ }
return results;
}
@@ -667,3 +650,13 @@ PotraceTracingEngine::abort()
} // namespace Trace
} // namespace Inkscape
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/trace/potrace/inkscape-potrace.h b/src/trace/potrace/inkscape-potrace.h
index b32ab6461..5ed0c0e5a 100644
--- a/src/trace/potrace/inkscape-potrace.h
+++ b/src/trace/potrace/inkscape-potrace.h
@@ -286,3 +286,13 @@ class PotraceTracingEngine : public TracingEngine
#endif //__INKSCAPE_POTRACE_H__
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :