Solving issue 1103: I can't process my 16MPix images (RT crash because it lacks memory)

This commit is contained in:
natureh
2011-11-08 17:40:09 +01:00
parent 47df7710b0
commit a3c123cd58
5 changed files with 269 additions and 241 deletions

View File

@@ -245,8 +245,15 @@ namespace rtengine {
scale = scales[0]; scale = scales[0];
pitch = pitches[0]; pitch = pitches[0];
// freeing as much memory as possible since the next call to idirpyr will need lots
for(int i = 1; i < maxlevel; i++) {
delete dirpyrLablo[i];
}
idirpyr(dirpyrLablo[0], dst, 0, rangefn_L, nrwt_l, nrwt_ab, pitch, scale, dnparams.luma, dnparams.chroma/*, Lcurve, abcurve*/ ); idirpyr(dirpyrLablo[0], dst, 0, rangefn_L, nrwt_l, nrwt_ab, pitch, scale, dnparams.luma, dnparams.chroma/*, Lcurve, abcurve*/ );
// freeing the last bunch of memory
delete dirpyrLablo[0];
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -271,16 +278,6 @@ namespace rtengine {
} }
} }
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for(int i = 0; i < maxlevel; i++)
{
delete dirpyrLablo[i];
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}; };
void ImProcFunctions::dirpyr(LabImage* data_fine, LabImage* data_coarse, int level, \ void ImProcFunctions::dirpyr(LabImage* data_fine, LabImage* data_coarse, int level, \

View File

@@ -70,6 +70,8 @@ class ImageSource : public InitialImage {
virtual int load (Glib::ustring fname, bool batch = false) =0; virtual int load (Glib::ustring fname, bool batch = false) =0;
virtual void preprocess (const RAWParams &raw){}; virtual void preprocess (const RAWParams &raw){};
virtual void demosaic (const RAWParams &raw){}; virtual void demosaic (const RAWParams &raw){};
virtual void flushRawData (){};
virtual void flushRGB (){};
virtual void HLRecovery_Global (HRecParams hrp){}; virtual void HLRecovery_Global (HRecParams hrp){};
virtual void HLRecovery_inpaint (float** red, float** green, float** blue){}; virtual void HLRecovery_inpaint (float** red, float** green, float** blue){};

View File

@@ -1132,6 +1132,32 @@ void RawImageSource::demosaic(const RAWParams &raw)
} }
} }
void RawImageSource::flushRawData() {
if(cache) {
delete [] cache;
cache = 0;
}
if (rawData) {
freeArray<float>(rawData, H);
rawData = 0;
}
}
void RawImageSource::flushRGB() {
if (green) {
freeArray<float>(green, H);
green = 0;
}
if (red) {
freeArray<float>(red, H);
red = 0;
}
if (blue) {
freeArray<float>(blue, H);
blue = 0;
}
}
void RawImageSource::HLRecovery_Global(HRecParams hrp ) void RawImageSource::HLRecovery_Global(HRecParams hrp )
{ {
//color propagation highlight recovery //color propagation highlight recovery

View File

@@ -102,7 +102,7 @@ class RawImageSource : public ImageSource {
double* cache; double* cache;
int threshold; int threshold;
float** rawData; // holds preprocessed pixel values, data[i][j] corresponds to the ith row and jth column float** rawData; // holds preprocessed pixel values, rowData[i][j] corresponds to the ith row and jth column
// the interpolated green plane: // the interpolated green plane:
float** green; float** green;
@@ -134,6 +134,8 @@ class RawImageSource : public ImageSource {
int load (Glib::ustring fname, bool batch = false); int load (Glib::ustring fname, bool batch = false);
void preprocess (const RAWParams &raw); void preprocess (const RAWParams &raw);
void demosaic (const RAWParams &raw); void demosaic (const RAWParams &raw);
void flushRawData ();
void flushRGB ();
void HLRecovery_Global (HRecParams hrp); void HLRecovery_Global (HRecParams hrp);
void refinement_lassus (); void refinement_lassus ();

View File

@@ -110,7 +110,6 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
imgsrc->getImage (currWB, tr, baseImg, pp, params.hlrecovery, params.icm, params.raw); imgsrc->getImage (currWB, tr, baseImg, pp, params.hlrecovery, params.icm, params.raw);
if (pl) pl->setProgress (0.45); if (pl) pl->setProgress (0.45);
// perform first analysis // perform first analysis
LUTu hist16 (65536); LUTu hist16 (65536);
ipf.firstAnalysis (baseImg, &params, hist16, imgsrc->getGamma()); ipf.firstAnalysis (baseImg, &params, hist16, imgsrc->getGamma());
@@ -145,6 +144,12 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
ipf.getAutoExp (aehist, aehistcompr, imgsrc->getDefGain(), params.toneCurve.clip, br, bl); ipf.getAutoExp (aehist, aehistcompr, imgsrc->getDefGain(), params.toneCurve.clip, br, bl);
} }
// at this stage, we can flush the raw data to free up quite an important amount of memory
imgsrc->flushRawData();
// at this stage, we can flush the raw data to free up quite an important amount of memory
imgsrc->flushRGB();
LUTf curve1 (65536,0); LUTf curve1 (65536,0);
LUTf curve2 (65536,0); LUTf curve2 (65536,0);
LUTf curve (65536,0); LUTf curve (65536,0);
@@ -216,8 +221,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
cw = params.crop.w; cw = params.crop.w;
ch = params.crop.h; ch = params.crop.h;
} }
if(params.icm.gamma != "default" || params.icm.freegamma) if(params.icm.gamma != "default" || params.icm.freegamma) { // if select gamma output between BT709, sRGB, linear, low, high, 2.2 , 1.8
{ // if select gamma output between BT709, sRGB, linear, low, high, 2.2 , 1.8
//or selected Free gamma //or selected Free gamma
Image16* readyImgP; Image16* readyImgP;
Image16* readyImg = ipf.lab2rgb16b (labView, cx, cy, cw, ch, params.icm.output, params.icm.working, params.icm.gamma, params.icm.freegamma, params.icm.gampos, params.icm.slpos); Image16* readyImg = ipf.lab2rgb16b (labView, cx, cy, cw, ch, params.icm.output, params.icm.working, params.icm.gamma, params.icm.freegamma, params.icm.gampos, params.icm.slpos);
@@ -242,10 +246,13 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
else if(j==5) chpro=options.rtSettings.bruce; else if(j==5) chpro=options.rtSettings.bruce;
else if(j==6) chpro=options.rtSettings.srgb; else if(j==6) chpro=options.rtSettings.srgb;
for (int i=0; i<opnames.size(); i++) { for (int i=0; i<opnames.size(); i++) {
if(chpro.compare(opnames[i]) ==0) present_space[j]=1; } if(chpro.compare(opnames[i]) ==0) present_space[j]=1;
}
if (present_space[j]==0) { if (present_space[j]==0) {
if (pl) pl->setProgressStr ("Missing file..");pl->setProgress (0.0);// display file not present: not very good display information...!! if (pl) pl->setProgressStr ("Missing file..");
if (settings->verbose) printf("Missing file: %s \n", chpro.c_str());} //c_str() pl->setProgress (0.0);// display file not present: not very good display information...!!
if (settings->verbose) printf("Missing file: %s \n", chpro.c_str());
} //c_str()
} }
// Check that output profiles exist, otherwise use LCMS2 // Check that output profiles exist, otherwise use LCMS2
@@ -287,12 +294,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
break; break;
case (3): case (3):
// FitBox // FitBox
if ((double)refw/(double)refh > (double)params.resize.width/(double)params.resize.height) { if ((double)refw/(double)refh > (double)params.resize.width/(double)params.resize.height)
tmpScale = (double)params.resize.width/(double)refw; tmpScale = (double)params.resize.width/(double)refw;
} else
else {
tmpScale = (double)params.resize.height/(double)refh; tmpScale = (double)params.resize.height/(double)refh;
}
break; break;
default: default:
// Scale // Scale
@@ -301,8 +306,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
} }
// resize image // resize image
if (fabs(tmpScale-1.0)>1e-5) if (fabs(tmpScale-1.0)>1e-5) {
{
int imw, imh; int imw, imh;
if (params.crop.enabled && params.resize.appliesTo == "Full image") { if (params.crop.enabled && params.resize.appliesTo == "Full image") {
imw = cw; imw = cw;
@@ -345,8 +349,8 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
return readyImg; return readyImg;
} }
else else {
{//if default mode : profil = selection by choice in list (Prophoto.icm, sRGB.icm, etc., etc.) , gamma = gamma of profile or not selected Free gamma //if default mode : profil = selection by choice in list (Prophoto.icm, sRGB.icm, etc., etc.) , gamma = gamma of profile or not selected Free gamma
Image16* readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm.output); Image16* readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm.output);
delete labView; delete labView;
if (pl) pl->setProgress (0.70); if (pl) pl->setProgress (0.70);
@@ -380,12 +384,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
break; break;
case (3): case (3):
// FitBox // FitBox
if ((double)refw/(double)refh > (double)params.resize.width/(double)params.resize.height) { if ((double)refw/(double)refh > (double)params.resize.width/(double)params.resize.height)
tmpScale = (double)params.resize.width/(double)refw; tmpScale = (double)params.resize.width/(double)refw;
} else
else {
tmpScale = (double)params.resize.height/(double)refh; tmpScale = (double)params.resize.height/(double)refh;
}
break; break;
default: default:
// Scale // Scale
@@ -394,8 +396,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
} }
// resize image // resize image
if (fabs(tmpScale-1.0)>1e-5) if (fabs(tmpScale-1.0)>1e-5) {
{
int imw, imh; int imw, imh;
if (params.crop.enabled && params.resize.appliesTo == "Full image") { if (params.crop.enabled && params.resize.appliesTo == "Full image") {
imw = cw; imw = cw;