3
Vote

Value of '-141' is not valid for 'alpha'. 'alpha' should be greater than or equal to 0 and less than or equal to 255.

description

Exceptions on some images while optimizing.
But this images can be easily loaded by Bitmap. So seems to be bug in optimizer.

{System.ArgumentException: Value of '-141' is not valid for 'alpha'. 'alpha' should be greater than or equal to 0 and less than or equal to 255.
at System.Drawing.Color.CheckByte(Int32 value, String name)
at System.Drawing.Color.FromArgb(Int32 alpha, Int32 red, Int32 green, Int32 blue)
at nQuant.WuQuantizer.GetQuantizedPalette(Int32 colorCount, ColorData data, IEnumerable`1 cubes, Int32 alphaThreshold) in c:\dev\nquant\nQuant.Core\WuQuantizer.cs:line 90
at nQuant.WuQuantizerBase.QuantizeImage(Bitmap image, Int32 alphaThreshold, Int32 alphaFader) in c:\dev\nquant\nQuant.Core\WuQuantizerBase.cs:line 31
at nQuant.WuQuantizerBase.QuantizeImage(Bitmap image) in c:\dev\nquant\nQuant.Core\WuQuantizerBase.cs:line 22


Image for example:

https://dl.dropbox.com/u/1026115/test.png

Thanks.

comments

philjones_ca wrote Jun 24 at 12:03 AM

Hi,

I know this comment is about 4 years old but I've tracked this bug down in a fork of the nQuant code.

When dealing with large files, there is possibility that if there are too many pixels with the same colour, it will wrap the int.
This is particularly likely with the Alpha value because a non-transparent image will have values of 255 for each pixel.

The fix was to change it to use ulong instead of int.

Here is a link to that commit:
https://github.com/philjones/nquant/commit/e604deb0eeb3ddc17eb522f9bd9a04b76bb4475d