Support for saving TIFFs as BigTIFF (#6690)

This commit is contained in:
Flössie 2023-03-01 12:47:55 +01:00
parent 23408bfcb3
commit a07c38f405
14 changed files with 113 additions and 30 deletions

View File

@ -2061,6 +2061,7 @@ SAMPLEFORMAT_16;16-bit floating-point
SAMPLEFORMAT_32;24-bit floating-point SAMPLEFORMAT_32;24-bit floating-point
SAMPLEFORMAT_64;32-bit floating-point SAMPLEFORMAT_64;32-bit floating-point
SAVEDLG_AUTOSUFFIX;Automatically add a suffix if the file already exists SAVEDLG_AUTOSUFFIX;Automatically add a suffix if the file already exists
SAVEDLG_BIGTIFF;BigTIFF
SAVEDLG_FILEFORMAT;File format SAVEDLG_FILEFORMAT;File format
SAVEDLG_FILEFORMAT_FLOAT; floating-point SAVEDLG_FILEFORMAT_FLOAT; floating-point
SAVEDLG_FORCEFORMATOPTS;Force saving options SAVEDLG_FORCEFORMATOPTS;Force saving options

View File

@ -1882,7 +1882,13 @@ public:
* @param bps can be 8 or 16 depending on the bits per pixels the output file will have * @param bps can be 8 or 16 depending on the bits per pixels the output file will have
* @param isFloat is true for saving float images. Will be ignored by file format not supporting float data * @param isFloat is true for saving float images. Will be ignored by file format not supporting float data
@return the error code, 0 if none */ @return the error code, 0 if none */
virtual int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const = 0; virtual int saveAsTIFF (
const Glib::ustring &fname,
int bps = -1,
bool isFloat = false,
bool uncompressed = false,
bool big = false
) const = 0;
/** @brief Sets the progress listener if you want to follow the progress of the image saving operations (optional). /** @brief Sets the progress listener if you want to follow the progress of the image saving operations (optional).
* @param pl is the pointer to the class implementing the ProgressListener interface */ * @param pl is the pointer to the class implementing the ProgressListener interface */
virtual void setSaveProgressListener (ProgressListener* pl) = 0; virtual void setSaveProgressListener (ProgressListener* pl) = 0;

View File

@ -81,7 +81,7 @@ public:
return saveJPEG(fname, quality, subSamp); return saveJPEG(fname, quality, subSamp);
} }
int saveAsTIFF(const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override int saveAsTIFF(const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false, bool big = false) const override
{ {
return saveTIFF(fname, bps, isFloat, uncompressed); return saveTIFF(fname, bps, isFloat, uncompressed);
} }

View File

@ -79,9 +79,15 @@ public:
return saveJPEG (fname, quality, subSamp); return saveJPEG (fname, quality, subSamp);
} }
int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override int saveAsTIFF (
const Glib::ustring &fname,
int bps = -1,
bool isFloat = false,
bool uncompressed = false,
bool big = false
) const override
{ {
return saveTIFF (fname, bps, isFloat, uncompressed); return saveTIFF (fname, bps, isFloat, uncompressed, big);
} }
void setSaveProgressListener (ProgressListener* pl) override void setSaveProgressListener (ProgressListener* pl) override

View File

@ -82,9 +82,15 @@ public:
{ {
return saveJPEG (fname, quality, subSamp); return saveJPEG (fname, quality, subSamp);
} }
int saveAsTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const override int saveAsTIFF (
const Glib::ustring &fname,
int bps = -1,
bool isFloat = false,
bool uncompressed = false,
bool big = false
) const override
{ {
return saveTIFF (fname, bps, isFloat, uncompressed); return saveTIFF (fname, bps, isFloat, uncompressed, big);
} }
void setSaveProgressListener (ProgressListener* pl) override void setSaveProgressListener (ProgressListener* pl) override
{ {

View File

@ -17,21 +17,17 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <https://www.gnu.org/licenses/>. * along with RawTherapee. If not, see <https://www.gnu.org/licenses/>.
*/ */
#include <png.h>
#include <glib/gstdio.h>
#include <tiff.h>
#include <tiffio.h>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <fcntl.h>
#include <libiptcdata/iptc-jpeg.h>
#include <memory> #include <memory>
#include "rt_math.h" #include <string>
#include "procparams.h"
#include "utils.h" #include <fcntl.h>
#include "../rtgui/options.h" #include <glib/gstdio.h>
#include "../rtgui/version.h" #include <libiptcdata/iptc-jpeg.h>
#include "../rtexif/rtexif.h" #include <png.h>
#include <tiff.h>
#include <tiffio.h>
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>
@ -39,12 +35,20 @@
#include <netinet/in.h> #include <netinet/in.h>
#endif #endif
#include "color.h"
#include "iccjpeg.h"
#include "imageio.h" #include "imageio.h"
#include "iptcpairs.h" #include "iptcpairs.h"
#include "iccjpeg.h"
#include "color.h"
#include "jpeg.h" #include "jpeg.h"
#include "procparams.h"
#include "rt_math.h"
#include "utils.h"
#include "../rtgui/options.h"
#include "../rtgui/version.h"
#include "../rtexif/rtexif.h"
using namespace std; using namespace std;
using namespace rtengine; using namespace rtengine;
@ -1328,7 +1332,13 @@ int ImageIO::saveJPEG (const Glib::ustring &fname, int quality, int subSamp) con
return IMIO_SUCCESS; return IMIO_SUCCESS;
} }
int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool uncompressed) const int ImageIO::saveTIFF (
const Glib::ustring &fname,
int bps,
bool isFloat,
bool uncompressed,
bool big
) const
{ {
if (getWidth() < 1 || getHeight() < 1) { if (getWidth() < 1 || getHeight() < 1) {
return IMIO_HEADERERROR; return IMIO_HEADERERROR;
@ -1345,15 +1355,28 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
int lineWidth = width * 3 * bps / 8; int lineWidth = width * 3 * bps / 8;
unsigned char* linebuffer = new unsigned char[lineWidth]; unsigned char* linebuffer = new unsigned char[lineWidth];
std::string mode = "w";
// little hack to get libTiff to use proper byte order (see TIFFClienOpen()): // little hack to get libTiff to use proper byte order (see TIFFClienOpen()):
const char *mode = !exifRoot ? "w" : (exifRoot->getOrder() == rtexif::INTEL ? "wl" : "wb"); if (exifRoot) {
if (exifRoot->getOrder() == rtexif::INTEL) {
mode += 'l';
} else {
mode += 'b';
}
}
if (big) {
mode += '8';
}
#ifdef WIN32 #ifdef WIN32
FILE *file = g_fopen_withBinaryAndLock (fname); FILE *file = g_fopen_withBinaryAndLock (fname);
int fileno = _fileno(file); int fileno = _fileno(file);
int osfileno = _get_osfhandle(fileno); int osfileno = _get_osfhandle(fileno);
TIFF* out = TIFFFdOpen (osfileno, fname.c_str(), mode); TIFF* out = TIFFFdOpen (osfileno, fname.c_str(), mode.c_str());
#else #else
TIFF* out = TIFFOpen(fname.c_str(), mode); TIFF* out = TIFFOpen(fname.c_str(), mode.c_str());
int fileno = TIFFFileno (out); int fileno = TIFFFileno (out);
#endif #endif

View File

@ -113,7 +113,13 @@ public:
int savePNG (const Glib::ustring &fname, int bps = -1) const; int savePNG (const Glib::ustring &fname, int bps = -1) const;
int saveJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const; int saveJPEG (const Glib::ustring &fname, int quality = 100, int subSamp = 3) const;
int saveTIFF (const Glib::ustring &fname, int bps = -1, bool isFloat = false, bool uncompressed = false) const; int saveTIFF (
const Glib::ustring &fname,
int bps = -1,
bool isFloat = false,
bool uncompressed = false,
bool big = false
) const;
cmsHPROFILE getEmbeddedProfile () const; cmsHPROFILE getEmbeddedProfile () const;
void getEmbeddedProfileData (int& length, unsigned char*& pdata) const; void getEmbeddedProfileData (int& length, unsigned char*& pdata) const;

View File

@ -264,6 +264,7 @@ bool BatchQueue::saveBatchQueue ()
<< saveFormat.tiffBits << '|' << (saveFormat.tiffFloat ? 1 : 0) << '|' << saveFormat.tiffUncompressed << '|' << saveFormat.tiffBits << '|' << (saveFormat.tiffFloat ? 1 : 0) << '|' << saveFormat.tiffUncompressed << '|'
<< saveFormat.saveParams << '|' << entry->forceFormatOpts << '|' << saveFormat.saveParams << '|' << entry->forceFormatOpts << '|'
<< entry->fast_pipeline << '|' << entry->fast_pipeline << '|'
<< saveFormat.bigTiff << '|'
<< std::endl; << std::endl;
} }
} }
@ -331,6 +332,7 @@ bool BatchQueue::loadBatchQueue ()
const auto saveParams = nextIntOr (options.saveFormat.saveParams); const auto saveParams = nextIntOr (options.saveFormat.saveParams);
const auto forceFormatOpts = nextIntOr (options.forceFormatOpts); const auto forceFormatOpts = nextIntOr (options.forceFormatOpts);
const auto fast = nextIntOr(false); const auto fast = nextIntOr(false);
const auto bigTiff = nextIntOr (options.saveFormat.bigTiff);
rtengine::procparams::ProcParams pparams; rtengine::procparams::ProcParams pparams;
@ -370,6 +372,7 @@ bool BatchQueue::loadBatchQueue ()
saveFormat.tiffBits = tiffBits; saveFormat.tiffBits = tiffBits;
saveFormat.tiffFloat = tiffFloat == 1; saveFormat.tiffFloat = tiffFloat == 1;
saveFormat.tiffUncompressed = tiffUncompressed != 0; saveFormat.tiffUncompressed = tiffUncompressed != 0;
saveFormat.bigTiff = bigTiff != 0;
saveFormat.saveParams = saveParams != 0; saveFormat.saveParams = saveParams != 0;
entry->forceFormatOpts = forceFormatOpts != 0; entry->forceFormatOpts = forceFormatOpts != 0;
} else { } else {
@ -693,7 +696,13 @@ rtengine::ProcessingJob* BatchQueue::imageReady(rtengine::IImagefloat* img)
int err = 0; int err = 0;
if (saveFormat.format == "tif") { if (saveFormat.format == "tif") {
err = img->saveAsTIFF (fname, saveFormat.tiffBits, saveFormat.tiffFloat, saveFormat.tiffUncompressed); err = img->saveAsTIFF (
fname,
saveFormat.tiffBits,
saveFormat.tiffFloat,
saveFormat.tiffUncompressed,
saveFormat.bigTiff
);
} else if (saveFormat.format == "png") { } else if (saveFormat.format == "png") {
err = img->saveAsPNG (fname, saveFormat.pngBits); err = img->saveAsPNG (fname, saveFormat.pngBits);
} else if (saveFormat.format == "jpg") { } else if (saveFormat.format == "jpg") {

View File

@ -201,6 +201,9 @@ std::tuple<Glib::ustring, bool> BatchQueueEntry::getToolTip (int x, int y) const
if (saveFormat.tiffUncompressed) { if (saveFormat.tiffUncompressed) {
tooltip += Glib::ustring::compose("\n%1", M("SAVEDLG_TIFFUNCOMPRESSED")); tooltip += Glib::ustring::compose("\n%1", M("SAVEDLG_TIFFUNCOMPRESSED"));
} }
if (saveFormat.bigTiff) {
tooltip += Glib::ustring::compose("\n%1", M("SAVEDLG_BIGTIFF"));
}
} }
} }
} }

View File

@ -2013,7 +2013,7 @@ bool EditorPanel::idle_saveImage (ProgressConnector<rtengine::IImagefloat*> *pc,
img->setSaveProgressListener (parent->getProgressListener()); img->setSaveProgressListener (parent->getProgressListener());
if (sf.format == "tif") if (sf.format == "tif")
ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsTIFF), fname, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed), ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsTIFF), fname, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed, sf.bigTiff),
sigc::bind (sigc::mem_fun (*this, &EditorPanel::idle_imageSaved), ld, img, fname, sf, pparams)); sigc::bind (sigc::mem_fun (*this, &EditorPanel::idle_imageSaved), ld, img, fname, sf, pparams));
else if (sf.format == "png") else if (sf.format == "png")
ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsPNG), fname, sf.pngBits), ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsPNG), fname, sf.pngBits),
@ -2270,7 +2270,7 @@ bool EditorPanel::saveImmediately (const Glib::ustring &filename, const SaveForm
if (gimpPlugin) { if (gimpPlugin) {
err = img->saveAsTIFF (filename, 32, true, true); err = img->saveAsTIFF (filename, 32, true, true);
} else if (sf.format == "tif") { } else if (sf.format == "tif") {
err = img->saveAsTIFF (filename, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed); err = img->saveAsTIFF (filename, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed, sf.bigTiff);
} else if (sf.format == "png") { } else if (sf.format == "png") {
err = img->saveAsPNG (filename, sf.pngBits); err = img->saveAsPNG (filename, sf.pngBits);
} else if (sf.format == "jpg") { } else if (sf.format == "jpg") {
@ -2380,7 +2380,7 @@ bool EditorPanel::idle_sendToGimp ( ProgressConnector<rtengine::IImagefloat*> *p
ProgressConnector<int> *ld = new ProgressConnector<int>(); ProgressConnector<int> *ld = new ProgressConnector<int>();
img->setSaveProgressListener (parent->getProgressListener()); img->setSaveProgressListener (parent->getProgressListener());
ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsTIFF), fileName, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed), ld->startFunc (sigc::bind (sigc::mem_fun (img, &rtengine::IImagefloat::saveAsTIFF), fileName, sf.tiffBits, sf.tiffFloat, sf.tiffUncompressed, sf.bigTiff),
sigc::bind (sigc::mem_fun (*this, &EditorPanel::idle_sentToGimp), ld, img, fileName)); sigc::bind (sigc::mem_fun (*this, &EditorPanel::idle_sentToGimp), ld, img, fileName));
} else { } else {
Glib::ustring msg_ = Glib::ustring ("<b> Error during image processing\n</b>"); Glib::ustring msg_ = Glib::ustring ("<b> Error during image processing\n</b>");

View File

@ -313,6 +313,7 @@ void Options::setDefaults()
saveFormat.tiffBits = 16; saveFormat.tiffBits = 16;
saveFormat.tiffFloat = false; saveFormat.tiffFloat = false;
saveFormat.tiffUncompressed = true; saveFormat.tiffUncompressed = true;
saveFormat.bigTiff = false;
saveFormat.saveParams = true; saveFormat.saveParams = true;
saveFormatBatch.format = "jpg"; saveFormatBatch.format = "jpg";
@ -1046,6 +1047,10 @@ void Options::readFromFile(Glib::ustring fname)
saveFormat.tiffUncompressed = keyFile.get_boolean("Output", "TiffUncompressed"); saveFormat.tiffUncompressed = keyFile.get_boolean("Output", "TiffUncompressed");
} }
if (keyFile.has_key("Output", "BigTiff")) {
saveFormat.bigTiff = keyFile.get_boolean("Output", "BigTiff");
}
if (keyFile.has_key("Output", "SaveProcParams")) { if (keyFile.has_key("Output", "SaveProcParams")) {
saveFormat.saveParams = keyFile.get_boolean("Output", "SaveProcParams"); saveFormat.saveParams = keyFile.get_boolean("Output", "SaveProcParams");
} }
@ -2447,6 +2452,7 @@ void Options::saveToFile(Glib::ustring fname)
keyFile.set_integer("Output", "TiffBps", saveFormat.tiffBits); keyFile.set_integer("Output", "TiffBps", saveFormat.tiffBits);
keyFile.set_boolean("Output", "TiffFloat", saveFormat.tiffFloat); keyFile.set_boolean("Output", "TiffFloat", saveFormat.tiffFloat);
keyFile.set_boolean("Output", "TiffUncompressed", saveFormat.tiffUncompressed); keyFile.set_boolean("Output", "TiffUncompressed", saveFormat.tiffUncompressed);
keyFile.set_boolean("Output", "BigTiff", saveFormat.bigTiff);
keyFile.set_boolean("Output", "SaveProcParams", saveFormat.saveParams); keyFile.set_boolean("Output", "SaveProcParams", saveFormat.saveParams);
keyFile.set_string("Output", "FormatBatch", saveFormatBatch.format); keyFile.set_string("Output", "FormatBatch", saveFormatBatch.format);

View File

@ -72,6 +72,7 @@ struct SaveFormat {
int _tiff_bits, int _tiff_bits,
bool _tiff_float, bool _tiff_float,
bool _tiff_uncompressed, bool _tiff_uncompressed,
bool _big_tiff,
bool _save_params bool _save_params
) : ) :
format(_format), format(_format),
@ -81,6 +82,7 @@ struct SaveFormat {
tiffBits(_tiff_bits), tiffBits(_tiff_bits),
tiffFloat(_tiff_float), tiffFloat(_tiff_float),
tiffUncompressed(_tiff_uncompressed), tiffUncompressed(_tiff_uncompressed),
bigTiff(_big_tiff),
saveParams(_save_params) saveParams(_save_params)
{ {
} }
@ -98,6 +100,7 @@ struct SaveFormat {
_tiff_bits, _tiff_bits,
_tiff_float, _tiff_float,
true, true,
false,
true true
) )
{ {
@ -114,6 +117,7 @@ struct SaveFormat {
int tiffBits; int tiffBits;
bool tiffFloat; bool tiffFloat;
bool tiffUncompressed; bool tiffUncompressed;
bool bigTiff;
bool saveParams; bool saveParams;
}; };

View File

@ -100,6 +100,11 @@ SaveFormatPanel::SaveFormatPanel () : listener (nullptr)
tiffUncompressed->signal_toggled().connect( sigc::mem_fun(*this, &SaveFormatPanel::formatChanged)); tiffUncompressed->signal_toggled().connect( sigc::mem_fun(*this, &SaveFormatPanel::formatChanged));
tiffUncompressed->show_all(); tiffUncompressed->show_all();
bigTiff = new Gtk::CheckButton (M("SAVEDLG_BIGTIFF"));
setExpandAlignProperties(bigTiff, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_CENTER);
bigTiff->signal_toggled().connect( sigc::mem_fun(*this, &SaveFormatPanel::formatChanged));
bigTiff->show_all();
// --------------------- MAIN BOX // --------------------- MAIN BOX
@ -114,12 +119,14 @@ SaveFormatPanel::SaveFormatPanel () : listener (nullptr)
attach (*hb1, 0, 0, 1, 1); attach (*hb1, 0, 0, 1, 1);
attach (*jpegOpts, 0, 1, 1, 1); attach (*jpegOpts, 0, 1, 1, 1);
attach (*tiffUncompressed, 0, 2, 1, 1); attach (*tiffUncompressed, 0, 2, 1, 1);
attach (*bigTiff, 0, 3, 1, 1);
attach (*savesPP, 0, 4, 1, 2); attach (*savesPP, 0, 4, 1, 2);
} }
SaveFormatPanel::~SaveFormatPanel () SaveFormatPanel::~SaveFormatPanel ()
{ {
delete jpegQual; delete jpegQual;
delete tiffUncompressed; delete tiffUncompressed;
delete bigTiff;
} }
void SaveFormatPanel::init (SaveFormat &sf) void SaveFormatPanel::init (SaveFormat &sf)
@ -158,6 +165,7 @@ void SaveFormatPanel::init (SaveFormat &sf)
jpegQual->setValue(sf.jpegQuality); jpegQual->setValue(sf.jpegQuality);
savesPP->set_active(sf.saveParams); savesPP->set_active(sf.saveParams);
tiffUncompressed->set_active(sf.tiffUncompressed); tiffUncompressed->set_active(sf.tiffUncompressed);
bigTiff->set_active(sf.bigTiff);
listener = tmp; listener = tmp;
} }
@ -175,6 +183,7 @@ SaveFormat SaveFormatPanel::getFormat ()
sf.jpegQuality = jpegQual->getValue(); sf.jpegQuality = jpegQual->getValue();
sf.jpegSubSamp = jpegSubSamp->get_active_row_number() + 1; sf.jpegSubSamp = jpegSubSamp->get_active_row_number() + 1;
sf.tiffUncompressed = tiffUncompressed->get_active(); sf.tiffUncompressed = tiffUncompressed->get_active();
sf.bigTiff = bigTiff->get_active();
sf.saveParams = savesPP->get_active(); sf.saveParams = savesPP->get_active();
return sf; return sf;
@ -193,12 +202,15 @@ void SaveFormatPanel::formatChanged ()
if (fr == "jpg") { if (fr == "jpg") {
jpegOpts->show_all(); jpegOpts->show_all();
tiffUncompressed->hide(); tiffUncompressed->hide();
bigTiff->hide();
} else if (fr == "png") { } else if (fr == "png") {
jpegOpts->hide(); jpegOpts->hide();
tiffUncompressed->hide(); tiffUncompressed->hide();
bigTiff->hide();
} else if (fr == "tif") { } else if (fr == "tif") {
jpegOpts->hide(); jpegOpts->hide();
tiffUncompressed->show_all(); tiffUncompressed->show_all();
bigTiff->show_all();
} }
if (listener) { if (listener) {

View File

@ -39,6 +39,7 @@ class SaveFormatPanel : public Gtk::Grid, public AdjusterListener, public rtengi
protected: protected:
Adjuster* jpegQual; Adjuster* jpegQual;
Gtk::CheckButton* tiffUncompressed; Gtk::CheckButton* tiffUncompressed;
Gtk::CheckButton* bigTiff;
MyComboBoxText* format; MyComboBoxText* format;
MyComboBoxText* jpegSubSamp; MyComboBoxText* jpegSubSamp;
Gtk::Grid* formatOpts; Gtk::Grid* formatOpts;