diff --git a/rtengine/calc_distort.cc b/rtengine/calc_distort.cc index 80d61d654..7af47adb2 100644 --- a/rtengine/calc_distort.cc +++ b/rtengine/calc_distort.cc @@ -102,6 +102,9 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow if (n < 5) { printf ("Not sufficient features.\n"); distortion = 0.0; + KLTFreeFeatureTable(ft); + KLTFreeFeatureList(fl); + KLTFreeTrackingContext(tc); return -1; } @@ -154,6 +157,9 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow if (new_n < 5) { printf ("Not sufficient features.\n"); distortion = 0.0; + KLTFreeFeatureTable(ft); + KLTFreeFeatureList(fl); + KLTFreeTrackingContext(tc); return -1; } @@ -252,17 +258,27 @@ int calcDistortion(unsigned char* img1, unsigned char* img2, int ncols, int nrow if (total_delta / new_n > DELTA_2) { printf ("Deviation is too big.\n"); distortion = 0.0; + KLTFreeFeatureTable(ft); + KLTFreeFeatureList(fl); + KLTFreeTrackingContext(tc); return -2; } if (rxy < RXY_LIMIT) { printf ("Not linear enough\n"); distortion = 0.0; + KLTFreeFeatureTable(ft); + KLTFreeFeatureList(fl); + KLTFreeTrackingContext(tc); return -3; } printf ("distortion amount=%lf scale=%lf deviation=%lf, rxy=%lf\n", a, b, total_delta / n, rxy); distortion = a; + + KLTFreeFeatureTable(ft); + KLTFreeFeatureList(fl); + KLTFreeTrackingContext(tc); return 1; } diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 028e55a33..3a4134dc5 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -89,7 +89,7 @@ class ImProcFunctions } double rd, gd, bd; - double yr[4], yg[4], yb[4]; + double yr[4] = {0.0}, yg[4] = {0.0}, yb[4] = {0.0}; for (int k = ys, kx = 0; k < ys + 4; k++, kx++) { rd = gd = bd = 0.0; diff --git a/rtengine/lcp.cc b/rtengine/lcp.cc index e198948ba..ca1ab8405 100644 --- a/rtengine/lcp.cc +++ b/rtengine/lcp.cc @@ -172,7 +172,7 @@ void LCPPersModel::print() const // if !vignette then geometric and CA LCPMapper::LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP, - int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg) + int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg) :useCADist(false), swapXY(false), isFisheye(false), enableCA(false) { if (pProf == nullptr) { return; @@ -388,18 +388,20 @@ LCPProfile::LCPProfile(const Glib::ustring &fname) FILE *pFile = g_fopen(fname.c_str (), "rb"); - bool done; + if(pFile) { + bool done; - do { - int bytesRead = (int)fread(buf, 1, BufferSize, pFile); - done = feof(pFile); + do { + int bytesRead = (int)fread(buf, 1, BufferSize, pFile); + done = feof(pFile); - if (XML_Parse(parser, buf, bytesRead, done) == XML_STATUS_ERROR) { - throw "Invalid XML in LCP file"; - } - } while (!done); + if (XML_Parse(parser, buf, bytesRead, done) == XML_STATUS_ERROR) { + throw "Invalid XML in LCP file"; + } + } while (!done); - fclose(pFile); + fclose(pFile); + } XML_ParserFree(parser); @@ -736,7 +738,7 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons nameStart++; } - strcpy(pProf->lastTag, nameStart); + strncpy(pProf->lastTag, nameStart, 255); pProf->handle_text(attr[i+1]); //XmlTextHandler(pLCPProfile, attr[i + 1], strlen(attr[i + 1])); diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index e200ba610..b0622c093 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -768,6 +768,8 @@ void WaveletParams::setDefaults() for(int i = 0; i < 9; i ++) { ch[i] = 0; } + greenlow = greenmed = greenhigh = 0.0; + bluelow = bluemed = bluehigh = 0.0; } @@ -832,6 +834,7 @@ void DirPyrDenoiseParams::setDefaults() redchro = 0; bluechro = 0; gamma = 1.7; + perform = false; } void DirPyrDenoiseParams::getCurves(NoiseCurve &lCurve, NoiseCurve &cCurve) const diff --git a/rtengine/utils.cc b/rtengine/utils.cc index c9bce803d..4ab5bc1b8 100644 --- a/rtengine/utils.cc +++ b/rtengine/utils.cc @@ -189,34 +189,38 @@ void rotate(unsigned char* img, int& w, int& h, int deg) void hflip(unsigned char* img, int w, int h) { - unsigned char* flipped = new unsigned char[3 * w * h]; - int ix = 0; + if(w > 0 && h > 0) { + unsigned char* flipped = new unsigned char[3 * w * h]; + int ix = 0; - for (int i = 0; i < h; i++) - for (int j = 0; j < w; j++) { - flipped[3 * (w * i + w - 1 - j) + 0] = img[ix++]; - flipped[3 * (w * i + w - 1 - j) + 1] = img[ix++]; - flipped[3 * (w * i + w - 1 - j) + 2] = img[ix++]; - } + for (int i = 0; i < h; i++) + for (int j = 0; j < w; j++) { + flipped[3 * (w * i + w - 1 - j) + 0] = img[ix++]; + flipped[3 * (w * i + w - 1 - j) + 1] = img[ix++]; + flipped[3 * (w * i + w - 1 - j) + 2] = img[ix++]; + } - memcpy(img, flipped, 3 * w * h); - delete[] flipped; + memcpy(img, flipped, 3 * w * h); + delete[] flipped; + } } void vflip(unsigned char* img, int w, int h) { - unsigned char* flipped = new unsigned char[3 * w * h]; - int ix = 0; + if(w > 0 && h > 0) { + unsigned char* flipped = new unsigned char[3 * w * h]; + int ix = 0; - for (int i = 0; i < h; i++) - for (int j = 0; j < w; j++) { - flipped[3 * (w * (h - 1 - i) + j) + 0] = img[ix++]; - flipped[3 * (w * (h - 1 - i) + j) + 1] = img[ix++]; - flipped[3 * (w * (h - 1 - i) + j) + 2] = img[ix++]; - } + for (int i = 0; i < h; i++) + for (int j = 0; j < w; j++) { + flipped[3 * (w * (h - 1 - i) + j) + 0] = img[ix++]; + flipped[3 * (w * (h - 1 - i) + j) + 1] = img[ix++]; + flipped[3 * (w * (h - 1 - i) + j) + 2] = img[ix++]; + } - memcpy(img, flipped, 3 * w * h); - delete[] flipped; + memcpy(img, flipped, 3 * w * h); + delete[] flipped; + } } Glib::ustring getFileExtension(const Glib::ustring& filename) diff --git a/rtexif/rtexif.cc b/rtexif/rtexif.cc index dcfc60d0b..b67a64994 100644 --- a/rtexif/rtexif.cc +++ b/rtexif/rtexif.cc @@ -780,6 +780,7 @@ Tag::Tag (TagDirectory* p, FILE* f, int base) // (only a small part of it will actually be parsed though) if ((int)type < 1 || (int)type > 14 || count > 10 * 1024 * 1024) { type = INVALID; + valuesize = 0; return; } @@ -1346,7 +1347,9 @@ void Tag::fromString (const char* v, int size) value = new unsigned char [valuesize]; } - memcpy ((char*)value, v, valuesize); + if(value) { + memcpy ((char*)value, v, valuesize); + } } int Tag::toInt (int ofs, TagType astype) @@ -1450,7 +1453,6 @@ double Tag::toDouble (int ofs) return 0.; // Quick fix for missing cases (INVALID, DOUBLE, OLYUNDEF, SUBDIR) } - return 0.; } /** @@ -1655,17 +1657,15 @@ int Tag::calculateSize () if (j > 1) { size += 4 * j; } + if (makerNoteKind != NOMK) { + count = directory[0]->calculateSize () / getTypeSize (type); + } } else if (valuesize > 4) { size += valuesize + (valuesize % 2); // we align tags to even byte positions } - if (makerNoteKind != NOMK) { - count = directory[0]->calculateSize () / getTypeSize (type); - } - if (makerNoteKind == NIKON3 || makerNoteKind == OLYMPUS2 || makerNoteKind == FUJI) { - size += valuesize; - } else if (makerNoteKind == HEADERIFD) { + if (makerNoteKind == NIKON3 || makerNoteKind == OLYMPUS2 || makerNoteKind == FUJI || makerNoteKind == HEADERIFD) { size += valuesize; } @@ -1913,14 +1913,19 @@ TagDirectory* ExifManager::parseCIFF (FILE* f, int base, int length) Tag* ExifManager::saveCIFFMNTag (FILE* f, TagDirectory* root, int len, const char* name) { int s = ftell (f); - char* data = new char [len]; - fread (data, len, 1, f); - TagDirectory* mn = root->getTag ("Exif")->getDirectory()->getTag ("MakerNote")->getDirectory(); - Tag* cs = new Tag (mn, lookupAttrib (canonAttribs, name)); - cs->initUndefArray (data, len); - mn->addTag (cs); - fseek (f, s, SEEK_SET); - return cs; + if(s >= 0) { + char* data = new char [len]; + fread (data, len, 1, f); + TagDirectory* mn = root->getTag ("Exif")->getDirectory()->getTag ("MakerNote")->getDirectory(); + Tag* cs = new Tag (mn, lookupAttrib (canonAttribs, name)); + cs->initUndefArray (data, len); + mn->addTag (cs); + fseek (f, s, SEEK_SET); + delete [] data; + return cs; + } else { + return nullptr; + } } void ExifManager::parseCIFF (FILE* f, int base, int length, TagDirectory* root) @@ -2500,6 +2505,8 @@ parse_leafdata (TagDirectory* root, ByteOrder order) if (*p1 != '\0') { t->initInt (atoi (p1), LONG); exif->getDirectory()->addTagFront (t); + } else { + delete t; } } else if (strcmp (tag, "DateTimeOriginal") == 0 && sscanf (val, "%d-%d-%dT%d:%d:%dZ", diff --git a/rtgui/adjuster.cc b/rtgui/adjuster.cc index 2e08e3129..a4f57499d 100644 --- a/rtgui/adjuster.cc +++ b/rtgui/adjuster.cc @@ -588,38 +588,23 @@ void Adjuster::editedToggled () eventPending = false; } -double Adjuster::trimValue (double val) +void Adjuster::trimValue (double &val) { - if (val > vMax) { - val = vMax; // shapeValue(vMax) ? - } else if (val < vMin) { - val = vMin; // shapeValue(vMin) ? - } + val = rtengine::LIM(val, vMin, vMax); - return val; } -int Adjuster::trimValue (int val) +void Adjuster::trimValue (int &val) { - if (val > (int)vMax) { - val = (int)vMax; // shapeValue(vMax) ? - } else if (val < (int)vMin) { - val = (int)vMin; // shapeValue(vMin) ? - } + val = rtengine::LIM(val, static_cast(vMin), static_cast(vMax)); - return val; } -float Adjuster::trimValue (float val) +void Adjuster::trimValue (float &val) { - if (val > (float)vMax) { - val = (float)vMax; // shapeValue(vMax) ? - } else if (val < (float)vMin) { - val = (float)vMin; // shapeValue(vMin) ? - } + val = rtengine::LIM(val, static_cast(vMin), static_cast(vMax)); - return val; } diff --git a/rtgui/adjuster.h b/rtgui/adjuster.h index 9f413a142..768406a33 100644 --- a/rtgui/adjuster.h +++ b/rtgui/adjuster.h @@ -56,13 +56,11 @@ protected: sigc::connection autoChange; sigc::connection buttonReleaseSlider; sigc::connection buttonReleaseSpin; - bool listenerReady; double defaultVal; // current default value (it can change when switching from ADD or SET mode) double ctorDefaultVal; // default value at construction time EditedState editedState; EditedState defEditedState; EditedState autoState; - EditedState defAutoState; int digits; Gtk::CheckButton* editedCheckBox; bool afterReset; @@ -172,9 +170,9 @@ public: void resetValue (bool toInitial); void resetPressed (GdkEventButton* event); void editedToggled (); - double trimValue (double val); - float trimValue (float val); - int trimValue (int val); + void trimValue (double &val); + void trimValue (float &val); + void trimValue (int &val); }; #endif diff --git a/rtgui/crop.cc b/rtgui/crop.cc index a2a0e36ed..429edf0ff 100644 --- a/rtgui/crop.cc +++ b/rtgui/crop.cc @@ -1219,10 +1219,6 @@ void Crop::cropResized (int &x, int &y, int& x2, int& y2) W = maxw; } - if (H > maxh) { - H = maxh; - } - if (fixr->get_active()) { double r = getRatio (); diff --git a/rtgui/cropwindow.cc b/rtgui/cropwindow.cc index d7a2f5740..d51674b5e 100644 --- a/rtgui/cropwindow.cc +++ b/rtgui/cropwindow.cc @@ -895,7 +895,7 @@ void CropWindow::pointerMoved (int bstate, int x, int y) } else if (state == SDragPicker) { Coord imgPos; action_x = x - press_x; - action_x = y - press_y; + action_y = y - press_y; screenCoordToImage (x, y, imgPos.x, imgPos.y); if (imgPos.x < 0) { imgPos.x = 0; diff --git a/rtgui/diagonalcurveeditorsubgroup.cc b/rtgui/diagonalcurveeditorsubgroup.cc index 936bf0d64..b64034b96 100644 --- a/rtgui/diagonalcurveeditorsubgroup.cc +++ b/rtgui/diagonalcurveeditorsubgroup.cc @@ -525,7 +525,8 @@ void DiagonalCurveEditorSubGroup::pipetteDrag(EditDataProvider *provider, int mo case (DCT_Parametric): if (editedAdjuster) { - int trimmedValue = editedAdjuster->trimValue(editedAdjusterValue - (provider->deltaScreen.y / 2)); + int trimmedValue = editedAdjusterValue - (provider->deltaScreen.y / 2); + editedAdjuster->trimValue(trimmedValue); if (trimmedValue != editedAdjuster->getIntValue()) { editedAdjuster->setValue(trimmedValue); diff --git a/rtgui/filepanel.cc b/rtgui/filepanel.cc index a8c24e83d..1aa997095 100644 --- a/rtgui/filepanel.cc +++ b/rtgui/filepanel.cc @@ -22,7 +22,7 @@ #include "inspector.h" #include "placesbrowser.h" -FilePanel::FilePanel () : parent(nullptr) +FilePanel::FilePanel () : parent(nullptr), error(0) { // Contains everything except for the batch Tool Panel and tabs (Fast Export, Inspect, etc) diff --git a/rtgui/filmsimulation.cc b/rtgui/filmsimulation.cc index e21857ec9..a1471f970 100644 --- a/rtgui/filmsimulation.cc +++ b/rtgui/filmsimulation.cc @@ -191,7 +191,7 @@ void FilmSimulation::setAdjusterBehavior( bool strength ) void FilmSimulation::trimValues( rtengine::procparams::ProcParams* pp ) { - pp->filmSimulation.strength = m_strength->trimValue( pp->filmSimulation.strength ); + m_strength->trimValue( pp->filmSimulation.strength ); } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: diff --git a/rtgui/guiutils.cc b/rtgui/guiutils.cc index 91284e983..91348e52f 100644 --- a/rtgui/guiutils.cc +++ b/rtgui/guiutils.cc @@ -1281,6 +1281,8 @@ MyImageMenuItem::MyImageMenuItem(Glib::ustring label, Glib::ustring imageFileNam if (!imageFileName.empty()) { image = Gtk::manage( new RTImage(imageFileName) ); box->attach_next_to(*image, Gtk::POS_LEFT, 1, 1); + } else { + image = nullptr; } box->attach_next_to(*this->label, Gtk::POS_RIGHT, 1, 1); diff --git a/rtgui/inspector.cc b/rtgui/inspector.cc index 79839b5f9..8af99b2ab 100644 --- a/rtgui/inspector.cc +++ b/rtgui/inspector.cc @@ -259,6 +259,7 @@ void Inspector::switchImage (const Glib::ustring &fullPath) images.push_back(iBuffer); currImage = images.at(images.size() - 1); } else { + delete iBuffer; currImage = nullptr; } } diff --git a/rtgui/previewloader.cc b/rtgui/previewloader.cc index a43c47d2e..0c0ecf9f6 100644 --- a/rtgui/previewloader.cc +++ b/rtgui/previewloader.cc @@ -168,11 +168,6 @@ PreviewLoader::PreviewLoader(): { } -PreviewLoader::~PreviewLoader() -{ - delete impl_; -} - PreviewLoader* PreviewLoader::getInstance() { static PreviewLoader instance_; diff --git a/rtgui/previewloader.h b/rtgui/previewloader.h index d2f21b013..d5207cd44 100644 --- a/rtgui/previewloader.h +++ b/rtgui/previewloader.h @@ -88,7 +88,6 @@ public: private: PreviewLoader(); - ~PreviewLoader(); class Impl; Impl* impl_; diff --git a/rtgui/profilepanel.cc b/rtgui/profilepanel.cc index 8fe546546..6d317f5a4 100644 --- a/rtgui/profilepanel.cc +++ b/rtgui/profilepanel.cc @@ -753,7 +753,6 @@ void ProfilePanel::initProfile (const Glib::ustring& profileFullPath, ProcParams // adding the Last Saved combobox entry, if needed if (lastsaved) { - defprofile = lastsaved; lasSavedEntry = getLastSavedRow(); } diff --git a/rtgui/thresholdadjuster.h b/rtgui/thresholdadjuster.h index 9c22eede4..200fe2175 100644 --- a/rtgui/thresholdadjuster.h +++ b/rtgui/thresholdadjuster.h @@ -60,7 +60,6 @@ protected: //sigc::connection spinChange; sigc::connection selectorChange; sigc::connection editedChange; - bool listenerReady; double initialDefaultVal[4]; // default value at construction time EditedState editedState; EditedState defEditedState; diff --git a/rtgui/thumbimageupdater.cc b/rtgui/thumbimageupdater.cc index b30047c2f..95618d5ab 100644 --- a/rtgui/thumbimageupdater.cc +++ b/rtgui/thumbimageupdater.cc @@ -184,11 +184,6 @@ ThumbImageUpdater::ThumbImageUpdater(): { } -ThumbImageUpdater::~ThumbImageUpdater() -{ - delete impl_; -} - void ThumbImageUpdater::add(ThumbBrowserEntryBase* tbe, bool* priority, bool upgrade, ThumbImageUpdateListener* l) { diff --git a/rtgui/thumbimageupdater.h b/rtgui/thumbimageupdater.h index 0ac92a31a..3b34c9456 100644 --- a/rtgui/thumbimageupdater.h +++ b/rtgui/thumbimageupdater.h @@ -93,7 +93,6 @@ public: private: ThumbImageUpdater(); - ~ThumbImageUpdater(); class Impl; Impl* impl_;