Skip to content

Commit e2961dc

Browse files
Merge pull request #1506 from SixLabors/bp/Issue1505
Fix for Issue #1505
2 parents da7a8b7 + b3146a7 commit e2961dc

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/ImageSharp/Processing/Processors/Quantization/OctreeQuantizer{TPixel}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Numerics;
77
using System.Runtime.CompilerServices;
88
using System.Runtime.InteropServices;
9-
using SixLabors.ImageSharp.Advanced;
109
using SixLabors.ImageSharp.Memory;
1110
using SixLabors.ImageSharp.PixelFormats;
1211

@@ -96,7 +95,7 @@ public void AddPaletteColors(Buffer2DRegion<TPixel> pixelRegion)
9695
this.octree.Palletize(paletteSpan, this.maxColors, ref paletteIndex);
9796

9897
// Length of reduced palette + transparency.
99-
ReadOnlyMemory<TPixel> result = this.paletteOwner.Memory.Slice(0, Math.Min(paletteIndex + 2, QuantizerConstants.MaxColors));
98+
ReadOnlyMemory<TPixel> result = this.paletteOwner.Memory.Slice(0, Math.Min(paletteIndex + 2, this.maxColors));
10099
this.pixelMap = new EuclideanPixelMap<TPixel>(this.Configuration, result);
101100

102101
this.palette = result;

tests/ImageSharp.Tests/Quantization/QuantizedImageTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ public void WuQuantizerYieldsCorrectTransparentPixel<TPixel>(TestImageProvider<T
110110
}
111111
}
112112

113+
// Test case for issue: https://github.com/SixLabors/ImageSharp/issues/1505
114+
[Theory]
115+
[WithFile(TestImages.Gif.Issues.Issue1505, PixelTypes.Rgba32)]
116+
public void Issue1505<TPixel>(TestImageProvider<TPixel> provider)
117+
where TPixel : unmanaged, IPixel<TPixel>
118+
{
119+
using (Image<TPixel> image = provider.GetImage())
120+
{
121+
var octreeQuantizer = new OctreeQuantizer();
122+
IQuantizer<TPixel> quantizer = octreeQuantizer.CreatePixelSpecificQuantizer<TPixel>(Configuration.Default, new QuantizerOptions() { MaxColors = 128 });
123+
ImageFrame<TPixel> frame = image.Frames[0];
124+
quantizer.BuildPaletteAndQuantizeFrame(frame, frame.Bounds());
125+
}
126+
}
127+
113128
private int GetTransparentIndex<TPixel>(IndexedImageFrame<TPixel> quantized)
114129
where TPixel : unmanaged, IPixel<TPixel>
115130
{

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ public static class Issues
415415
public const string BadAppExtLength = "Gif/issues/issue405_badappextlength252.gif";
416416
public const string BadAppExtLength_2 = "Gif/issues/issue405_badappextlength252-2.gif";
417417
public const string BadDescriptorWidth = "Gif/issues/issue403_baddescriptorwidth.gif";
418+
public const string Issue1505 = "Gif/issues/issue1505_argumentoutofrange.png";
418419
}
419420

420421
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };
100 KB
Loading

0 commit comments

Comments
 (0)