Merged RTEngine enhancements from DEFAULT
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* This file is part of RawTherapee.
|
||||
*
|
||||
* Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
|
||||
* Copyright (c) 2010 Oliver Duis <www.oliverduis.de>
|
||||
*
|
||||
* RawTherapee is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -45,6 +46,22 @@ using namespace rtengine::procparams;
|
||||
|
||||
Glib::ustring ImageIO::errorMsg[6] = {"Success", "Cannot read file.", "Invalid header.","Error while reading header.","File reading error", "Image format not supported."};
|
||||
|
||||
// For only copying the raw input data
|
||||
void ImageIO::setMetadata (const rtexif::TagDirectory* eroot) {
|
||||
if (exifRoot!=NULL) { delete exifRoot; exifRoot = NULL; }
|
||||
|
||||
if (eroot) {
|
||||
rtexif::TagDirectory* td = ((rtexif::TagDirectory*)eroot)->clone (NULL);
|
||||
|
||||
// make IPTC and XMP pass through
|
||||
td->keepTag(0x83bb); // IPTC
|
||||
td->keepTag(0x02bc); // XMP
|
||||
|
||||
exifRoot=td;
|
||||
}
|
||||
}
|
||||
|
||||
// For merging with RT specific data
|
||||
void ImageIO::setMetadata (const rtexif::TagDirectory* eroot, const std::vector<ExifPair>& exif, const std::vector<IPTCPair>& iptcc) {
|
||||
|
||||
// store exif info
|
||||
@@ -53,15 +70,13 @@ void ImageIO::setMetadata (const rtexif::TagDirectory* eroot, const std::vector<
|
||||
exifChange[i].first = exif[i].field;
|
||||
exifChange[i].second = exif[i].value;
|
||||
}
|
||||
delete exifRoot;
|
||||
|
||||
exifRoot = NULL;
|
||||
if (exifRoot!=NULL) { delete exifRoot; exifRoot = NULL; }
|
||||
|
||||
if (eroot)
|
||||
exifRoot = ((rtexif::TagDirectory*)eroot)->clone (NULL);
|
||||
|
||||
if (iptc)
|
||||
iptc_data_free (iptc);
|
||||
iptc = NULL;
|
||||
if (iptc!=NULL) { iptc_data_free (iptc); iptc = NULL; }
|
||||
|
||||
// build iptc structures for libiptcdata
|
||||
if (iptcc.size()==0)
|
||||
@@ -136,7 +151,7 @@ int ImageIO::loadPNG (Glib::ustring fname) {
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Loading PNG file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_LOADPNG");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -252,7 +267,7 @@ int ImageIO::loadPNG (Glib::ustring fname) {
|
||||
delete [] row;
|
||||
fclose(file);
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
return IMIO_SUCCESS;
|
||||
@@ -269,7 +284,7 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
|
||||
if ( setjmp(((rt_jpeg_error_mgr*)cinfo.src)->error_jmp_buf) == 0 )
|
||||
{
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Loading JPEG file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_LOADJPEG");
|
||||
pl->setProgress (0.0);
|
||||
|
||||
}
|
||||
@@ -313,7 +328,7 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize)
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
return IMIO_SUCCESS;
|
||||
@@ -340,7 +355,7 @@ int ImageIO::loadJPEG (Glib::ustring fname) {
|
||||
if ( setjmp(((rt_jpeg_error_mgr*)cinfo.src)->error_jmp_buf) == 0 )
|
||||
{
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Loading JPEG file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_LOADJPEG");
|
||||
pl->setProgress (0.0);
|
||||
|
||||
}
|
||||
@@ -385,7 +400,7 @@ int ImageIO::loadJPEG (Glib::ustring fname) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(file);
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
return IMIO_SUCCESS;
|
||||
@@ -409,7 +424,7 @@ int ImageIO::loadTIFF (Glib::ustring fname) {
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Loading TIFF file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_LOADTIFF");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -467,7 +482,7 @@ int ImageIO::loadTIFF (Glib::ustring fname) {
|
||||
delete [] linebuffer;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
|
||||
@@ -502,17 +517,13 @@ int ImageIO::loadPPMFromMemory(const char* buffer, int width, int height, bool s
|
||||
|
||||
int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
|
||||
|
||||
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
|
||||
Glib::ustring tmpFname=fname;
|
||||
tmpFname.append(".tmp");
|
||||
|
||||
FILE *file = safe_g_fopen (tmpFname, "wb");
|
||||
FILE *file = safe_g_fopen_WriteBinLock (fname);
|
||||
|
||||
if (!file)
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Saving PNG file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_SAVEPNG");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -573,11 +584,8 @@ int ImageIO::savePNG (Glib::ustring fname, int compression, int bps) {
|
||||
delete [] row;
|
||||
fclose (file);
|
||||
|
||||
// Rename temporary filename, practically atomic
|
||||
safe_g_rename(tmpFname,fname);
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
|
||||
@@ -593,17 +601,13 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
|
||||
cinfo.err = jpeg_std_error (&jerr);
|
||||
jpeg_create_compress (&cinfo);
|
||||
|
||||
// create a temporary file name that is opened in parallel by e.g. image viewers whilte RT is still writing
|
||||
Glib::ustring tmpFname=fname;
|
||||
tmpFname.append(".tmp");
|
||||
|
||||
FILE *file = safe_g_fopen (tmpFname, "wb");
|
||||
FILE *file = safe_g_fopen_WriteBinLock (fname);
|
||||
|
||||
if (!file)
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Saving JPEG file...");
|
||||
pl->setProgressStr ("PROGRESSBAR_SAVEJPEG");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -689,11 +693,8 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
|
||||
|
||||
fclose (file);
|
||||
|
||||
// Rename temporary filename, practically atomic
|
||||
safe_g_rename(tmpFname,fname);
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
|
||||
@@ -712,13 +713,13 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
|
||||
unsigned char* linebuffer = new unsigned char[lineWidth];
|
||||
// TODO the following needs to be looked into - do we really need two ways to write a Tiff file ?
|
||||
if (exifRoot && uncompressed) {
|
||||
FILE *file = safe_g_fopen (fname, "wb");
|
||||
FILE *file = safe_g_fopen_WriteBinLock (fname);
|
||||
|
||||
if (!file)
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Saving TIFF file ...");
|
||||
pl->setProgressStr ("PROGRESSBAR_SAVETIFF");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -771,7 +772,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
|
||||
return IMIO_CANNOTREADFILE;
|
||||
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Saving TIFF file ...");
|
||||
pl->setProgressStr ("PROGRESSBAR_SAVETIFF");
|
||||
pl->setProgress (0.0);
|
||||
}
|
||||
|
||||
@@ -842,7 +843,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
|
||||
|
||||
delete [] linebuffer;
|
||||
if (pl) {
|
||||
pl->setProgressStr ("Ready.");
|
||||
pl->setProgressStr ("PROGRESSBAR_READY");
|
||||
pl->setProgress (1.0);
|
||||
}
|
||||
|
||||
@@ -885,7 +886,8 @@ void png_flush(png_structp png_ptr) {
|
||||
int ImageIO::load (Glib::ustring fname) {
|
||||
|
||||
int lastdot = fname.find_last_of ('.');
|
||||
|
||||
if( Glib::ustring::npos == lastdot )
|
||||
return IMIO_FILETYPENOTSUPPORTED;
|
||||
if (!fname.casefold().compare (lastdot, 4, ".png"))
|
||||
return loadPNG (fname);
|
||||
else if (!fname.casefold().compare (lastdot, 4, ".jpg"))
|
||||
@@ -898,7 +900,8 @@ int ImageIO::load (Glib::ustring fname) {
|
||||
int ImageIO::save (Glib::ustring fname) {
|
||||
|
||||
int lastdot = fname.find_last_of ('.');
|
||||
|
||||
if( Glib::ustring::npos == lastdot )
|
||||
return IMIO_FILETYPENOTSUPPORTED;
|
||||
if (!fname.casefold().compare (lastdot, 4, ".png"))
|
||||
return savePNG (fname);
|
||||
else if (!fname.casefold().compare (lastdot, 4, ".jpg"))
|
||||
|
Reference in New Issue
Block a user