Skip to content

Commit

Permalink
Merge pull request #4054 from kwvanderlinde/performance/1.13-environm…
Browse files Browse the repository at this point in the history
…ental-lights--improvements
  • Loading branch information
cwisniew authored May 11, 2023
2 parents 041b9cc + 4add570 commit 05d252c
Showing 1 changed file with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,26 @@ public void blendRow(int[] dstPixels, int[] srcPixels, int[] outPixels, int samp
final int srcPixel = srcPixels[x];
final int dstPixel = dstPixels[x];

int resultPixel = 0;
for (int shift = 0; shift < 24; shift += 8) {
final var dstC = (dstPixel >>> shift) & 0xFF;
final var srcC = (srcPixel >>> shift) & 0xFF;
final int resultR, resultG, resultB;

resultPixel |= (renormalize((255 - srcC) * dstC) << shift);
{
final var dstC = (dstPixel >>> 16) & 0xFF;
final var srcC = (srcPixel >>> 16) & 0xFF;
resultR = renormalize((255 - srcC) * dstC);
}
{
final var dstC = (dstPixel >>> 8) & 0xFF;
final var srcC = (srcPixel >>> 8) & 0xFF;
resultG = renormalize((255 - srcC) * dstC);
}
{
final var dstC = dstPixel & 0xFF;
final var srcC = srcPixel & 0xFF;
resultB = renormalize((255 - srcC) * dstC);
}
// This keeps the light alpha around instead of the base.
resultPixel += srcPixel;

outPixels[x] = resultPixel;
// This keeps the light alpha around instead of the base.
outPixels[x] = srcPixel + ((resultR << 16) | (resultG << 8) | resultB);
}
}
}
Expand Down Expand Up @@ -209,20 +218,26 @@ public void blendRow(int[] dstPixels, int[] srcPixels, int[] outPixels, int samp
final int srcPixel = srcPixels[x];
final int dstPixel = dstPixels[x];

int resultPixel = 0;
for (int shift = 0; shift < 24; shift += 8) {
final var dstC = (dstPixel >>> shift) & 0xFF;
final var srcC = (srcPixel >>> shift) & 0xFF;

// dstPart is the minimum of dstC and 255 - dstC.
final var dstPart = dstC + (dstC >>> 7) * (255 - 2 * dstC);
final int resultR, resultG, resultB;

resultPixel |= (renormalize(srcC * dstPart) << shift);
{
final var dstC = (dstPixel >>> 16) & 0xFF;
final var srcC = (srcPixel >>> 16) & 0xFF;
resultR = renormalize(srcC * (dstC < 128 ? dstC : 255 - dstC));
}
{
final var dstC = (dstPixel >>> 8) & 0xFF;
final var srcC = (srcPixel >>> 8) & 0xFF;
resultG = renormalize(srcC * (dstC < 128 ? dstC : 255 - dstC));
}
{
final var dstC = dstPixel & 0xFF;
final var srcC = srcPixel & 0xFF;
resultB = renormalize(srcC * (dstC < 128 ? dstC : 255 - dstC));
}
// This deliberately keeps the bottom alpha around.
resultPixel += dstPixel;

outPixels[x] = resultPixel;
// This deliberately keeps the bottom alpha around.
outPixels[x] = dstPixel + ((resultR << 16) | (resultG << 8) | resultB);
}
}
}
Expand Down

0 comments on commit 05d252c

Please sign in to comment.