imageio: do not fail in saving an image if no metadata is available

(cherry picked from commit 86d48be88b6f9fe36e5e25185ec4fda7696efc25)
This commit is contained in:
Alberto Griggio
2020-03-10 08:16:39 -07:00
committed by Lawrence Lee
parent e205ff86cc
commit ea3cf2fe8f

View File

@@ -41,6 +41,7 @@
#include "iccjpeg.h" #include "iccjpeg.h"
#include "color.h" #include "color.h"
#include "imagedata.h" #include "imagedata.h"
#include "settings.h"
#include "jpeg.h" #include "jpeg.h"
@@ -48,6 +49,8 @@ using namespace std;
using namespace rtengine; using namespace rtengine;
using namespace rtengine::procparams; using namespace rtengine::procparams;
namespace rtengine { extern const Settings *settings; }
namespace namespace
{ {
@@ -1355,8 +1358,18 @@ bool ImageIO::saveMetadata(const Glib::ustring &fname) const
return true; return true;
} }
bool has_meta = true;
try { try {
metadataInfo.load(); metadataInfo.load();
} catch (const std::exception& exc) {
if (settings->verbose) {
std::cout << "EXIF LOAD ERROR: " << exc.what() << std::endl;
}
has_meta = false;
}
if (has_meta) {
try {
metadataInfo.saveToImage(fname); metadataInfo.saveToImage(fname);
// auto src = open_exiv2(metadataInfo.filename()); // auto src = open_exiv2(metadataInfo.filename());
// auto dst = open_exiv2(fname); // auto dst = open_exiv2(fname);
@@ -1384,9 +1397,11 @@ bool ImageIO::saveMetadata(const Glib::ustring &fname) const
// } // }
// } // }
// dst->writeMetadata(); // dst->writeMetadata();
return true;
} catch (const std::exception& exc) { } catch (const std::exception& exc) {
std::cout << "EXIF ERROR: " << exc.what() << std::endl; std::cout << "EXIF ERROR: " << exc.what() << std::endl;
return false; return false;
} }
}
return true;
} }