diff options
| author | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2013-03-29 23:52:42 +0000 |
| commit | a168040d5a452544328a1e6ad35aaac351f94d44 (patch) | |
| tree | fae1ba829f543a473da281bd5fa6e4deabbf6912 /src/trace | |
| parent | Removed function pointers from SPObject and subclasses. (diff) | |
| parent | Dutch translation update (diff) | |
| download | inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.tar.gz inkscape-a168040d5a452544328a1e6ad35aaac351f94d44.zip | |
merged from trunk
(bzr r11608.1.56)
Diffstat (limited to 'src/trace')
| -rw-r--r-- | src/trace/filterset.cpp | 35 | ||||
| -rw-r--r-- | src/trace/filterset.h | 6 | ||||
| -rw-r--r-- | src/trace/imagemap-gdk.cpp | 77 | ||||
| -rw-r--r-- | src/trace/imagemap-gdk.h | 8 | ||||
| -rw-r--r-- | src/trace/imagemap.cpp | 82 | ||||
| -rw-r--r-- | src/trace/quantize.cpp | 16 | ||||
| -rw-r--r-- | src/trace/siox.cpp | 4 | ||||
| -rw-r--r-- | src/trace/trace.h | 11 |
8 files changed, 64 insertions, 175 deletions
diff --git a/src/trace/filterset.cpp b/src/trace/filterset.cpp index 908985225..f6c025956 100644 --- a/src/trace/filterset.cpp +++ b/src/trace/filterset.cpp @@ -365,41 +365,6 @@ grayMapCanny(GrayMap *gm, double lowThreshold, double highThreshold) - - - - -/** - * - */ -GdkPixbuf * -gdkCanny(GdkPixbuf *img, double lowThreshold, double highThreshold) -{ - if (!img) - return NULL; - - - GrayMap *grayMap = gdkPixbufToGrayMap(img); - if (!grayMap) - return NULL; - - /*grayMap->writePPM(grayMap, "gbefore.ppm");*/ - - GrayMap *cannyGm = grayMapCanny(grayMap,lowThreshold, highThreshold); - - grayMap->destroy(grayMap); - - if (!cannyGm) - return NULL; - - /*grayMap->writePPM(grayMap, "gafter.ppm");*/ - - GdkPixbuf *newImg = grayMapToGdkPixbuf(cannyGm); - - - return newImg; -} - /*######################################################################### ### Q U A N T I Z A T I O N #########################################################################*/ diff --git a/src/trace/filterset.h b/src/trace/filterset.h index eeafc079f..820d225c3 100644 --- a/src/trace/filterset.h +++ b/src/trace/filterset.h @@ -40,12 +40,6 @@ GrayMap *grayMapCanny(GrayMap *gmap, /** * */ -GdkPixbuf *gdkCanny(GdkPixbuf *img, - double lowThreshold, double highThreshold); - -/** - * - */ GrayMap *quantizeBand(RgbMap *rgbmap, int nrColors); diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index e5ff23ad0..7c7139002 100644 --- a/src/trace/imagemap-gdk.cpp +++ b/src/trace/imagemap-gdk.cpp @@ -58,7 +58,7 @@ GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, grayMap->width, grayMap->height, - rowstride, NULL, NULL); + rowstride, (GdkPixbufDestroyNotify)g_free, NULL); //### Fill in the odd cells with RGB values int x,y; @@ -122,44 +122,6 @@ PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf) return ppMap; } -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) -{ - if (!ppMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * ppMap->width * ppMap->height * 3); - if (!pixdata) - return NULL; - - int n_channels = 3; - int rowstride = ppMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, ppMap->width, ppMap->height, - rowstride, NULL, NULL); - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; y<ppMap->height ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; x<ppMap->width ; x++) - { - unsigned long rgb = ppMap->getPixel(ppMap, x, y); - p[0] = (rgb >> 16) & 0xff; - p[1] = (rgb >> 8) & 0xff; - p[2] = (rgb ) & 0xff; - p += n_channels; - } - row += rowstride; - } - - return buf; -} - - /*######################################################################### ## R G B M A P @@ -203,42 +165,7 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) return rgbMap; } -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) -{ - if (!rgbMap) - return NULL; - - guchar *pixdata = (guchar *) - malloc(sizeof(guchar) * rgbMap->width * rgbMap->height * 3); - if (!pixdata) - return NULL; - int n_channels = 3; - int rowstride = rgbMap->width * 3; - - GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, - 0, 8, rgbMap->width, rgbMap->height, - rowstride, NULL, NULL); - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; y<rgbMap->height ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; x<rgbMap->width ; x++) - { - RGB rgb = rgbMap->getPixel(rgbMap, x, y); - p[0] = rgb.r & 0xff; - p[1] = rgb.g & 0xff; - p[2] = rgb.b & 0xff; - p += n_channels; - } - row += rowstride; - } - - return buf; -} /*######################################################################### ## I N D E X E D M A P @@ -260,7 +187,7 @@ GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, iMap->width, iMap->height, - rowstride, NULL, NULL); + rowstride, (GdkPixbufDestroyNotify)g_free, NULL); //### Fill in the cells with RGB values int x,y; diff --git a/src/trace/imagemap-gdk.h b/src/trace/imagemap-gdk.h index d04a84d8e..63281658a 100644 --- a/src/trace/imagemap-gdk.h +++ b/src/trace/imagemap-gdk.h @@ -24,17 +24,9 @@ extern "C" { #endif GrayMap *gdkPixbufToGrayMap(GdkPixbuf *buf); - GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap); - PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf); - -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); - RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf); - -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); - GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap); diff --git a/src/trace/imagemap.cpp b/src/trace/imagemap.cpp index c5a6bc2b5..a8d8a8c8f 100644 --- a/src/trace/imagemap.cpp +++ b/src/trace/imagemap.cpp @@ -192,16 +192,18 @@ PackedPixelMap *PackedPixelMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (unsigned long *) - malloc(sizeof(unsigned long) * width * height); - me->rows = (unsigned long **) - malloc(sizeof(unsigned long *) * height); - if (!me->pixels) - { + me->pixels = (unsigned long *) malloc(sizeof(unsigned long) * width * height); + if (!me->pixels){ free(me); return NULL; - } - + } + me->rows = (unsigned long **) malloc(sizeof(unsigned long *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } + unsigned long *row = me->pixels; for (int i=0 ; i<height ; i++) { @@ -270,10 +272,12 @@ static int rWritePPM(RgbMap *me, char *fileName) static void rDestroy(RgbMap *me) { - if (me->pixels) + if (me->pixels){ free(me->pixels); - if (me->rows) + } + if (me->rows){ free(me->rows); + } free(me); } @@ -283,9 +287,10 @@ RgbMap *RgbMapCreate(int width, int height) { RgbMap *me = (RgbMap *)malloc(sizeof(RgbMap)); - if (!me) + if (!me){ return NULL; - + } + /** methods **/ me->setPixel = rSetPixel; me->setPixelRGB = rSetPixelRGB; @@ -297,22 +302,23 @@ RgbMap *RgbMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (RGB *) - malloc(sizeof(RGB) * width * height); - me->rows = (RGB **) - malloc(sizeof(RGB *) * height); - if (!me->pixels) - { + me->pixels = (RGB *) malloc(sizeof(RGB) * width * height); + if (!me->pixels){ free(me); return NULL; - } + } + me->rows = (RGB **) malloc(sizeof(RGB *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } RGB *row = me->pixels; - for (int i=0 ; i<height ; i++) - { + for (int i=0 ; i<height ; i++){ me->rows[i] = row; row += width; - } + } return me; } @@ -376,10 +382,12 @@ static int iWritePPM(IndexedMap *me, char *fileName) static void iDestroy(IndexedMap *me) { - if (me->pixels) + if (me->pixels){ free(me->pixels); - if (me->rows) + } + if (me->rows){ free(me->rows); + } free(me); } @@ -403,31 +411,31 @@ IndexedMap *IndexedMapCreate(int width, int height) /** fields **/ me->width = width; me->height = height; - me->pixels = (unsigned int *) - malloc(sizeof(unsigned int) * width * height); - me->rows = (unsigned int **) - malloc(sizeof(unsigned int *) * height); - if (!me->pixels) - { + me->pixels = (unsigned int *) malloc(sizeof(unsigned int) * width * height); + if (!me->pixels){ free(me); return NULL; - } + } + me->rows = (unsigned int **) malloc(sizeof(unsigned int *) * height); + if (!me->rows){ + free(me->pixels); //allocated as me->pixels is not NULL here: see previous check + free(me); + return NULL; + } unsigned int *row = me->pixels; - for (int i=0 ; i<height ; i++) - { + for (int i=0 ; i<height ; i++){ me->rows[i] = row; row += width; - } + } me->nrColors = 0; RGB rgb; rgb.r = rgb.g = rgb.b = 0; - for (int i=0; i<256 ; i++) - { + for (int i=0; i<256 ; i++){ me->clut[i] = rgb; - } + } return me; } diff --git a/src/trace/quantize.cpp b/src/trace/quantize.cpp index 2db1bbf34..c386c0ee9 100644 --- a/src/trace/quantize.cpp +++ b/src/trace/quantize.cpp @@ -16,6 +16,7 @@ #include "pool.h" #include "imagemap.h" +#include "quantize.h" typedef struct Ocnode_def Ocnode; @@ -191,6 +192,7 @@ static void octreeDelete(pool<Ocnode> *pool, Ocnode *node) /** * pretty-print an octree, debugging purposes */ +#if 0 static void ocnodePrint(Ocnode *node, int indent) { if (!node) return; @@ -211,16 +213,18 @@ static void ocnodePrint(Ocnode *node, int indent) ocnodePrint(node->child[i], indent+2); } } + void octreePrint(Ocnode *node) { printf("<<octree>>\n"); if (node) printf("[r:%p] ", node); ocnodePrint(node, 2); } +#endif /** * builds a single <rgb> color leaf at location <ref> */ -void ocnodeLeaf(pool<Ocnode> *pool, Ocnode **ref, RGB rgb) +static void ocnodeLeaf(pool<Ocnode> *pool, Ocnode **ref, RGB rgb) { assert(ref); Ocnode *node = ocnodeNew(pool); @@ -237,7 +241,7 @@ void ocnodeLeaf(pool<Ocnode> *pool, Ocnode **ref, RGB rgb) /** * merge nodes <node1> and <node2> at location <ref> with parent <parent> */ -int octreeMerge(pool<Ocnode> *pool, Ocnode *parent, Ocnode **ref, Ocnode *node1, Ocnode *node2) +static int octreeMerge(pool<Ocnode> *pool, Ocnode *parent, Ocnode **ref, Ocnode *node1, Ocnode *node2) { assert(ref); if (!node1 && !node2) return 0; @@ -415,7 +419,7 @@ static void ocnodeStrip(pool<Ocnode> *pool, Ocnode **ref, int *count, unsigned l /** * reduce the leaves of an octree to a given number */ -void octreePrune(pool<Ocnode> *pool, Ocnode **ref, int ncolor) +static void octreePrune(pool<Ocnode> *pool, Ocnode **ref, int ncolor) { assert(ref); assert(ncolor > 0); @@ -435,8 +439,8 @@ void octreePrune(pool<Ocnode> *pool, Ocnode **ref, int ncolor) * build an octree associated to the area of a color map <rgbmap>, * included in the specified (x1,y1)--(x2,y2) rectangle. */ -void octreeBuildArea(pool<Ocnode> *pool, RgbMap *rgbmap, Ocnode **ref, - int x1, int y1, int x2, int y2, int ncolor) +static void octreeBuildArea(pool<Ocnode> *pool, RgbMap *rgbmap, Ocnode **ref, + int x1, int y1, int x2, int y2, int ncolor) { int dx = x2 - x1, dy = y2 - y1; int xm = x1 + dx/2, ym = y1 + dy/2; @@ -465,7 +469,7 @@ void octreeBuildArea(pool<Ocnode> *pool, RgbMap *rgbmap, Ocnode **ref, * build an octree associated to the <rgbmap> color map, * pruned to <ncolor> colors. */ -Ocnode *octreeBuild(pool<Ocnode> *pool, RgbMap *rgbmap, int ncolor) +static Ocnode *octreeBuild(pool<Ocnode> *pool, RgbMap *rgbmap, int ncolor) { //create the octree Ocnode *node = NULL; diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp index 9376fad66..1a1426b83 100644 --- a/src/trace/siox.cpp +++ b/src/trace/siox.cpp @@ -591,7 +591,7 @@ bool SioxImage::writePPM(const std::string &fileName) if (!f) return false; - fprintf(f, "P6 %d %d 255\n", width, height); + fprintf(f, "P6 %u %u 255\n", width, height); for (unsigned int y=0 ; y<height; y++) { @@ -933,7 +933,7 @@ SioxImage Siox::extractForeground(const SioxImage &originalImage, //trace("### bgSignature:%d", bgSignature.size()); - if (bgSignature.size() < 1) + if (bgSignature.empty()) { // segmentation impossible error("Signature size is < 1. Segmentation is impossible"); diff --git a/src/trace/trace.h b/src/trace/trace.h index f811f4891..9f9f44b14 100644 --- a/src/trace/trace.h +++ b/src/trace/trace.h @@ -48,12 +48,11 @@ public: */ TracingEngineResult(const std::string &theStyle, const std::string &thePathData, - long theNodeCount) - { - style = theStyle; - pathData = thePathData; - nodeCount = theNodeCount; - } + long theNodeCount) : + style(theStyle), + pathData(thePathData), + nodeCount(theNodeCount) + {} TracingEngineResult(const TracingEngineResult &other) { assign(other); } |
