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

@ -76,7 +76,6 @@ 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)
{ {
int ix = 0; int ix = 0;
for (int i = 0; i < dh; i++) { for (int i = 0; i < dh; i++) {
@ -134,7 +133,6 @@ 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++) {
@ -152,7 +150,6 @@ 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;
} }
@ -192,7 +189,6 @@ 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)
{ {
unsigned char* flipped = new unsigned char[3 * w * h]; unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0; int ix = 0;
@ -209,7 +205,6 @@ 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)
{ {
unsigned char* flipped = new unsigned char[3 * w * h]; unsigned char* flipped = new unsigned char[3 * w * h];
int ix = 0; int ix = 0;
@ -224,34 +219,30 @@ void vflip (unsigned char* img, int w, int 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,16 +19,16 @@
#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);
@ -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,12 +276,17 @@ 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('.'));
} }