diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-03-27 01:33:44 +0000 |
| commit | 5a4fb2325f60d292b47330f540b26a3279341c90 (patch) | |
| tree | d2aa7967be25450b83e625025366c618101ae49f /src/trace | |
| parent | The Polar Arrange Tab of the Arrange Dialog now hides the parametric (diff) | |
| parent | Remove Snap menu item and improve grid menu item text (diff) | |
| download | inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.tar.gz inkscape-5a4fb2325f60d292b47330f540b26a3279341c90.zip | |
Commit a merge to trunk, with probabal errors
(bzr r11073.1.36)
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 | 81 | ||||
| -rw-r--r-- | src/trace/imagemap-gdk.h | 8 | ||||
| -rw-r--r-- | src/trace/imagemap.cpp | 82 | ||||
| -rw-r--r-- | src/trace/pool.h | 18 | ||||
| -rw-r--r-- | src/trace/quantize.cpp | 16 | ||||
| -rw-r--r-- | src/trace/siox.cpp | 21 | ||||
| -rw-r--r-- | src/trace/siox.h | 12 | ||||
| -rw-r--r-- | src/trace/trace.cpp | 29 | ||||
| -rw-r--r-- | src/trace/trace.h | 13 |
11 files changed, 107 insertions, 214 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..298414074 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 @@ -190,9 +152,9 @@ RgbMap *gdkPixbufToRgbMap(GdkPixbuf *buf) { int alpha = (int)p[3]; int white = 255 - alpha; - int r = (int)p[2]; r = r * alpha / 256 + white; + int r = (int)p[0]; r = r * alpha / 256 + white; int g = (int)p[1]; g = g * alpha / 256 + white; - int b = (int)p[0]; b = b * alpha / 256 + white; + int b = (int)p[2]; b = b * alpha / 256 + white; rgbMap->setPixel(rgbMap, x, y, r, g, b); p += n_channels; @@ -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/pool.h b/src/trace/pool.h index d072a460b..88fd82bcd 100644 --- a/src/trace/pool.h +++ b/src/trace/pool.h @@ -59,17 +59,21 @@ class pool { public: pool() - { + { cblock = 0; size = sizeof(T) > sizeof(void *) ? sizeof(T) : sizeof(void *); next = NULL; - } + for (int k = 0; k < 64; k++) { + block[k] = NULL; + } + } ~pool() - { - for (int k = 0; k < cblock; k++) - free(block[k]); - } + { + for (int k = 0; k < cblock; k++) { + free(block[k]); + } + } T *draw() { @@ -89,7 +93,7 @@ class pool { int size; int cblock; - void *block[64]; //enough to store unlimited number of objects + void *block[64]; //enough to store unlimited number of objects, if 64 is changed: see constructor too void *next; void addblock() 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..065e891ed 100644 --- a/src/trace/siox.cpp +++ b/src/trace/siox.cpp @@ -2,18 +2,8 @@ Copyright 2005, 2006 by Gerald Friedland, Kristian Jantz and Lars Knipping Conversion to C++ for Inkscape by Bob Jamison - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + + Released under GNU GPL, read the file 'COPYING' for more information */ #include "siox.h" @@ -21,6 +11,7 @@ #include <stdarg.h> #include <map> #include <algorithm> +#include <cstdlib> namespace org @@ -591,7 +582,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++) { @@ -898,7 +889,7 @@ SioxImage Siox::extractForeground(const SioxImage &originalImage, return workImage; } - trace("knownBg:%zu knownFg:%zu", knownBg.size(), knownFg.size()); + trace("knownBg:%u knownFg:%u", static_cast<unsigned int>(knownBg.size()), static_cast<unsigned int>(knownFg.size())); std::vector<CieLab> bgSignature ; @@ -933,7 +924,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/siox.h b/src/trace/siox.h index 9a44ce1cf..fa18ac238 100644 --- a/src/trace/siox.h +++ b/src/trace/siox.h @@ -5,17 +5,7 @@ * * Conversion to C++ for Inkscape by Bob Jamison * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Released under GNU GPL, read the file 'COPYING' for more information */ /* diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index cad8ea9be..cb83541e3 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -31,6 +31,7 @@ #include <2geom/transforms.h> #include "verbs.h" +#include "display/cairo-utils.h" #include "display/drawing.h" #include "display/drawing-shape.h" @@ -212,7 +213,7 @@ Glib::RefPtr<Gdk::Pixbuf> Tracer::sioxProcessImage(SPImage *img, Glib::RefPtr<Gd SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) { - g_warning(_("Trace: No active desktop")); + g_warning("%s", _("Trace: No active desktop")); return Glib::RefPtr<Gdk::Pixbuf>(NULL); } @@ -309,7 +310,7 @@ Glib::RefPtr<Gdk::Pixbuf> Tracer::sioxProcessImage(SPImage *img, Glib::RefPtr<Gd SioxImage result = sengine.extractForeground(simage, 0xffffff); if (!result.isValid()) { - g_warning(_("Invalid SIOX result")); + g_warning("%s", _("Invalid SIOX result")); return Glib::RefPtr<Gdk::Pixbuf>(NULL); } @@ -336,8 +337,17 @@ Glib::RefPtr<Gdk::Pixbuf> Tracer::getSelectedImage() if (!img->pixbuf) return Glib::RefPtr<Gdk::Pixbuf>(NULL); - Glib::RefPtr<Gdk::Pixbuf> pixbuf = - Glib::wrap(img->pixbuf, true); + GdkPixbuf *raw_pb = img->pixbuf->getPixbufRaw(false); + GdkPixbuf *trace_pb = gdk_pixbuf_copy(raw_pb); + if (img->pixbuf->pixelFormat() == Inkscape::Pixbuf::PF_CAIRO) { + convert_pixels_argb32_to_pixbuf( + gdk_pixbuf_get_pixels(trace_pb), + gdk_pixbuf_get_width(trace_pb), + gdk_pixbuf_get_height(trace_pb), + gdk_pixbuf_get_rowstride(trace_pb)); + } + + Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(trace_pb, false); if (sioxEnabled) { @@ -410,7 +420,16 @@ void Tracer::traceThread() return; } - Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(img->pixbuf, true); + GdkPixbuf *trace_pb = gdk_pixbuf_copy(img->pixbuf->getPixbufRaw(false)); + if (img->pixbuf->pixelFormat() == Inkscape::Pixbuf::PF_CAIRO) { + convert_pixels_argb32_to_pixbuf( + gdk_pixbuf_get_pixels(trace_pb), + gdk_pixbuf_get_width(trace_pb), + gdk_pixbuf_get_height(trace_pb), + gdk_pixbuf_get_rowstride(trace_pb)); + } + + Glib::RefPtr<Gdk::Pixbuf> pixbuf = Glib::wrap(trace_pb, false); pixbuf = sioxProcessImage(img, pixbuf); diff --git a/src/trace/trace.h b/src/trace/trace.h index f811f4891..662b2537e 100644 --- a/src/trace/trace.h +++ b/src/trace/trace.h @@ -26,7 +26,7 @@ #include <vector> #include <sp-shape.h> -struct SPImage; +class SPImage; class SPItem; namespace Inkscape { @@ -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); } |
