From aca1914d674a5e81234208248e3c8515a60dd19d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Oct 2012 12:30:12 +1000 Subject: code cleanup: make more functions static, add includes. (bzr r11737) --- src/trace/quantize.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/trace') diff --git a/src/trace/quantize.cpp b/src/trace/quantize.cpp index 2db1bbf34..ba9306da8 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; @@ -211,16 +212,19 @@ static void ocnodePrint(Ocnode *node, int indent) ocnodePrint(node->child[i], indent+2); } } + +#if 0 void octreePrint(Ocnode *node) { printf("<>\n"); if (node) printf("[r:%p] ", node); ocnodePrint(node, 2); } +#endif /** * builds a single color leaf at location */ -void ocnodeLeaf(pool *pool, Ocnode **ref, RGB rgb) +static void ocnodeLeaf(pool *pool, Ocnode **ref, RGB rgb) { assert(ref); Ocnode *node = ocnodeNew(pool); @@ -237,7 +241,7 @@ void ocnodeLeaf(pool *pool, Ocnode **ref, RGB rgb) /** * merge nodes and at location with parent */ -int octreeMerge(pool *pool, Ocnode *parent, Ocnode **ref, Ocnode *node1, Ocnode *node2) +static int octreeMerge(pool *pool, Ocnode *parent, Ocnode **ref, Ocnode *node1, Ocnode *node2) { assert(ref); if (!node1 && !node2) return 0; @@ -415,7 +419,7 @@ static void ocnodeStrip(pool *pool, Ocnode **ref, int *count, unsigned l /** * reduce the leaves of an octree to a given number */ -void octreePrune(pool *pool, Ocnode **ref, int ncolor) +static void octreePrune(pool *pool, Ocnode **ref, int ncolor) { assert(ref); assert(ncolor > 0); @@ -435,8 +439,8 @@ void octreePrune(pool *pool, Ocnode **ref, int ncolor) * build an octree associated to the area of a color map , * included in the specified (x1,y1)--(x2,y2) rectangle. */ -void octreeBuildArea(pool *pool, RgbMap *rgbmap, Ocnode **ref, - int x1, int y1, int x2, int y2, int ncolor) +static void octreeBuildArea(pool *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 *pool, RgbMap *rgbmap, Ocnode **ref, * build an octree associated to the color map, * pruned to colors. */ -Ocnode *octreeBuild(pool *pool, RgbMap *rgbmap, int ncolor) +static Ocnode *octreeBuild(pool *pool, RgbMap *rgbmap, int ncolor) { //create the octree Ocnode *node = NULL; -- cgit v1.2.3 From 15f08c37a261583b138f9cbecd6c271921f4e514 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 15 Nov 2012 11:42:04 +0000 Subject: cppcheck: Simple fixes for src/ui/dialog (bzr r11874) --- src/trace/trace.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/trace') 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); } -- cgit v1.2.3 From 8fedd906a88ff12dc3bc425d710db39a40b5d2ca Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 20 Jan 2013 17:54:58 +0100 Subject: Fixed memory leaks (bzr r12050) --- src/trace/imagemap.cpp | 82 +++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 37 deletions(-) (limited to 'src/trace') 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 ; ipixels) + 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 ; irows[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 ; irows[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; } -- cgit v1.2.3 From a695510ee8752fee48b98f7b4177115876a0a3a6 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 23 Jan 2013 22:18:32 +0100 Subject: fix Memory leak in bitmap trace (Bug #996695) (bzr r12057) --- src/trace/imagemap-gdk.cpp | 14 ++++++++------ src/trace/imagemap-gdk.h | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src/trace') diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index e5ff23ad0..06f355de7 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,7 +122,7 @@ PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf) return ppMap; } -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) +/*GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) { if (!ppMap) return NULL; @@ -137,7 +137,7 @@ GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, ppMap->width, ppMap->height, - rowstride, NULL, NULL); + rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? //### Fill in the cells with RGB values int x,y; @@ -158,7 +158,7 @@ GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap) return buf; } - +*/ /*######################################################################### @@ -203,6 +203,7 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) return rgbMap; } +/* GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) { if (!rgbMap) @@ -218,7 +219,7 @@ GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) GdkPixbuf *buf = gdk_pixbuf_new_from_data(pixdata, GDK_COLORSPACE_RGB, 0, 8, rgbMap->width, rgbMap->height, - rowstride, NULL, NULL); + rowstride, NULL, NULL); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? //### Fill in the cells with RGB values int x,y; @@ -239,6 +240,7 @@ GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap) return buf; } +*/ /*######################################################################### ## I N D E X E D M A P @@ -260,7 +262,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..3b4631f50 100644 --- a/src/trace/imagemap-gdk.h +++ b/src/trace/imagemap-gdk.h @@ -29,11 +29,11 @@ GdkPixbuf *grayMapToGdkPixbuf(GrayMap *grayMap); PackedPixelMap *gdkPixbufToPackedPixelMap(GdkPixbuf *buf); -GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); +//GdkPixbuf *packedPixelMapToGdkPixbuf(PackedPixelMap *ppMap); RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf); -GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); +//GdkPixbuf *rgbMapToGdkPixbuf(RgbMap *rgbMap); GdkPixbuf *indexedMapToGdkPixbuf(IndexedMap *iMap); -- cgit v1.2.3 From 1d66df63a0263476b774fe9fe4854afea60489f2 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Wed, 30 Jan 2013 18:24:39 +0100 Subject: removing some more unused functions (bzr r12076) --- src/trace/filterset.cpp | 35 ---------------------- src/trace/filterset.h | 6 ---- src/trace/imagemap-gdk.cpp | 75 ---------------------------------------------- src/trace/imagemap-gdk.h | 8 ----- 4 files changed, 124 deletions(-) (limited to 'src/trace') 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 @@ -37,12 +37,6 @@ RgbMap *rgbMapGaussian(RgbMap *rgbmap); GrayMap *grayMapCanny(GrayMap *gmap, double lowThreshold, double highThreshold); -/** - * - */ -GdkPixbuf *gdkCanny(GdkPixbuf *img, - double lowThreshold, double highThreshold); - /** * */ diff --git a/src/trace/imagemap-gdk.cpp b/src/trace/imagemap-gdk.cpp index 06f355de7..7c7139002 100644 --- a/src/trace/imagemap-gdk.cpp +++ b/src/trace/imagemap-gdk.cpp @@ -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); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; 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,44 +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); //first NULL: replace by (GdkPixbufDestroyNotify)g_free ?? - - //### Fill in the cells with RGB values - int x,y; - int row = 0; - for (y=0 ; yheight ; y++) - { - guchar *p = pixdata + row; - for (x=0 ; xwidth ; 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 diff --git a/src/trace/imagemap-gdk.h b/src/trace/imagemap-gdk.h index 3b4631f50..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); -- cgit v1.2.3 From f6c82a02188953dcb6d2119123ffc0aaa8d35010 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 16 Mar 2013 20:42:47 +0100 Subject: cppcheck (bzr r12217) --- src/trace/siox.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/trace') 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 Date: Mon, 18 Mar 2013 13:07:58 +0000 Subject: Drop remaining unused functions (bzr r12224) --- src/trace/quantize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/trace') diff --git a/src/trace/quantize.cpp b/src/trace/quantize.cpp index ba9306da8..c386c0ee9 100644 --- a/src/trace/quantize.cpp +++ b/src/trace/quantize.cpp @@ -192,6 +192,7 @@ static void octreeDelete(pool *pool, Ocnode *node) /** * pretty-print an octree, debugging purposes */ +#if 0 static void ocnodePrint(Ocnode *node, int indent) { if (!node) return; @@ -213,7 +214,6 @@ static void ocnodePrint(Ocnode *node, int indent) } } -#if 0 void octreePrint(Ocnode *node) { printf("<>\n"); -- cgit v1.2.3