Merge with newlocallab...

This commit is contained in:
Pandagrapher
2018-09-25 23:40:09 +02:00
2269 changed files with 56201 additions and 198310 deletions

View File

@@ -29,6 +29,11 @@
#include <unistd.h>
#include "iccstore.h"
#include <iostream>
#include <fstream>
#include <string>
#include "color.h"
#ifdef _OPENMP
#include <omp.h>
#endif
@@ -96,7 +101,7 @@ ImProcCoordinator::ImProcCoordinator()
fw(0), fh(0), tr(0),
fullw(1), fullh(1),
pW(-1), pH(-1),
plistener(nullptr), awbListener(nullptr), imageListener(nullptr), aeListener(nullptr), acListener(nullptr), abwListener(nullptr), actListener(nullptr), adnListener(nullptr), awavListener(nullptr), dehaListener(nullptr), frameCountListener(nullptr), imageTypeListener(nullptr), hListener(nullptr),
plistener(nullptr), imageListener(nullptr), aeListener(nullptr), acListener(nullptr), abwListener(nullptr), awbListener(nullptr), frameCountListener(nullptr), imageTypeListener(nullptr), actListener(nullptr), adnListener(nullptr), awavListener(nullptr), dehaListener(nullptr), hListener(nullptr),
resultValid(false), lastOutputProfile("BADFOOD"), lastOutputIntent(RI__COUNT), lastOutputBPC(false), thread(nullptr), changeSinceLast(0), updaterRunning(false), destroying(false), utili(false), autili(false),
butili(false), ccutili(false), cclutili(false), clcutili(false), opautili(false), wavcontlutili(false),
locallutili(false), localcutili(false), localskutili(false), localexutili(false), LHutili(false), HHutili(false),
@@ -258,8 +263,17 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
printf("Demosaic X-Trans image with using method: %s\n", rp.xtranssensor.method.c_str());
}
}
if(imgsrc->getSensorType() == ST_BAYER) {
if(params.raw.bayersensor.method != RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::PIXELSHIFT)) {
imgsrc->setBorder(params.raw.bayersensor.border);
} else {
imgsrc->setBorder(std::max(params.raw.bayersensor.border, 2));
}
}
bool autoContrast = false;
double contrastThreshold = 0.f;
imgsrc->demosaic(rp, autoContrast, contrastThreshold); //enabled demosaic
imgsrc->demosaic(rp); //enabled demosaic
// if a demosaic happened we should also call getimage later, so we need to set the M_INIT flag
todo |= M_INIT;
@@ -340,6 +354,30 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
awbListener->WBChanged(params.wb.temperature, params.wb.green);
}
/*
GammaValues g_a;
double pwr = 1.0 / params.icm.gampos;
double ts = params.icm.slpos;
int mode = 0;
Color::calcGamma(pwr, ts, mode, g_a); // call to calcGamma with selected gamma and slope
printf("ga[0]=%f ga[1]=%f ga[2]=%f ga[3]=%f ga[4]=%f\n", g_a[0],g_a[1],g_a[2],g_a[3],g_a[4]);
Glib::ustring datal;
datal = "lutsrgb.txt";
ofstream fou(datal, ios::out | ios::trunc);
for(int i=0; i < 212; i++) {
//printf("igamma2=%i\n", (int) 65535.f*Color::igamma2(i/212.0));
float gam = Color::igamma2(i/211.0);
int lutga = nearbyint(65535.f* gam);
// fou << 65535*(int)Color::igamma2(i/212.0) << endl;
fou << i << " " << lutga << endl;
}
fou.close();
*/
int tr = getCoarseBitMask(params.coarse);
imgsrc->getFullSize(fw, fh, tr);
@@ -438,9 +476,9 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
const int W = oprevi->getWidth();
const int H = oprevi->getHeight();
LabImage labcbdl(W, H);
ipf.rgb2lab(*oprevi, labcbdl, params.icm.working);
ipf.rgb2lab(*oprevi, labcbdl, params.icm.workingProfile);
ipf.dirpyrequalizer(&labcbdl, scale);
ipf.lab2rgb(labcbdl, *oprevi, params.icm.working);
ipf.lab2rgb(labcbdl, *oprevi, params.icm.workingProfile);
}
readyphase++;
@@ -462,7 +500,9 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
}
if (params.toneCurve.histmatching) {
imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve);
if (!params.toneCurve.fromHistMatching) {
imgsrc->getAutoMatchedToneCurve(params.icm, params.toneCurve.curve);
}
if (params.toneCurve.autoexp) {
params.toneCurve.expcomp = 0.0;
@@ -474,6 +514,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
params.toneCurve.brightness = 0;
params.toneCurve.contrast = 0;
params.toneCurve.black = 0;
params.toneCurve.fromHistMatching = true;
if (aeListener) {
aeListener->autoMatchedToneCurveChanged(params.toneCurve.curveMode, params.toneCurve.curve);
@@ -483,6 +524,48 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
progress("Exposure curve & CIELAB conversion...", 100 * readyphase / numofphases);
if (todo & (M_AUTOEXP | M_RGBCURVE)) {
if (params.icm.workingTRC == "Custom") { //exec TRC IN free
Glib::ustring profile;
profile = params.icm.workingProfile;
if (profile == "sRGB" || profile == "Adobe RGB" || profile == "ProPhoto" || profile == "WideGamut" || profile == "BruceRGB" || profile == "Beta RGB" || profile == "BestRGB" || profile == "Rec2020" || profile == "ACESp0" || profile == "ACESp1") {
int cw = oprevi->getWidth();
int ch = oprevi->getHeight();
// put gamma TRC to 1
Imagefloat* readyImg0 = NULL;
readyImg0 = ipf.workingtrc(oprevi, cw, ch, -5, params.icm.workingProfile, 2.4, 12.92310);
#pragma omp parallel for
for (int row = 0; row < ch; row++) {
for (int col = 0; col < cw; col++) {
oprevi->r(row, col) = (float)readyImg0->r(row, col);
oprevi->g(row, col) = (float)readyImg0->g(row, col);
oprevi->b(row, col) = (float)readyImg0->b(row, col);
}
}
delete readyImg0;
//adjust TRC
Imagefloat* readyImg = NULL;
readyImg = ipf.workingtrc(oprevi, cw, ch, 5, params.icm.workingProfile, params.icm.workingTRCGamma, params.icm.workingTRCSlope);
#pragma omp parallel for
for (int row = 0; row < ch; row++) {
for (int col = 0; col < cw; col++) {
oprevi->r(row, col) = (float)readyImg->r(row, col);
oprevi->g(row, col) = (float)readyImg->g(row, col);
oprevi->b(row, col) = (float)readyImg->b(row, col);
}
}
delete readyImg;
}
}
}
if ((todo & M_RGBCURVE) || (todo & M_CROP)) {
// if (hListener) oprevi->calcCroppedHistogram(params, scale, histCropped);
@@ -501,7 +584,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
opautili = false;
if (params.colorToning.enabled) {
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix(params.icm.working);
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix(params.icm.workingProfile);
double wp[3][3] = {
{wprof[0][0], wprof[0][1], wprof[0][2]},
{wprof[1][0], wprof[1][1], wprof[1][2]},
@@ -614,6 +697,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
lhist16(32768);
if (todo & (M_LUMACURVE | M_CROP)) {
LUTu lhist16(32768);
lhist16.clear();
#ifdef _OPENMP
const int numThreads = min(max(pW * pH / (int)lhist16.getSize(), 1), omp_get_max_threads());
@@ -933,8 +1017,8 @@ void ImProcCoordinator::updatePreviewImage(int todo, Crop* cropCall)
}
// Update the monitor color transform if necessary
if ((todo & M_MONITOR) || (lastOutputProfile != params.icm.output) || lastOutputIntent != params.icm.outputIntent || lastOutputBPC != params.icm.outputBPC) {
lastOutputProfile = params.icm.output;
if ((todo & M_MONITOR) || (lastOutputProfile != params.icm.outputProfile) || lastOutputIntent != params.icm.outputIntent || lastOutputBPC != params.icm.outputBPC) {
lastOutputProfile = params.icm.outputProfile;
lastOutputIntent = params.icm.outputIntent;
lastOutputBPC = params.icm.outputBPC;
ipf.updateColorProfiles(monitorProfile, monitorIntent, softProof, gamutCheck);
@@ -1194,7 +1278,7 @@ bool ImProcCoordinator::getAutoWB(double& temp, double& green, double equal, dou
}
}
void ImProcCoordinator::getCamWB(double & temp, double & green)
void ImProcCoordinator::getCamWB(double& temp, double& green)
{
if (imgsrc) {
@@ -1203,7 +1287,7 @@ void ImProcCoordinator::getCamWB(double & temp, double & green)
}
}
void ImProcCoordinator::getSpotWB(int x, int y, int rect, double & temp, double & tgreen)
void ImProcCoordinator::getSpotWB(int x, int y, int rect, double& temp, double& tgreen)
{
ColorTemp ret;
@@ -1270,13 +1354,13 @@ void ImProcCoordinator::getAutoCrop(double ratio, int &x, int &y, int &w, int &h
y = (fullh - h) / 2;
}
void ImProcCoordinator::setMonitorProfile(const Glib::ustring & profile, RenderingIntent intent)
void ImProcCoordinator::setMonitorProfile(const Glib::ustring& profile, RenderingIntent intent)
{
monitorProfile = profile;
monitorIntent = intent;
}
void ImProcCoordinator::getMonitorProfile(Glib::ustring & profile, RenderingIntent & intent) const
void ImProcCoordinator::getMonitorProfile(Glib::ustring& profile, RenderingIntent& intent) const
{
profile = monitorProfile;
intent = monitorIntent;
@@ -1288,7 +1372,7 @@ void ImProcCoordinator::setSoftProofing(bool softProof, bool gamutCheck)
this->gamutCheck = gamutCheck;
}
void ImProcCoordinator::getSoftProofing(bool & softProof, bool & gamutCheck)
void ImProcCoordinator::getSoftProofing(bool &softProof, bool &gamutCheck)
{
softProof = this->softProof;
gamutCheck = this->gamutCheck;
@@ -1299,7 +1383,7 @@ void ImProcCoordinator::setSharpMask(bool sharpMask)
this->sharpMask = sharpMask;
}
void ImProcCoordinator::saveInputICCReference(const Glib::ustring & fname, bool apply_wb)
void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool apply_wb)
{
MyMutex::MyLock lock(mProcessing);
@@ -1312,10 +1396,11 @@ void ImProcCoordinator::saveInputICCReference(const Glib::ustring & fname, bool
PreviewProps pp(0, 0, fW, fH, 1);
ProcParams ppar = params;
ppar.toneCurve.hrenabled = false;
ppar.icm.input = "(none)";
ppar.icm.inputProfile = "(none)";
Imagefloat* im = new Imagefloat(fW, fH);
imgsrc->preprocess(ppar.raw, ppar.lensProf, ppar.coarse);
imgsrc->demosaic(ppar.raw);
double dummy = 0.0;
imgsrc->demosaic(ppar.raw, false, dummy);
ColorTemp currWB = ColorTemp(params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method);
if (params.wb.method == "Camera") {