Clean-ups for #3616

This commit is contained in:
Flössie 2017-01-20 21:19:55 +01:00
parent 62451f471f
commit f25e161d16
4 changed files with 63 additions and 79 deletions

View File

@ -29,7 +29,7 @@ using namespace std;
namespace rtengine 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__ #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
*(dest++) = b; *(dest++) = b;
@ -44,7 +44,7 @@ void poke255_uc(unsigned char* &dest, unsigned char r, unsigned char g, unsigned
#endif #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__ #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
*(dest++) = (unsigned char)(b * 255.); *(dest++) = (unsigned char)(b * 255.);
@ -59,7 +59,7 @@ void poke01_d(unsigned char* &dest, double r, double g, double b)
#endif #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__ #if __BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__
*(dest++) = (unsigned char)(b * 255.f); *(dest++) = (unsigned char)(b * 255.f);
@ -74,9 +74,8 @@ void poke01_f(unsigned char* &dest, float r, float g, float b)
#endif #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; int ix = 0;
for (int i = 0; i < dh; i++) { 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; int ix = 0;
for (int i = 0; i < dh; i++) { 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) { if (deg == 0) {
return; 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++]; rotated[3 * (w * (h - i - 1) + w - j - 1) + 2] = img[ix++];
} }
memcpy (img, rotated, 3 * w * h); memcpy(img, rotated, 3 * w * h);
delete [] rotated; 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]; unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0; 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++]; flipped[3 * (w * i + w - 1 - j) + 2] = img[ix++];
} }
memcpy (img, flipped, 3 * w * h); memcpy(img, flipped, 3 * w * h);
delete [] flipped; 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]; unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0; 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++]; flipped[3 * (w * (h - 1 - i) + j) + 2] = img[ix++];
} }
memcpy (img, flipped, 3 * w * h); memcpy(img, flipped, 3 * w * h);
delete [] flipped; delete[] flipped;
} }
/** Glib::ustring getFileExtension(const Glib::ustring& filename)
* Return lower case extension without the "." or "" if the given name contains no "." {
*/ const Glib::ustring::size_type lastdot_pos = filename.find_last_of('.');
Glib::ustring getFileExtension(const Glib::ustring &fname) { return
// issue 3598 do not use casefold() to compare ignoring case - it seems to mangle sharp-s character and length of string lastdot_pos != Glib::ustring::npos
// simply get extension first, then use lowercase() ? filename.substr(lastdot_pos + 1).lowercase()
const Glib::ustring::size_type lastdot = fname.find_last_of ('.'); : Glib::ustring();
if( Glib::ustring::npos == lastdot ) {
return "";
}
return fname.substr(lastdot + 1).lowercase();
} }
bool hasJpegExtension(const Glib::ustring &fname) { bool hasJpegExtension(const Glib::ustring& filename)
const Glib::ustring extension = getFileExtension(fname); {
return ((extension == "jpg") || (extension == "jpeg")); const Glib::ustring extension = getFileExtension(filename);
return extension == "jpg" || extension == "jpeg";
} }
bool hasTiffExtension(const Glib::ustring &fname) { bool hasTiffExtension(const Glib::ustring& filename)
const Glib::ustring extension = getFileExtension(fname); {
return ((extension == "tif") || (extension == "tiff")); const Glib::ustring extension = getFileExtension(filename);
return extension == "tif" || extension == "tiff";
} }
bool hasPngExtension(const Glib::ustring &fname) { bool hasPngExtension(const Glib::ustring& filename)
const Glib::ustring extension = getFileExtension(fname); {
return (extension == "png"); return getFileExtension(filename) == "png";
} }
} }

View File

@ -19,23 +19,23 @@
#pragma once #pragma once
#include <type_traits> #include <type_traits>
#include <glibmm.h> #include <glibmm/ustring.h>
namespace rtengine namespace rtengine
{ {
// update a point of a Cairo::Surface by accessing the raw data // 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); 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 // Update a point of a Cairo::Surface by accessing the raw data
void poke01_d(unsigned char* &dest, double r, double g, double b); void poke01_d(unsigned char*& dest, double r, double g, double b);
// update a point of a Cairo::Surface by accessing the raw data // 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 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 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 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 rotate(unsigned char* img, int& w, int& h, int deg);
void hflip (unsigned char* img, int w, int h); void hflip(unsigned char* img, int w, int h);
void vflip (unsigned char* img, int w, int h); void vflip(unsigned char* img, int w, int h);
template<typename ENUM> template<typename ENUM>
typename std::underlying_type<ENUM>::type toUnderlying(ENUM value) typename std::underlying_type<ENUM>::type toUnderlying(ENUM value)
@ -43,24 +43,13 @@ typename std::underlying_type<ENUM>::type toUnderlying(ENUM value)
return static_cast<typename std::underlying_type<ENUM>::type>(value); return static_cast<typename std::underlying_type<ENUM>::type>(value);
} }
/** // Return lower case extension without the "." or "" if the given name contains no "."
* 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)
Glib::ustring getFileExtension(const Glib::ustring &fname); 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 .jpeg or .jpg extension (ignoring case) // Return true if file has .png extension (ignoring case)
*/ bool hasPngExtension(const Glib::ustring& filename);
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);
} }

View File

@ -2377,7 +2377,7 @@ bool Options::has_retained_extention (Glib::ustring fname)
bool Options::is_extention_enabled (Glib::ustring ext) bool Options::is_extention_enabled (Glib::ustring ext)
{ {
for (int j = 0; j < (int)parseExtensions.size(); j++) 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]; return j >= (int)parseExtensionsEnabled.size() || parseExtensionsEnabled[j];
} }

View File

@ -269,7 +269,6 @@ int ProfileStore::findFolderId(const Glib::ustring &path)
*/ */
const ProfileStoreEntry* ProfileStore::findEntryFromFullPathU(Glib::ustring path) const ProfileStoreEntry* ProfileStore::findEntryFromFullPathU(Glib::ustring path)
{ {
if (path.empty()) { if (path.empty()) {
return nullptr; return nullptr;
} }
@ -277,14 +276,19 @@ const ProfileStoreEntry* ProfileStore::findEntryFromFullPathU(Glib::ustring path
if (path == DEFPROFILE_INTERNAL) { if (path == DEFPROFILE_INTERNAL) {
return internalDefaultEntry; 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))) // consistently apply casefold() to make sure dot position is correct
// removing the extension 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() // 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 // dir separator may come from options file and may be \ or /, we convert them to G_DIR_SEPARATOR_S