diff options
author | dan <[email protected]> | 2023-03-13 16:30:13 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-03-13 16:30:13 -0400 |
commit | 889c58413b613d234e880007966fc38b262d77e2 (patch) | |
tree | 29be552479d4c9f036aac9a02326356e0d1d0467 /lib | |
parent | 5f1f3fa55e998cd6021af7614275c3a1afb8b501 (diff) | |
download | 54-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')
-rw-r--r-- | lib/exif_wrapper.cpp | 30 | ||||
-rw-r--r-- | lib/exif_wrapper.h | 3 |
2 files changed, 31 insertions, 2 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"; } -} +}*/ diff --git a/lib/exif_wrapper.h b/lib/exif_wrapper.h index ec51406..ab649c8 100644 --- a/lib/exif_wrapper.h +++ b/lib/exif_wrapper.h @@ -1,4 +1,5 @@ #include <stdint.h> unsigned int getExifOrientation(uint8_t* imgBytes, unsigned int size); -void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigned int orientation); +//void setExifOrientation(uint8_t* imgBytes, unsigned int size, unsigned int orientation); +void setExifOrientation(char* fileName, unsigned int orientation); |