kis_tiff_export.cc (krita-5.1.3.tar.xz) | : | kis_tiff_export.cc (krita-5.1.4.tar.xz) | ||
---|---|---|---|---|
skipping to change at line 17 | skipping to change at line 17 | |||
#include "kis_tiff_export.h" | #include "kis_tiff_export.h" | |||
#include <QBuffer> | #include <QBuffer> | |||
#include <QFileInfo> | #include <QFileInfo> | |||
#include <memory> | #include <memory> | |||
#include <exiv2/exiv2.hpp> | #include <exiv2/exiv2.hpp> | |||
#include <kpluginfactory.h> | #include <kpluginfactory.h> | |||
#ifdef Q_OS_WIN | ||||
#include <io.h> | ||||
#endif | ||||
#include <tiffio.h> | #include <tiffio.h> | |||
#include <KisDocument.h> | #include <KisDocument.h> | |||
#include <KisExportCheckRegistry.h> | #include <KisExportCheckRegistry.h> | |||
#include <KoColorModelStandardIds.h> | #include <KoColorModelStandardIds.h> | |||
#include <KoDocumentInfo.h> | #include <KoDocumentInfo.h> | |||
#include <KoUnit.h> | #include <KoUnit.h> | |||
#include <kis_assert.h> | #include <kis_assert.h> | |||
#include <kis_group_layer.h> | #include <kis_group_layer.h> | |||
#include <kis_layer_utils.h> | #include <kis_layer_utils.h> | |||
#include <kis_meta_data_backend_registry.h> | #include <kis_meta_data_backend_registry.h> | |||
#include <kis_paint_layer.h> | #include <kis_paint_layer.h> | |||
#include <kis_tiff_writer_visitor.h> | #include <kis_tiff_writer_visitor.h> | |||
#include <KisExiv2IODevice.h> | ||||
#include <config-tiff.h> | #include <config-tiff.h> | |||
#ifdef TIFF_CAN_WRITE_PSD_TAGS | #ifdef TIFF_CAN_WRITE_PSD_TAGS | |||
#include "kis_tiff_psd_writer_visitor.h" | #include "kis_tiff_psd_writer_visitor.h" | |||
#endif | #endif | |||
#include "kis_dlg_options_tiff.h" | #include "kis_dlg_options_tiff.h" | |||
#include "kis_tiff_converter.h" | #include "kis_tiff_converter.h" | |||
#include "kis_tiff_logger.h" | #include "kis_tiff_logger.h" | |||
skipping to change at line 105 | skipping to change at line 109 | |||
image->addNode(KisNodeSP(l.data()), image->rootLayer().data()); | image->addNode(KisNodeSP(l.data()), image->rootLayer().data()); | |||
return image; | return image; | |||
} else { | } else { | |||
return document->savingImage(); | return document->savingImage(); | |||
} | } | |||
}(); | }(); | |||
dbgFile << "Start writing TIFF File"; | dbgFile << "Start writing TIFF File"; | |||
KIS_ASSERT_RECOVER_RETURN_VALUE(kisimage, ImportExportCodes::InternalError); | KIS_ASSERT_RECOVER_RETURN_VALUE(kisimage, ImportExportCodes::InternalError); | |||
QFile file(filename()); | ||||
if (!file.open(QFile::ReadWrite)) { | ||||
return {KisImportExportErrorCannotRead(file.error())}; | ||||
} | ||||
// Open file for writing | // Open file for writing | |||
const QByteArray encodedFilename = QFile::encodeName(filename()); | const QByteArray encodedFilename = QFile::encodeName(filename()); | |||
std::unique_ptr<TIFF, decltype(&TIFFClose)> image( | ||||
TIFFOpen(encodedFilename.data(), "w"), | // https://gitlab.com/libtiff/libtiff/-/issues/173 | |||
&TIFFClose); | #ifdef Q_OS_WIN | |||
const int handle = (int)(_get_osfhandle(file.handle())); | ||||
#else | ||||
const int handle = file.handle(); | ||||
#endif | ||||
// NOLINTNEXTLINE(bugprone-narrowing-conversions, cppcoreguidelines-narrowin | ||||
g-conversions) | ||||
std::unique_ptr<TIFF, decltype(&TIFFCleanup)> image(TIFFFdOpen(handle, encod | ||||
edFilename.data(), "w"), &TIFFCleanup); | ||||
if (!image) { | if (!image) { | |||
dbgFile << "Could not open the file for writing" << filename(); | dbgFile << "Could not open the file for writing" << filename(); | |||
return ImportExportCodes::NoAccessToWrite; | return ImportExportCodes::NoAccessToWrite; | |||
} | } | |||
// Set the document information | // Set the document information | |||
KoDocumentInfo *info = document->documentInfo(); | KoDocumentInfo *info = document->documentInfo(); | |||
QString title = info->aboutInfo("title"); | QString title = info->aboutInfo("title"); | |||
if (!title.isEmpty()) { | if (!title.isEmpty()) { | |||
skipping to change at line 159 | skipping to change at line 175 | |||
// because we convert from | // because we convert from | |||
// pointer-per-inchs to points | // pointer-per-inchs to points | |||
return ImportExportCodes::ErrorWhileWriting; | return ImportExportCodes::ErrorWhileWriting; | |||
} | } | |||
if (!TIFFSetField(image.get(), | if (!TIFFSetField(image.get(), | |||
TIFFTAG_YRESOLUTION, | TIFFTAG_YRESOLUTION, | |||
INCH_TO_POINT(kisimage->yRes()))) { | INCH_TO_POINT(kisimage->yRes()))) { | |||
return ImportExportCodes::ErrorWhileWriting; | return ImportExportCodes::ErrorWhileWriting; | |||
} | } | |||
if (!TIFFSetField(image.get(), TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH)) { | ||||
return ImportExportCodes::ErrorWhileWriting; | ||||
} | ||||
KisGroupLayer *root = | KisGroupLayer *root = | |||
dynamic_cast<KisGroupLayer *>(kisimage->rootLayer().data()); | dynamic_cast<KisGroupLayer *>(kisimage->rootLayer().data()); | |||
KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(root, | KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(root, | |||
ImportExportCodes::InternalError); | ImportExportCodes::InternalError); | |||
#ifdef TIFF_CAN_WRITE_PSD_TAGS | #ifdef TIFF_CAN_WRITE_PSD_TAGS | |||
if (options.saveAsPhotoshop) { | if (options.saveAsPhotoshop) { | |||
KisTiffPsdWriter writer(image.get(), &options); | KisTiffPsdWriter writer(image.get(), &options); | |||
KisImportExportErrorCode result = writer.writeImage(root); | KisImportExportErrorCode result = writer.writeImage(root); | |||
if (!result.isOk()) { | if (!result.isOk()) { | |||
skipping to change at line 181 | skipping to change at line 201 | |||
} else | } else | |||
#endif // TIFF_CAN_WRITE_PSD_TAGS | #endif // TIFF_CAN_WRITE_PSD_TAGS | |||
{ | { | |||
KisTIFFWriterVisitor visitor(image.get(), &options); | KisTIFFWriterVisitor visitor(image.get(), &options); | |||
if (!(visitor.visit(root))) { | if (!(visitor.visit(root))) { | |||
return ImportExportCodes::Failure; | return ImportExportCodes::Failure; | |||
} | } | |||
} | } | |||
image.reset(); | image.reset(); | |||
file.close(); | ||||
if (!options.flatten && !options.saveAsPhotoshop) { | if (!options.flatten && !options.saveAsPhotoshop) { | |||
// HACK!! Externally inject the Exif metadata | // HACK!! Externally inject the Exif metadata | |||
// libtiff has no way to access the fields wholesale | // libtiff has no way to access the fields wholesale | |||
try { | try { | |||
const std::string encodedFilename = | KisExiv2IODevice::ptr_type basicIoDevice(new KisExiv2IODevice(filena | |||
QFile::encodeName(filename()).toStdString(); | me())); | |||
const std::unique_ptr<Exiv2::Image> img( | const std::unique_ptr<Exiv2::Image> img(Exiv2::ImageFactory::open(ba | |||
Exiv2::ImageFactory::open(encodedFilename).release()); | sicIoDevice).release()); | |||
img->readMetadata(); | img->readMetadata(); | |||
Exiv2::ExifData &data = img->exifData(); | Exiv2::ExifData &data = img->exifData(); | |||
const KisMetaData::IOBackend *io = | const KisMetaData::IOBackend *io = | |||
KisMetadataBackendRegistry::instance()->value("exif"); | KisMetadataBackendRegistry::instance()->value("exif"); | |||
// All IFDs are paint layer children of root | // All IFDs are paint layer children of root | |||
KisNodeSP node = root->firstChild(); | KisNodeSP node = root->firstChild(); | |||
End of changes. 8 change blocks. | ||||
7 lines changed or deleted | 30 lines changed or added |