dlemstra / Magick.NET

The .NET library for ImageMagick
Apache License 2.0
3.42k stars 413 forks source link

ImageMagick.MagickResourceLimitErrorException when trying to map an altered DDS image to it's original color map #1596

Open thegreatgramcracker opened 5 months ago

thegreatgramcracker commented 5 months ago

Magick.NET version

Magick.NET-Q8-AnyCPU

Environment (Operating system, version and so on)

Windows 10, Visual Studio 2022

Description

Creating a new MagickImage using the colors of an image pre-alterations and then attempting to use that image as a map for the image after alterations such as an ordered dither like so:

MagickImage magickImage = new MagickImage(decompressedBytes);
magickImage.Settings.SetDefine(MagickFormat.Dds, "compression", "none");

MagickImage originalColors = new MagickImage(magickImage.UniqueColors());
magickImage.OrderedDither("o4x4,8");
magickImage.Map(originalColors);

Results in the following error:

Unhandled exception. ImageMagick.MagickResourceLimitErrorException: unable to create colormap `' @ error/colormap.c/AcquireImageColormap/123
   at ImageMagick.MagickExceptionHelper.Check(IntPtr exception) in /_/src/Magick.NET/Exceptions/MagickExceptionHelper.cs:line 18
   at ImageMagick.NativeHelper.CheckException(IntPtr exception) in /_/src/Magick.NET/Native/NativeHelper.cs:line 27
   at ImageMagick.MagickImage.NativeMagickImage.Map(IMagickImage image, IQuantizeSettings settings) in /_/src/Magick.NET/Native/MagickImage.cs:line 6376
   at ImageMagick.MagickImage.Map(IMagickImage image, IQuantizeSettings settings) in /_/src/Magick.NET/MagickImage.cs:line 4063
   at ImageMagick.MagickImage.Map(IMagickImage image) in /_/src/Magick.NET/MagickImage.cs:line 4049
   at (my program) ...

I have tried a few variations to rule out certain causes, such as doing no image manipulation, but even simply creating the image and using it as a map with no changes results in this same error. This only seems to be occuring with DDS images, because I tested both with a compressed one that was saved on my desktop and an uncompressed one saved as a byte array in memory. However, doing the same thing with a PNG image did not result in the error.

Strangely, if I used the image itself as it's own map (ex: magickImage.Map(magickImage)) there was no error, even with DDS.

Steps to Reproduce

  1. Create a MagickImage from a DDS file.
  2. Create another MagickImage using the first image.
  3. Remap the first image using the image from step 2
dlemstra commented 5 months ago

Your originalColors image probably has more than 256 colors. With the Q8 version your color map can only contain 256 colors.