Fix MSVC++ UNICODE builds (#9)
* Problem: in MSVC++ UNICODE builds, the _tcsncmp and _tcsicmp defined via <tchar.h> need wchar_t* input, but that's not what we have available here Solution: 1) in place of _tcsncmp, just use strncmp, which ought to be standard: http://www.cplusplus.com/reference/cstring/strncmp/ 2) in place of _tcsicmp, call strcasecmp, and in MSVC++ builds create a wrapper that actually calls _stricmp (and never _wcsicmp) * #include <string.h> and not <strings.h>
This commit is contained in:
28
TinyEXIF.cpp
28
TinyEXIF.cpp
@@ -45,11 +45,13 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <tchar.h>
|
namespace {
|
||||||
|
int strcasecmp(const char* a, const char* b) {
|
||||||
|
return _stricmp(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#include <strings.h>
|
#include <string.h>
|
||||||
#define _tcsncmp strncmp
|
|
||||||
#define _tcsicmp strcasecmp
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +66,7 @@ namespace Tools {
|
|||||||
return NULL;
|
return NULL;
|
||||||
for (size_t i=len-needle_len; i-- > 0; ) {
|
for (size_t i=len-needle_len; i-- > 0; ) {
|
||||||
if (haystack[0] == needle[0] &&
|
if (haystack[0] == needle[0] &&
|
||||||
0 == _tcsncmp(haystack, needle, needle_len))
|
0 == strncmp(haystack, needle, needle_len))
|
||||||
return haystack;
|
return haystack;
|
||||||
haystack++;
|
haystack++;
|
||||||
}
|
}
|
||||||
@@ -628,7 +630,7 @@ void EXIFInfo::parseIFDExif(EntryParser& parser) {
|
|||||||
void EXIFInfo::parseIFDMakerNote(EntryParser& parser) {
|
void EXIFInfo::parseIFDMakerNote(EntryParser& parser) {
|
||||||
const unsigned startOff = parser.GetOffset();
|
const unsigned startOff = parser.GetOffset();
|
||||||
const uint32_t off = parser.GetSubIFD();
|
const uint32_t off = parser.GetSubIFD();
|
||||||
if (0 != _tcsicmp(Make.c_str(), "DJI"))
|
if (0 != strcasecmp(Make.c_str(), "DJI"))
|
||||||
return;
|
return;
|
||||||
int num_entries = EntryParser::parse16(parser.GetBuffer()+off, parser.IsIntelAligned());
|
int num_entries = EntryParser::parse16(parser.GetBuffer()+off, parser.IsIntelAligned());
|
||||||
if (uint32_t(2 + 12 * num_entries) > parser.GetLength())
|
if (uint32_t(2 + 12 * num_entries) > parser.GetLength())
|
||||||
@@ -638,7 +640,7 @@ void EXIFInfo::parseIFDMakerNote(EntryParser& parser) {
|
|||||||
--num_entries;
|
--num_entries;
|
||||||
std::string maker;
|
std::string maker;
|
||||||
if (parser.GetTag() == 1 && parser.Fetch(maker)) {
|
if (parser.GetTag() == 1 && parser.Fetch(maker)) {
|
||||||
if (0 == _tcsicmp(maker.c_str(), "DJI")) {
|
if (0 == strcasecmp(maker.c_str(), "DJI")) {
|
||||||
while (--num_entries >= 0) {
|
while (--num_entries >= 0) {
|
||||||
parser.ParseTag();
|
parser.ParseTag();
|
||||||
switch (parser.GetTag()) {
|
switch (parser.GetTag()) {
|
||||||
@@ -1039,11 +1041,11 @@ int EXIFInfo::parseFromXMPSegmentXML(const char* szXML, unsigned len) {
|
|||||||
if (element != NULL) {
|
if (element != NULL) {
|
||||||
const char* const szProjectionType(element->GetText());
|
const char* const szProjectionType(element->GetText());
|
||||||
if (szProjectionType != NULL) {
|
if (szProjectionType != NULL) {
|
||||||
if (0 == _tcsicmp(szProjectionType, "perspective"))
|
if (0 == strcasecmp(szProjectionType, "perspective"))
|
||||||
ProjectionType = 1;
|
ProjectionType = 1;
|
||||||
else
|
else
|
||||||
if (0 == _tcsicmp(szProjectionType, "equirectangular") ||
|
if (0 == strcasecmp(szProjectionType, "equirectangular") ||
|
||||||
0 == _tcsicmp(szProjectionType, "spherical"))
|
0 == strcasecmp(szProjectionType, "spherical"))
|
||||||
ProjectionType = 2;
|
ProjectionType = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1070,7 +1072,7 @@ int EXIFInfo::parseFromXMPSegmentXML(const char* szXML, unsigned len) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const char* szAbout(document->Attribute("rdf:about"));
|
const char* szAbout(document->Attribute("rdf:about"));
|
||||||
if (0 == _tcsicmp(Make.c_str(), "DJI") || (szAbout != NULL && 0 == _tcsicmp(szAbout, "DJI Meta Data"))) {
|
if (0 == strcasecmp(Make.c_str(), "DJI") || (szAbout != NULL && 0 == strcasecmp(szAbout, "DJI Meta Data"))) {
|
||||||
ParseXMP::Value(document, "drone-dji:AbsoluteAltitude", GeoLocation.Altitude);
|
ParseXMP::Value(document, "drone-dji:AbsoluteAltitude", GeoLocation.Altitude);
|
||||||
ParseXMP::Value(document, "drone-dji:RelativeAltitude", GeoLocation.RelativeAltitude);
|
ParseXMP::Value(document, "drone-dji:RelativeAltitude", GeoLocation.RelativeAltitude);
|
||||||
ParseXMP::Value(document, "drone-dji:GimbalRollDegree", GeoLocation.RollDegree);
|
ParseXMP::Value(document, "drone-dji:GimbalRollDegree", GeoLocation.RollDegree);
|
||||||
@@ -1080,7 +1082,7 @@ int EXIFInfo::parseFromXMPSegmentXML(const char* szXML, unsigned len) {
|
|||||||
ParseXMP::Value(document, "drone-dji:CalibratedOpticalCenterX", Calibration.OpticalCenterX);
|
ParseXMP::Value(document, "drone-dji:CalibratedOpticalCenterX", Calibration.OpticalCenterX);
|
||||||
ParseXMP::Value(document, "drone-dji:CalibratedOpticalCenterY", Calibration.OpticalCenterY);
|
ParseXMP::Value(document, "drone-dji:CalibratedOpticalCenterY", Calibration.OpticalCenterY);
|
||||||
} else
|
} else
|
||||||
if (0 == _tcsicmp(Make.c_str(), "senseFly") || 0 == _tcsicmp(Make.c_str(), "Sentera")) {
|
if (0 == strcasecmp(Make.c_str(), "senseFly") || 0 == strcasecmp(Make.c_str(), "Sentera")) {
|
||||||
ParseXMP::Value(document, "Camera:Roll", GeoLocation.RollDegree);
|
ParseXMP::Value(document, "Camera:Roll", GeoLocation.RollDegree);
|
||||||
if (ParseXMP::Value(document, "Camera:Pitch", GeoLocation.PitchDegree)) {
|
if (ParseXMP::Value(document, "Camera:Pitch", GeoLocation.PitchDegree)) {
|
||||||
// convert to DJI format: senseFly uses pitch 0 as NADIR, whereas DJI -90
|
// convert to DJI format: senseFly uses pitch 0 as NADIR, whereas DJI -90
|
||||||
@@ -1090,7 +1092,7 @@ int EXIFInfo::parseFromXMPSegmentXML(const char* szXML, unsigned len) {
|
|||||||
ParseXMP::Value(document, "Camera:GPSXYAccuracy", GeoLocation.AccuracyXY);
|
ParseXMP::Value(document, "Camera:GPSXYAccuracy", GeoLocation.AccuracyXY);
|
||||||
ParseXMP::Value(document, "Camera:GPSZAccuracy", GeoLocation.AccuracyZ);
|
ParseXMP::Value(document, "Camera:GPSZAccuracy", GeoLocation.AccuracyZ);
|
||||||
} else
|
} else
|
||||||
if (0 == _tcsicmp(Make.c_str(), "PARROT")) {
|
if (0 == strcasecmp(Make.c_str(), "PARROT")) {
|
||||||
ParseXMP::Value(document, "Camera:Roll", GeoLocation.RollDegree) ||
|
ParseXMP::Value(document, "Camera:Roll", GeoLocation.RollDegree) ||
|
||||||
ParseXMP::Value(document, "drone-parrot:CameraRollDegree", GeoLocation.RollDegree);
|
ParseXMP::Value(document, "drone-parrot:CameraRollDegree", GeoLocation.RollDegree);
|
||||||
if (ParseXMP::Value(document, "Camera:Pitch", GeoLocation.PitchDegree) ||
|
if (ParseXMP::Value(document, "Camera:Pitch", GeoLocation.PitchDegree) ||
|
||||||
|
|||||||
Reference in New Issue
Block a user