Merge branch 'dev' into spot-removal-tool
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "alignedbuffer.h"
|
||||
#include "rt_math.h"
|
||||
#include "color.h"
|
||||
#include "procparams.h"
|
||||
|
||||
using namespace rtengine;
|
||||
|
||||
@@ -44,48 +45,38 @@ Imagefloat::~Imagefloat ()
|
||||
}
|
||||
|
||||
// Call this method to handle floating points input values of different size
|
||||
void Imagefloat::setScanline (int row, unsigned char* buffer, int bps, float *minValue, float *maxValue)
|
||||
void Imagefloat::setScanline (int row, unsigned char* buffer, int bps, unsigned int numSamples)
|
||||
{
|
||||
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The DNG decoder convert to 32 bits float data even if the file contains 16 or 24 bits data.
|
||||
// DNG_HalfToFloat and DNG_FP24ToFloat from dcraw.cc can be used to manually convert
|
||||
// from 16 and 24 bits to 32 bits float respectively
|
||||
switch (sampleFormat) {
|
||||
case (IIOSF_FLOAT): {
|
||||
case (IIOSF_FLOAT16): {
|
||||
int ix = 0;
|
||||
uint16_t* sbuffer = (uint16_t*) buffer;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
r(row, i) = 65535.f * DNG_HalfToFloat(sbuffer[ix++]);
|
||||
g(row, i) = 65535.f * DNG_HalfToFloat(sbuffer[ix++]);
|
||||
b(row, i) = 65535.f * DNG_HalfToFloat(sbuffer[ix++]);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
//case (IIOSF_FLOAT24):
|
||||
case (IIOSF_FLOAT32): {
|
||||
int ix = 0;
|
||||
float* sbuffer = (float*) buffer;
|
||||
|
||||
for (int i = 0; i < width; i++) {
|
||||
r(row, i) = sbuffer[ix];
|
||||
|
||||
if (minValue) {
|
||||
if (sbuffer[ix] < minValue[0]) {
|
||||
minValue[0] = sbuffer[ix];
|
||||
} else if (sbuffer[ix] > maxValue[0]) {
|
||||
maxValue[0] = sbuffer[ix];
|
||||
} ++ix;
|
||||
}
|
||||
|
||||
g(row, i) = sbuffer[ix];
|
||||
|
||||
if (minValue) {
|
||||
if (sbuffer[ix] < minValue[1]) {
|
||||
minValue[1] = sbuffer[ix];
|
||||
} else if (sbuffer[ix] > maxValue[1]) {
|
||||
maxValue[1] = sbuffer[ix];
|
||||
} ++ix;
|
||||
}
|
||||
|
||||
b(row, i) = sbuffer[ix];
|
||||
|
||||
if (minValue) {
|
||||
if (sbuffer[ix] < minValue[2]) {
|
||||
minValue[2] = sbuffer[ix];
|
||||
} else if (sbuffer[ix] > maxValue[2]) {
|
||||
maxValue[2] = sbuffer[ix];
|
||||
} ++ix;
|
||||
}
|
||||
r(row, i) = 65535.f * sbuffer[ix++];
|
||||
g(row, i) = 65535.f * sbuffer[ix++];
|
||||
b(row, i) = 65535.f * sbuffer[ix++];
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -104,34 +95,8 @@ void Imagefloat::setScanline (int row, unsigned char* buffer, int bps, float *mi
|
||||
// TODO: we may have to handle other color space than sRGB!
|
||||
Color::xyz2srgb(xyzvalues[0], xyzvalues[1], xyzvalues[2], rgbvalues[0], rgbvalues[1], rgbvalues[2]);
|
||||
r(row, i) = rgbvalues[0];
|
||||
|
||||
if (minValue) {
|
||||
if (rgbvalues[0] < minValue[0]) {
|
||||
minValue[0] = rgbvalues[0];
|
||||
} else if (rgbvalues[0] > maxValue[0]) {
|
||||
maxValue[0] = rgbvalues[0];
|
||||
}
|
||||
}
|
||||
|
||||
g(row, i) = rgbvalues[1];
|
||||
|
||||
if (minValue) {
|
||||
if (rgbvalues[1] < minValue[1]) {
|
||||
minValue[1] = rgbvalues[1];
|
||||
} else if (rgbvalues[1] > maxValue[1]) {
|
||||
maxValue[1] = rgbvalues[1];
|
||||
}
|
||||
}
|
||||
|
||||
b(row, i) = rgbvalues[2];
|
||||
|
||||
if (minValue) {
|
||||
if (rgbvalues[2] < minValue[2]) {
|
||||
minValue[2] = rgbvalues[2];
|
||||
} else if (rgbvalues[2] > maxValue[2]) {
|
||||
maxValue[2] = rgbvalues[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -143,40 +108,54 @@ void Imagefloat::setScanline (int row, unsigned char* buffer, int bps, float *mi
|
||||
}
|
||||
}
|
||||
|
||||
void Imagefloat::getScanline (int row, unsigned char* buffer, int bps)
|
||||
|
||||
void Imagefloat::getScanline (int row, unsigned char* buffer, int bps, bool isFloat) const
|
||||
{
|
||||
|
||||
if (data == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bps == 32) {
|
||||
int ix = 0;
|
||||
float* sbuffer = (float*) buffer;
|
||||
|
||||
// agriggio -- assume the image is normalized to [0, 65535]
|
||||
for (int i = 0; i < width; i++) {
|
||||
sbuffer[ix++] = r(row, i) / 65535.f;
|
||||
sbuffer[ix++] = g(row, i) / 65535.f;
|
||||
sbuffer[ix++] = b(row, i) / 65535.f;
|
||||
if (isFloat) {
|
||||
if (bps == 32) {
|
||||
int ix = 0;
|
||||
float* sbuffer = (float*) buffer;
|
||||
// agriggio -- assume the image is normalized to [0, 65535]
|
||||
for (int i = 0; i < width; i++) {
|
||||
sbuffer[ix++] = r(row, i) / 65535.f;
|
||||
sbuffer[ix++] = g(row, i) / 65535.f;
|
||||
sbuffer[ix++] = b(row, i) / 65535.f;
|
||||
}
|
||||
} else if (bps == 16) {
|
||||
int ix = 0;
|
||||
uint16_t* sbuffer = (uint16_t*) buffer;
|
||||
// agriggio -- assume the image is normalized to [0, 65535]
|
||||
for (int i = 0; i < width; i++) {
|
||||
sbuffer[ix++] = DNG_FloatToHalf(r(row, i) / 65535.f);
|
||||
sbuffer[ix++] = DNG_FloatToHalf(g(row, i) / 65535.f);
|
||||
sbuffer[ix++] = DNG_FloatToHalf(b(row, i) / 65535.f);
|
||||
}
|
||||
}
|
||||
} else if (bps == 16) {
|
||||
} else {
|
||||
unsigned short *sbuffer = (unsigned short *)buffer;
|
||||
for (int i = 0, ix = 0; i < width; i++) {
|
||||
sbuffer[ix++] = CLIP(r(row, i));
|
||||
sbuffer[ix++] = CLIP(g(row, i));
|
||||
sbuffer[ix++] = CLIP(b(row, i));
|
||||
}
|
||||
} else if (bps == 8) {
|
||||
for (int i = 0, ix = 0; i < width; i++) {
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(r(row, i)));
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(g(row, i)));
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(b(row, i)));
|
||||
float ri = r(row, i);
|
||||
float gi = g(row, i);
|
||||
float bi = b(row, i);
|
||||
if (bps == 16) {
|
||||
sbuffer[ix++] = CLIP(ri);
|
||||
sbuffer[ix++] = CLIP(gi);
|
||||
sbuffer[ix++] = CLIP(bi);
|
||||
} else if (bps == 8) {
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(ri));
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(gi));
|
||||
buffer[ix++] = rtengine::uint16ToUint8Rounded(CLIP(bi));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Imagefloat* Imagefloat::copy ()
|
||||
Imagefloat* Imagefloat::copy () const
|
||||
{
|
||||
|
||||
Imagefloat* cp = new Imagefloat (width, height);
|
||||
@@ -199,7 +178,7 @@ Imagefloat* Imagefloat::copySubRegion (int x, int y, int width, int height)
|
||||
}
|
||||
|
||||
// This is called by the StdImageSource class. We assume that fp images from StdImageSource don't have to deal with gamma
|
||||
void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, const PreviewProps & pp, bool first, procparams::ToneCurveParams hrp)
|
||||
void Imagefloat::getStdImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp) const
|
||||
{
|
||||
|
||||
// compute channel multipliers
|
||||
@@ -249,6 +228,8 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, cons
|
||||
gm /= area;
|
||||
bm /= area;
|
||||
|
||||
const auto CLIP0 = [](float v) -> float { return std::max(v, 0.f); };
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel
|
||||
{
|
||||
@@ -281,9 +262,9 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, cons
|
||||
continue;
|
||||
}
|
||||
|
||||
lineR[dst_x] = CLIP(rm2 * r(src_y, src_x));
|
||||
lineG[dst_x] = CLIP(gm2 * g(src_y, src_x));
|
||||
lineB[dst_x] = CLIP(bm2 * b(src_y, src_x));
|
||||
lineR[dst_x] = CLIP0(rm2 * r(src_y, src_x));
|
||||
lineG[dst_x] = CLIP0(gm2 * g(src_y, src_x));
|
||||
lineB[dst_x] = CLIP0(bm2 * b(src_y, src_x));
|
||||
}
|
||||
} else {
|
||||
// source image, first line of the current destination row
|
||||
@@ -314,15 +295,15 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, cons
|
||||
// convert back to gamma and clip
|
||||
if (src_sub_width == skip && src_sub_height == skip) {
|
||||
// Common case where the sub-region is complete
|
||||
lineR[dst_x] = CLIP(rm * rtot);
|
||||
lineG[dst_x] = CLIP(gm * gtot);
|
||||
lineB[dst_x] = CLIP(bm * btot);
|
||||
lineR[dst_x] = CLIP0(rm * rtot);
|
||||
lineG[dst_x] = CLIP0(gm * gtot);
|
||||
lineB[dst_x] = CLIP0(bm * btot);
|
||||
} else {
|
||||
// computing a special factor for this incomplete sub-region
|
||||
float area = src_sub_width * src_sub_height;
|
||||
lineR[dst_x] = CLIP(rm2 * rtot / area);
|
||||
lineG[dst_x] = CLIP(gm2 * gtot / area);
|
||||
lineB[dst_x] = CLIP(bm2 * btot / area);
|
||||
lineR[dst_x] = CLIP0(rm2 * rtot / area);
|
||||
lineG[dst_x] = CLIP0(gm2 * gtot / area);
|
||||
lineB[dst_x] = CLIP0(bm2 * btot / area);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -359,7 +340,7 @@ void Imagefloat::getStdImage (ColorTemp ctemp, int tran, Imagefloat* image, cons
|
||||
}
|
||||
|
||||
Image8*
|
||||
Imagefloat::to8()
|
||||
Imagefloat::to8() const
|
||||
{
|
||||
Image8* img8 = new Image8(width, height);
|
||||
#ifdef _OPENMP
|
||||
@@ -368,9 +349,9 @@ Imagefloat::to8()
|
||||
|
||||
for (int h = 0; h < height; ++h) {
|
||||
for (int w = 0; w < width; ++w) {
|
||||
img8->r(h, w) = uint16ToUint8Rounded(r(h, w));
|
||||
img8->g(h, w) = uint16ToUint8Rounded(g(h, w));
|
||||
img8->b(h, w) = uint16ToUint8Rounded(b(h, w));
|
||||
img8->r(h, w) = uint16ToUint8Rounded(CLIP(r(h, w)));
|
||||
img8->g(h, w) = uint16ToUint8Rounded(CLIP(g(h, w)));
|
||||
img8->b(h, w) = uint16ToUint8Rounded(CLIP(b(h, w)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +359,7 @@ Imagefloat::to8()
|
||||
}
|
||||
|
||||
Image16*
|
||||
Imagefloat::to16()
|
||||
Imagefloat::to16() const
|
||||
{
|
||||
Image16* img16 = new Image16(width, height);
|
||||
#ifdef _OPENMP
|
||||
@@ -387,9 +368,9 @@ Imagefloat::to16()
|
||||
|
||||
for (int h = 0; h < height; ++h) {
|
||||
for (int w = 0; w < width; ++w) {
|
||||
img16->r(h, w) = r(h, w);
|
||||
img16->g(h, w) = g(h, w);
|
||||
img16->b(h, w) = b(h, w);
|
||||
img16->r(h, w) = CLIP(r(h, w));
|
||||
img16->g(h, w) = CLIP(g(h, w));
|
||||
img16->b(h, w) = CLIP(b(h, w));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,7 +443,7 @@ void Imagefloat::calcCroppedHistogram(const ProcParams ¶ms, float scale, LUT
|
||||
hist.clear();
|
||||
|
||||
// Set up factors to calc the lightness
|
||||
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix (params.icm.working);
|
||||
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix (params.icm.workingProfile);
|
||||
|
||||
float facRed = wprof[1][0];
|
||||
float facGreen = wprof[1][1];
|
||||
@@ -473,11 +454,15 @@ void Imagefloat::calcCroppedHistogram(const ProcParams ¶ms, float scale, LUT
|
||||
int x1, x2, y1, y2;
|
||||
params.crop.mapToResized(width, height, scale, x1, x2, y1, y2);
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel
|
||||
#endif
|
||||
{
|
||||
LUTu histThr(65536);
|
||||
histThr.clear();
|
||||
#ifdef _OPENMP
|
||||
#pragma omp for nowait
|
||||
#endif
|
||||
|
||||
for (int y = y1; y < y2; y++) {
|
||||
for (int x = x1; x < x2; x++) {
|
||||
@@ -493,7 +478,9 @@ void Imagefloat::calcCroppedHistogram(const ProcParams ¶ms, float scale, LUT
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp critical
|
||||
#endif
|
||||
{
|
||||
for(int i = 0; i <= 0xffff; i++) {
|
||||
hist[i] += histThr[i];
|
||||
@@ -516,7 +503,7 @@ void Imagefloat::ExecCMSTransform(cmsHTRANSFORM hTransform)
|
||||
AlignedBuffer<float> pBuf(width * 3);
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp for schedule(static)
|
||||
#pragma omp for schedule(dynamic, 16)
|
||||
#endif
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
@@ -545,7 +532,7 @@ void Imagefloat::ExecCMSTransform(cmsHTRANSFORM hTransform)
|
||||
}
|
||||
}
|
||||
|
||||
// Parallized transformation; create transform with cmsFLAGS_NOCACHE!
|
||||
// Parallelized transformation; create transform with cmsFLAGS_NOCACHE!
|
||||
void Imagefloat::ExecCMSTransform(cmsHTRANSFORM hTransform, const LabImage &labImage, int cx, int cy)
|
||||
{
|
||||
// LittleCMS cannot parallelize planar Lab float images
|
||||
|
Reference in New Issue
Block a user