Skip to content

Commit

Permalink
MMVII: GDAL: Driver choice for new image
Browse files Browse the repository at this point in the history
  • Loading branch information
meynardc committed Feb 5, 2024
1 parent 7c162f5 commit c3805a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MMVII/include/MMVII_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::string Postfix(const std::string & aStr,char aSep='.',bool SVP=false,bool P
std::string LastPostfix(const std::string & aStr,char aSep='.'); ///< No error: a=> "" a.b.c => "c"

bool starts_with(const std::string & aFullStr,const std::string & aBegining); /// as c++20 std::string.starts_with
bool ends_with(const std::string & aFullStr,const std::string & aEnding); /// as c++20 std::string.starts_with TO IMPLEMENT
bool ends_with(const std::string & aFullStr,const std::string & aEnding); /// as c++20 std::string.ends_with
bool contains(const std::string & aFullStr,const std::string & aEnding); /// as c++23 std::string.contains TO IMPLEMENT

// Direcytory and files names, Rely on std::filesystem
Expand Down
28 changes: 9 additions & 19 deletions MMVII/src/ImagesBase/FileImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,15 @@ namespace{ // Private

std::string ExtToGdalDriver( std::string aName )
{
// Return gdal driver in function of extension of aName

std::vector<string> strings;
std::string s;
char delimiter = '.';
std::istringstream iss(aName);

while (std::getline(iss, s, delimiter)) {
strings.push_back(s);
}

// Add other gdal driver here
std::string aDriver ;
if (strings.back() == "tif")
{
aDriver = "GTiff";
}

return aDriver;
auto aLowerName = ToLower(aName);
if (ends_with(aLowerName,".tif") || ends_with(aLowerName,".tiff"))
return "GTiff";
if (ends_with(aLowerName,".jpg") || ends_with(aLowerName,".jpeg"))
return "JPEG";
if (ends_with(aLowerName,".png"))
return "PNG";
MMVII_INTERNAL_ERROR("MMVIITOGDal: Unsupported image format for " + aName);
return "";
}


Expand Down
10 changes: 10 additions & 0 deletions MMVII/src/Utils/uti_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,16 @@ bool starts_with(const std::string & aFullStr,const std::string & aPrefix)
return anItPref==aPrefix.end();
}

bool ends_with(const std::string & aFullStr,const std::string & aEnding)
{
if (aFullStr.size() < aEnding.size())
return false;
auto it = aEnding.begin();
return std::all_of(std::next(aFullStr.begin(),aFullStr.size()-aEnding.size()), aFullStr.end(),
[&it](const char& c) { return c == *(it++);});

}

bool IsPrefixed(const std::string & aStr,char aSep)
{
return aStr.find(aSep) != std::string::npos;
Expand Down

0 comments on commit c3805a6

Please sign in to comment.