diff --git a/README-SAMPLES.md b/README-SAMPLES.md index eea883f3..28a5e6f1 100644 --- a/README-SAMPLES.md +++ b/README-SAMPLES.md @@ -112,18 +112,21 @@ This is a simple program to demonstrate dumping _**Exif**_ metadata in common fo #### exifprint ``` -Usage: exifprint [ path | --version | --version-test ] +Usage: exifprint [ [--lint] path | --version | --version-test ] ``` | Arguments | Description | |:-- |:--- | | path | Path to image | +| --lint path | Path to image. Type metadata test | | --version | Print version information from build | | --version-test | Tests Exiv2 VERSION API | This program demonstrates how to print _**Exif**_ metadata in an image. This program is also discussed in the platform ReadMe.txt file included in a build bundle. The option **--version** was added to enable the user to build a test application which dumps the build information. The option **--version-test** was added to test the macro EXIV2\_TEST\_VERSION() in **include/exiv2/version.hpp**. -There is one other unique feature of this program. It is the only test/sample program which can use the EXV\_UNICODE\_PATH build feature of Exiv2 on Windows. +You can process the metadata in two different ways. The default prints the metadata. The option --lint instructs exifprint to compare the type of the metadata to the standard. + +There is another unique feature of this program. It is the only test/sample program which can use the EXV\_UNICODE\_PATH build feature of Exiv2 on Windows. _Code: [exifprint.cpp](samples/exifprint.cpp)_ @@ -656,4 +659,4 @@ Read an XMP packet from a file, parse and re-serialize it. Robin Mills
robin@clanmills.com
-Revised: 2020-11-20 \ No newline at end of file +Revised: 2021-06-23 \ No newline at end of file diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index a8e81327..c8a85c59 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -33,7 +33,9 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN if (COMPILER_IS_GCC OR COMPILER_IS_CLANG) # This fails under Fedora - MinGW - Gcc 8.3 if (NOT (MINGW OR CYGWIN OR CMAKE_HOST_SOLARIS)) + if (NOT APPLE) # Don't know why this isn't working correctly on Apple with M1 processor check_cxx_compiler_flag(-fstack-clash-protection HAS_FSTACK_CLASH_PROTECTION) + endif() check_cxx_compiler_flag(-fcf-protection HAS_FCF_PROTECTION) check_cxx_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG) if(HAS_FSTACK_CLASH_PROTECTION) diff --git a/samples/exifprint.cpp b/samples/exifprint.cpp index 43dff727..7d464ada 100644 --- a/samples/exifprint.cpp +++ b/samples/exifprint.cpp @@ -42,6 +42,14 @@ #define _tmain main #endif +// copied from src/tiffvisitor_int.cpp +static const Exiv2::TagInfo* findTag(const Exiv2::TagInfo* pList,uint16_t tag) +{ + while ( pList->tag_ != 0xffff && pList->tag_ != tag ) pList++; + return pList->tag_ != 0xffff ? pList : NULL; +} + + int _tmain(int argc, _tchar* const argv[]) try { Exiv2::XmpParser::initialize(); @@ -51,19 +59,22 @@ try { #endif const _tchar* prog = argv[0]; - const _tchar* file = argv[1]; - - if (argc != 2) { - std::_tcout << _t("Usage: ") << prog << _t(" [ path | --version | --version-test ]") << std::endl; + if (argc == 1) { + std::_tcout << _t("Usage: ") << prog << _t(" [ [--lint] path | --version | --version-test ]") << std::endl; return 1; } + int rc = 0 ; + const _tchar* file = argv[1]; + bool bLint = _tstrcmp(file,_t("--lint")) == 0 && argc == 3; + if ( bLint ) file= argv[2]; + + if ( _tstrcmp(file,_t("--version")) == 0 ) { exv_grep_keys_t keys; Exiv2::dumpLibraryInfo(std::cout,keys); - return 0; - } - if (_tstrcmp(file, _t("--version-test")) == 0) { + return rc; + } else if ( _tstrcmp(file,_t("--version-test")) == 0 ) { // verifies/test macro EXIV2_TEST_VERSION // described in include/exiv2/version.hpp std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl @@ -86,7 +97,7 @@ try { #else std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n"; #endif - return 0; + return rc; } Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(file); @@ -101,21 +112,37 @@ try { auto end = exifData.end(); for (auto i = exifData.begin(); i != end; ++i) { - const char* tn = i->typeName(); - std::cout << std::setw(44) << std::setfill(' ') << std::left - << i->key() << " " - << "0x" << std::setw(4) << std::setfill('0') << std::right - << std::hex << i->tag() << " " - << std::setw(9) << std::setfill(' ') << std::left - << (tn ? tn : "Unknown") << " " - << std::dec << std::setw(3) - << std::setfill(' ') << std::right - << i->count() << " " - << std::dec << i->toString() - << "\n"; + if ( ! bLint ) { + const char* tn = i->typeName(); + std::cout << std::setw(44) << std::setfill(' ') << std::left + << i->key() << " " + << "0x" << std::setw(4) << std::setfill('0') << std::right + << std::hex << i->tag() << " " + << std::setw(9) << std::setfill(' ') << std::left + << (tn ? tn : "Unknown") << " " + << std::dec << std::setw(3) + << std::setfill(' ') << std::right + << i->count() << " " + << std::dec << i->toString() + << "\n"; + } else { + const Exiv2::TagInfo* tagInfo = findTag( Exiv2::ExifTags::tagList(i->groupName()),i->tag() ); + if ( tagInfo ) { + Exiv2::TypeId type = i->typeId(); + if ( type!= tagInfo-> typeId_ + &&!(tagInfo->typeId_ == Exiv2::comment && type == Exiv2::undefined) // Comment is stored as Undefined + ) { + std::cerr << i->key() + << " type " << i->typeName() << " (" << type << ")" + << " expected " << Exiv2::TypeInfo::typeName(tagInfo-> typeId_) << " (" << tagInfo-> typeId_ << ")" + << std::endl; + rc=2; + } + } + } } - return 0; + return rc; } //catch (std::exception& e) { //catch (Exiv2::AnyError& e) {