metadata: make sure to include XResolution and YResolution when writing TIFFs

This is mandatory (according to http://dpfmanager.org), and in fact needed for
Photoshop compatibility

(cherry picked from commit 5d281810cc7a7f7dc563dde030cf90c78dbf55d0)
This commit is contained in:
Alberto Griggio
2021-01-27 10:06:25 -08:00
committed by Lawrence Lee
parent 939315f67b
commit 522f6f4473
3 changed files with 66 additions and 2 deletions

View File

@@ -1098,6 +1098,7 @@ int ImageIO::saveJPEG (const Glib::ustring &fname, int quality, int subSamp) con
return IMIO_SUCCESS;
}
int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool uncompressed) const
{
if (getWidth() < 1 || getHeight() < 1) {
@@ -1168,6 +1169,31 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
}
}();*/
// somehow Exiv2 (tested with 0.27.3) doesn't seem to be able to update
// XResolution and YResolution, so we do it ourselves here....
constexpr float default_resolution = 300.f;
float x_res = default_resolution;
float y_res = default_resolution;
int res_unit = RESUNIT_INCH;
if (!metadataInfo.filename().empty()) {
auto exif = metadataInfo.getOutputExifData();
auto it = exif.findKey(Exiv2::ExifKey("Exif.Image.XResolution"));
if (it != exif.end()) {
x_res = it->toFloat();
}
it = exif.findKey(Exiv2::ExifKey("Exif.Image.YResolution"));
if (it != exif.end()) {
y_res = it->toFloat();
}
it = exif.findKey(Exiv2::ExifKey("Exif.Image.ResolutionUnit"));
if (it != exif.end()) {
res_unit = it->toLong();
}
}
TIFFSetField(out, TIFFTAG_XRESOLUTION, x_res);
TIFFSetField(out, TIFFTAG_YRESOLUTION, y_res);
TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);
if (!uncompressed) {
TIFFSetField (out, TIFFTAG_PREDICTOR, (bps == 16 || bps == 32) && isFloat ? PREDICTOR_FLOATINGPOINT : PREDICTOR_HORIZONTAL);
}