From f25e161d16d942d09cda27e94b2f80ab2f93783f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=B6ssie?= Date: Fri, 20 Jan 2017 21:19:55 +0100 Subject: [PATCH] Clean-ups for #3616 --- rtengine/utils.cc | 73 +++++++++++++++++++------------------------ rtengine/utils.h | 51 ++++++++++++------------------ rtgui/options.cc | 2 +- rtgui/profilestore.cc | 16 ++++++---- 4 files changed, 63 insertions(+), 79 deletions(-) diff --git a/rtengine/utils.cc b/rtengine/utils.cc index c23823c59..f5b3e496b 100644 --- a/rtengine/utils.cc +++ b/rtengine/utils.cc @@ -29,7 +29,7 @@ using namespace std; namespace rtengine { -void poke255_uc(unsigned char* &dest, unsigned char r, unsigned char g, unsigned char b) +void poke255_uc(unsigned char*& dest, unsigned char r, unsigned char g, unsigned char b) { #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ *(dest++) = b; @@ -44,7 +44,7 @@ void poke255_uc(unsigned char* &dest, unsigned char r, unsigned char g, unsigned #endif } -void poke01_d(unsigned char* &dest, double r, double g, double b) +void poke01_d(unsigned char*& dest, double r, double g, double b) { #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ *(dest++) = (unsigned char)(b * 255.); @@ -59,7 +59,7 @@ void poke01_d(unsigned char* &dest, double r, double g, double b) #endif } -void poke01_f(unsigned char* &dest, float r, float g, float b) +void poke01_f(unsigned char*& dest, float r, float g, float b) { #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__ *(dest++) = (unsigned char)(b * 255.f); @@ -74,9 +74,8 @@ void poke01_f(unsigned char* &dest, float r, float g, float b) #endif } -void bilinearInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) +void bilinearInterp(const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) { - int ix = 0; for (int i = 0; i < dh; i++) { @@ -132,9 +131,8 @@ void bilinearInterp (const unsigned char* src, int sw, int sh, unsigned char* ds } } -void nearestInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) +void nearestInterp(const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) { - int ix = 0; for (int i = 0; i < dh; i++) { @@ -150,9 +148,8 @@ void nearestInterp (const unsigned char* src, int sw, int sh, unsigned char* dst } } -void rotate (unsigned char* img, int& w, int& h, int deg) +void rotate(unsigned char* img, int& w, int& h, int deg) { - if (deg == 0) { return; } @@ -186,13 +183,12 @@ void rotate (unsigned char* img, int& w, int& h, int deg) rotated[3 * (w * (h - i - 1) + w - j - 1) + 2] = img[ix++]; } - memcpy (img, rotated, 3 * w * h); - delete [] rotated; + memcpy(img, rotated, 3 * w * h); + delete[] rotated; } -void hflip (unsigned char* img, int w, int h) +void hflip(unsigned char* img, int w, int h) { - unsigned char* flipped = new unsigned char[3 * w * h]; int ix = 0; @@ -203,13 +199,12 @@ void hflip (unsigned char* img, int w, int h) 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) +void vflip(unsigned char* img, int w, int h) { - unsigned char* flipped = new unsigned char[3 * w * h]; int ix = 0; @@ -220,38 +215,34 @@ void vflip (unsigned char* img, int w, int h) 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; } -/** - * Return lower case extension without the "." or "" if the given name contains no "." - */ -Glib::ustring getFileExtension(const Glib::ustring &fname) { - // issue 3598 do not use casefold() to compare ignoring case - it seems to mangle sharp-s character and length of string - // simply get extension first, then use lowercase() - const Glib::ustring::size_type lastdot = fname.find_last_of ('.'); - if( Glib::ustring::npos == lastdot ) { - return ""; - } - return fname.substr(lastdot + 1).lowercase(); +Glib::ustring getFileExtension(const Glib::ustring& filename) +{ + const Glib::ustring::size_type lastdot_pos = filename.find_last_of('.'); + return + lastdot_pos != Glib::ustring::npos + ? filename.substr(lastdot_pos + 1).lowercase() + : Glib::ustring(); } -bool hasJpegExtension(const Glib::ustring &fname) { - const Glib::ustring extension = getFileExtension(fname); - return ((extension == "jpg") || (extension == "jpeg")); +bool hasJpegExtension(const Glib::ustring& filename) +{ + const Glib::ustring extension = getFileExtension(filename); + return extension == "jpg" || extension == "jpeg"; } -bool hasTiffExtension(const Glib::ustring &fname) { - const Glib::ustring extension = getFileExtension(fname); - return ((extension == "tif") || (extension == "tiff")); +bool hasTiffExtension(const Glib::ustring& filename) +{ + const Glib::ustring extension = getFileExtension(filename); + return extension == "tif" || extension == "tiff"; } -bool hasPngExtension(const Glib::ustring &fname) { - const Glib::ustring extension = getFileExtension(fname); - return (extension == "png"); +bool hasPngExtension(const Glib::ustring& filename) +{ + return getFileExtension(filename) == "png"; } } - - diff --git a/rtengine/utils.h b/rtengine/utils.h index 50286239b..b2c1d16a8 100644 --- a/rtengine/utils.h +++ b/rtengine/utils.h @@ -19,23 +19,23 @@ #pragma once #include -#include +#include namespace rtengine { -// update a point of a Cairo::Surface by accessing the raw data -void poke255_uc(unsigned char* &dest, unsigned char r, unsigned char g, unsigned char b); -// update a point of a Cairo::Surface by accessing the raw data -void poke01_d(unsigned char* &dest, double r, double g, double b); -// update a point of a Cairo::Surface by accessing the raw data -void poke01_f(unsigned char* &dest, float r, float g, float b); +// Update a point of a Cairo::Surface by accessing the raw data +void poke255_uc(unsigned char*& dest, unsigned char r, unsigned char g, unsigned char b); +// Update a point of a Cairo::Surface by accessing the raw data +void poke01_d(unsigned char*& dest, double r, double g, double b); +// Update a point of a Cairo::Surface by accessing the raw data +void poke01_f(unsigned char*& dest, float r, float g, float b); -void bilinearInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh); -void nearestInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh); -void rotate (unsigned char* img, int& w, int& h, int deg); -void hflip (unsigned char* img, int w, int h); -void vflip (unsigned char* img, int w, int h); +void bilinearInterp(const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh); +void nearestInterp(const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh); +void rotate(unsigned char* img, int& w, int& h, int deg); +void hflip(unsigned char* img, int w, int h); +void vflip(unsigned char* img, int w, int h); template typename std::underlying_type::type toUnderlying(ENUM value) @@ -43,24 +43,13 @@ typename std::underlying_type::type toUnderlying(ENUM value) return static_cast::type>(value); } -/** - * Return lower case extension without the "." or "" if the given name contains no "." - */ -Glib::ustring getFileExtension(const Glib::ustring &fname); - -/** - * Return true if file has .jpeg or .jpg extension (ignoring case) - */ -bool hasJpegExtension(const Glib::ustring &fname); - -/** - * Return true if file has .tiff or .tif extension (ignoring case) - */ -bool hasTiffExtension(const Glib::ustring &fname); - -/** - * Return true if file has .png extension (ignoring case) - */ -bool hasPngExtension(const Glib::ustring &fname); +// Return lower case extension without the "." or "" if the given name contains no "." +Glib::ustring getFileExtension(const Glib::ustring& filename); +// Return true if file has .jpeg or .jpg extension (ignoring case) +bool hasJpegExtension(const Glib::ustring& filename); +// Return true if file has .tiff or .tif extension (ignoring case) +bool hasTiffExtension(const Glib::ustring& filename); +// Return true if file has .png extension (ignoring case) +bool hasPngExtension(const Glib::ustring& filename); } diff --git a/rtgui/options.cc b/rtgui/options.cc index 4d8a3a36b..397b5996a 100644 --- a/rtgui/options.cc +++ b/rtgui/options.cc @@ -2377,7 +2377,7 @@ bool Options::has_retained_extention (Glib::ustring fname) bool Options::is_extention_enabled (Glib::ustring ext) { for (int j = 0; j < (int)parseExtensions.size(); j++) - if (parseExtensions[j].casefold() == ext.casefold()) { // issue 3598 REVIEW OK - no change required + if (parseExtensions[j].casefold() == ext.casefold()) { return j >= (int)parseExtensionsEnabled.size() || parseExtensionsEnabled[j]; } diff --git a/rtgui/profilestore.cc b/rtgui/profilestore.cc index f3d480382..ddb6782d4 100644 --- a/rtgui/profilestore.cc +++ b/rtgui/profilestore.cc @@ -269,7 +269,6 @@ int ProfileStore::findFolderId(const Glib::ustring &path) */ const ProfileStoreEntry* ProfileStore::findEntryFromFullPathU(Glib::ustring path) { - if (path.empty()) { return nullptr; } @@ -277,14 +276,19 @@ const ProfileStoreEntry* ProfileStore::findEntryFromFullPathU(Glib::ustring path if (path == DEFPROFILE_INTERNAL) { return internalDefaultEntry; } - // consistently apply casefold() to make sure dot position is correct - const Glib::ustring::size_type lastdot = path.casefold().find_last_of ('.'); - if ((lastdot != Glib::ustring::npos) && (lastdot <= path.casefold().size() - 4) && (!path.casefold().compare (lastdot, 4, paramFileExtension))) - // removing the extension + // consistently apply casefold() to make sure dot position is correct + const Glib::ustring casefolded_path = path.casefold(); + const Glib::ustring::size_type lastdot_pos = casefolded_path.find_last_of('.'); + + if ( + lastdot_pos != Glib::ustring::npos + && lastdot_pos <= casefolded_path.size() - 4 + && !casefolded_path.compare(lastdot_pos, 4, paramFileExtension)) { + // removing the extension // now use dot position without casefold() - path = path.substr(0, path.find_last_of ('.')); + path = path.substr(0, path.find_last_of('.')); } // dir separator may come from options file and may be \ or /, we convert them to G_DIR_SEPARATOR_S