[SCM] exiv2 packaging branch, master, updated. debian/0.25-3.1-3734-gdcbc29a

Maximiliano Curia maxy at moszumanska.debian.org
Thu Jul 13 17:44:56 UTC 2017


Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/exiv2.git;a=commitdiff;h=917efc5

The following commit has been merged in the master branch:
commit 917efc5d05e88b2c77e46392a3c9fe27955940b9
Author: Robin Mills <robin at clanmills.com>
Date:   Wed Mar 25 18:21:43 2015 +0000

    Adding samples/exifdata.cpp and samples/exifvalue.cpp
---
 samples/Makefile      |   4 +-
 samples/exifdata.cpp  | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++
 samples/exifvalue.cpp |  43 +++++++++++
 3 files changed, 247 insertions(+), 1 deletion(-)

diff --git a/samples/Makefile b/samples/Makefile
index 53c7c27..10c736b 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -59,7 +59,9 @@ BINSRC = addmoddel.cpp        \
          easyaccess-test.cpp  \
          exifcomment.cpp      \
          exifdata-test.cpp    \
+         exifdata.cpp         \
          exifprint.cpp        \
+         exifvalue.cpp        \
          exiv2json.cpp        \
          httptest.cpp         \
          iotest.cpp           \
@@ -113,7 +115,7 @@ DEP = $(BINSRC:%.cpp=$(DEPDIR)/%.d) $(OTHERSRC:%.cpp=$(DEPDIR)/%.d)
 endif
 
 PREFIX = /usr/local/lib
-LINK.cc += -rpath $(PREFIX) -L$(PREFIX) 
+LINK.cc += -rpath $(PREFIX) -L$(PREFIX)
 COMPILE.cc += -I$(top_srcdir)/include/exiv2
 
 # ******************************************************************************
diff --git a/samples/exifdata.cpp b/samples/exifdata.cpp
new file mode 100644
index 0000000..5f13016
--- /dev/null
+++ b/samples/exifdata.cpp
@@ -0,0 +1,201 @@
+// ***************************************************************** -*- C++ -*-
+// exifdata.cpp, $Rev: 3090 $
+// Sample program to format exif data in various external formats
+
+#include <exiv2/exiv2.hpp>
+
+#include <iostream>
+#include <iomanip>
+#include <cassert>
+#include <string>
+
+typedef std::map<std::string,int> format_t;
+typedef format_t::const_iterator  format_i;
+typedef enum  { wolf ,  csv , json , xml } format_e;
+
+void syntax(const char* argv[],format_t& formats)
+{
+	std::cout << "Usage: " << argv[0] << " file format" << std::endl;
+	int count = 0;
+	std::cout << "formats: ";
+	for ( format_i i = formats.begin() ; i != formats.end() ; i++ ) {
+		std::cout << ( count++ ? " | " : "") << i->first ;
+	}
+	std::cout << std::endl;
+}
+
+size_t formatInit(Exiv2::ExifData& exifData)
+{
+	size_t result = 0;
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != exifData.end() ; ++i) {
+		result ++ ;
+	}
+	return result ;
+}
+
+///////////////////////////////////////////////////////////////////////
+std::string escapeCSV(Exiv2::ExifData::const_iterator it,bool bValue)
+{
+	std::string   result ;
+
+	std::ostringstream os;
+	if ( bValue ) os << it->value() ; else os << it->key() ;
+
+	std::string s = os.str();
+	for ( size_t i = 0 ;i < s.length() ; i ++ ) {
+		if ( s[i] == ',' ) result += '\';
+		result += s[i];
+	}
+
+	return result ;
+}
+
+std::string formatCSV(Exiv2::ExifData& exifData)
+{
+	size_t count  = 0;
+	size_t length = formatInit(exifData);
+	std::ostringstream result;
+
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); count++ < length; ++i) {
+		result << escapeCSV(i,false) << (count != length ? ", " : "" ) ;
+	}
+	result << std::endl;
+
+	count = 0;
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); count++ < length ; ++i) {
+		result << escapeCSV(i,true) << (count != length ? ", " : "" ) ;
+	}
+	return result.str();
+}
+
+///////////////////////////////////////////////////////////////////////
+std::string formatWolf(Exiv2::ExifData& exifData)
+{
+	size_t count  = 0;
+	size_t length = formatInit(exifData);
+	std::ostringstream result;
+
+	result << "{ " << std::endl;
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); count++ < length ; ++i) {
+		result << "  " << i->key()  << " -> " << i->value()  << (count != length ? "," : "" ) << std::endl ;
+	}
+	result << "}";
+	return result.str();
+}
+
+///////////////////////////////////////////////////////////////////////
+std::string escapeJSON(Exiv2::ExifData::const_iterator it,bool bValue=true)
+{
+	std::string   result ;
+
+	std::ostringstream os;
+	if ( bValue ) os << it->value() ; else os << it->key() ;
+
+	std::string s = os.str();
+	for ( size_t i = 0 ;i < s.length() ; i ++ ) {
+		if ( s[i] == '"' ) result += "\\"";
+		result += s[i];
+	}
+
+	std::string q = "\"";
+	return q + result + q ;
+}
+
+std::string formatJSON(Exiv2::ExifData& exifData)
+{
+	size_t count  = 0;
+	size_t length = formatInit(exifData);
+	std::ostringstream result;
+
+	result << "{" << std::endl ;
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); count++ < length ; ++i) {
+		result << "  " << escapeJSON(i,false)  << ":" << escapeJSON(i,true) << ( count != length ? "," : "" ) << std::endl ;
+	}
+	result << "}";
+	return result.str();
+}
+
+///////////////////////////////////////////////////////////////////////
+std::string escapeXML(Exiv2::ExifData::const_iterator it,bool bValue=true)
+{
+	std::string   result ;
+
+	std::ostringstream os;
+	if ( bValue ) os << it->value() ; else os << it->key() ;
+
+	std::string s = os.str();
+	for ( size_t i = 0 ;i < s.length() ; i ++ ) {
+		if ( s[i] == '<' ) result += "≶";
+		if ( s[i] == '>' ) result += ">";
+		result += s[i];
+	}
+
+	return result ;
+}
+
+std::string formatXML(Exiv2::ExifData& exifData)
+{
+	size_t count  = 0;
+	size_t length = formatInit(exifData);
+	std::ostringstream result;
+
+	result << "<exif>" << std::endl;
+	for (Exiv2::ExifData::const_iterator i = exifData.begin(); count++ < length ; ++i) {
+		std::string key   = escapeXML(i,false);
+		std::string value = escapeXML(i,true);
+		result << "  <" << key << ">" << value << "<" << key << "/>" << std::endl ;
+	}
+	result << "</exif>" << std::endl;
+	return result.str();
+}
+
+///////////////////////////////////////////////////////////////////////
+int main(int argc,const char* argv[])
+{
+	format_t formats;
+	formats["wolf"] = wolf;
+	formats["csv" ] = csv ;
+	formats["json"] = json;
+	formats["xml" ] = xml ;
+
+	int result = 0 ;
+    if (argc != 3) {
+    	syntax(argv,formats) ;
+        result = 1;
+    }
+
+    const char* file   = argv[1];
+    const char* format = argv[2];
+
+	if ( !result && formats.find(format) == formats.end() ) {
+        std::cout << "Unrecognised format " << format << std::endl;
+        syntax(argv,formats);
+        result = 2;
+	}
+
+	if ( !result ) try {
+		Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
+		assert(image.get() != 0);
+		image->readMetadata();
+		Exiv2::ExifData &exifData = image->exifData();
+
+		switch ( formats.find(format)->second ) {
+			case wolf : std::cout << formatWolf(exifData) << std::endl; break;
+			case csv  : std::cout << formatCSV (exifData) << std::endl; break;
+			case json : std::cout << formatJSON(exifData) << std::endl; break;
+			case xml  : std::cout << formatXML (exifData) << std::endl; break;
+
+			default   : std::cout << "*** error: format not implemented yet: " << format << " ***" << std::endl;
+			            result = 3;
+			break;
+		}
+	} catch (Exiv2::AnyError& e) {
+    	std::cerr << "*** error exiv2 exception '" << e << "' ***" << std::endl;
+    	result = 4;
+	} catch ( ... ) {
+    	std::cerr << "*** error exception" << std::endl;
+    	result = 5;
+	}
+
+    return result;
+}
diff --git a/samples/exifvalue.cpp b/samples/exifvalue.cpp
new file mode 100644
index 0000000..34b0e0d
--- /dev/null
+++ b/samples/exifvalue.cpp
@@ -0,0 +1,43 @@
+// ***************************************************************** -*- C++ -*-
+// exifvalue.cpp, $Rev: 3090 $
+// Sample program to print value of an exif key in an image
+
+#include <exiv2/exiv2.hpp>
+
+#include <iostream>
+#include <iomanip>
+#include <cassert>
+#include <string>
+
+int main(int argc, char* const argv[])
+{
+    if (argc != 3) {
+        std::cerr << "Usage: " << argv[0] << " file key
";
+        return 1;
+    }
+
+    const char* file = argv[1];
+    const char* key  = argv[2];
+
+    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(file);
+    assert(image.get() != 0);
+    image->readMetadata();
+    Exiv2::ExifData &exifData = image->exifData();
+
+    if ( exifData.empty()) {
+		std::cerr << "no metadata found in file " << file << std::endl;
+		exit(2);
+	}
+
+	try {
+     	std::cout << exifData[key] << std::endl;
+	} catch (Exiv2::AnyError& e) {
+    	std::cerr << "Caught Exiv2 exception '" << e << "'" << std::endl;
+    	exit(3);
+	} catch ( ... ) {
+		std::cerr << "Caught a cold!" << std::endl;
+    	exit(4);
+	}
+
+    return 0;
+}

-- 
exiv2 packaging



More information about the pkg-kde-commits mailing list