Transferring loads of array variables from Stack to Heap

This commit is contained in:
Hombre
2010-12-27 12:47:45 +01:00
parent 69284246b1
commit 6152b5d9dd
26 changed files with 192 additions and 73 deletions

View File

@@ -400,7 +400,7 @@ template<class T> void bilateral (T** src, int** dst, int W, int H, int sigmar,
// exponential lookup table
int scale = (2.0*sigmar*sigmar) / scaleg;
int scalem = 65535/((1+2*r)*(1+2*r));
int ec[256000];
int *ec = new int[256000];
for (int i=0; i<256000; i++)
ec[i] = exp (-i/scaleg) * scalem;
@@ -425,6 +425,7 @@ template<class T> void bilateral (T** src, int** dst, int W, int H, int sigmar,
}
}
delete [] kernel;
delete [] ec;
time_t t2 = clock ();
printf ("bilateral: %d\n", t2-t1);

View File

@@ -956,17 +956,21 @@ void CurveFactory::complexCurve (double ecomp, double black, double hlcompr, dou
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int CurveFactory::gammatab [65536];
int CurveFactory::igammatab_srgb [65536];
int CurveFactory::gammatab_srgb [65536];
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int *CurveFactory::gammatab = 0;
int *CurveFactory::igammatab_srgb = 0;
int *CurveFactory::gammatab_srgb = 0;
void CurveFactory::init () {
gammatab = new int[65536];
igammatab_srgb = new int[65536];
gammatab_srgb = new int[65536];
for (int i=0; i<65536; i++)
gammatab_srgb[i] = (int)(65535 * gamma2 (i/65535.0));
for (int i=0; i<65536; i++)
@@ -980,5 +984,11 @@ void CurveFactory::init () {
fclose (f);*/
}
void CurveFactory::cleanup () {
delete [] gammatab;
delete [] igammatab_srgb;
delete [] gammatab_srgb;
}
}

View File

@@ -38,11 +38,11 @@ class CurveFactory {
protected:
// look-up tables for the standard srgb gamma and its inverse (filled by init())
static int igammatab_srgb[65536];
static int gammatab_srgb[65536];
static int *igammatab_srgb;
static int *gammatab_srgb;
// look-up tables for the simple exponential gamma
static int gammatab[65536];
static int *gammatab;
// functions calculating the parameters of the contrast curve based on the desired slope at the center
static double solve_upper (double m, double c, double deriv);
static double solve_lower (double m, double c, double deriv);
@@ -135,6 +135,7 @@ class CurveFactory {
public:
static void init ();
static void cleanup ();
static inline double centercontrast (double x, double b, double m);

View File

@@ -100,7 +100,7 @@ namespace rtengine {
//float gam = 2.0;//MIN(3.0, 0.1*fabs(c[4])/3.0+0.001);
float gamthresh = 0.03;
float gamslope = exp(log((double)gamthresh)/gam)/gamthresh;
unsigned short gamcurve[65536];
unsigned short * gamcurve = new unsigned short [65536];
for (int i=0; i<65536; i++) {
int g = (int)(CurveFactory::gamma((double)i/65535.0, gam, gamthresh, gamslope, 1.0, 0.0) * 65535.0);
//if (i<500) printf("%d %d \n",i,g);
@@ -261,6 +261,7 @@ namespace rtengine {
delete [] rangefn_ab;
delete [] nrwt_l;
delete [] nrwt_ab;
delete [] gamcurve;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
};

View File

@@ -82,7 +82,7 @@ namespace rtengine {
/*float gam = 2.0;//MIN(3.0, 0.1*fabs(c[4])/3.0+0.001);
float gamthresh = 0.03;
float gamslope = exp(log((double)gamthresh)/gam)/gamthresh;
unsigned short gamcurve[65536];
unsigned short * gamcurve = new unsigned short [65536];
for (int i=0; i<65536; i++) {
int g = (int)(CurveFactory::gamma((double)i/65535.0, gam, gamthresh, gamslope, 1.0, 0.0) * 65535.0);
//if (i<500) printf("%d %d \n",i,g);
@@ -266,6 +266,7 @@ namespace rtengine {
//delete [] rangefn_L;
//delete [] rangefn_ab;
delete [] rangefn;
//delete [] gamcurve;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@@ -66,7 +66,7 @@ namespace rtengine {
/*float gam = 2.0;//MIN(3.0, 0.1*fabs(c[4])/3.0+0.001);
float gamthresh = 0.03;
float gamslope = exp(log((double)gamthresh)/gam)/gamthresh;
unsigned short gamcurve[65536];
unsigned short *gamcurve = new unsigned short[65536];
for (int i=0; i<65536; i++) {
int g = (int)(CurveFactory::gamma((double)i/65535.0, gam, gamthresh, gamslope, 1.0, 0.0) * 65535.0);
//if (i<500) printf("%d %d \n",i,g);
@@ -191,6 +191,7 @@ namespace rtengine {
freeArray<int>(buffer, srcheight);
delete [] rangefn;
//delete [] gamcurve;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@@ -25,15 +25,21 @@
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
static float dirwt[0x10000];
static float *dirwt;
static void __attribute__((constructor)) setup_dirwt()
{
dirwt = new float[0x10000];
//set up directional weight function
for (int i=0; i<0x10000; i++)
dirwt[i] = 1.0/SQR(1.0+i);
}
static void __attribute__((destructor)) cleanup_dirwt()
{
delete [] dirwt;
}
void RawImageSource::fast_demo(int winx, int winy, int winw, int winh) {
//int winx=0, winy=0;
//int winw=W, winh=H;

View File

@@ -621,7 +621,7 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
jpeg_start_compress(&cinfo, TRUE);
// buffer for exif and iptc markers
unsigned char buffer[165535];
unsigned char* buffer = new unsigned char[165535]; //TODO: Is it really 165535... or 65535 ?
unsigned int size;
// assemble and write exif marker
if (exifRoot) {
@@ -674,6 +674,8 @@ int ImageIO::saveJPEG (Glib::ustring fname, int quality) {
jpeg_destroy_compress (&cinfo);
delete [] row;
delete [] buffer;
fclose (file);
if (pl) {
@@ -707,7 +709,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
}
// buffer for the exif and iptc
unsigned char buffer[165535];
unsigned char* buffer = new unsigned char[165535]; //TODO: Is it really 165535... or 65535 ?
unsigned char* iptcdata = NULL;
unsigned int iptclen = 0;
if (iptc && iptc_data_save (iptc, &iptcdata, &iptclen) && iptcdata) {
@@ -717,6 +719,9 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
int size = rtexif::ExifManager::createTIFFHeader (exifRoot, exifChange, width, height, bps, profileData, profileLength, (char*)iptcdata, iptclen, buffer);
if (iptcdata)
iptc_data_free_buf (iptc, iptcdata);
// The maximum lenght is strangely not the same than for the JPEG file...
// Which maximum length is the good one ?
if (size>0 && size<165530)
fwrite (buffer, size, 1, file);
@@ -734,6 +739,7 @@ int ImageIO::saveTIFF (Glib::ustring fname, int bps, bool uncompressed) {
if (pl && !(i%100))
pl->setProgress ((double)(i+1)/height);
}
delete [] buffer;
fclose (file);
}

View File

@@ -30,9 +30,31 @@ extern Settings* settings;
ImProcCoordinator::ImProcCoordinator ()
: awbComputed(false), ipf(&params, true), scale(10), allocated(false),
pW(-1), pH(-1), plistener(NULL), imageListener(NULL),fineDetailsProcessed(false),
aeListener(NULL), hListener(NULL), resultValid(false),
pW(-1), pH(-1), plistener(NULL),fineDetailsProcessed(false),
imageListener(NULL), aeListener(NULL), hListener(NULL), resultValid(false),
changeSinceLast(0), updaterRunning(false), destroying(false) {
dummy1 = new float[65536];
dummy2 = new float[65536];
hltonecurve = new float[65536];
shtonecurve = new float[65536];
tonecurve = new int[65536];
lumacurve = new int[65536];
chroma_acurve = new int[65536];
chroma_bcurve = new int[65536];
vhist16 = new unsigned int[65536];
lhist16 = new unsigned int[65536];
rhist = new unsigned int[256];
ghist = new unsigned int[256];
bhist = new unsigned int[256];
Lhist = new unsigned int[256];
bcrgbhist = new unsigned int[256];
bcLhist = new unsigned int[256];
bcabhist = new unsigned int[256];
}
void ImProcCoordinator::assign (ImageSource* imgsrc) {
@@ -53,6 +75,27 @@ ImProcCoordinator::~ImProcCoordinator () {
for (int i=0; i<toDel.size(); i++)
delete toDel[i];
delete [] dummy1;
delete [] dummy2;
delete [] hltonecurve;
delete [] shtonecurve;
delete [] tonecurve;
delete [] lumacurve;
delete [] chroma_acurve;
delete [] chroma_bcurve;
delete [] vhist16;
delete [] lhist16;
delete [] rhist;
delete [] ghist;
delete [] bhist;
delete [] Lhist;
delete [] bcrgbhist;
delete [] bcLhist;
delete [] bcabhist;
imgsrc->decreaseRef ();
updaterThreadStart.unlock ();
}
@@ -149,11 +192,12 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) {
if (todo & M_AUTOEXP) {
if (params.toneCurve.autoexp) {
unsigned int aehist[65536]; int aehistcompr;
unsigned int *aehist = new unsigned int[65536]; int aehistcompr;
imgsrc->getAEHistogram (aehist, aehistcompr);
ipf.getAutoExp (aehist, aehistcompr, imgsrc->getDefGain(), params.toneCurve.clip, params.toneCurve.expcomp, params.toneCurve.black);
if (aeListener)
aeListener->autoExpChanged (params.toneCurve.expcomp, params.toneCurve.black);
delete [] aehist;
}
}

View File

@@ -62,20 +62,20 @@ class ImProcCoordinator : public StagedImageProcessor {
void freeAll ();
float dummy1 [65536];
float dummy2 [65536];
float hltonecurve [65536];
float shtonecurve [65536];
int tonecurve [65536];
float *dummy1;
float *dummy2;
float *hltonecurve;
float *shtonecurve;
int *tonecurve;
int lumacurve [65536];
int chroma_acurve [65536];
int chroma_bcurve [65536];
int *lumacurve;
int *chroma_acurve;
int *chroma_bcurve;
unsigned int vhist16[65536];
unsigned int lhist16[65536];
unsigned int *vhist16;
unsigned int *lhist16;
unsigned int rhist[256], ghist[256], bhist[256], Lhist[256], bcrgbhist[256], bcLhist[256], bcabhist[256];
unsigned int *rhist, *ghist, *bhist, *Lhist, *bcrgbhist, *bcLhist, *bcabhist;
int fw, fh, tr, fullw, fullh;
int pW, pH;

View File

@@ -61,20 +61,21 @@ using namespace procparams;
extern const Settings* settings;
int* ImProcFunctions::cacheL;
int* ImProcFunctions::cachea;
int* ImProcFunctions::cacheb;
int* ImProcFunctions::xcache;
int* ImProcFunctions::ycache;
int* ImProcFunctions::zcache;
unsigned short ImProcFunctions::gamma2curve[65536];
int* ImProcFunctions::cacheL = 0;
int* ImProcFunctions::cachea = 0;
int* ImProcFunctions::cacheb = 0;
int* ImProcFunctions::xcache = 0;
int* ImProcFunctions::ycache = 0;
int* ImProcFunctions::zcache = 0;
unsigned short* ImProcFunctions::gamma2curve = 0;
void ImProcFunctions::initCache () {
int maxindex = 2*65536;
const int maxindex = 2*65536;
cacheL = new int[maxindex];
cachea = new int[maxindex];
cacheb = new int[maxindex];
gamma2curve = new unsigned short[65536];
int threshold = (int)(0.008856*CMAXVAL);
for (int i=0; i<maxindex; i++)
@@ -112,6 +113,17 @@ void ImProcFunctions::initCache () {
}
}
void ImProcFunctions::cleanupCache () {
delete [] cacheL;
delete [] cachea;
delete [] cacheb;
delete [] xcache;
delete [] ycache;
delete [] zcache;
delete [] gamma2curve;
}
ImProcFunctions::~ImProcFunctions () {
if (monitorTransform!=NULL)

View File

@@ -38,7 +38,7 @@ class ImProcFunctions {
static int* xcache;
static int* ycache;
static int* zcache;
static unsigned short gamma2curve[65536];
static unsigned short* gamma2curve;
cmsHTRANSFORM monitorTransform;
@@ -69,6 +69,7 @@ class ImProcFunctions {
double lumimul[3];
static void initCache ();
static void cleanupCache ();
ImProcFunctions (const ProcParams* iparams, bool imultiThread=true)
: monitorTransform(NULL), params(iparams), scale(1), multiThread(imultiThread) {}

View File

@@ -22,6 +22,7 @@
#include <improccoordinator.h>
#include <curves.h>
#include <dfmanager.h>
#include <rtthumbnail.h>
namespace rtengine {
@@ -36,12 +37,20 @@ int init (const Settings* s) {
iccStore->parseDir (s->iccDirectory);
CurveFactory::init ();
ImProcFunctions::initCache ();
Thumbnail::initGamma ();
delete lcmsMutex;
lcmsMutex = new Glib::Mutex;
dfm.init( s->darkFramesPath );
return 0;
}
void cleanup () {
CurveFactory::cleanup ();
ImProcFunctions::cleanupCache ();
Thumbnail::cleanupGamma ();
}
StagedImageProcessor* StagedImageProcessor::create (InitialImage* initialImage) {
ImProcCoordinator* ipc = new ImProcCoordinator ();

View File

@@ -72,7 +72,7 @@ class RawImageSource : public ImageSource {
int max[3];
double initialGain; // initial gain calculated after scale_colors
double defGain;
int blcode[16][16][32];
//int blcode[16][16][32]; // Looks like it's an unused variable...
bool full;
cmsHPROFILE camProfile;
cmsHPROFILE embProfile;

View File

@@ -304,6 +304,9 @@ namespace rtengine {
* @param s is a struct of basic settings */
int init (const Settings* s);
/** Cleanup the RT engine (static variables) */
void cleanup ();
/** Returns the available output profile names
* @return a vector of the available output profile names */
std::vector<std::string> getOutputProfiles ();

View File

@@ -484,6 +484,23 @@ Thumbnail* Thumbnail::loadFromRaw (const Glib::ustring& fname, RawMetaDataLocati
#undef FISBLUE
unsigned short *Thumbnail::igammatab = 0;
unsigned char *Thumbnail::gammatab = 0;
void Thumbnail::initGamma () {
igammatab = new unsigned short[256];
gammatab = new unsigned char[65536];
for (int i=0; i<256; i++)
igammatab[i] = (unsigned short)(255.0*pow((double)i/255.0,1.0/0.45));
for (int i=0; i<65536; i++)
gammatab[i] = (unsigned char)(255.0*pow((double)i/65535.0,0.45));
}
void Thumbnail::cleanupGamma () {
delete [] igammatab;
delete [] gammatab;
}
void Thumbnail::init () {
RawImageSource::inverse33 (colorMatrix, iColorMatrix);
@@ -495,20 +512,8 @@ void Thumbnail::init () {
camProfile = iccStore->createFromMatrix (camToD50, false, "Camera");
}
bool Thumbnail::igammacomputed = false;
unsigned short Thumbnail::igammatab[256];
unsigned char Thumbnail::gammatab[65536];
Thumbnail::Thumbnail () :
camProfile(NULL), thumbImg(NULL), aeHistogram(NULL), embProfileData(NULL), embProfile(NULL) {
if (!igammacomputed) {
for (int i=0; i<256; i++)
igammatab[i] = (unsigned short)(255.0*pow(i/255.0,1.0/0.45));
for (int i=0; i<65536; i++)
gammatab[i] = (unsigned char)(255.0*pow(i/65535.0,0.45));
igammacomputed = true;
}
}
Thumbnail::~Thumbnail () {

View File

@@ -36,9 +36,8 @@ namespace rtengine {
void transformPixel (int x, int y, int tran, int& tx, int& ty);
static bool igammacomputed;
static unsigned short igammatab[256];
static unsigned char gammatab[65536];
static unsigned short *igammatab;
static unsigned char *gammatab;
Image16* thumbImg;
double camwbRed;
@@ -67,6 +66,8 @@ namespace rtengine {
~Thumbnail ();
Thumbnail ();
static void initGamma ();
static void cleanupGamma ();
void init ();
IImage8* processImage (const procparams::ProcParams& pparams, int rheight, TypeInterpolation interp, double& scale);

View File

@@ -46,7 +46,6 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
if (!ii) {
ii = InitialImage::load (job->fname, job->isRaw, &errorCode);
if (errorCode) {
ii->decreaseRef ();
delete job;
return NULL;
}
@@ -135,9 +134,10 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
int bl = params.toneCurve.black;
if (params.toneCurve.autoexp) {
unsigned int aehist[65536]; int aehistcompr;
unsigned int* aehist = new unsigned int [65536]; int aehistcompr;
imgsrc->getAEHistogram (aehist, aehistcompr);
ipf.getAutoExp (aehist, aehistcompr, imgsrc->getDefGain(), params.toneCurve.clip, br, bl);
delete [] aehist;
}
float* curve1 = new float [65536];

View File

@@ -112,9 +112,9 @@ bool BatchQueue::loadBatchQueue( )
if (f==NULL)
return false;
char buffer[1024];
char *buffer = new char[1024];
unsigned numLoaded=0;
while (fgets (buffer, sizeof(buffer), f)){
while (fgets (buffer, 1024, f)){
char *p = strchr(buffer,';' );
if( p ){
char *le = buffer + strlen(buffer);
@@ -156,6 +156,7 @@ bool BatchQueue::loadBatchQueue( )
}
}
}
delete [] buffer;
fclose(f);
arrangeFiles ();
queue_draw ();

View File

@@ -37,6 +37,8 @@ CurveEditor::CurveEditor (Glib::ustring text, CurveEditorGroup* ceGroup) {
bgHistValid = false;
selected = Linear;
histogram = new unsigned int[256]; // histogram values
group = ceGroup;
if (group && text.size())
@@ -58,11 +60,11 @@ CurveEditor::CurveEditor (Glib::ustring text, CurveEditorGroup* ceGroup) {
curveType->show();
}
/*
CurveEditor::~CurveEditor () {
delete [] histogram;
}
*/
void CurveEditor::setCurve (const std::vector<double>& p) {
tempCurve = p;

View File

@@ -43,7 +43,7 @@ private:
CurveType selected;
PopUpToggleButton* curveType;
unsigned int histogram[256]; // histogram values
unsigned int* histogram; // histogram values
bool bgHistValid;
CurveEditorGroup* group;
@@ -57,7 +57,7 @@ public:
friend class CurveEditorGroup;
CurveEditor (Glib::ustring text, CurveEditorGroup* ceGroup);
//~CurveEditor ();
~CurveEditor ();
void typeSelectionChanged (int n);
void curveTypeToggled();
void setCurve (const std::vector<double>& p);

View File

@@ -77,6 +77,11 @@ void HistogramPanel::rgbv_toggled () {
HistogramArea::HistogramArea () :
valid(false), showFull(true), oldwidth(-1), needVal(true), needRed(true), needGreen(true), needBlue(true) {
lhist = new unsigned int[256];
rhist = new unsigned int[256];
ghist = new unsigned int[256];
bhist = new unsigned int[256];
haih = new HistogramAreaIdleHelper;
haih->harea = this;
haih->destroyed = false;
@@ -91,6 +96,11 @@ HistogramArea::~HistogramArea () {
haih->destroyed = true;
else
delete haih;
delete [] lhist;
delete [] rhist;
delete [] ghist;
delete [] bhist;
}
void HistogramArea::updateOptions (bool r, bool g, bool b, bool v) {

View File

@@ -44,10 +44,10 @@ class HistogramArea : public Gtk::DrawingArea {
Gdk::Color lgray;
Gdk::Color mgray;
Gdk::Color dgray;
unsigned int lhist[256];
unsigned int rhist[256];
unsigned int ghist[256];
unsigned int bhist[256];
unsigned int* lhist;
unsigned int* rhist;
unsigned int* ghist;
unsigned int* bhist;
bool valid;
bool showFull;
int oldwidth, oldheight;

View File

@@ -57,7 +57,7 @@ int main(int argc, char **argv)
std::string argv0_, argv1_;
#ifdef WIN32
char exname[512];
char *exname = new char[512];
GetModuleFileName (NULL, exname, 512);
argv0_ = exname;
// get the path where the rawtherapee is stored
@@ -124,6 +124,8 @@ int main(int argc, char **argv)
m.run(*rtWindow);
gdk_threads_leave ();
delete rtWindow;
rtengine::cleanup();
delete [] exname;
return 0;
}

View File

@@ -32,6 +32,8 @@ MyCurve::MyCurve () : listener(NULL), activeParam(-1), bghistvalid(false) {
lit_point = -1;
buttonPressed = false;
bghist = new unsigned int[256];
set_extension_events(Gdk::EXTENSION_EVENTS_ALL);
add_events(Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK | Gdk::POINTER_MOTION_HINT_MASK | Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK);
signal_event().connect( sigc::mem_fun(*this, &MyCurve::handleEvents) );
@@ -54,8 +56,8 @@ MyCurve::~MyCurve () {
mcih->destroyed = true;
else
delete mcih;
//curve.x.clear();
//curve.y.clear();
delete [] bghist;
}
std::vector<double> MyCurve::get_vector (int veclen) {

View File

@@ -84,7 +84,7 @@ class MyCurve : public Gtk::DrawingArea {
std::vector<Gdk::Point> upoint;
std::vector<Gdk::Point> lpoint;
int activeParam;
unsigned int bghist[256]; // histogram values
unsigned int* bghist; // histogram values
bool bghistvalid;
bool buttonPressed;
MyCurveIdleHelper* mcih;