Further cleanup and astyled lcp.*
This commit is contained in:
401
rtengine/lcp.cc
401
rtengine/lcp.cc
@@ -34,21 +34,21 @@ using namespace rtengine;
|
|||||||
|
|
||||||
|
|
||||||
LCPModelCommon::LCPModelCommon() :
|
LCPModelCommon::LCPModelCommon() :
|
||||||
foc_len_x(-1.0f),
|
foc_len_x (-1.0f),
|
||||||
foc_len_y(-1.0f),
|
foc_len_y (-1.0f),
|
||||||
img_center_x(0.5f),
|
img_center_x (0.5f),
|
||||||
img_center_y(0.5f),
|
img_center_y (0.5f),
|
||||||
param{{}},
|
param{{}},
|
||||||
scale_factor(1.0f),
|
scale_factor (1.0f),
|
||||||
mean_error(0.0),
|
mean_error (0.0),
|
||||||
bad_error(false),
|
bad_error (false),
|
||||||
x0(0.0f),
|
x0 (0.0f),
|
||||||
y0(0.0f),
|
y0 (0.0f),
|
||||||
fx(0.0f),
|
fx (0.0f),
|
||||||
fy(0.0f),
|
fy (0.0f),
|
||||||
rfx(0.0f),
|
rfx (0.0f),
|
||||||
rfy(0.0f),
|
rfy (0.0f),
|
||||||
vign_param{{}}
|
vign_param{{}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +59,13 @@ bool LCPModelCommon::empty() const
|
|||||||
|
|
||||||
void LCPModelCommon::print() const
|
void LCPModelCommon::print() const
|
||||||
{
|
{
|
||||||
printf("focLen %g/%g; imgCenter %g/%g; scale %g; err %g\n", foc_len_x, foc_len_y, img_center_x, img_center_y, scale_factor, mean_error);
|
printf ("focLen %g/%g; imgCenter %g/%g; scale %g; err %g\n", foc_len_x, foc_len_y, img_center_x, img_center_y, scale_factor, mean_error);
|
||||||
printf("xy0 %g/%g fxy %g/%g\n", x0, y0, fx, fy);
|
printf ("xy0 %g/%g fxy %g/%g\n", x0, y0, fx, fy);
|
||||||
printf("param: %g/%g/%g/%g/%g\n", param[0], param[1], param[2], param[3], param[4]);
|
printf ("param: %g/%g/%g/%g/%g\n", param[0], param[1], param[2], param[3], param[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// weighted merge two parameters
|
// weighted merge two parameters
|
||||||
void LCPModelCommon::merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA)
|
void LCPModelCommon::merge (const LCPModelCommon& a, const LCPModelCommon& b, float facA)
|
||||||
{
|
{
|
||||||
const float facB = 1.0f - facA;
|
const float facB = 1.0f - facA;
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ void LCPModelCommon::merge(const LCPModelCommon& a, const LCPModelCommon& b, flo
|
|||||||
param[i] = facA * a.param[i] + facB * b.param[i];
|
param[i] = facA * a.param[i] + facB * b.param[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
const float param0Sqr = param[0] * param[0];
|
const double param0Sqr = param[0] * param[0];
|
||||||
|
|
||||||
vign_param[0] = -param[0];
|
vign_param[0] = -param[0];
|
||||||
vign_param[1] = param0Sqr - param[1];
|
vign_param[1] = param0Sqr - param[1];
|
||||||
@@ -89,10 +89,10 @@ void LCPModelCommon::merge(const LCPModelCommon& a, const LCPModelCommon& b, flo
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCPModelCommon::prepareParams(int fullWidth, int fullHeight, float focalLength, float focalLength35mm, float sensorFormatFactor, bool swapXY, bool mirrorX, bool mirrorY)
|
void LCPModelCommon::prepareParams (int fullWidth, int fullHeight, float focalLength, float focalLength35mm, float sensorFormatFactor, bool swapXY, bool mirrorX, bool mirrorY)
|
||||||
{
|
{
|
||||||
// Mention that the Adobe technical paper has a bug here, the DMAX is handled differently for focLen and imgCenter
|
// Mention that the Adobe technical paper has a bug here, the DMAX is handled differently for focLen and imgCenter
|
||||||
const int Dmax = std::max(fullWidth, fullHeight);
|
const int Dmax = std::max (fullWidth, fullHeight);
|
||||||
|
|
||||||
// correct focLens
|
// correct focLens
|
||||||
if (foc_len_x < 0.0f) { // they may not be given
|
if (foc_len_x < 0.0f) { // they may not be given
|
||||||
@@ -115,8 +115,9 @@ void LCPModelCommon::prepareParams(int fullWidth, int fullHeight, float focalLen
|
|||||||
fx = foc_len_x * Dmax;
|
fx = foc_len_x * Dmax;
|
||||||
fy = foc_len_y * Dmax;
|
fy = foc_len_y * Dmax;
|
||||||
}
|
}
|
||||||
rfx = 1.0f / fx;
|
|
||||||
rfy = 1.0f / fy;
|
rfx = 1.0 / fx; // calculatiom with double precision doesn't cost anything at this step
|
||||||
|
rfy = 1.0 / fy; // "
|
||||||
|
|
||||||
//printf("FW %i /X0 %g FH %i /Y0 %g %g\n",fullWidth,x0,fullHeight,y0, imgYCenter);
|
//printf("FW %i /X0 %g FH %i /Y0 %g %g\n",fullWidth,x0,fullHeight,y0, imgYCenter);
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,7 @@ LCPPersModel::LCPPersModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mode: 0=distortion, 1=vignette, 2=CA
|
// mode: 0=distortion, 1=vignette, 2=CA
|
||||||
bool LCPPersModel::hasModeData(int mode) const
|
bool LCPPersModel::hasModeData (int mode) const
|
||||||
{
|
{
|
||||||
return (mode == 0 && !vignette.empty() && !vignette.bad_error) || (mode == 1 && !base.empty() && !base.bad_error)
|
return (mode == 0 && !vignette.empty() && !vignette.bad_error) || (mode == 1 && !base.empty() && !base.bad_error)
|
||||||
|| (mode == 2 && !chromRG.empty() && !chromG.empty() && !chromBG.empty() &&
|
|| (mode == 2 && !chromRG.empty() && !chromG.empty() && !chromBG.empty() &&
|
||||||
@@ -136,36 +137,36 @@ bool LCPPersModel::hasModeData(int mode) const
|
|||||||
|
|
||||||
void LCPPersModel::print() const
|
void LCPPersModel::print() const
|
||||||
{
|
{
|
||||||
printf("--- PersModel focLen %g; focDist %g; aperture %g\n", focLen, focDist, aperture);
|
printf ("--- PersModel focLen %g; focDist %g; aperture %g\n", focLen, focDist, aperture);
|
||||||
printf("Base:\n");
|
printf ("Base:\n");
|
||||||
base.print();
|
base.print();
|
||||||
|
|
||||||
if (!chromRG.empty()) {
|
if (!chromRG.empty()) {
|
||||||
printf("ChromRG:\n");
|
printf ("ChromRG:\n");
|
||||||
chromRG.print();
|
chromRG.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chromG.empty()) {
|
if (!chromG.empty()) {
|
||||||
printf("ChromG:\n");
|
printf ("ChromG:\n");
|
||||||
chromG.print();
|
chromG.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!chromBG.empty()) {
|
if (!chromBG.empty()) {
|
||||||
printf("ChromBG:\n");
|
printf ("ChromBG:\n");
|
||||||
chromBG.print();
|
chromBG.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vignette.empty()) {
|
if (!vignette.empty()) {
|
||||||
printf("Vignette:\n");
|
printf ("Vignette:\n");
|
||||||
vignette.print();
|
vignette.print();
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf ("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// if !vignette then geometric and CA
|
// if !vignette then geometric and CA
|
||||||
LCPMapper::LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP,
|
LCPMapper::LCPMapper (LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP,
|
||||||
int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg)
|
int fullWidth, int fullHeight, const CoarseTransformParams& coarse, int rawRotationDeg)
|
||||||
{
|
{
|
||||||
if (pProf == nullptr) {
|
if (pProf == nullptr) {
|
||||||
return;
|
return;
|
||||||
@@ -186,21 +187,21 @@ LCPMapper::LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm
|
|||||||
bool mirrorY = (rot == 180 || rot == 270);
|
bool mirrorY = (rot == 180 || rot == 270);
|
||||||
//printf("Vign: %i, fullWidth: %i/%i, focLen %g SwapXY: %i / MirX/Y %i / %i on rot:%i from %i\n",vignette, fullWidth, fullHeight, focalLength, swapXY, mirrorX, mirrorY, rot, rawRotationDeg);
|
//printf("Vign: %i, fullWidth: %i/%i, focLen %g SwapXY: %i / MirX/Y %i / %i on rot:%i from %i\n",vignette, fullWidth, fullHeight, focalLength, swapXY, mirrorX, mirrorY, rot, rawRotationDeg);
|
||||||
|
|
||||||
pProf->calcParams(vignette ? 0 : 1, focalLength, focusDist, aperture, &mc, nullptr, nullptr);
|
pProf->calcParams (vignette ? 0 : 1, focalLength, focusDist, aperture, &mc, nullptr, nullptr);
|
||||||
mc.prepareParams(fullWidth, fullHeight, focalLength, focalLength35mm, pProf->sensorFormatFactor, swapXY, mirrorX, mirrorY);
|
mc.prepareParams (fullWidth, fullHeight, focalLength, focalLength35mm, pProf->sensorFormatFactor, swapXY, mirrorX, mirrorY);
|
||||||
|
|
||||||
if (!vignette) {
|
if (!vignette) {
|
||||||
pProf->calcParams(2, focalLength, focusDist, aperture, &chrom[0], &chrom[1], &chrom[2]);
|
pProf->calcParams (2, focalLength, focusDist, aperture, &chrom[0], &chrom[1], &chrom[2]);
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
chrom[i].prepareParams(fullWidth, fullHeight, focalLength, focalLength35mm, pProf->sensorFormatFactor, swapXY, mirrorX, mirrorY);
|
chrom[i].prepareParams (fullWidth, fullHeight, focalLength, focalLength35mm, pProf->sensorFormatFactor, swapXY, mirrorX, mirrorY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableCA = !vignette && focusDist > 0;
|
enableCA = !vignette && focusDist > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCPMapper::correctDistortion(double& x, double& y) const
|
void LCPMapper::correctDistortion (double& x, double& y) const
|
||||||
{
|
{
|
||||||
double xd = (x - mc.x0) / mc.fx, yd = (y - mc.y0) / mc.fy;
|
double xd = (x - mc.x0) / mc.fx, yd = (y - mc.y0) / mc.fy;
|
||||||
|
|
||||||
@@ -218,7 +219,7 @@ void LCPMapper::correctDistortion(double& x, double& y) const
|
|||||||
y = ynew * mc.fy + mc.y0;
|
y = ynew * mc.fy + mc.y0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCPMapper::correctCA(double& x, double& y, int channel) const
|
void LCPMapper::correctCA (double& x, double& y, int channel) const
|
||||||
{
|
{
|
||||||
if (!enableCA) {
|
if (!enableCA) {
|
||||||
return;
|
return;
|
||||||
@@ -265,47 +266,39 @@ void LCPMapper::correctCA(double& x, double& y, int channel) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float LCPMapper::calcVignetteFac(int x, int y) const
|
SSEFUNCTION void LCPMapper::processVignetteLine (int width, int y, float *line) const
|
||||||
{
|
|
||||||
// No need for swapXY, since vignette is in RAW and always before rotation
|
|
||||||
float xd = ((float)x - mc.x0) * mc.rfx, yd = ((float)y - mc.y0) * mc.rfy;
|
|
||||||
|
|
||||||
const LCPModelCommon::VignParam vignParam = mc.vign_param;
|
|
||||||
float rsqr = xd * xd + yd * yd;
|
|
||||||
|
|
||||||
return rsqr * (vignParam[0] + rsqr * ((vignParam[1]) - (vignParam[2]) * rsqr + (vignParam[3]) * rsqr * rsqr));
|
|
||||||
}
|
|
||||||
|
|
||||||
SSEFUNCTION void LCPMapper::processVignetteLine(int width, int y, float *line) const
|
|
||||||
{
|
{
|
||||||
// No need for swapXY, since vignette is in RAW and always before rotation
|
// No need for swapXY, since vignette is in RAW and always before rotation
|
||||||
float yd = ((float)y - mc.y0) * mc.rfy;
|
float yd = ((float)y - mc.y0) * mc.rfy;
|
||||||
yd *= yd;
|
yd *= yd;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const vfloat fourv = F2V(4.f);
|
const vfloat fourv = F2V (4.f);
|
||||||
const vfloat zerov = F2V(0.f);
|
const vfloat zerov = F2V (0.f);
|
||||||
const vfloat ydv = F2V(yd);
|
const vfloat ydv = F2V (yd);
|
||||||
const vfloat p0 = F2V(mc.vign_param[0]);
|
const vfloat p0 = F2V (mc.vign_param[0]);
|
||||||
const vfloat p1 = F2V(mc.vign_param[1]);
|
const vfloat p1 = F2V (mc.vign_param[1]);
|
||||||
const vfloat p2 = F2V(mc.vign_param[2]);
|
const vfloat p2 = F2V (mc.vign_param[2]);
|
||||||
const vfloat p3 = F2V(mc.vign_param[3]);
|
const vfloat p3 = F2V (mc.vign_param[3]);
|
||||||
const vfloat x0v = F2V(mc.x0);
|
const vfloat x0v = F2V (mc.x0);
|
||||||
const vfloat rfxv = F2V(mc.rfx);
|
const vfloat rfxv = F2V (mc.rfx);
|
||||||
|
|
||||||
vfloat xv = _mm_setr_ps(0.f, 1.f, 2.f, 3.f);
|
vfloat xv = _mm_setr_ps (0.f, 1.f, 2.f, 3.f);
|
||||||
for (; x < width-3; x+=4) {
|
|
||||||
|
for (; x < width - 3; x += 4) {
|
||||||
vfloat xdv = (xv - x0v) * rfxv;
|
vfloat xdv = (xv - x0v) * rfxv;
|
||||||
vfloat rsqr = xdv * xdv + ydv;
|
vfloat rsqr = xdv * xdv + ydv;
|
||||||
vfloat vignFactorv = rsqr * (p0 + rsqr * (p1 - p2 * rsqr + p3 * rsqr * rsqr));
|
vfloat vignFactorv = rsqr * (p0 + rsqr * (p1 - p2 * rsqr + p3 * rsqr * rsqr));
|
||||||
vfloat valv = LVFU(line[x]);
|
vfloat valv = LVFU (line[x]);
|
||||||
valv += valv * vselfzero(vmaskf_gt(valv, zerov), vignFactorv);
|
valv += valv * vselfzero (vmaskf_gt (valv, zerov), vignFactorv);
|
||||||
STVFU(line[x], valv);
|
STVFU (line[x], valv);
|
||||||
xv += fourv;
|
xv += fourv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __SSE2__
|
#endif // __SSE2__
|
||||||
|
|
||||||
for (; x < width; x++) {
|
for (; x < width; x++) {
|
||||||
if (line[x] > 0) {
|
if (line[x] > 0.f) {
|
||||||
float xd = ((float)x - mc.x0) * mc.rfx;
|
float xd = ((float)x - mc.x0) * mc.rfx;
|
||||||
const LCPModelCommon::VignParam vignParam = mc.vign_param;
|
const LCPModelCommon::VignParam vignParam = mc.vign_param;
|
||||||
float rsqr = xd * xd + yd;
|
float rsqr = xd * xd + yd;
|
||||||
@@ -314,39 +307,40 @@ SSEFUNCTION void LCPMapper::processVignetteLine(int width, int y, float *line) c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SSEFUNCTION void LCPMapper::processVignetteLine3Channels(int width, int y, float *line) const
|
void LCPMapper::processVignetteLine3Channels (int width, int y, float *line) const
|
||||||
{
|
{
|
||||||
// No need for swapXY, since vignette is in RAW and always before rotation
|
// No need for swapXY, since vignette is in RAW and always before rotation
|
||||||
float yd = ((float)y - mc.y0) * mc.rfy;
|
float yd = ((float)y - mc.y0) * mc.rfy;
|
||||||
yd *= yd;
|
yd *= yd;
|
||||||
const LCPModelCommon::VignParam vignParam = mc.vign_param;
|
const LCPModelCommon::VignParam vignParam = mc.vign_param;
|
||||||
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
float xd = ((float)x - mc.x0) * mc.rfx;
|
float xd = ((float)x - mc.x0) * mc.rfx;
|
||||||
float rsqr = xd * xd + yd;
|
float rsqr = xd * xd + yd;
|
||||||
float vignetteFactor = rsqr * (vignParam[0] + rsqr * ((vignParam[1]) - (vignParam[2]) * rsqr + (vignParam[3]) * rsqr * rsqr));
|
float vignetteFactor = rsqr * (vignParam[0] + rsqr * ((vignParam[1]) - (vignParam[2]) * rsqr + (vignParam[3]) * rsqr * rsqr));
|
||||||
for(int c = 0;c < 3; ++c) {
|
|
||||||
if (line[3*x+c] > 0) {
|
for (int c = 0; c < 3; ++c) {
|
||||||
line[3*x+c] += line[3*x+c] * vignetteFactor;
|
if (line[3 * x + c] > 0) {
|
||||||
|
line[3 * x + c] += line[3 * x + c] * vignetteFactor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LCPProfile::LCPProfile (const Glib::ustring &fname)
|
||||||
LCPProfile::LCPProfile(const Glib::ustring &fname)
|
|
||||||
{
|
{
|
||||||
const int BufferSize = 8192;
|
const int BufferSize = 8192;
|
||||||
char buf[BufferSize];
|
char buf[BufferSize];
|
||||||
|
|
||||||
XML_Parser parser = XML_ParserCreate(nullptr);
|
XML_Parser parser = XML_ParserCreate (nullptr);
|
||||||
|
|
||||||
if (!parser) {
|
if (!parser) {
|
||||||
throw "Couldn't allocate memory for XML parser";
|
throw "Couldn't allocate memory for XML parser";
|
||||||
}
|
}
|
||||||
|
|
||||||
XML_SetElementHandler(parser, XmlStartHandler, XmlEndHandler);
|
XML_SetElementHandler (parser, XmlStartHandler, XmlEndHandler);
|
||||||
XML_SetCharacterDataHandler(parser, XmlTextHandler);
|
XML_SetCharacterDataHandler (parser, XmlTextHandler);
|
||||||
XML_SetUserData(parser, (void *)this);
|
XML_SetUserData (parser, (void *)this);
|
||||||
|
|
||||||
|
|
||||||
isFisheye = inCamProfiles = firstLIDone = inPerspect = inAlternateLensID = inAlternateLensNames = false;
|
isFisheye = inCamProfiles = firstLIDone = inPerspect = inAlternateLensID = inAlternateLensNames = false;
|
||||||
@@ -359,51 +353,51 @@ LCPProfile::LCPProfile(const Glib::ustring &fname)
|
|||||||
persModelCount = 0;
|
persModelCount = 0;
|
||||||
*inInvalidTag = 0;
|
*inInvalidTag = 0;
|
||||||
|
|
||||||
FILE *pFile = g_fopen(fname.c_str (), "rb");
|
FILE *pFile = g_fopen (fname.c_str (), "rb");
|
||||||
|
|
||||||
bool done;
|
bool done;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int bytesRead = (int)fread(buf, 1, BufferSize, pFile);
|
int bytesRead = (int)fread (buf, 1, BufferSize, pFile);
|
||||||
done = feof(pFile);
|
done = feof (pFile);
|
||||||
|
|
||||||
if (XML_Parse(parser, buf, bytesRead, done) == XML_STATUS_ERROR) {
|
if (XML_Parse (parser, buf, bytesRead, done) == XML_STATUS_ERROR) {
|
||||||
throw "Invalid XML in LCP file";
|
throw "Invalid XML in LCP file";
|
||||||
}
|
}
|
||||||
} while (!done);
|
} while (!done);
|
||||||
|
|
||||||
fclose(pFile);
|
fclose (pFile);
|
||||||
|
|
||||||
XML_ParserFree(parser);
|
XML_ParserFree (parser);
|
||||||
|
|
||||||
//printf("Parsing %s\n", fname.c_str());
|
//printf("Parsing %s\n", fname.c_str());
|
||||||
// Two phase filter: first filter out the very rough ones, that distord the average a lot
|
// Two phase filter: first filter out the very rough ones, that distord the average a lot
|
||||||
// force it, even if there are few frames (community profiles)
|
// force it, even if there are few frames (community profiles)
|
||||||
filterBadFrames(2.0, 0);
|
filterBadFrames (2.0, 0);
|
||||||
// from the non-distorded, filter again on new average basis, but only if there are enough frames left
|
// from the non-distorded, filter again on new average basis, but only if there are enough frames left
|
||||||
filterBadFrames(1.5, 100);
|
filterBadFrames (1.5, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from all frames not marked as bad already, take average and filter out frames with higher deviation than this if there are enough values
|
// from all frames not marked as bad already, take average and filter out frames with higher deviation than this if there are enough values
|
||||||
int LCPProfile::filterBadFrames(double maxAvgDevFac, int minFramesLeft)
|
int LCPProfile::filterBadFrames (double maxAvgDevFac, int minFramesLeft)
|
||||||
{
|
{
|
||||||
// take average error per type, then calculated the maximum deviation allowed
|
// take average error per type, then calculated the maximum deviation allowed
|
||||||
double errBase = 0, errChrom = 0, errVignette = 0;
|
double errBase = 0, errChrom = 0, errVignette = 0;
|
||||||
int baseCount = 0, chromCount = 0, vignetteCount = 0;
|
int baseCount = 0, chromCount = 0, vignetteCount = 0;
|
||||||
|
|
||||||
for (int pm = 0; pm < MaxPersModelCount && aPersModel[pm]; pm++) {
|
for (int pm = 0; pm < MaxPersModelCount && aPersModel[pm]; pm++) {
|
||||||
if (aPersModel[pm]->hasModeData(0)) {
|
if (aPersModel[pm]->hasModeData (0)) {
|
||||||
errVignette += aPersModel[pm]->vignette.mean_error;
|
errVignette += aPersModel[pm]->vignette.mean_error;
|
||||||
vignetteCount++;
|
vignetteCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(1)) {
|
if (aPersModel[pm]->hasModeData (1)) {
|
||||||
errBase += aPersModel[pm]->base.mean_error;
|
errBase += aPersModel[pm]->base.mean_error;
|
||||||
baseCount++;
|
baseCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(2)) {
|
if (aPersModel[pm]->hasModeData (2)) {
|
||||||
errChrom += std::max(std::max(aPersModel[pm]->chromRG.mean_error, aPersModel[pm]->chromG.mean_error), aPersModel[pm]->chromBG.mean_error);
|
errChrom += std::max (std::max (aPersModel[pm]->chromRG.mean_error, aPersModel[pm]->chromG.mean_error), aPersModel[pm]->chromBG.mean_error);
|
||||||
chromCount++;
|
chromCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,17 +420,17 @@ int LCPProfile::filterBadFrames(double maxAvgDevFac, int minFramesLeft)
|
|||||||
|
|
||||||
// Now mark all the bad ones as bad, and hasModeData will return false;
|
// Now mark all the bad ones as bad, and hasModeData will return false;
|
||||||
for (int pm = 0; pm < MaxPersModelCount && aPersModel[pm]; pm++) {
|
for (int pm = 0; pm < MaxPersModelCount && aPersModel[pm]; pm++) {
|
||||||
if (aPersModel[pm]->hasModeData(0) && aPersModel[pm]->vignette.mean_error > maxAvgDevFac * errVignette) {
|
if (aPersModel[pm]->hasModeData (0) && aPersModel[pm]->vignette.mean_error > maxAvgDevFac * errVignette) {
|
||||||
aPersModel[pm]->vignette.bad_error = true;
|
aPersModel[pm]->vignette.bad_error = true;
|
||||||
filtered++;
|
filtered++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(1) && aPersModel[pm]->base.mean_error > maxAvgDevFac * errBase) {
|
if (aPersModel[pm]->hasModeData (1) && aPersModel[pm]->base.mean_error > maxAvgDevFac * errBase) {
|
||||||
aPersModel[pm]->base.bad_error = true;
|
aPersModel[pm]->base.bad_error = true;
|
||||||
filtered++;
|
filtered++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(2) &&
|
if (aPersModel[pm]->hasModeData (2) &&
|
||||||
(aPersModel[pm]->chromRG.mean_error > maxAvgDevFac * errChrom || aPersModel[pm]->chromG.mean_error > maxAvgDevFac * errChrom
|
(aPersModel[pm]->chromRG.mean_error > maxAvgDevFac * errChrom || aPersModel[pm]->chromG.mean_error > maxAvgDevFac * errChrom
|
||||||
|| aPersModel[pm]->chromBG.mean_error > maxAvgDevFac * errChrom)) {
|
|| aPersModel[pm]->chromBG.mean_error > maxAvgDevFac * errChrom)) {
|
||||||
aPersModel[pm]->chromRG.bad_error = aPersModel[pm]->chromG.bad_error = aPersModel[pm]->chromBG.bad_error = true;
|
aPersModel[pm]->chromRG.bad_error = aPersModel[pm]->chromG.bad_error = aPersModel[pm]->chromBG.bad_error = true;
|
||||||
@@ -450,23 +444,22 @@ int LCPProfile::filterBadFrames(double maxAvgDevFac, int minFramesLeft)
|
|||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// mode: 0=vignette, 1=distortion, 2=CA
|
// mode: 0=vignette, 1=distortion, 2=CA
|
||||||
void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float aperture, LCPModelCommon *pCorr1, LCPModelCommon *pCorr2, LCPModelCommon *pCorr3) const
|
void LCPProfile::calcParams (int mode, float focalLength, float focusDist, float aperture, LCPModelCommon *pCorr1, LCPModelCommon *pCorr2, LCPModelCommon *pCorr3) const
|
||||||
{
|
{
|
||||||
float euler = exp(1.0);
|
float euler = exp (1.0);
|
||||||
|
|
||||||
// find the frames with the least distance, focal length wise
|
// find the frames with the least distance, focal length wise
|
||||||
LCPPersModel *pLow = nullptr, *pHigh = nullptr;
|
LCPPersModel *pLow = nullptr, *pHigh = nullptr;
|
||||||
|
|
||||||
float focalLengthLog = log(focalLength); //, apertureLog=aperture>0 ? log(aperture) : 0;
|
float focalLengthLog = log (focalLength); //, apertureLog=aperture>0 ? log(aperture) : 0;
|
||||||
float focusDistLog = focusDist > 0 ? log(focusDist) + euler : 0;
|
float focusDistLog = focusDist > 0 ? log (focusDist) + euler : 0;
|
||||||
|
|
||||||
// Pass 1: determining best focal length, if possible different focusDistances (for the focDist is not given case)
|
// Pass 1: determining best focal length, if possible different focusDistances (for the focDist is not given case)
|
||||||
for (int pm = 0; pm < persModelCount; pm++) {
|
for (int pm = 0; pm < persModelCount; pm++) {
|
||||||
float f = aPersModel[pm]->focLen;
|
float f = aPersModel[pm]->focLen;
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(mode)) {
|
if (aPersModel[pm]->hasModeData (mode)) {
|
||||||
if (f <= focalLength && (pLow == nullptr || f > pLow->focLen || (focusDist == 0 && f == pLow->focLen && pLow->focDist > aPersModel[pm]->focDist))) {
|
if (f <= focalLength && (pLow == nullptr || f > pLow->focLen || (focusDist == 0 && f == pLow->focLen && pLow->focDist > aPersModel[pm]->focDist))) {
|
||||||
pLow = aPersModel[pm];
|
pLow = aPersModel[pm];
|
||||||
}
|
}
|
||||||
@@ -490,10 +483,10 @@ void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float
|
|||||||
for (int pm = 0; pm < persModelCount; pm++) {
|
for (int pm = 0; pm < persModelCount; pm++) {
|
||||||
float aper = aPersModel[pm]->aperture; // float aperLog=log(aper);
|
float aper = aPersModel[pm]->aperture; // float aperLog=log(aper);
|
||||||
float focDist = aPersModel[pm]->focDist;
|
float focDist = aPersModel[pm]->focDist;
|
||||||
float focDistLog = log(focDist) + euler;
|
float focDistLog = log (focDist) + euler;
|
||||||
double meanErr;
|
double meanErr;
|
||||||
|
|
||||||
if (aPersModel[pm]->hasModeData(mode)) {
|
if (aPersModel[pm]->hasModeData (mode)) {
|
||||||
if (mode == 0) {
|
if (mode == 0) {
|
||||||
meanErr = aPersModel[pm]->vignette.mean_error;
|
meanErr = aPersModel[pm]->vignette.mean_error;
|
||||||
|
|
||||||
@@ -502,14 +495,14 @@ void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float
|
|||||||
if (aPersModel[pm]->focLen == bestFocLenLow && (
|
if (aPersModel[pm]->focLen == bestFocLenLow && (
|
||||||
(aper == aperture && pLow->vignette.mean_error > meanErr)
|
(aper == aperture && pLow->vignette.mean_error > meanErr)
|
||||||
|| (aper >= aperture && aper < pLow->aperture && pLow->aperture > aperture)
|
|| (aper >= aperture && aper < pLow->aperture && pLow->aperture > aperture)
|
||||||
|| (aper <= aperture && (pLow->aperture > aperture || fabs(aperture - aper) < fabs(aperture - pLow->aperture))))) {
|
|| (aper <= aperture && (pLow->aperture > aperture || fabs (aperture - aper) < fabs (aperture - pLow->aperture))))) {
|
||||||
pLow = aPersModel[pm];
|
pLow = aPersModel[pm];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->focLen == bestFocLenHigh && (
|
if (aPersModel[pm]->focLen == bestFocLenHigh && (
|
||||||
(aper == aperture && pHigh->vignette.mean_error > meanErr)
|
(aper == aperture && pHigh->vignette.mean_error > meanErr)
|
||||||
|| (aper <= aperture && aper > pHigh->aperture && pHigh->aperture < aperture)
|
|| (aper <= aperture && aper > pHigh->aperture && pHigh->aperture < aperture)
|
||||||
|| (aper >= aperture && (pHigh->aperture < aperture || fabs(aperture - aper) < fabs(aperture - pHigh->aperture))))) {
|
|| (aper >= aperture && (pHigh->aperture < aperture || fabs (aperture - aper) < fabs (aperture - pHigh->aperture))))) {
|
||||||
pHigh = aPersModel[pm];
|
pHigh = aPersModel[pm];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -520,14 +513,14 @@ void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float
|
|||||||
if (aPersModel[pm]->focLen == bestFocLenLow && (
|
if (aPersModel[pm]->focLen == bestFocLenLow && (
|
||||||
(focDist == focusDist && (mode == 1 ? pLow->base.mean_error : pLow->chromG.mean_error) > meanErr)
|
(focDist == focusDist && (mode == 1 ? pLow->base.mean_error : pLow->chromG.mean_error) > meanErr)
|
||||||
|| (focDist >= focusDist && focDist < pLow->focDist && pLow->focDist > focusDist)
|
|| (focDist >= focusDist && focDist < pLow->focDist && pLow->focDist > focusDist)
|
||||||
|| (focDist <= focusDist && (pLow->focDist > focusDist || fabs(focusDistLog - focDistLog) < fabs(focusDistLog - (log(pLow->focDist) + euler)))))) {
|
|| (focDist <= focusDist && (pLow->focDist > focusDist || fabs (focusDistLog - focDistLog) < fabs (focusDistLog - (log (pLow->focDist) + euler)))))) {
|
||||||
pLow = aPersModel[pm];
|
pLow = aPersModel[pm];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aPersModel[pm]->focLen == bestFocLenHigh && (
|
if (aPersModel[pm]->focLen == bestFocLenHigh && (
|
||||||
(focDist == focusDist && (mode == 1 ? pHigh->base.mean_error : pHigh->chromG.mean_error) > meanErr)
|
(focDist == focusDist && (mode == 1 ? pHigh->base.mean_error : pHigh->chromG.mean_error) > meanErr)
|
||||||
|| (focDist <= focusDist && focDist > pHigh->focDist && pHigh->focDist < focusDist)
|
|| (focDist <= focusDist && focDist > pHigh->focDist && pHigh->focDist < focusDist)
|
||||||
|| (focDist >= focusDist && (pHigh->focDist < focusDist || fabs(focusDistLog - focDistLog) < fabs(focusDistLog - (log(pHigh->focDist) + euler)))))) {
|
|| (focDist >= focusDist && (pHigh->focDist < focusDist || fabs (focusDistLog - focDistLog) < fabs (focusDistLog - (log (pHigh->focDist) + euler)))))) {
|
||||||
pHigh = aPersModel[pm];
|
pHigh = aPersModel[pm];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -552,7 +545,7 @@ void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float
|
|||||||
|
|
||||||
// There is as foclen range, take that as basis
|
// There is as foclen range, take that as basis
|
||||||
if (pLow->focLen < pHigh->focLen) {
|
if (pLow->focLen < pHigh->focLen) {
|
||||||
facLow = (log(pHigh->focLen) - focalLengthLog) / (log(pHigh->focLen) - log(pLow->focLen));
|
facLow = (log (pHigh->focLen) - focalLengthLog) / (log (pHigh->focLen) - log (pLow->focLen));
|
||||||
} else {
|
} else {
|
||||||
focLenOnSpot = pLow->focLen == pHigh->focLen && pLow->focLen == focalLength;
|
focLenOnSpot = pLow->focLen == pHigh->focLen && pLow->focLen == focalLength;
|
||||||
}
|
}
|
||||||
@@ -564,45 +557,45 @@ void LCPProfile::calcParams(int mode, float focalLength, float focusDist, float
|
|||||||
facLow = focLenOnSpot ? facAperLow : (0.5 * facLow + 0.5 * facAperLow);
|
facLow = focLenOnSpot ? facAperLow : (0.5 * facLow + 0.5 * facAperLow);
|
||||||
} else if (mode != 0 && focusDist > 0 && pLow->focDist < focusDist && pHigh->focDist > focusDist) {
|
} else if (mode != 0 && focusDist > 0 && pLow->focDist < focusDist && pHigh->focDist > focusDist) {
|
||||||
// focus distance for all else (if focus distance is given)
|
// focus distance for all else (if focus distance is given)
|
||||||
float facDistLow = (log(pHigh->focDist) + euler - focusDistLog) / (log(pHigh->focDist) - log(pLow->focDist));
|
float facDistLow = (log (pHigh->focDist) + euler - focusDistLog) / (log (pHigh->focDist) - log (pLow->focDist));
|
||||||
facLow = focLenOnSpot ? facDistLow : (0.8 * facLow + 0.2 * facDistLow);
|
facLow = focLenOnSpot ? facDistLow : (0.8 * facLow + 0.2 * facDistLow);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 0: // vignette
|
case 0: // vignette
|
||||||
pCorr1->merge(pLow->vignette, pHigh->vignette, facLow);
|
pCorr1->merge (pLow->vignette, pHigh->vignette, facLow);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // distortion
|
case 1: // distortion
|
||||||
pCorr1->merge(pLow->base, pHigh->base, facLow);
|
pCorr1->merge (pLow->base, pHigh->base, facLow);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // CA
|
case 2: // CA
|
||||||
pCorr1->merge(pLow->chromRG, pHigh->chromRG, facLow);
|
pCorr1->merge (pLow->chromRG, pHigh->chromRG, facLow);
|
||||||
pCorr2->merge(pLow->chromG, pHigh->chromG, facLow);
|
pCorr2->merge (pLow->chromG, pHigh->chromG, facLow);
|
||||||
pCorr3->merge(pLow->chromBG, pHigh->chromBG, facLow);
|
pCorr3->merge (pLow->chromBG, pHigh->chromBG, facLow);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("LCP mode=%i, dist: %g found frames: Fno %g-%g; FocLen %g-%g; Dist %g-%g with weight %g\n", mode, focusDist, pLow->aperture, pHigh->aperture, pLow->focLen, pHigh->focLen, pLow->focDist, pHigh->focDist, facLow);
|
//printf("LCP mode=%i, dist: %g found frames: Fno %g-%g; FocLen %g-%g; Dist %g-%g with weight %g\n", mode, focusDist, pLow->aperture, pHigh->aperture, pLow->focLen, pHigh->focLen, pLow->focDist, pHigh->focDist, facLow);
|
||||||
} else {
|
} else {
|
||||||
printf("Error: LCP file contained no %s parameters\n", mode == 0 ? "vignette" : mode == 1 ? "distortion" : "CA" );
|
printf ("Error: LCP file contained no %s parameters\n", mode == 0 ? "vignette" : mode == 1 ? "distortion" : "CA" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LCPProfile::print() const
|
void LCPProfile::print() const
|
||||||
{
|
{
|
||||||
printf("=== Profile %s\n", profileName.c_str());
|
printf ("=== Profile %s\n", profileName.c_str());
|
||||||
printf("Frames: %i, RAW: %i; Fisheye: %i; Sensorformat: %f\n", persModelCount, isRaw, isFisheye, sensorFormatFactor);
|
printf ("Frames: %i, RAW: %i; Fisheye: %i; Sensorformat: %f\n", persModelCount, isRaw, isFisheye, sensorFormatFactor);
|
||||||
|
|
||||||
for (int pm = 0; pm < persModelCount; pm++) {
|
for (int pm = 0; pm < persModelCount; pm++) {
|
||||||
aPersModel[pm]->print();
|
aPersModel[pm]->print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, const char **attr)
|
void XMLCALL LCPProfile::XmlStartHandler (void *pLCPProfile, const char *el, const char **attr)
|
||||||
{
|
{
|
||||||
LCPProfile *pProf = static_cast<LCPProfile*>(pLCPProfile);
|
LCPProfile *pProf = static_cast<LCPProfile*> (pLCPProfile);
|
||||||
bool parseAttr = false;
|
bool parseAttr = false;
|
||||||
|
|
||||||
if (*pProf->inInvalidTag) {
|
if (*pProf->inInvalidTag) {
|
||||||
@@ -610,29 +603,29 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// clean up tagname
|
// clean up tagname
|
||||||
const char* src = strrchr(el, ':');
|
const char* src = strrchr (el, ':');
|
||||||
|
|
||||||
if (src == nullptr) {
|
if (src == nullptr) {
|
||||||
src = const_cast<char*>(el);
|
src = const_cast<char*> (el);
|
||||||
} else {
|
} else {
|
||||||
src++;
|
src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pProf->lastTag, src);
|
strcpy (pProf->lastTag, src);
|
||||||
|
|
||||||
if (!strcmp("VignetteModelPiecewiseParam", src)) {
|
if (!strcmp ("VignetteModelPiecewiseParam", src)) {
|
||||||
strcpy(pProf->inInvalidTag, src);
|
strcpy (pProf->inInvalidTag, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("CameraProfiles", src)) {
|
if (!strcmp ("CameraProfiles", src)) {
|
||||||
pProf->inCamProfiles = true;
|
pProf->inCamProfiles = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("AlternateLensIDs", src)) {
|
if (!strcmp ("AlternateLensIDs", src)) {
|
||||||
pProf->inAlternateLensID = true;
|
pProf->inAlternateLensID = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("AlternateLensNames", src)) {
|
if (!strcmp ("AlternateLensNames", src)) {
|
||||||
pProf->inAlternateLensNames = true;
|
pProf->inAlternateLensNames = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -640,37 +633,37 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("li", src)) {
|
if (!strcmp ("li", src)) {
|
||||||
pProf->pCurPersModel = new LCPPersModel();
|
pProf->pCurPersModel = new LCPPersModel();
|
||||||
pProf->pCurCommon = &pProf->pCurPersModel->base; // iterated to next tags within persModel
|
pProf->pCurCommon = &pProf->pCurPersModel->base; // iterated to next tags within persModel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp("PerspectiveModel", src)) {
|
if (!strcmp ("PerspectiveModel", src)) {
|
||||||
pProf->firstLIDone = true;
|
pProf->firstLIDone = true;
|
||||||
pProf->inPerspect = true;
|
pProf->inPerspect = true;
|
||||||
return;
|
return;
|
||||||
} else if (!strcmp("FisheyeModel", src)) {
|
} else if (!strcmp ("FisheyeModel", src)) {
|
||||||
pProf->firstLIDone = true;
|
pProf->firstLIDone = true;
|
||||||
pProf->inPerspect = true;
|
pProf->inPerspect = true;
|
||||||
pProf->isFisheye = true; // just misses third param, and different path, rest is the same
|
pProf->isFisheye = true; // just misses third param, and different path, rest is the same
|
||||||
return;
|
return;
|
||||||
} else if (!strcmp("Description", src)) {
|
} else if (!strcmp ("Description", src)) {
|
||||||
parseAttr = true;
|
parseAttr = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move pointer to general section
|
// Move pointer to general section
|
||||||
if (pProf->inPerspect) {
|
if (pProf->inPerspect) {
|
||||||
if (!strcmp("ChromaticRedGreenModel", src)) {
|
if (!strcmp ("ChromaticRedGreenModel", src)) {
|
||||||
pProf->pCurCommon = &pProf->pCurPersModel->chromRG;
|
pProf->pCurCommon = &pProf->pCurPersModel->chromRG;
|
||||||
parseAttr = true;
|
parseAttr = true;
|
||||||
} else if (!strcmp("ChromaticGreenModel", src)) {
|
} else if (!strcmp ("ChromaticGreenModel", src)) {
|
||||||
pProf->pCurCommon = &pProf->pCurPersModel->chromG;
|
pProf->pCurCommon = &pProf->pCurPersModel->chromG;
|
||||||
parseAttr = true;
|
parseAttr = true;
|
||||||
} else if (!strcmp("ChromaticBlueGreenModel", src)) {
|
} else if (!strcmp ("ChromaticBlueGreenModel", src)) {
|
||||||
pProf->pCurCommon = &pProf->pCurPersModel->chromBG;
|
pProf->pCurCommon = &pProf->pCurPersModel->chromBG;
|
||||||
parseAttr = true;
|
parseAttr = true;
|
||||||
} else if (!strcmp("VignetteModel", src)) {
|
} else if (!strcmp ("VignetteModel", src)) {
|
||||||
pProf->pCurCommon = &pProf->pCurPersModel->vignette;
|
pProf->pCurCommon = &pProf->pCurPersModel->vignette;
|
||||||
parseAttr = true;
|
parseAttr = true;
|
||||||
}
|
}
|
||||||
@@ -680,23 +673,23 @@ void XMLCALL LCPProfile::XmlStartHandler(void *pLCPProfile, const char *el, cons
|
|||||||
// simulate tags by feeding them in
|
// simulate tags by feeding them in
|
||||||
if (parseAttr && attr != nullptr) {
|
if (parseAttr && attr != nullptr) {
|
||||||
for (int i = 0; attr[i]; i += 2) {
|
for (int i = 0; attr[i]; i += 2) {
|
||||||
const char* nameStart = strrchr(attr[i], ':');
|
const char* nameStart = strrchr (attr[i], ':');
|
||||||
|
|
||||||
if (nameStart == nullptr) {
|
if (nameStart == nullptr) {
|
||||||
nameStart = const_cast<char*>(attr[i]);
|
nameStart = const_cast<char*> (attr[i]);
|
||||||
} else {
|
} else {
|
||||||
nameStart++;
|
nameStart++;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(pProf->lastTag, nameStart);
|
strcpy (pProf->lastTag, nameStart);
|
||||||
XmlTextHandler(pLCPProfile, attr[i + 1], strlen(attr[i + 1]));
|
XmlTextHandler (pLCPProfile, attr[i + 1], strlen (attr[i + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, int len)
|
void XMLCALL LCPProfile::XmlTextHandler (void *pLCPProfile, const XML_Char *s, int len)
|
||||||
{
|
{
|
||||||
LCPProfile *pProf = static_cast<LCPProfile*>(pLCPProfile);
|
LCPProfile *pProf = static_cast<LCPProfile*> (pLCPProfile);
|
||||||
|
|
||||||
if (!pProf->inCamProfiles || pProf->inAlternateLensID || pProf->inAlternateLensNames || *pProf->inInvalidTag) {
|
if (!pProf->inCamProfiles || pProf->inAlternateLensID || pProf->inAlternateLensNames || *pProf->inInvalidTag) {
|
||||||
return;
|
return;
|
||||||
@@ -707,7 +700,7 @@ void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, in
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (i < len && onlyWhiteSpace) {
|
while (i < len && onlyWhiteSpace) {
|
||||||
onlyWhiteSpace = isspace(s[i]);
|
onlyWhiteSpace = isspace (s[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,32 +710,32 @@ void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, in
|
|||||||
|
|
||||||
// convert to null terminated
|
// convert to null terminated
|
||||||
char raw[len + 1];
|
char raw[len + 1];
|
||||||
memcpy(raw, s, len);
|
memcpy (raw, s, len);
|
||||||
raw[len] = 0;
|
raw[len] = 0;
|
||||||
char* tag = pProf->lastTag;
|
char* tag = pProf->lastTag;
|
||||||
|
|
||||||
// Common data section
|
// Common data section
|
||||||
if (!pProf->firstLIDone) {
|
if (!pProf->firstLIDone) {
|
||||||
// Generic tags are the same for all
|
// Generic tags are the same for all
|
||||||
if (!strcmp("ProfileName", tag)) {
|
if (!strcmp ("ProfileName", tag)) {
|
||||||
pProf->profileName = Glib::ustring(raw);
|
pProf->profileName = Glib::ustring (raw);
|
||||||
} else if (!strcmp("Model", tag)) {
|
} else if (!strcmp ("Model", tag)) {
|
||||||
pProf->camera = Glib::ustring(raw);
|
pProf->camera = Glib::ustring (raw);
|
||||||
} else if (!strcmp("Lens", tag)) {
|
} else if (!strcmp ("Lens", tag)) {
|
||||||
pProf->lens = Glib::ustring(raw);
|
pProf->lens = Glib::ustring (raw);
|
||||||
} else if (!strcmp("CameraPrettyName", tag)) {
|
} else if (!strcmp ("CameraPrettyName", tag)) {
|
||||||
pProf->cameraPrettyName = Glib::ustring(raw);
|
pProf->cameraPrettyName = Glib::ustring (raw);
|
||||||
} else if (!strcmp("LensPrettyName", tag)) {
|
} else if (!strcmp ("LensPrettyName", tag)) {
|
||||||
pProf->lensPrettyName = Glib::ustring(raw);
|
pProf->lensPrettyName = Glib::ustring (raw);
|
||||||
} else if (!strcmp("CameraRawProfile", tag)) {
|
} else if (!strcmp ("CameraRawProfile", tag)) {
|
||||||
pProf->isRaw = !strcmp("True", raw);
|
pProf->isRaw = !strcmp ("True", raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Now all floating points. Must replace local dot characters
|
// --- Now all floating points. Must replace local dot characters
|
||||||
// WARNING: called by different threads, that may run on different local settings,
|
// WARNING: called by different threads, that may run on different local settings,
|
||||||
// so don't use system params
|
// so don't use system params
|
||||||
if (atof("1,2345") == 1.2345) {
|
if (atof ("1,2345") == 1.2345) {
|
||||||
char* p = raw;
|
char* p = raw;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
@@ -755,69 +748,69 @@ void XMLCALL LCPProfile::XmlTextHandler(void *pLCPProfile, const XML_Char *s, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!pProf->firstLIDone) {
|
if (!pProf->firstLIDone) {
|
||||||
if (!strcmp("SensorFormatFactor", tag)) {
|
if (!strcmp ("SensorFormatFactor", tag)) {
|
||||||
pProf->sensorFormatFactor = atof(raw);
|
pProf->sensorFormatFactor = atof (raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perspective model base data
|
// Perspective model base data
|
||||||
if (!strcmp("FocalLength", tag)) {
|
if (!strcmp ("FocalLength", tag)) {
|
||||||
pProf->pCurPersModel->focLen = atof(raw);
|
pProf->pCurPersModel->focLen = atof (raw);
|
||||||
} else if (!strcmp("FocusDistance", tag)) {
|
} else if (!strcmp ("FocusDistance", tag)) {
|
||||||
double focDist = atof(raw);
|
double focDist = atof (raw);
|
||||||
pProf->pCurPersModel->focDist = focDist < 10000 ? focDist : 10000;
|
pProf->pCurPersModel->focDist = focDist < 10000 ? focDist : 10000;
|
||||||
} else if (!strcmp("ApertureValue", tag)) {
|
} else if (!strcmp ("ApertureValue", tag)) {
|
||||||
pProf->pCurPersModel->aperture = atof(raw);
|
pProf->pCurPersModel->aperture = atof (raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Section depended
|
// Section depended
|
||||||
if (!strcmp("FocalLengthX", tag)) {
|
if (!strcmp ("FocalLengthX", tag)) {
|
||||||
pProf->pCurCommon->foc_len_x = atof(raw);
|
pProf->pCurCommon->foc_len_x = atof (raw);
|
||||||
} else if (!strcmp("FocalLengthY", tag)) {
|
} else if (!strcmp ("FocalLengthY", tag)) {
|
||||||
pProf->pCurCommon->foc_len_y = atof(raw);
|
pProf->pCurCommon->foc_len_y = atof (raw);
|
||||||
} else if (!strcmp("ImageXCenter", tag)) {
|
} else if (!strcmp ("ImageXCenter", tag)) {
|
||||||
pProf->pCurCommon->img_center_x = atof(raw);
|
pProf->pCurCommon->img_center_x = atof (raw);
|
||||||
} else if (!strcmp("ImageYCenter", tag)) {
|
} else if (!strcmp ("ImageYCenter", tag)) {
|
||||||
pProf->pCurCommon->img_center_y = atof(raw);
|
pProf->pCurCommon->img_center_y = atof (raw);
|
||||||
} else if (!strcmp("ScaleFactor", tag)) {
|
} else if (!strcmp ("ScaleFactor", tag)) {
|
||||||
pProf->pCurCommon->scale_factor = atof(raw);
|
pProf->pCurCommon->scale_factor = atof (raw);
|
||||||
} else if (!strcmp("ResidualMeanError", tag)) {
|
} else if (!strcmp ("ResidualMeanError", tag)) {
|
||||||
pProf->pCurCommon->mean_error = atof(raw);
|
pProf->pCurCommon->mean_error = atof (raw);
|
||||||
} else if (!strcmp("RadialDistortParam1", tag) || !strcmp("VignetteModelParam1", tag)) {
|
} else if (!strcmp ("RadialDistortParam1", tag) || !strcmp ("VignetteModelParam1", tag)) {
|
||||||
pProf->pCurCommon->param[0] = atof(raw);
|
pProf->pCurCommon->param[0] = atof (raw);
|
||||||
} else if (!strcmp("RadialDistortParam2", tag) || !strcmp("VignetteModelParam2", tag)) {
|
} else if (!strcmp ("RadialDistortParam2", tag) || !strcmp ("VignetteModelParam2", tag)) {
|
||||||
pProf->pCurCommon->param[1] = atof(raw);
|
pProf->pCurCommon->param[1] = atof (raw);
|
||||||
} else if (!strcmp("RadialDistortParam3", tag) || !strcmp("VignetteModelParam3", tag)) {
|
} else if (!strcmp ("RadialDistortParam3", tag) || !strcmp ("VignetteModelParam3", tag)) {
|
||||||
pProf->pCurCommon->param[2] = atof(raw);
|
pProf->pCurCommon->param[2] = atof (raw);
|
||||||
} else if (!strcmp("RadialDistortParam4", tag) || !strcmp("TangentialDistortParam1", tag)) {
|
} else if (!strcmp ("RadialDistortParam4", tag) || !strcmp ("TangentialDistortParam1", tag)) {
|
||||||
pProf->pCurCommon->param[3] = atof(raw);
|
pProf->pCurCommon->param[3] = atof (raw);
|
||||||
} else if (!strcmp("RadialDistortParam5", tag) || !strcmp("TangentialDistortParam2", tag)) {
|
} else if (!strcmp ("RadialDistortParam5", tag) || !strcmp ("TangentialDistortParam2", tag)) {
|
||||||
pProf->pCurCommon->param[4] = atof(raw);
|
pProf->pCurCommon->param[4] = atof (raw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XMLCALL LCPProfile::XmlEndHandler(void *pLCPProfile, const char *el)
|
void XMLCALL LCPProfile::XmlEndHandler (void *pLCPProfile, const char *el)
|
||||||
{
|
{
|
||||||
LCPProfile *pProf = static_cast<LCPProfile*>(pLCPProfile);
|
LCPProfile *pProf = static_cast<LCPProfile*> (pLCPProfile);
|
||||||
|
|
||||||
// We ignore everything in dirty tag till it's gone
|
// We ignore everything in dirty tag till it's gone
|
||||||
if (*pProf->inInvalidTag) {
|
if (*pProf->inInvalidTag) {
|
||||||
if (strstr(el, pProf->inInvalidTag)) {
|
if (strstr (el, pProf->inInvalidTag)) {
|
||||||
*pProf->inInvalidTag = 0;
|
*pProf->inInvalidTag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(el, ":CameraProfiles")) {
|
if (strstr (el, ":CameraProfiles")) {
|
||||||
pProf->inCamProfiles = false;
|
pProf->inCamProfiles = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(el, ":AlternateLensIDs")) {
|
if (strstr (el, ":AlternateLensIDs")) {
|
||||||
pProf->inAlternateLensID = false;
|
pProf->inAlternateLensID = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(el, ":AlternateLensNames")) {
|
if (strstr (el, ":AlternateLensNames")) {
|
||||||
pProf->inAlternateLensNames = false;
|
pProf->inAlternateLensNames = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -825,9 +818,9 @@ void XMLCALL LCPProfile::XmlEndHandler(void *pLCPProfile, const char *el)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(el, ":PerspectiveModel") || strstr(el, ":FisheyeModel")) {
|
if (strstr (el, ":PerspectiveModel") || strstr (el, ":FisheyeModel")) {
|
||||||
pProf->inPerspect = false;
|
pProf->inPerspect = false;
|
||||||
} else if (strstr(el, ":li")) {
|
} else if (strstr (el, ":li")) {
|
||||||
pProf->aPersModel[pProf->persModelCount] = pProf->pCurPersModel;
|
pProf->aPersModel[pProf->persModelCount] = pProf->pCurPersModel;
|
||||||
pProf->pCurPersModel = nullptr;
|
pProf->pCurPersModel = nullptr;
|
||||||
pProf->persModelCount++;
|
pProf->persModelCount++;
|
||||||
@@ -843,11 +836,11 @@ LCPStore* LCPStore::getInstance()
|
|||||||
|
|
||||||
LCPProfile* LCPStore::getProfile (Glib::ustring filename)
|
LCPProfile* LCPStore::getProfile (Glib::ustring filename)
|
||||||
{
|
{
|
||||||
if (filename.length() == 0 || !isValidLCPFileName(filename)) {
|
if (filename.length() == 0 || !isValidLCPFileName (filename)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyMutex::MyLock lock(mtx);
|
MyMutex::MyLock lock (mtx);
|
||||||
|
|
||||||
std::map<Glib::ustring, LCPProfile*>::iterator r = profileCache.find (filename);
|
std::map<Glib::ustring, LCPProfile*>::iterator r = profileCache.find (filename);
|
||||||
|
|
||||||
@@ -856,12 +849,12 @@ LCPProfile* LCPStore::getProfile (Glib::ustring filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add profile (if exists)
|
// Add profile (if exists)
|
||||||
profileCache[filename] = new LCPProfile(filename);
|
profileCache[filename] = new LCPProfile (filename);
|
||||||
//profileCache[filename]->print();
|
//profileCache[filename]->print();
|
||||||
return profileCache[filename];
|
return profileCache[filename];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LCPStore::isValidLCPFileName(Glib::ustring filename) const
|
bool LCPStore::isValidLCPFileName (Glib::ustring filename) const
|
||||||
{
|
{
|
||||||
if (!Glib::file_test (filename, Glib::FILE_TEST_EXISTS) || Glib::file_test (filename, Glib::FILE_TEST_IS_DIR)) {
|
if (!Glib::file_test (filename, Glib::FILE_TEST_EXISTS) || Glib::file_test (filename, Glib::FILE_TEST_IS_DIR)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -879,10 +872,10 @@ Glib::ustring LCPStore::getDefaultCommonDirectory() const
|
|||||||
WCHAR pathW[MAX_PATH] = {0};
|
WCHAR pathW[MAX_PATH] = {0};
|
||||||
char pathA[MAX_PATH];
|
char pathA[MAX_PATH];
|
||||||
|
|
||||||
if (SHGetSpecialFolderPathW(NULL, pathW, CSIDL_COMMON_APPDATA, false)) {
|
if (SHGetSpecialFolderPathW (NULL, pathW, CSIDL_COMMON_APPDATA, false)) {
|
||||||
char pathA[MAX_PATH];
|
char pathA[MAX_PATH];
|
||||||
WideCharToMultiByte(CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0);
|
WideCharToMultiByte (CP_UTF8, 0, pathW, -1, pathA, MAX_PATH, 0, 0);
|
||||||
Glib::ustring fullDir = Glib::ustring(pathA) + Glib::ustring("\\Adobe\\CameraRaw\\LensProfiles\\1.0");
|
Glib::ustring fullDir = Glib::ustring (pathA) + Glib::ustring ("\\Adobe\\CameraRaw\\LensProfiles\\1.0");
|
||||||
|
|
||||||
if (Glib::file_test (fullDir, Glib::FILE_TEST_IS_DIR)) {
|
if (Glib::file_test (fullDir, Glib::FILE_TEST_IS_DIR)) {
|
||||||
dir = fullDir;
|
dir = fullDir;
|
||||||
|
@@ -39,8 +39,8 @@ public:
|
|||||||
LCPModelCommon();
|
LCPModelCommon();
|
||||||
bool empty() const; // is it empty
|
bool empty() const; // is it empty
|
||||||
void print() const; // printf all values
|
void print() const; // printf all values
|
||||||
void merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA);
|
void merge (const LCPModelCommon& a, const LCPModelCommon& b, float facA);
|
||||||
void prepareParams(int fullWidth, int fullHeight, float focalLength, float focalLength35mm, float sensorFormatFactor, bool swapXY, bool mirrorX, bool mirrorY);
|
void prepareParams (int fullWidth, int fullHeight, float focalLength, float focalLength35mm, float sensorFormatFactor, bool swapXY, bool mirrorX, bool mirrorY);
|
||||||
|
|
||||||
//private:
|
//private:
|
||||||
using Param = std::array<float, 5>;
|
using Param = std::array<float, 5>;
|
||||||
@@ -75,7 +75,7 @@ public:
|
|||||||
LCPModelCommon vignette; // vignette (may be empty)
|
LCPModelCommon vignette; // vignette (may be empty)
|
||||||
|
|
||||||
LCPPersModel();
|
LCPPersModel();
|
||||||
bool hasModeData(int mode) const;
|
bool hasModeData (int mode) const;
|
||||||
void print() const;
|
void print() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,11 +88,11 @@ class LCPProfile
|
|||||||
LCPPersModel* pCurPersModel;
|
LCPPersModel* pCurPersModel;
|
||||||
LCPModelCommon* pCurCommon;
|
LCPModelCommon* pCurCommon;
|
||||||
|
|
||||||
static void XMLCALL XmlStartHandler(void *pLCPProfile, const char *el, const char **attr);
|
static void XMLCALL XmlStartHandler (void *pLCPProfile, const char *el, const char **attr);
|
||||||
static void XMLCALL XmlTextHandler (void *pLCPProfile, const XML_Char *s, int len);
|
static void XMLCALL XmlTextHandler (void *pLCPProfile, const XML_Char *s, int len);
|
||||||
static void XMLCALL XmlEndHandler (void *pLCPProfile, const char *el);
|
static void XMLCALL XmlEndHandler (void *pLCPProfile, const char *el);
|
||||||
|
|
||||||
int filterBadFrames(double maxAvgDevFac, int minFramesLeft);
|
int filterBadFrames (double maxAvgDevFac, int minFramesLeft);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Common data
|
// Common data
|
||||||
@@ -105,9 +105,9 @@ public:
|
|||||||
static const int MaxPersModelCount = 3000;
|
static const int MaxPersModelCount = 3000;
|
||||||
LCPPersModel* aPersModel[MaxPersModelCount]; // Do NOT use std::list or something, it's buggy in GCC!
|
LCPPersModel* aPersModel[MaxPersModelCount]; // Do NOT use std::list or something, it's buggy in GCC!
|
||||||
|
|
||||||
explicit LCPProfile(const Glib::ustring &fname);
|
explicit LCPProfile (const Glib::ustring &fname);
|
||||||
|
|
||||||
void calcParams(int mode, float focalLength, float focusDist, float aperture, LCPModelCommon *pCorr1, LCPModelCommon *pCorr2, LCPModelCommon *pCorr3) const; // Interpolates between the persModels frames
|
void calcParams (int mode, float focalLength, float focusDist, float aperture, LCPModelCommon *pCorr1, LCPModelCommon *pCorr2, LCPModelCommon *pCorr3) const; // Interpolates between the persModels frames
|
||||||
|
|
||||||
void print() const;
|
void print() const;
|
||||||
};
|
};
|
||||||
@@ -121,8 +121,8 @@ class LCPStore
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Glib::ustring getDefaultCommonDirectory() const;
|
Glib::ustring getDefaultCommonDirectory() const;
|
||||||
bool isValidLCPFileName(Glib::ustring filename) const;
|
bool isValidLCPFileName (Glib::ustring filename) const;
|
||||||
LCPProfile* getProfile(Glib::ustring filename);
|
LCPProfile* getProfile (Glib::ustring filename);
|
||||||
|
|
||||||
static LCPStore* getInstance();
|
static LCPStore* getInstance();
|
||||||
};
|
};
|
||||||
@@ -143,14 +143,13 @@ public:
|
|||||||
bool enableCA; // is the mapper capable if CA correction?
|
bool enableCA; // is the mapper capable if CA correction?
|
||||||
|
|
||||||
// precalculates the mapper.
|
// precalculates the mapper.
|
||||||
LCPMapper(LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP, int fullWidth, int fullHeight,
|
LCPMapper (LCPProfile* pProf, float focalLength, float focalLength35mm, float focusDist, float aperture, bool vignette, bool useCADistP, int fullWidth, int fullHeight,
|
||||||
const CoarseTransformParams& coarse, int rawRotationDeg);
|
const CoarseTransformParams& coarse, int rawRotationDeg);
|
||||||
|
|
||||||
void correctDistortion(double& x, double& y) const; // MUST be the first stage
|
void correctDistortion (double& x, double& y) const; // MUST be the first stage
|
||||||
void correctCA(double& x, double& y, int channel) const;
|
void correctCA (double& x, double& y, int channel) const;
|
||||||
float calcVignetteFac (int x, int y) const; // MUST be in RAW
|
void processVignetteLine (int width, int y, float *line) const;
|
||||||
void processVignetteLine(int width, int y, float *line) const;
|
void processVignetteLine3Channels (int width, int y, float *line) const;
|
||||||
void processVignetteLine3Channels(int width, int y, float *line) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user