diff --git a/dw/fltkimgbuf.cc b/dw/fltkimgbuf.cc index dbada5c..3b6bb57 100644 --- a/dw/fltkimgbuf.cc +++ b/dw/fltkimgbuf.cc @@ -37,30 +37,30 @@ using namespace lout::container::typed; const enum ScaleMode { SIMPLE, BEAUTIFUL, BEAUTIFUL_GAMMA } scaleMode = BEAUTIFUL_GAMMA; -Vector *FltkImgbuf::gammaCorrectionTables - = new Vector (true, 2); +std::vector< std::unique_ptr< FltkImgbuf::GammaCorrectionTable > > FltkImgbuf::gammaCorrectionTables; uchar *FltkImgbuf::findGammaCorrectionTable (double gamma) { // Since the number of possible keys is low, a linear search is // sufficiently fast. - for (int i = 0; i < gammaCorrectionTables->size(); i++) { - GammaCorrectionTable *gct = gammaCorrectionTables->get(i); + for (std::size_t i = 0; i < gammaCorrectionTables.size(); i++) { + GammaCorrectionTable *gct = gammaCorrectionTables.at(i).get(); if (gct->gamma == gamma) return gct->map; } _MSG("Creating new table for gamma = %g\n", gamma); - GammaCorrectionTable *gct = new GammaCorrectionTable(); + auto gct = std::make_unique< GammaCorrectionTable >(); gct->gamma = gamma; for (int i = 0; i < 256; i++) gct->map[i] = 255 * pow((double)i / 255, gamma); - gammaCorrectionTables->put (gct); - return gct->map; + auto *rv= gct->map; + gammaCorrectionTables.push_back (std::move(gct)); + return rv; } bool FltkImgbuf::excessiveImageDimensions (int width, int height) @@ -72,8 +72,7 @@ bool FltkImgbuf::excessiveImageDimensions (int width, int height) void FltkImgbuf::freeall () { _MSG("Deleting gammaCorrectionTables\n"); - delete gammaCorrectionTables; - gammaCorrectionTables = NULL; + gammaCorrectionTables.clear(); } FltkImgbuf::FltkImgbuf (Type type, int width, int height, double gamma) diff --git a/dw/fltkimgbuf.hh b/dw/fltkimgbuf.hh index 73c13c1..5c2be4c 100644 --- a/dw/fltkimgbuf.hh +++ b/dw/fltkimgbuf.hh @@ -36,8 +36,7 @@ private: // the image buffer. lout::misc::BitSet *copiedRows; - static lout::container::typed::Vector - *gammaCorrectionTables; + static std::vector< std::unique_ptr< GammaCorrectionTable > > gammaCorrectionTables; static uchar *findGammaCorrectionTable (double gamma); static bool excessiveImageDimensions (int width, int height); diff --git a/src/dialog.cc b/src/dialog.cc index 079ddb4..eadbe0a 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -372,10 +372,10 @@ int a_Dialog_choice(const char *title, const char *msg, ...) window->set_modal(); window->begin(); - Fl_Text_Buffer *buf = new Fl_Text_Buffer(); + auto buf = std::make_unique< Fl_Text_Buffer >(); buf->text(msg); Fl_Text_Display *td = new Fl_Text_Display(0, 0, ww, wh - bh); - td->buffer(buf); + td->buffer(buf.get()); td->textsize((int) rint(14.0 * prefs.font_factor)); td->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0); @@ -400,8 +400,8 @@ int a_Dialog_choice(const char *title, const char *msg, ...) while (window->shown()) Fl::wait(); _MSG("Dialog_choice answer = %d\n", answer); - td->buffer(NULL); - delete buf; + td->buffer(nullptr); + buf.reset(); window.reset(); return choice_answer;