Simplify copyAndClampLine, make in place transformations when gamutwarning is disabled

This commit is contained in:
Ingo Weyrich
2019-12-28 13:19:45 +01:00
parent a62b0f8040
commit f501ec6398

View File

@@ -38,14 +38,8 @@ namespace {
inline void copyAndClampLine(const float *src, unsigned char *dst, const int W) inline void copyAndClampLine(const float *src, unsigned char *dst, const int W)
{ {
for (int j = 0, iy = 0; j < W; ++j) { for (int j = 0; j < W * 3; ++j) {
float r = src[iy] * MAXVALF; dst[j] = uint16ToUint8Rounded(CLIP(src[j] * MAXVALF));
float g = src[iy+1] * MAXVALF;
float b = src[iy+2] * MAXVALF;
dst[iy] = uint16ToUint8Rounded(CLIP(r));
dst[iy+1] = uint16ToUint8Rounded(CLIP(g));
dst[iy+2] = uint16ToUint8Rounded(CLIP(b));
iy += 3;
} }
} }
@@ -90,8 +84,8 @@ void ImProcFunctions::lab2monitorRgb(LabImage* lab, Image8* image)
{ {
if (monitorTransform) { if (monitorTransform) {
int W = lab->W; const int W = lab->W;
int H = lab->H; const int H = lab->H;
unsigned char * data = image->data; unsigned char * data = image->data;
// cmsDoTransform is relatively expensive // cmsDoTransform is relatively expensive
@@ -100,18 +94,19 @@ void ImProcFunctions::lab2monitorRgb(LabImage* lab, Image8* image)
#endif #endif
{ {
AlignedBuffer<float> pBuf(3 * lab->W); AlignedBuffer<float> pBuf(3 * lab->W);
AlignedBuffer<float> mBuf(3 * lab->W);
AlignedBuffer<float> mBuf;
AlignedBuffer<float> gwBuf1; AlignedBuffer<float> gwBuf1;
AlignedBuffer<float> gwBuf2; AlignedBuffer<float> gwBuf2;
if (gamutWarning) { if (gamutWarning) {
gwBuf1.resize(3 * lab->W); gwBuf1.resize(3 * lab->W);
gwBuf2.resize(3 * lab->W); gwBuf2.resize(3 * lab->W);
mBuf.resize(3 * lab->W);
} }
float *buffer = pBuf.data; float *buffer = pBuf.data;
float *outbuffer = mBuf.data; float *outbuffer = gamutWarning ? mBuf.data : pBuf.data; // make in place transformations when gamutWarning is not needed
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp for schedule(dynamic,16) #pragma omp for schedule(dynamic,16)
@@ -132,7 +127,7 @@ void ImProcFunctions::lab2monitorRgb(LabImage* lab, Image8* image)
buffer[iy++] = rb[j] / 327.68f; buffer[iy++] = rb[j] / 327.68f;
} }
cmsDoTransform (monitorTransform, buffer, outbuffer, W); cmsDoTransform(monitorTransform, buffer, outbuffer, W);
copyAndClampLine(outbuffer, data + ix, W); copyAndClampLine(outbuffer, data + ix, W);
if (gamutWarning) { if (gamutWarning) {