Use AlignedBuffer helper class in rgbProc, use SSE in standard tone curve application.

This commit is contained in:
gatoatigrado
2017-12-25 00:41:43 -05:00
parent a2bf608155
commit 3ccfb9b203
3 changed files with 70 additions and 17 deletions

View File

@@ -23,6 +23,7 @@
#include <omp.h>
#endif
#include "alignedbuffer.h"
#include "rtengine.h"
#include "improcfun.h"
#include "curves.h"
@@ -3409,31 +3410,28 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
#pragma omp parallel if (multiThread)
#endif
{
char *buffer;
size_t perChannelSizeBytes = padToAlignment(sizeof (float) * TS * TS + 4 * 64);
AlignedBuffer<float> buffer(3 * perChannelSizeBytes);
char *editIFloatBuffer = nullptr;
char *editWhateverBuffer = nullptr;
buffer = (char *) malloc (3 * sizeof (float) * TS * TS + 20 * 64 + 63);
char *data;
data = (char*) ( ( uintptr_t (buffer) + uintptr_t (63)) / 64 * 64);
float *rtemp = (float (*))data;
float *gtemp = (float (*)) ((char*)rtemp + sizeof (float) * TS * TS + 4 * 64);
float *btemp = (float (*)) ((char*)gtemp + sizeof (float) * TS * TS + 8 * 64);
float *rtemp = buffer.data;
float *gtemp = &rtemp[perChannelSizeBytes / sizeof(float)];
float *btemp = &gtemp[perChannelSizeBytes / sizeof(float)];
int istart;
int jstart;
int tW;
int tH;
// zero out the buffers
memset(buffer, 0, 3 * sizeof (float) * TS * TS + 20 * 64 + 63);
memset(rtemp, 0, 3 * perChannelSizeBytes);
// Allocating buffer for the PipetteBuffer
float *editIFloatTmpR = nullptr, *editIFloatTmpG = nullptr, *editIFloatTmpB = nullptr, *editWhateverTmp = nullptr;
if (editImgFloat) {
editIFloatBuffer = (char *) malloc (3 * sizeof (float) * TS * TS + 20 * 64 + 63);
data = (char*) ( ( uintptr_t (editIFloatBuffer) + uintptr_t (63)) / 64 * 64);
char *data = (char*) ( ( uintptr_t (editIFloatBuffer) + uintptr_t (63)) / 64 * 64);
editIFloatTmpR = (float (*))data;
editIFloatTmpG = (float (*)) ((char*)editIFloatTmpR + sizeof (float) * TS * TS + 4 * 64);
@@ -3442,7 +3440,7 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
if (editWhatever) {
editWhateverBuffer = (char *) malloc (sizeof (float) * TS * TS + 20 * 64 + 63);
data = (char*) ( ( uintptr_t (editWhateverBuffer) + uintptr_t (63)) / 64 * 64);
char *data = (char*) ( ( uintptr_t (editWhateverBuffer) + uintptr_t (63)) / 64 * 64);
editWhateverTmp = (float (*))data;
}
@@ -3618,10 +3616,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
if (hasToneCurve1) {
if (curveMode == ToneCurveParams::TcMode::STD) { // Standard
for (int i = istart, ti = 0; i < tH; i++, ti++) {
for (int j = jstart, tj = 0; j < tW; j++, tj++) {
const StandardToneCurve& userToneCurve = static_cast<const StandardToneCurve&> (customToneCurve1);
userToneCurve.Apply (rtemp[ti * TS + tj], gtemp[ti * TS + tj], btemp[ti * TS + tj]);
}
const StandardToneCurve& userToneCurve = static_cast<const StandardToneCurve&> (customToneCurve1);
userToneCurve.BatchApply (
0, tW - jstart,
&rtemp[ti * TS], &gtemp[ti * TS], &btemp[ti * TS]);
}
} else if (curveMode == ToneCurveParams::TcMode::FILMLIKE) { // Adobe like
for (int i = istart, ti = 0; i < tH; i++, ti++) {
@@ -4529,8 +4527,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
}
}
free (buffer);
if (editIFloatBuffer) {
free (editIFloatBuffer);
}