Skip to content

Commit c3805a6

Browse files
committed
MMVII: GDAL: Driver choice for new image
1 parent 7c162f5 commit c3805a6

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

MMVII/include/MMVII_util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ std::string Postfix(const std::string & aStr,char aSep='.',bool SVP=false,bool P
8989
std::string LastPostfix(const std::string & aStr,char aSep='.'); ///< No error: a=> "" a.b.c => "c"
9090

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

9595
// Direcytory and files names, Rely on std::filesystem

MMVII/src/ImagesBase/FileImages.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,15 @@ namespace{ // Private
6060

6161
std::string ExtToGdalDriver( std::string aName )
6262
{
63-
// Return gdal driver in function of extension of aName
64-
65-
std::vector<string> strings;
66-
std::string s;
67-
char delimiter = '.';
68-
std::istringstream iss(aName);
69-
70-
while (std::getline(iss, s, delimiter)) {
71-
strings.push_back(s);
72-
}
73-
74-
// Add other gdal driver here
75-
std::string aDriver ;
76-
if (strings.back() == "tif")
77-
{
78-
aDriver = "GTiff";
79-
}
80-
81-
return aDriver;
63+
auto aLowerName = ToLower(aName);
64+
if (ends_with(aLowerName,".tif") || ends_with(aLowerName,".tiff"))
65+
return "GTiff";
66+
if (ends_with(aLowerName,".jpg") || ends_with(aLowerName,".jpeg"))
67+
return "JPEG";
68+
if (ends_with(aLowerName,".png"))
69+
return "PNG";
70+
MMVII_INTERNAL_ERROR("MMVIITOGDal: Unsupported image format for " + aName);
71+
return "";
8272
}
8373

8474

MMVII/src/Utils/uti_string.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,16 @@ bool starts_with(const std::string & aFullStr,const std::string & aPrefix)
660660
return anItPref==aPrefix.end();
661661
}
662662

663+
bool ends_with(const std::string & aFullStr,const std::string & aEnding)
664+
{
665+
if (aFullStr.size() < aEnding.size())
666+
return false;
667+
auto it = aEnding.begin();
668+
return std::all_of(std::next(aFullStr.begin(),aFullStr.size()-aEnding.size()), aFullStr.end(),
669+
[&it](const char& c) { return c == *(it++);});
670+
671+
}
672+
663673
bool IsPrefixed(const std::string & aStr,char aSep)
664674
{
665675
return aStr.find(aSep) != std::string::npos;

0 commit comments

Comments
 (0)