Browse Source

Avoid calculating the row start index inside the loop

af/merge-core
Brian Popow 7 years ago
parent
commit
81ed8ca8e2
  1. 6
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

6
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -387,9 +387,10 @@ namespace SixLabors.ImageSharp.Formats.Bmp
if (rowHasUndefinedPixels) if (rowHasUndefinedPixels)
{ {
// Slow path with undefined pixels. // Slow path with undefined pixels.
int rowStartIdx = y * width * 3;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
int idx = (y * width * 3) + (x * 3); int idx = rowStartIdx + (x * 3);
if (undefinedPixels[x, y]) if (undefinedPixels[x, y])
{ {
switch (this.options.RleSkippedPixelHandling) switch (this.options.RleSkippedPixelHandling)
@ -418,9 +419,10 @@ namespace SixLabors.ImageSharp.Formats.Bmp
else else
{ {
// Fast path without any undefined pixels. // Fast path without any undefined pixels.
int rowStartIdx = y * width * 3;
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
int idx = (y * width * 3) + (x * 3); int idx = rowStartIdx + (x * 3);
color.FromBgr24(Unsafe.As<byte, Bgr24>(ref bufferSpan[idx])); color.FromBgr24(Unsafe.As<byte, Bgr24>(ref bufferSpan[idx]));
pixelRow[x] = color; pixelRow[x] = color;
} }

Loading…
Cancel
Save