Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ArgumentOutOfRangeException: Specified argument was out of the range of valid values" when trying to quantize image from MemoryStream with transparent pixels. #1497

Closed
4 tasks done
VladiStep opened this issue Jan 9, 2021 · 5 comments · Fixed by #1506

Comments

@VladiStep
Copy link

VladiStep commented Jan 9, 2021

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

When I trying to quantize image from MemoryStream (which filled from System.Drawing.Bitmap), this exception throws:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at SixLabors.ImageSharp.Processing.Processors.Quantization.OctreeQuantizer`1.AddPaletteColors(Buffer2DRegion`1 pixelRegion)
   at SixLabors.ImageSharp.Processing.Processors.Quantization.QuantizerUtilities.BuildPaletteAndQuantizeFrame[TPixel](IQuantizer`1 quantizer, ImageFrame`1 source, Rectangle bounds)
   at SixLabors.ImageSharp.Processing.Processors.Quantization.QuantizeProcessor`1.OnFrameApply(ImageFrame`1 source)
   at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(ImageFrame`1 source)

Steps to Reproduce

  1. Load image from MemoryStream, filled from this Bitmap sample (img.PixelFormat is PixelFormat.Format32bppArgb):
SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32> imgIS;

using (MemoryStream memoryStream = new MemoryStream())
{
	img.Save(memoryStream, ImageFormat.Png);

	memoryStream.Seek(0, SeekOrigin.Begin);

	imgIS = SixLabors.ImageSharp.Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(memoryStream, new SixLabors.ImageSharp.Formats.Png.PngDecoder());
}
  1. Quantize it.
SixLabors.ImageSharp.Processing.Processors.Quantization.IQuantizer quantizer = new SixLabors.ImageSharp.Processing.Processors.Quantization.OctreeQuantizer(new SixLabors.ImageSharp.Processing.Processors.Quantization.QuantizerOptions { MaxColors = 81 });
imgIS.Mutate(x => x.Quantize(quantizer));

One detail: I am using ImageSharp without using SixLabors.ImageSharp;, only using SixLabors.ImageSharp.Processing;

System Configuration

  • SixLabors.ImageSharp version - 1.0.2:
  • Environment: Windows 7 Ultimate SP1 x64.
  • .NET Framework version: 4.8.03761; .NET version - 5.0.101 (project uses .NET 5.0).
  • Additional information: Microsoft Visual Studio Community 2019, version 16.8.3.
@VladiStep
Copy link
Author

VladiStep commented Jan 10, 2021

Update: similar exception thrown on "Desert.jpg" from standard Windows 7 "Sample pictures" folder, even if I load an image like that:

SixLabors.ImageSharp.Image<SixLabors.ImageSharp.PixelFormats.Rgba32> imgIS = SixLabors.ImageSharp.Image.Load<SixLabors.ImageSharp.PixelFormats.Rgba32>(fileName);

Exception stack trace:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

   at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.Apply(ImageFrame`1 source)
   at SixLabors.ImageSharp.Processing.Processors.ImageProcessor`1.SixLabors.ImageSharp.Processing.Processors.IImageProcessor<TPixel>.Execute()

@VladiStep
Copy link
Author

VladiStep commented Jan 17, 2021

After disabling "Just my code", I found exact source of exception:
ReadOnlyMemory<TPixel> val2 = System.Memory<TPixel>.op_Implicit(paletteOwner.get_Memory().Slice(0, Math.Min(paletteIndex + 2, 256));
in AddPaletteColors(Buffer2DRegion`1 pixelRegion) method.

paletteIndex = 80, maxColors = 81 .

@brianpopow
Copy link
Collaborator

brianpopow commented Jan 19, 2021

I think this issue is the same as #1505. It was fixed with #1506.

@VladiStep could you try our latest version of ImageSharp from the MyGet Feed and test if the issue is still there or fixed?

@VladiStep
Copy link
Author

I think this issue is the same as #1505. It was fixed with #1506.

@VladiStep could you try our latest version of ImageSharp from the MyGet Feed and test if the issue is still there or fixed?

Yes, that version is fixed it.

@brianpopow brianpopow linked a pull request Jan 20, 2021 that will close this issue
4 tasks
@JimBobSquarePants
Copy link
Member

@VladiStep Thanks for providing so much information to let us triage this issue. We really appreciate it!

stesee added a commit to Codeuctivity/OpenXmlToHtml that referenced this issue Mar 14, 2021
seems like the last image sharp version bump broke something SixLabors/ImageSharp#1497
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants