Merge branch 'dev' into metadata-exiv2
This commit is contained in:
@@ -17,19 +17,18 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* 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 <cstring>
|
||||
#include <fcntl.h>
|
||||
#include <memory>
|
||||
#include "rt_math.h"
|
||||
#include "procparams.h"
|
||||
#include "utils.h"
|
||||
#include "../rtgui/options.h"
|
||||
#include "../rtgui/version.h"
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <png.h>
|
||||
#include <tiff.h>
|
||||
#include <tiffio.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
@@ -37,13 +36,19 @@
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "imageio.h"
|
||||
#include "iccjpeg.h"
|
||||
#include "color.h"
|
||||
#include "iccjpeg.h"
|
||||
#include "imagedata.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include "imageio.h"
|
||||
#include "jpeg.h"
|
||||
#include "procparams.h"
|
||||
#include "rt_math.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include "../rtgui/options.h"
|
||||
#include "../rtgui/version.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace rtengine;
|
||||
@@ -1099,7 +1104,13 @@ int ImageIO::saveJPEG (const Glib::ustring &fname, int quality, int subSamp) con
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
return IMIO_HEADERERROR;
|
||||
@@ -1113,23 +1124,26 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
|
||||
bps = getBPS ();
|
||||
}
|
||||
|
||||
int lineWidth = width * 3 * bps / 8;
|
||||
unsigned char* linebuffer = new unsigned char[lineWidth];
|
||||
int lineWidth = width * 3 * (bps / 8);
|
||||
std::vector<unsigned char> linebuffer(lineWidth);
|
||||
|
||||
std::string mode = "w";
|
||||
|
||||
if (big) {
|
||||
mode += '8';
|
||||
}
|
||||
|
||||
// little hack to get libTiff to use proper byte order (see TIFFClienOpen()):
|
||||
const char* const mode = "w";
|
||||
#ifdef WIN32
|
||||
FILE *file = g_fopen_withBinaryAndLock (fname);
|
||||
int fileno = _fileno(file);
|
||||
int osfileno = _get_osfhandle(fileno);
|
||||
TIFF* out = TIFFFdOpen (osfileno, fname.c_str(), mode);
|
||||
TIFF* out = TIFFFdOpen (osfileno, fname.c_str(), mode.c_str());
|
||||
#else
|
||||
TIFF* out = TIFFOpen(fname.c_str(), mode);
|
||||
TIFF* out = TIFFOpen(fname.c_str(), mode.c_str());
|
||||
// int fileno = TIFFFileno (out);
|
||||
#endif
|
||||
|
||||
if (!out) {
|
||||
delete [] linebuffer;
|
||||
return IMIO_CANNOTWRITEFILE;
|
||||
}
|
||||
|
||||
@@ -1185,32 +1199,25 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
|
||||
}
|
||||
|
||||
for (int row = 0; row < height; row++) {
|
||||
getScanline (row, linebuffer, bps, isFloat);
|
||||
getScanline (row, linebuffer.data(), bps, isFloat);
|
||||
|
||||
if (bps == 16) {
|
||||
if(needsReverse && !uncompressed && isFloat) {
|
||||
for(int i = 0; i < lineWidth; i += 2) {
|
||||
char temp = linebuffer[i];
|
||||
linebuffer[i] = linebuffer[i + 1];
|
||||
linebuffer[i + 1] = temp;
|
||||
std::swap(linebuffer[i], linebuffer[i + 1]);
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
std::swap(linebuffer[i], linebuffer[i + 3]);
|
||||
std::swap(linebuffer[i + 1], linebuffer[i + 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TIFFWriteScanline (out, linebuffer, row, 0) < 0) {
|
||||
if (TIFFWriteScanline (out, linebuffer.data(), row, 0) < 0) {
|
||||
TIFFClose (out);
|
||||
delete [] linebuffer;
|
||||
return IMIO_CANNOTWRITEFILE;
|
||||
}
|
||||
|
||||
@@ -1228,8 +1235,6 @@ int ImageIO::saveTIFF (const Glib::ustring &fname, int bps, bool isFloat, bool u
|
||||
fclose (file);
|
||||
#endif
|
||||
|
||||
delete [] linebuffer;
|
||||
|
||||
if (!saveMetadata(fname)) {
|
||||
writeOk = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user