Implementing issue #190 (a new "Fit box" option in the resize tool), and correction of issue #28, #92, #149, #237 and #345, but i had to disable the resize preview for that.

This commit is contained in:
Hombre
2010-12-12 22:24:53 +01:00
parent e394b29d6d
commit 5027c8c00b
24 changed files with 934 additions and 727 deletions

View File

@@ -52,14 +52,9 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
}
}
procparams::ProcParams& params = job->pparams;
// aquire image from imagesource
ImageSource* imgsrc = ii->getImageSource ();
ColorTemp currWB = ColorTemp (params.wb.temperature, params.wb.green);
if (params.wb.method=="Camera")
currWB = imgsrc->getWB ();
else if (params.wb.method=="Auto")
currWB = imgsrc->getAutoWB ();
int tr = TR_NONE;
if (params.coarse.rotate==90) tr |= TR_R90;
@@ -71,25 +66,42 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
int fw, fh;
imgsrc->getFullSize (fw, fh, tr);
// check the crop params
if (params.crop.x > fw || params.crop.y > fh) {
// the crop is completely out of the image, so we disable the crop
params.crop.enabled = false;
// and we set the values to the defaults
params.crop.x = 0;
params.crop.y = 0;
params.crop.w = fw;
params.crop.h = fh;
}
else {
if ((params.crop.x + params.crop.w) > fw) {
// crop overflow in the width dimension ; we trim it
params.crop.w = fw-params.crop.x;
}
if ((params.crop.y + params.crop.h) > fh) {
// crop overflow in the height dimension ; we trim it
params.crop.h = fh-params.crop.y;
}
}
ImProcFunctions ipf (&params, true);
// set the color temperature
ColorTemp currWB = ColorTemp (params.wb.temperature, params.wb.green);
if (params.wb.method=="Camera")
currWB = imgsrc->getWB ();
else if (params.wb.method=="Auto")
currWB = imgsrc->getAutoWB ();
Image16* baseImg;
PreviewProps pp (0, 0, fw, fh, 1);
imgsrc->preprocess( params.raw );
imgsrc->demosaic( params.raw );
if (fabs(params.resize.scale-1.0)<1e-5) {
baseImg = new Image16 (fw, fh);
imgsrc->getImage (currWB, tr, baseImg, pp, params.hlrecovery, params.icm, params.raw);
}
else {
Image16* oorig = new Image16 (fw, fh);
imgsrc->getImage (currWB, tr, oorig, pp, params.hlrecovery, params.icm, params.raw);
fw *= params.resize.scale;
fh *= params.resize.scale;
baseImg = new Image16 (fw, fh);
ipf.resize (oorig, baseImg);
delete oorig;
}
baseImg = new Image16 (fw, fh);
imgsrc->getImage (currWB, tr, baseImg, pp, params.hlrecovery, params.icm, params.raw);
if (pl)
pl->setProgress (0.25);
@@ -97,7 +109,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
unsigned int* hist16 = new unsigned int[65536];
ipf.firstAnalysis (baseImg, &params, hist16, imgsrc->getGamma());
// perform transform
// perform transform (excepted resizing)
if (ipf.needsTransform()) {
Image16* trImg = new Image16 (fw, fh);
ipf.transform (baseImg, trImg, 0, 0, 0, 0, fw, fh);
@@ -184,9 +196,9 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
delete [] buffer;
if (pl)
pl->setProgress (0.75);
pl->setProgress (0.70);
// obtain final image
// crop and convert to rgb16
Image16* readyImg;
int cx = 0, cy = 0, cw = labView->W, ch = labView->H;
if (params.crop.enabled) {
@@ -197,6 +209,73 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
}
readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm.output);
if (pl)
pl->setProgress (0.85);
// get the resize parameters
int refw, refh;
double tmpScale;
if (params.resize.enabled) {
if (params.crop.enabled && params.resize.appliesTo == "Cropped area") {
// the resize values applies to the crop dimensions
refw = cw;
refh = ch;
}
else {
// the resize values applies to the image dimensions
// if a crop exists, it will be resized to the calculated scale
refw = fw;
refh = fh;
}
switch(params.resize.dataspec) {
case (1):
// Width
tmpScale = (double)params.resize.width/(double)refw;
break;
case (2):
// Height
tmpScale = (double)params.resize.height/(double)refh;
break;
case (3):
// FitBox
if ((double)refw/(double)refh > (double)params.resize.width/(double)params.resize.height) {
tmpScale = (double)params.resize.width/(double)refw;
}
else {
tmpScale = (double)params.resize.height/(double)refh;
}
break;
default:
// Scale
tmpScale = params.resize.scale;
break;
}
// resize image
if (fabs(tmpScale-1.0)>1e-5)
{
int imw, imh;
if (params.crop.enabled && params.resize.appliesTo == "Full image") {
imw = cw;
imh = ch;
}
else {
imw = refw;
imh = refh;
}
imw = (int)( (double)imw * tmpScale + 0.5 );
imh = (int)( (double)imh * tmpScale + 0.5 );
Image16* tempImage = new Image16 (imw, imh);
ipf.resize (readyImg, tempImage, tmpScale);
delete readyImg;
readyImg = tempImage;
}
}
if (pl)
pl->setProgress (1.0);