Merge pull request #3276 from Floessie/fix-haldclut-overrun

Fix buffer overrun when applying HaldCLUT (#3154)
This commit is contained in:
Ingo Weyrich 2016-05-04 20:30:37 +02:00
commit 678315672b

View File

@ -4354,12 +4354,14 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
if (hald_clut) {
float out_rgbx[4 * TS] ALIGNED16;
for (int i = istart, ti = 0; i < tH; i++, ti++) {
if (!clutAndWorkingProfilesAreSame) {
// Convert from working to clut profile
int j = jstart;
int tj = 0;
#ifdef __SSE2__
if (!(std::min(TS, tW - jstart) & ~3)) {
for (int j = jstart, tj = 0; j < tW; j += 4, tj += 4) {
for (; j < tW - 3; j += 4, tj += 4) {
vfloat sourceR = LVF(rtemp[ti * TS + tj]);
vfloat sourceG = LVF(gtemp[ti * TS + tj]);
vfloat sourceB = LVF(btemp[ti * TS + tj]);
@ -4374,11 +4376,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
STVF(gtemp[ti * TS + tj], sourceG);
STVF(btemp[ti * TS + tj], sourceB);
}
}
else
#endif
{
for (int j = jstart, tj = 0; j < tW; j++, tj++) {
for (; j < tW; j++, tj++) {
float &sourceR = rtemp[ti * TS + tj];
float &sourceG = gtemp[ti * TS + tj];
float &sourceB = btemp[ti * TS + tj];
@ -4388,7 +4387,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
Color::xyz2rgb(x, y, z, sourceR, sourceG, sourceB, xyz2clut);
}
}
}
for (int j = jstart, tj = 0; j < tW; j++, tj++) {
float &sourceR = rtemp[ti * TS + tj];
@ -4424,9 +4422,10 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
if (!clutAndWorkingProfilesAreSame) {
// Convert from clut to working profile
int j = jstart;
int tj = 0;
#ifdef __SSE2__
if (!(std::min(TS, tW - jstart) & ~3)) {
for (int j = jstart, tj = 0; j < tW; j += 4, tj += 4) {
for (; j < tW - 3; j += 4, tj += 4) {
vfloat sourceR = LVF(rtemp[ti * TS + tj]);
vfloat sourceG = LVF(gtemp[ti * TS + tj]);
vfloat sourceB = LVF(btemp[ti * TS + tj]);
@ -4441,11 +4440,8 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
STVF(gtemp[ti * TS + tj], sourceG);
STVF(btemp[ti * TS + tj], sourceB);
}
}
else
#endif
{
for (int j = jstart, tj = 0; j < tW; j++, tj++) {
for (; j < tW; j++, tj++) {
float &sourceR = rtemp[ti * TS + tj];
float &sourceG = gtemp[ti * TS + tj];
float &sourceB = btemp[ti * TS + tj];
@ -4457,7 +4453,6 @@ void ImProcFunctions::rgbProc (Imagefloat* working, LabImage* lab, PipetteBuffer
}
}
}
}
if (!blackwhite) {