annotate src/name/blackcap/exifwasher/exiv2/native.cpp @ 22:cd2ca4727b7f

Builds under Windows.
author davidb
date Thu, 16 Apr 2020 11:10:39 -0700
parents a59d84674fb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
1 #include <jni.h>
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
2 #include <string.h>
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
3 #include <exiv2/exiv2.hpp>
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
4 #include <exception>
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
5 #include <iostream>
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
6 #include <iomanip>
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
7 #include <cassert>
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
8
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
9 /* Functions for class name_blackcap_exifwasher_exiv2_Image */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
10
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
11 #ifndef _Included_name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
12 #define _Included_name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
13 #ifdef __cplusplus
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
14 extern "C" {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
15 #endif
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
16
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
17 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
18 * Utility function to get pointer field.
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
19 */
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
20 Exiv2::Image *getPointer(JNIEnv *jEnv, jobject jThis) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
21 return reinterpret_cast<Exiv2::Image *>
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
22 (jEnv->GetLongField(jThis,
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
23 jEnv->GetFieldID(jEnv->GetObjectClass(jThis), "pointer", "J")));
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
24 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
25
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
26 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
27 * Class: name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
28 * Method: _ctor
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
29 * Signature: (Ljava/lang/String;)J
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
30 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
31 JNIEXPORT jlong JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1ctor
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
32 (JNIEnv *jEnv, jobject jThis, jstring path) {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
33 const char *cPath = jEnv->GetStringUTFChars(path, NULL);
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
34 jlong ret = 0;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
35 try {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
36 ret = reinterpret_cast<jlong> (Exiv2::ImageFactory::open(cPath).release());
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
37 } catch (std::exception& e) {
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
38 jEnv->ExceptionClear();
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
39 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception");
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
40 jEnv->ThrowNew(ex, e.what());
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
41 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
42 jEnv->ReleaseStringUTFChars(path, cPath);
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
43 return ret;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
44 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
45
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
46 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
47 * Class: name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
48 * Method: _writeMetadata
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
49 * Signature: ()V
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
50 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
51 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1writeMetadata
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
52 (JNIEnv *jEnv, jobject jThis) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
53 Exiv2::Image *image = getPointer(jEnv, jThis);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
54 if (jEnv->ExceptionCheck()) return;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
55 try {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
56 image->writeMetadata();
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
57 } catch (std::exception& e) {
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
58 jEnv->ExceptionClear();
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
59 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception");
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
60 jEnv->ThrowNew(ex, e.what());
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
61 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
62 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
63
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
64 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
65 * Class: name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
66 * Method: _getMetadata
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
67 * Signature: ()J
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
68 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
69 JNIEXPORT jlong JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1getMetadata
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 (JNIEnv *jEnv, jobject jThis) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
71 Exiv2::Image *image = getPointer(jEnv, jThis);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
72 if (jEnv->ExceptionCheck()) return 0;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 try {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 image->readMetadata();
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
75 } catch (std::exception& e) {
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
76 jEnv->ExceptionClear();
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception");
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
78 jEnv->ThrowNew(ex, e.what());
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
79 return 0;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 }
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
81 return reinterpret_cast<jlong>(image);
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
83
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
84 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 * Class: name_blackcap_exifwasher_exiv2_Image
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
86 * Method: _dtor
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
87 * Signature: ()V
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
89 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_Image__1dtor
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 (JNIEnv *jEnv, jobject jThis) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
91 Exiv2::Image *image = getPointer(jEnv, jThis);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
92 if (jEnv->ExceptionCheck()) return;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 delete image;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
94 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
95
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 #ifdef __cplusplus
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 #endif
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 #endif
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 /* Header for class name_blackcap_exifwasher_exiv2_ExifData */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
101
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
102 /*
22
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
103 * Utility function to parse out a type prefix from a key name.
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
104 */
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
105 char *getType(const char *key) {
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
106 const char *dot = strchr(key, '.');
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
107 if (dot == NULL)
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
108 throw std::invalid_argument(std::string("invalid key: ") + std::string(key));
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
109 int length = dot - key;
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
110 char *ret = (char *) malloc(length + 1);
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
111 memcpy(ret, key, length);
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
112 ret[length] = '\0';
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
113 return ret;
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
114 }
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
115
cd2ca4727b7f Builds under Windows.
davidb
parents: 13
diff changeset
116 /*
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
117 * Utility function to delete a (key, value) pair.
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
118 */
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
119 template<class D, class K>
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
120 void deleteValue(D &data, const char *key) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
121 typename D::iterator found = data.findKey(K(std::string(key)));
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
122 data.erase(found);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
123 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
124
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
125 /*
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
126 * Utility function to retrieve a value, given a key.
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
127 */
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
128 template<class D, class K>
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
129 jobject getValue(JNIEnv *jEnv, D &data, const char *key) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
130 typename D::iterator found = data.findKey(K(std::string(key)));
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
131 if (found == data.end()) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
132 return NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
133 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
134 jclass klass = jEnv->FindClass("name/blackcap/exifwasher/exiv2/ExifData$Value");
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
135 if (jEnv->ExceptionCheck()) return NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
136 jstring type = jEnv->NewStringUTF(found->typeName());
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
137 jstring value = jEnv->NewStringUTF(found->toString().c_str());
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
138 jmethodID method = jEnv->GetMethodID(klass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
139 if (jEnv->ExceptionCheck()) return NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
140 return jEnv->NewObject(klass, method, type, value);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
141 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
142
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
143 /*
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
144 * Utility function to read keys, given a target to put them and a collection
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
145 * of data.
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
146 */
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
147 template<class D>
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
148 jsize getKeys(JNIEnv *jEnv, jobjectArray target, jsize start, D &data) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
149 typename D::const_iterator end = data.end();
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
150 jsize j = start;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
151 for (typename D::const_iterator i = data.begin(); i != end; ++i) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
152 jEnv->SetObjectArrayElement(target, j++, jEnv->NewStringUTF(i->key().c_str()));
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
153 if (jEnv->ExceptionCheck()) break;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
154 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
155 return j;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
156 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
157
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
158 #ifndef _Included_name_blackcap_exifwasher_exiv2_ExifData
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
159 #define _Included_name_blackcap_exifwasher_exiv2_ExifData
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
160 #ifdef __cplusplus
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
161 extern "C" {
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
162 #endif
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
163
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
164 /*
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
165 * Class: name_blackcap_exifwasher_exiv2_ExifData
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
166 * Method: _erase
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
167 * Signature: (Ljava/lang/String;)V
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
168 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
169 JNIEXPORT void JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1erase
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
170 (JNIEnv *jEnv, jobject jThis, jstring key) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
171 Exiv2::Image *image = getPointer(jEnv, jThis);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
172 if (jEnv->ExceptionCheck()) return;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
173 const char *cKey = jEnv->GetStringUTFChars(key, NULL);
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
174 char *type = NULL;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
175 try {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
176 type = getType(cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
177 if (!strcmp(type, "Exif")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
178 deleteValue<Exiv2::ExifData, Exiv2::ExifKey>(image->exifData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
179 } else if (!strcmp(type, "Xmp")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
180 deleteValue<Exiv2::XmpData, Exiv2::XmpKey>(image->xmpData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
181 } else if (!strcmp(type, "Iptc")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
182 deleteValue<Exiv2::IptcData, Exiv2::IptcKey>(image->iptcData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
183 } else {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
184 throw std::invalid_argument(std::string("invalid key: ") + std::string(cKey));
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
185 }
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
186 } catch (std::exception& e) {
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
187 jEnv->ExceptionClear();
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
188 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception");
2
efd9fe2d70d7 Rationalize exceptions, code whitelist, add command-line tool.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
189 jEnv->ThrowNew(ex, e.what());
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
190 }
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
191 if (type != NULL) free(type);
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
192 jEnv->ReleaseStringUTFChars(key, cKey);
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
193 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
194
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
195 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
196 * Class: name_blackcap_exifwasher_exiv2_ExifData
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
197 * Method: _value
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
198 * Signature: (Ljava/lang/String;)Lname/blackcap/exifwasher/exiv2/ExifData/Value;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
199 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
200 JNIEXPORT jobject JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1value
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
201 (JNIEnv *jEnv, jobject jThis, jstring key) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
202 Exiv2::Image *image = getPointer(jEnv, jThis);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
203 if (jEnv->ExceptionCheck()) return NULL;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
204 const char *cKey = jEnv->GetStringUTFChars(key, NULL);
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
205 char *type = NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
206 jobject ret = NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
207 try {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
208 type = getType(cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
209 if (!strcmp(type, "Exif")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
210 ret = getValue<Exiv2::ExifData, Exiv2::ExifKey>(jEnv, image->exifData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
211 } else if (!strcmp(type, "Xmp")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
212 ret = getValue<Exiv2::XmpData, Exiv2::XmpKey>(jEnv, image->xmpData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
213 } else if (!strcmp(type, "Iptc")) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
214 ret = getValue<Exiv2::IptcData, Exiv2::IptcKey>(jEnv, image->iptcData(), cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
215 } else {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
216 throw std::invalid_argument(std::string("invalid key: ") + std::string(cKey));
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
217 }
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
218 } catch (std::exception& e) {
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
219 jEnv->ExceptionClear();
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
220 jclass ex = jEnv->FindClass("name/blackcap/exifwasher/exiv2/Exiv2Exception");
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
221 jEnv->ThrowNew(ex, e.what());
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
222 }
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
223 if (type != NULL) free(type);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
224 jEnv->ReleaseStringUTFChars(key, cKey);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
225 return ret;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
226 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
227
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
228 /*
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
229 * Class: name_blackcap_exifwasher_exiv2_ExifData
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
230 * Method: _keys
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
231 * Signature: ()[Ljava/lang/String;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
232 */
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
233 JNIEXPORT jobjectArray JNICALL Java_name_blackcap_exifwasher_exiv2_ExifData__1keys
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
234 (JNIEnv *jEnv, jobject jThis) {
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
235 Exiv2::Image *image = getPointer(jEnv, jThis);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
236 Exiv2::ExifData eData = image->exifData();
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
237 Exiv2::XmpData xData = image->xmpData();
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
238 Exiv2::IptcData iData = image->iptcData();
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
239 if (jEnv->ExceptionCheck()) return NULL;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
240 jclass klass = jEnv->FindClass("java/lang/String");
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
241 if (jEnv->ExceptionCheck()) return NULL;
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
242 jobjectArray ret = jEnv->NewObjectArray(eData.count() + iData.count() + xData.count(), klass, NULL);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
243 if (jEnv->ExceptionCheck()) return NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
244 jsize start = getKeys(jEnv, ret, 0, eData);
1
42277ce58ace Improve exception handling; always use absolute paths on libs.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
245 if (jEnv->ExceptionCheck()) return NULL;
13
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
246 start = getKeys(jEnv, ret, start, xData);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
247 if (jEnv->ExceptionCheck()) return NULL;
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
248 start = getKeys(jEnv, ret, start, iData);
a59d84674fb0 Make it seamlessly work on IPTC and XMP metadata, too.
David Barts <davidb@stashtea.com>
parents: 2
diff changeset
249 if (jEnv->ExceptionCheck()) return NULL;
0
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
250 return ret;
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
251 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
252
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
253 #ifdef __cplusplus
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
254 }
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
255 #endif
db63d01a23c6 JNI calls and test case (finally!) seem to work.
David Barts <n5jrn@me.com>
parents:
diff changeset
256 #endif