exifprint_lint

main
Robin Mills 4 years ago
parent 3e099da7b7
commit fd2ab89de5

@ -112,18 +112,21 @@ This is a simple program to demonstrate dumping _**Exif**_ metadata in common fo
#### exifprint #### exifprint
``` ```
Usage: exifprint [ path | --version | --version-test ] Usage: exifprint [ [--lint] path | --version | --version-test ]
``` ```
| Arguments | Description | | Arguments | Description |
|:-- |:--- | |:-- |:--- |
| path | Path to image | | path | Path to image |
| --lint path | Path to image. Type metadata test |
| --version | Print version information from build | | --version | Print version information from build |
| --version-test | Tests Exiv2 VERSION API | | --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**. 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)_ _Code: [exifprint.cpp](samples/exifprint.cpp)_
@ -656,4 +659,4 @@ Read an XMP packet from a file, parse and re-serialize it.
Robin Mills<br> Robin Mills<br>
robin@clanmills.com<br> robin@clanmills.com<br>
Revised: 2020-11-20 Revised: 2021-06-23

@ -33,7 +33,9 @@ if ( MINGW OR UNIX OR MSYS ) # MINGW, Linux, APPLE, CYGWIN
if (COMPILER_IS_GCC OR COMPILER_IS_CLANG) if (COMPILER_IS_GCC OR COMPILER_IS_CLANG)
# This fails under Fedora - MinGW - Gcc 8.3 # This fails under Fedora - MinGW - Gcc 8.3
if (NOT (MINGW OR CYGWIN OR CMAKE_HOST_SOLARIS)) 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) 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(-fcf-protection HAS_FCF_PROTECTION)
check_cxx_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG) check_cxx_compiler_flag(-fstack-protector-strong HAS_FSTACK_PROTECTOR_STRONG)
if(HAS_FSTACK_CLASH_PROTECTION) if(HAS_FSTACK_CLASH_PROTECTION)

@ -42,6 +42,14 @@
#define _tmain main #define _tmain main
#endif #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[]) int _tmain(int argc, _tchar* const argv[])
try { try {
Exiv2::XmpParser::initialize(); Exiv2::XmpParser::initialize();
@ -51,19 +59,22 @@ try {
#endif #endif
const _tchar* prog = argv[0]; const _tchar* prog = argv[0];
const _tchar* file = argv[1]; if (argc == 1) {
std::_tcout << _t("Usage: ") << prog << _t(" [ [--lint] path | --version | --version-test ]") << std::endl;
if (argc != 2) {
std::_tcout << _t("Usage: ") << prog << _t(" [ path | --version | --version-test ]") << std::endl;
return 1; 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 ) { if ( _tstrcmp(file,_t("--version")) == 0 ) {
exv_grep_keys_t keys; exv_grep_keys_t keys;
Exiv2::dumpLibraryInfo(std::cout,keys); Exiv2::dumpLibraryInfo(std::cout,keys);
return 0; return rc;
} } else if ( _tstrcmp(file,_t("--version-test")) == 0 ) {
if (_tstrcmp(file, _t("--version-test")) == 0) {
// verifies/test macro EXIV2_TEST_VERSION // verifies/test macro EXIV2_TEST_VERSION
// described in include/exiv2/version.hpp // described in include/exiv2/version.hpp
std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl std::cout << "EXV_PACKAGE_VERSION " << EXV_PACKAGE_VERSION << std::endl
@ -86,7 +97,7 @@ try {
#else #else
std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n"; std::cout << "Compile-time Exiv2 version doesn't have Exiv2::testVersion()\n";
#endif #endif
return 0; return rc;
} }
Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(file); Exiv2::Image::UniquePtr image = Exiv2::ImageFactory::open(file);
@ -101,21 +112,37 @@ try {
auto end = exifData.end(); auto end = exifData.end();
for (auto i = exifData.begin(); i != end; ++i) { for (auto i = exifData.begin(); i != end; ++i) {
const char* tn = i->typeName(); if ( ! bLint ) {
std::cout << std::setw(44) << std::setfill(' ') << std::left const char* tn = i->typeName();
<< i->key() << " " std::cout << std::setw(44) << std::setfill(' ') << std::left
<< "0x" << std::setw(4) << std::setfill('0') << std::right << i->key() << " "
<< std::hex << i->tag() << " " << "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::setw(9) << std::setfill(' ') << std::left << std::hex << i->tag() << " "
<< (tn ? tn : "Unknown") << " " << std::setw(9) << std::setfill(' ') << std::left
<< std::dec << std::setw(3) << (tn ? tn : "Unknown") << " "
<< std::setfill(' ') << std::right << std::dec << std::setw(3)
<< i->count() << " " << std::setfill(' ') << std::right
<< std::dec << i->toString() << i->count() << " "
<< "\n"; << 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 (std::exception& e) {
//catch (Exiv2::AnyError& e) { //catch (Exiv2::AnyError& e) {

Loading…
Cancel
Save