summaryrefslogtreecommitdiffstats
path: root/src/trace
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2010-08-06 08:24:52 +0000
committerJon A. Cruz <jon@joncruz.org>2010-08-06 08:24:52 +0000
commit1c308c014c19e9e92fd3de5421f016ae48457143 (patch)
treedc2b7df63a4c9f3781fed61dbe4274b6aa82eb29 /src/trace
parentTranslations. Galician translation update by Leandro Regueiro. (diff)
downloadinkscape-1c308c014c19e9e92fd3de5421f016ae48457143.tar.gz
inkscape-1c308c014c19e9e92fd3de5421f016ae48457143.zip
Corrects delete/delete[] issue. Fixes bug #613723.
Fixed bugs: - https://launchpad.net/bugs/613723 (bzr r9606.1.41)
Diffstat (limited to 'src/trace')
-rw-r--r--src/trace/quantize.cpp58
1 files changed, 31 insertions, 27 deletions
diff --git a/src/trace/quantize.cpp b/src/trace/quantize.cpp
index 8acfe0c34..2db1bbf34 100644
--- a/src/trace/quantize.cpp
+++ b/src/trace/quantize.cpp
@@ -545,44 +545,48 @@ IndexedMap *rgbMapQuantize(RgbMap *rgbmap, int ncolor)
assert(rgbmap);
assert(ncolor > 0);
+ IndexedMap *newmap = 0;
+
pool<Ocnode> pool;
- Ocnode *tree;
+ Ocnode *tree = 0;
try {
- tree = octreeBuild(&pool, rgbmap, ncolor);
+ tree = octreeBuild(&pool, rgbmap, ncolor);
}
- catch (std::bad_alloc& ex) {
- return NULL; //should do smthg else?
+ catch (std::bad_alloc &ex) {
+ //should do smthg else?
}
- RGB *rgbpal = new RGB[ncolor];
- int indexes = 0;
- octreeIndex(tree, rgbpal, &indexes);
-
- octreeDelete(&pool, tree);
+ if ( tree ) {
+ RGB *rgbpal = new RGB[ncolor];
+ int indexes = 0;
+ octreeIndex(tree, rgbpal, &indexes);
- // stacking with increasing contrasts
- qsort((void *)rgbpal, indexes, sizeof(RGB), compRGB);
+ octreeDelete(&pool, tree);
- // make the new map
- IndexedMap *newmap = IndexedMapCreate(rgbmap->width, rgbmap->height);
- if (!newmap) { delete rgbpal; return NULL; }
+ // stacking with increasing contrasts
+ qsort((void *)rgbpal, indexes, sizeof(RGB), compRGB);
- // fill in the color lookup table
- for (int i = 0; i < indexes; i++) newmap->clut[i] = rgbpal[i];
- newmap->nrColors = indexes;
-
- // fill in new map pixels
- for (int y = 0; y < rgbmap->height; y++)
- {
- for (int x = 0; x < rgbmap->width; x++)
- {
- RGB rgb = rgbmap->getPixel(rgbmap, x, y);
- int index = findRGB(rgbpal, ncolor, rgb);
- newmap->setPixel(newmap, x, y, index);
+ // make the new map
+ newmap = IndexedMapCreate(rgbmap->width, rgbmap->height);
+ if (newmap) {
+ // fill in the color lookup table
+ for (int i = 0; i < indexes; i++) {
+ newmap->clut[i] = rgbpal[i];
+ }
+ newmap->nrColors = indexes;
+
+ // fill in new map pixels
+ for (int y = 0; y < rgbmap->height; y++) {
+ for (int x = 0; x < rgbmap->width; x++) {
+ RGB rgb = rgbmap->getPixel(rgbmap, x, y);
+ int index = findRGB(rgbpal, ncolor, rgb);
+ newmap->setPixel(newmap, x, y, index);
+ }
}
}
+ delete[] rgbpal;
+ }
- delete rgbpal;
return newmap;
}