Browse Source

Better trans index fix.

pull/2289/head
James Jackson-South 4 years ago
parent
commit
0e26da8979
  1. 17
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs

17
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -514,7 +514,7 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
int descriptorBottom = descriptorTop + descriptor.Height; int descriptorBottom = descriptorTop + descriptor.Height;
int descriptorLeft = descriptor.Left; int descriptorLeft = descriptor.Left;
int descriptorRight = descriptorLeft + descriptor.Width; int descriptorRight = descriptorLeft + descriptor.Width;
byte transparentIndex = this.graphicsControlExtension.TransparencyIndex; byte transIndex = this.graphicsControlExtension.TransparencyIndex;
int colorTableMaxIdx = colorTable.Length - 1; int colorTableMaxIdx = colorTable.Length - 1;
for (int y = descriptorTop; y < descriptorBottom && y < imageHeight; y++) for (int y = descriptorTop; y < descriptorBottom && y < imageHeight; y++)
@ -573,14 +573,17 @@ internal sealed class GifDecoderCore : IImageDecoderInternals
for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++) for (int x = descriptorLeft; x < descriptorRight && x < imageWidth; x++)
{ {
int rawIndex = Unsafe.Add(ref indicesRowRef, x - descriptorLeft); int rawIndex = Unsafe.Add(ref indicesRowRef, x - descriptorLeft);
int transIndex = Numerics.Clamp(rawIndex, 0, Math.Max(transparentIndex, colorTableMaxIdx));
int index = Numerics.Clamp(rawIndex, 0, colorTableMaxIdx); // Treat any out of bounds values as transparent.
if (transparentIndex != transIndex) if (rawIndex > colorTableMaxIdx || rawIndex == transIndex)
{ {
ref TPixel pixel = ref Unsafe.Add(ref rowRef, x); continue;
Rgb24 rgb = colorTable[index];
pixel.FromRgb24(rgb);
} }
int index = Numerics.Clamp(rawIndex, 0, colorTableMaxIdx);
ref TPixel pixel = ref Unsafe.Add(ref rowRef, x);
Rgb24 rgb = colorTable[index];
pixel.FromRgb24(rgb);
} }
} }
} }

Loading…
Cancel
Save