inkscape-potrace.cpp revision 82e32ab59627b2e384c7cc76265ca8b71b8c529f
/*
* This is the C++ glue between Inkscape and Potrace
*
* Authors:
* Bob Jamison <rjamison@titan.com>
*
* Copyright (C) 2004 Bob Jamison
*
* Released under GNU GPL, read the file 'COPYING' for more information
*
* Potrace, the wonderful tracer located at http://potrace.sourceforge.net,
* is provided by the generosity of Peter Selinger, to whom we are grateful.
*
*/
#include "trace/filterset.h"
#include "trace/imagemap-gdk.h"
#include <inkscape.h>
#include <desktop-handles.h>
#include "message-stack.h"
#include <sp-path.h>
#include <svg/stringstream.h>
#include "curve.h"
#include "bitmap.h"
#include "inkscape-potrace.h"
static void updateGui()
{
//## Allow the GUI to update
}
{
updateGui();
if (!userData)
return;
//g_message("progress: %f\n", progress);
//Inkscape::Trace::Potrace::PotraceTracingEngine *engine =
// (Inkscape::Trace::Potrace::PotraceTracingEngine *)userData;
}
//required by potrace
namespace Inkscape {
namespace Trace {
namespace Potrace {
/**
*
*/
{
//##### Our defaults
invert = false;
quantizationNrColors = 8;
brightnessThreshold = 0.45;
cannyHighThreshold = 0.65;
}
typedef struct
{
double x;
double y;
} Point;
/**
* Check a point against a list of points to see if it
* has already occurred.
*/
static bool
{
{
if (p.x == x && p.y == y)
return true;
}
return false;
}
/**
* Recursively descend the path_t node tree, writing paths in SVG
* format into the output stream. The Point vector is used to prevent
* redundant paths. Returns number of paths processed.
*/
static long
{
long nodeCount = 0L;
{
//g_message("node->fm:%d\n", node->fm);
if (!curve->n)
continue;
double x0 = 0.0;
double y0 = 0.0;
double x1 = 0.0;
double y1 = 0.0;
//Have we been here already?
{
//g_message("duplicate point: (%f,%f)\n", x2, y2);
continue;
}
else
{
Point p;
}
nodeCount++;
for (int i=0 ; i<curve->n ; i++)
{
return 0L;
{
case POTRACE_CORNER:
break;
case POTRACE_CURVETO:
break;
default:
break;
}
nodeCount++;
}
data << "z";
{
}
}
return nodeCount;
}
static GrayMap *
{
if (!pixbuf)
return NULL;
/*### Color quantization -- banding ###*/
{
//rgbMap->writePPM(rgbMap, "rgb.ppm");
//return newGm;
}
/*### Brightness threshold ###*/
{
double floor = 3.0 *
double cutoff = 3.0 *
{
{
else
}
}
//newGm->writePPM(newGm, "brightness.ppm");
//return newGm;
}
/*### Canny edge detection ###*/
{
//newGm->writePPM(newGm, "canny.ppm");
//return newGm;
}
/*### Do I invert the image? ###*/
{
{
{
}
}
}
return newGm;//none of the above
}
static IndexedMap *
{
if (!pixbuf)
return NULL;
/*### Color quant multiscan ###*/
{
if (engine.getMultiScanSmooth())
{
}
else
{
}
}
/*### Quant multiscan ###*/
{
if (engine.getMultiScanSmooth())
{
}
else
{
}
//Turn to grays
{
}
}
return newGm;
}
{
if ( traceType == TRACE_QUANT_COLOR ||
{
if (!gm)
return NULL;
return newBuf;
}
else
{
if (!gm)
return NULL;
return newBuf;
}
}
//*This is the core inkscape-to-potrace binding
{
/* get default parameters */
bm_clear(potraceBitmap, 0);
//##Read the data out of the GrayMap
{
{
BM_UPUT(potraceBitmap, x, y,
}
}
//##Debug
/*
FILE *f = fopen("poimage.pbm", "wb");
bm_writepbm(f, bm);
fclose(f);
*/
if (!keepGoing)
{
g_warning("aborted");
return NULL;
}
/* trace a bitmap*/
//## Free the Potrace bitmap
if (!keepGoing)
{
g_warning("aborted");
return NULL;
}
data << "";
//## copy the path information into our d="" attribute string
/* free a potrace items */
if (!keepGoing)
return NULL;
if ( nodeCount)
return d;
}
/**
* This is called for a single scan
*/
{
if (!thePixbuf)
return NULL;
if (!grayMap)
return NULL;
long nodeCount;
if (!d)
{
*nrPaths = 0;
return NULL;
}
char *style = "fill:#000000";
//g_message("### GOT '%s' \n", d);
free(d);
*nrPaths = 1;
return result;
}
/**
* Called for multiple-scanning algorithms
*/
{
if (!thePixbuf)
return NULL;
int traceCount = 0;
for ( brightnessThreshold = low ;
brightnessThreshold <= high ;
{
if (!grayMap)
return NULL;
long nodeCount;
if (!d)
{
*nrPaths = 0;
return NULL;
}
char style[31];
//g_message("### GOT '%s' \n", d);
free(d);
if (!results)
{
}
else
{
//walk to end of list
{}
}
if (!multiScanStack)
if (desktop)
{
}
}
//report the count of paths processed
return results;
}
/**
* Quantization
*/
{
if (!thePixbuf)
return NULL;
if (!iMap)
return NULL;
//Create and clear a gray map
{
/*Make a gray map for each color index */
{
{
if (indx == colorIndex)
{
}
else
{
if (!multiScanStack)
}
}
}
//## Now we have a traceable graymap
long nodeCount;
if (!d)
{
*nrPaths = 0;
return NULL;
}
//### get style info
char style[13];
//g_message("### GOT '%s' \n", d);
free(d);
if (!results)
{
}
else
{
//prepend
/*
result->next = results;
results = result;
*/
//append
{}
}
if (desktop)
{
}
}
//report the count of paths processed
return results;
}
/**
* This is the working method of this interface, and all
* implementing classes. Take a GdkPixbuf, trace it, and
* return the path data that is compatible with the d="" attribute
* of an SVG <path> element.
*/
{
//Set up for messages
keepGoing = 1;
if ( traceType == TRACE_QUANT_COLOR ||
{
}
else if ( traceType == TRACE_BRIGHTNESS_MULTI )
{
}
else
{
}
}
/**
* Abort the thread that is executing getPathDataFromPixbuf()
*/
void
{
//g_message("PotraceTracingEngine::abort()\n");
keepGoing = 0;
}
} // namespace Potrace
} // namespace Trace
} // namespace Inkscape