16-bit floating-point support for TIFF output image (see #2357)

This commit is contained in:
Hombre
2018-05-07 09:57:53 +02:00
parent 5ac11ef1b9
commit 30efa5930d
16 changed files with 83 additions and 42 deletions

View File

@@ -1765,8 +1765,9 @@ public:
/** @brief Saves the image to file in a tif format.
* @param fname is the name of the file
* @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
@return the error code, 0 if none */
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false) = 0;
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false) = 0;
/** @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 */
virtual void setSaveProgressListener (ProgressListener* pl) = 0;

View File

@@ -83,9 +83,9 @@ public:
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false)
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
{
return saveTIFF (fname, bps, uncompressed);
return saveTIFF (fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener (ProgressListener* pl)
{

View File

@@ -78,9 +78,9 @@ public:
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false)
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
{
return saveTIFF (fname, bps, uncompressed);
return saveTIFF (fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener (ProgressListener* pl)
{

View File

@@ -87,9 +87,9 @@ public:
{
return saveJPEG (fname, quality, subSamp);
}
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false)
virtual int saveAsTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false)
{
return saveTIFF (fname, bps, uncompressed);
return saveTIFF (fname, bps, isFloat, uncompressed);
}
virtual void setSaveProgressListener (ProgressListener* pl)
{

View File

@@ -1300,13 +1300,12 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality, int subSamp)
return IMIO_SUCCESS;
}
int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
int ImageIO::saveTIFF (Glib::ustring fname, int bps, float isFloat, bool uncompressed)
{
if (getWidth() < 1 || getHeight() < 1) {
return IMIO_HEADERERROR;
}
//TODO: Handling 32 bits floating point output images!
bool writeOk = true;
int width = getWidth ();
int height = getHeight ();
@@ -1458,10 +1457,10 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
TIFFSetField (out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField (out, TIFFTAG_COMPRESSION, uncompressed ? COMPRESSION_NONE : COMPRESSION_ADOBE_DEFLATE);
TIFFSetField (out, TIFFTAG_SAMPLEFORMAT, bps == 32 ? SAMPLEFORMAT_IEEEFP : SAMPLEFORMAT_UINT);
TIFFSetField (out, TIFFTAG_SAMPLEFORMAT, (bps == 16 || bps == 32) && isFloat ? SAMPLEFORMAT_IEEEFP : SAMPLEFORMAT_UINT);
if (!uncompressed) {
TIFFSetField (out, TIFFTAG_PREDICTOR, bps == 32 ? PREDICTOR_FLOATINGPOINT : PREDICTOR_HORIZONTAL);
TIFFSetField (out, TIFFTAG_PREDICTOR, (bps == 16 || bps == 32) && isFloat ? PREDICTOR_FLOATINGPOINT : PREDICTOR_HORIZONTAL);
}
if (profileData) {
TIFFSetField (out, TIFFTAG_ICCPROFILE, profileLength, profileData);
@@ -1470,14 +1469,24 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed)
for (int row = 0; row < height; row++) {
getScanline (row, linebuffer, bps);
if(needsReverse && !uncompressed && bps == 32) {
for(int i = 0; i < lineWidth; i += 4) {
char temp = linebuffer[i];
linebuffer[i] = linebuffer[i + 3];
linebuffer[i + 3] = temp;
temp = linebuffer[i + 1];
linebuffer[i + 1] = linebuffer[i + 2];
linebuffer[i + 2] = temp;
/*if (bps == 16) {
if(needsReverse && !uncompressed) {
for(int i = 0; i < lineWidth; i += 2) {
char temp = linebuffer[i];
linebuffer[i] = linebuffer[i + 1];
linebuffer[i + 1] = temp;
}
}
} else */ if (bps == 32) {
if(needsReverse && !uncompressed) {
for(int i = 0; i < lineWidth; i += 4) {
char temp = linebuffer[i];
linebuffer[i] = linebuffer[i + 3];
linebuffer[i + 3] = temp;
temp = linebuffer[i + 1];
linebuffer[i + 1] = linebuffer[i + 2];
linebuffer[i + 2] = temp;
}
}
}

View File

@@ -138,7 +138,7 @@ public:
int savePNG (Glib::ustring fname, volatile int bps = -1);
int saveJPEG (Glib::ustring fname, int quality = 100, int subSamp = 3);
int saveTIFF (Glib::ustring fname, int bps = -1, bool uncompressed = false);
int saveTIFF (Glib::ustring fname, int bps = -1, float isFloat = false, bool uncompressed = false);
cmsHPROFILE getEmbeddedProfile ()
{