Make XMP support optional (no need for tinyxml2) (#10)

This commit is contained in:
Juha Reunanen
2021-03-25 15:33:24 +02:00
committed by GitHub
parent 0574cbf4f2
commit 915d0e353b
2 changed files with 13 additions and 0 deletions

View File

@@ -32,7 +32,11 @@
*/ */
#include "TinyEXIF.h" #include "TinyEXIF.h"
#ifndef TINYEXIF_NO_XMP_SUPPORT
#include <tinyxml2.h> #include <tinyxml2.h>
#endif // TINYEXIF_NO_XMP_SUPPORT
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
@@ -434,11 +438,13 @@ void EXIFInfo::parseIFDImage(EntryParser& parser, unsigned& exif_sub_ifd_offset,
void EXIFInfo::parseIFDExif(EntryParser& parser) { void EXIFInfo::parseIFDExif(EntryParser& parser) {
switch (parser.GetTag()) { switch (parser.GetTag()) {
case 0x02bc: case 0x02bc:
#ifndef TINYEXIF_NO_XMP_SUPPORT
// XMP Metadata (Adobe technote 9-14-02) // XMP Metadata (Adobe technote 9-14-02)
if (parser.IsUndefined()) { if (parser.IsUndefined()) {
const std::string strXML(parser.FetchString()); const std::string strXML(parser.FetchString());
parseFromXMPSegmentXML(strXML.c_str(), (unsigned)strXML.length()); parseFromXMPSegmentXML(strXML.c_str(), (unsigned)strXML.length());
} }
#endif // TINYEXIF_NO_XMP_SUPPORT
break; break;
case 0x829a: case 0x829a:
@@ -808,6 +814,7 @@ int EXIFInfo::parseFrom(EXIFStream& stream) {
return app1s(PARSE_INVALID_JPEG); return app1s(PARSE_INVALID_JPEG);
switch (int ret=parseFromEXIFSegment(buf, sectionLength)) { switch (int ret=parseFromEXIFSegment(buf, sectionLength)) {
case PARSE_ABSENT_DATA: case PARSE_ABSENT_DATA:
#ifndef TINYEXIF_NO_XMP_SUPPORT
switch (ret=parseFromXMPSegment(buf, sectionLength)) { switch (ret=parseFromXMPSegment(buf, sectionLength)) {
case PARSE_ABSENT_DATA: case PARSE_ABSENT_DATA:
break; break;
@@ -818,6 +825,7 @@ int EXIFInfo::parseFrom(EXIFStream& stream) {
default: default:
return app1s(ret); // some error return app1s(ret); // some error
} }
#endif // TINYEXIF_NO_XMP_SUPPORT
break; break;
case PARSE_SUCCESS: case PARSE_SUCCESS:
if ((app1s|=FIELD_EXIF) == FIELD_ALL) if ((app1s|=FIELD_EXIF) == FIELD_ALL)
@@ -970,6 +978,8 @@ int EXIFInfo::parseFromEXIFSegment(const uint8_t* buf, unsigned len) {
return PARSE_SUCCESS; return PARSE_SUCCESS;
} }
#ifndef TINYEXIF_NO_XMP_SUPPORT
// //
// Main parsing function for a XMP segment. // Main parsing function for a XMP segment.
// Do a sanity check by looking for bytes "http://ns.adobe.com/xap/1.0/\0". // Do a sanity check by looking for bytes "http://ns.adobe.com/xap/1.0/\0".
@@ -1098,6 +1108,7 @@ int EXIFInfo::parseFromXMPSegmentXML(const char* szXML, unsigned len) {
return PARSE_SUCCESS; return PARSE_SUCCESS;
} }
#endif // TINYEXIF_NO_XMP_SUPPORT
void EXIFInfo::Geolocation_t::parseCoords() { void EXIFInfo::Geolocation_t::parseCoords() {
// Convert GPS latitude // Convert GPS latitude

View File

@@ -117,11 +117,13 @@ public:
// available (i.e., a blob starting with the bytes "Exif\0\0"). // available (i.e., a blob starting with the bytes "Exif\0\0").
int parseFromEXIFSegment(const uint8_t* buf, unsigned len); int parseFromEXIFSegment(const uint8_t* buf, unsigned len);
#ifndef TINYEXIF_NO_XMP_SUPPORT
// Parsing function for an XMP segment. This is used internally by parseFrom() // Parsing function for an XMP segment. This is used internally by parseFrom()
// but can be called for special cases where only the XMP section is // but can be called for special cases where only the XMP section is
// available (i.e., a blob starting with the bytes "http://ns.adobe.com/xap/1.0/\0"). // available (i.e., a blob starting with the bytes "http://ns.adobe.com/xap/1.0/\0").
int parseFromXMPSegment(const uint8_t* buf, unsigned len); int parseFromXMPSegment(const uint8_t* buf, unsigned len);
int parseFromXMPSegmentXML(const char* szXML, unsigned len); int parseFromXMPSegmentXML(const char* szXML, unsigned len);
#endif // TINYEXIF_NO_XMP_SUPPORT
// Set all data members to default values. // Set all data members to default values.
// Should be called before parsing a new stream. // Should be called before parsing a new stream.