diff --git a/rtengine/imageio.cc b/rtengine/imageio.cc index 6d2ac881c..eea9685f4 100644 --- a/rtengine/imageio.cc +++ b/rtengine/imageio.cc @@ -142,8 +142,8 @@ void ImageIO::setOutputProfile (char* pdata, int plen) { ImageIO::~ImageIO () { if (embProfile) - cmsCloseProfile(embProfile); - delete [] loadedProfileData; + cmsCloseProfile(embProfile); + deleteLoadedProfileData(); delete exifRoot; delete [] profileData; } @@ -339,7 +339,7 @@ int ImageIO::loadPNG (Glib::ustring fname) { } int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize) -{ +{ jpeg_decompress_struct cinfo; jpeg_error_mgr jerr; cinfo.err = my_jpeg_std_error(&jerr); @@ -359,10 +359,8 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize) //jpeg_memory_src (&cinfo,buffer,bufsize); jpeg_read_header(&cinfo, TRUE); - if( loadedProfileData ){ - delete [] loadedProfileData; - loadedProfileData = NULL; - } + deleteLoadedProfileData(); + loadedProfileDataJpg = true; bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength); if (hasprofile) embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength); @@ -406,7 +404,6 @@ int ImageIO::loadJPEGFromMemory (const char* buffer, int bufsize) } int ImageIO::loadJPEG (Glib::ustring fname) { - FILE *file=safe_g_fopen(fname,"rb"); if (!file) return IMIO_CANNOTREADFILE; @@ -435,8 +432,8 @@ int ImageIO::loadJPEG (Glib::ustring fname) { return IMIO_READERROR; } - delete loadedProfileData; - loadedProfileData = NULL; + deleteLoadedProfileData(); + loadedProfileDataJpg = true; bool hasprofile = read_icc_profile (&cinfo, (JOCTET**)&loadedProfileData, (unsigned int*)&loadedProfileLength); if (hasprofile) embProfile = cmsOpenProfileFromMem (loadedProfileData, loadedProfileLength); @@ -651,10 +648,8 @@ int ImageIO::loadTIFF (Glib::ustring fname) { char* profdata; - if( loadedProfileData ){ - delete [] loadedProfileData; - loadedProfileData = NULL; - } + deleteLoadedProfileData(); + loadedProfileDataJpg = false; if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &loadedProfileLength, &profdata)) { embProfile = cmsOpenProfileFromMem (profdata, loadedProfileLength); diff --git a/rtengine/imageio.h b/rtengine/imageio.h index d50c857bf..9484b6045 100644 --- a/rtengine/imageio.h +++ b/rtengine/imageio.h @@ -75,6 +75,7 @@ class ImageIO : virtual public ImageDatas { char* profileData; int profileLength; char* loadedProfileData; + bool loadedProfileDataJpg; int loadedProfileLength; procparams::ExifPairs exifChange; IptcData* iptc; @@ -83,10 +84,12 @@ class ImageIO : virtual public ImageDatas { IIOSampleFormat sampleFormat; IIOSampleArrangement sampleArrangement; + private: + void deleteLoadedProfileData( ) { if(loadedProfileData) {if(loadedProfileDataJpg) free(loadedProfileData); else delete[] loadedProfileData;} loadedProfileData = NULL; } public: static Glib::ustring errorMsg[6]; - ImageIO () : pl (NULL), embProfile(NULL), profileData(NULL), profileLength(0), loadedProfileData(NULL), + ImageIO () : pl (NULL), embProfile(NULL), profileData(NULL), profileLength(0), loadedProfileData(NULL),loadedProfileDataJpg(false), loadedProfileLength(0), iptc(NULL), exifRoot (NULL), sampleFormat(IIOSF_UNKNOWN), sampleArrangement(IIOSA_UNKNOWN) {}