summaryrefslogtreecommitdiffstats
path: root/lib/exif_wrapper.cpp
diff options
context:
space:
mode:
authordan <[email protected]>2023-03-13 16:30:13 -0400
committerdan <[email protected]>2023-03-13 16:30:13 -0400
commit889c58413b613d234e880007966fc38b262d77e2 (patch)
tree29be552479d4c9f036aac9a02326356e0d1d0467 /lib/exif_wrapper.cpp
parent5f1f3fa55e998cd6021af7614275c3a1afb8b501 (diff)
download54-889c58413b613d234e880007966fc38b262d77e2.tar.gz
54-889c58413b613d234e880007966fc38b262d77e2.tar.bz2
54-889c58413b613d234e880007966fc38b262d77e2.zip
partial-fix: images not corrupted (but still not displaying with correct orientation)
Diffstat (limited to 'lib/exif_wrapper.cpp')
-rw-r--r--lib/exif_wrapper.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/exif_wrapper.cpp b/lib/exif_wrapper.cpp
index eab5598..21ee6c6 100644
--- a/lib/exif_wrapper.cpp
+++ b/lib/exif_wrapper.cpp
@@ -35,10 +35,38 @@ extern "C" unsigned int getExifOrientation(uint8_t* imgBytes, unsigned int size)
}
}
+
+extern "C" void setExifOrientation(char* fileName, unsigned int orientation) {
+ try {
+ // Exiv init
+ Exiv2::XmpParser::initialize();
+ ::atexit(Exiv2::XmpParser::terminate);
+ Exiv2::enableBMFF();
+
+ // using blob works, except that exiv2 won't write back to the blob :(
+ // std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(imgBytes, size);
+ // So instead we load from the temp file
+ std::unique_ptr<Exiv2::Image> image = Exiv2::ImageFactory::open(fileName);
+ assert(image.get() != 0);
+ image->readMetadata();
+ Exiv2::ExifData &exifData = image->exifData();
+
+ exifData[ORIENTATION_KEY] = orientation;
+
+ // Save exif to image object & save image back to file
+ image->setExifData(exifData);
+ image->writeMetadata();
+ }
+ catch (Exiv2::Error& e) {
+ std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
+ }
+}
+/*
extern "C" void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigned int orientation) {
try {
// Hack to work around Exiv2 seeming to refuse to write back to blob, but will write
// back to a file. Create temp file -> operate on it -> copy back to blob, unlink file.
+ // tmpFileName gets overwritten with the actual filename by mkstemp
char tmpFileName[] = "/tmp/image-temp.XXXXXX";
int fd = mkstemp(tmpFileName);
assert(fd != -1);
@@ -74,4 +102,4 @@ extern "C" void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigne
catch (Exiv2::Error& e) {
std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
}
-}
+}*/