Quantize() produce unreadable PNG.
Prerequisites
- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of Magick.NET
- [x] I have searched open and closed issues to ensure it has not already been reported
Description
Using Quantize() to output 2-color image. It is not readable again by new MagickImage().
Steps to Reproduce
using (var magick = new MagickImage("../../input.png"))
{
QuantizeSettings qSetting = new QuantizeSettings();
qSetting.ColorSpace = ColorSpace.Gray;
qSetting.DitherMethod = DitherMethod.Riemersma;
qSetting.Colors = 2;
magick.Quantize(qSetting);
magick.Write("../../output.png", MagickFormat.Png00);
}
can write output.png, that is viewable, however, then
using(var magick = new MagickImage("../../output.png") {}
failed with error:
Unhandled Exception: ImageMagick.MagickCorruptImageErrorException: invalid colormap index `../../output.png' @ error/colormap-private.h/ConstrainColormapIndex/35
at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
at ImageMagick.MagickImage.NativeMagickImage.ReadFile(MagickSettings settings)
at ImageMagick.MagickImage.Read(String fileName, MagickReadSettings readSettings, Boolean ping)
at ImageMagick.MagickImage..ctor(String fileName)
at ConsoleApp4.Program.Main(String[] args) at c:\tmp\Repos\ConsoleApp4\ConsoleApp4\Program.cs:line 25
magick -identify says colormap index is invalid:
$ magick identify -verbose output.png
Image: output.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: PseudoClass
Geometry: 640x480+0+0
Resolution: 37.79x37.79
Print size: 16.9357x12.7018
Units: PixelsPerCentimeter
Colorspace: sRGB
Type: Bilevel
Base type: Undefined
Endianess: Undefined
Depth: 8/1-bit
Channel depth:
Red: 1-bit
Green: 1-bit
Blue: 1-bit
Channel statistics:
Pixels: 307200
Red:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: nan (nan)
kurtosis: 1.6384e+52
skewness: 9.375e+35
entropy: 0
Green:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: nan (nan)
kurtosis: 1.6384e+52
skewness: 9.375e+35
entropy: 0
Blue:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: nan (nan)
kurtosis: 1.6384e+52
skewness: 9.375e+35
entropy: 0
Image statistics:
Overall:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: nan (nan)
kurtosis: 8.192e+51
skewness: 1e+36
entropy: 0
Colors: 1
Histogram:
307200: (255,255,255) #FFFFFF white
Colormap entries: 2
Colormap:
0: (255,255,255,255) #FFFFFFFF white
1: ( 0, 0, 0,255) #000000FF black
Rendering intent: Perceptual
Gamma: 0.45455
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 640x480+0+0
Dispose: Undefined
Iterations: 0
Compression: Zip
Orientation: Undefined
Properties:
date:create: 2018-11-13T14:25:54+09:00
date:modify: 2018-11-13T14:40:06+09:00
icc:copyright: Copyright (c) 1998 Hewlett-Packard Company
icc:description: sRGB IEC61966-2.1
icc:manufacturer: IEC http://www.iec.ch
icc:model: IEC 61966-2.1 Default RGB colour space - sRGB
png:bKGD: chunk was found (see Background color, above)
png:gAMA: gamma=0.45455 (See Gamma, above)
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 3
png:IHDR.color_type: 3 (Indexed)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 640, 480
png:pHYs: x_res=3779, y_res=3779, units=1
png:PLTE.number_colors: 2
png:sRGB: intent=0 (Perceptual Intent)
png:text: 6 tEXt/zTXt/iTXt chunks were found
png:tIME: 2018-11-13T23:16:01Z
signature: a36b4e10f667ce91157ce8e08a554d84b2cb41eb3e50461a93d4eb9161b27979
Artifacts:
verbose: true
Tainted: False
Filesize: 10635B
Number pixels: 307200
Pixels per second: 16.1692MP
User time: 0.016u
Elapsed time: 0:01.018
Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-11-06 https://imagemagick.org
identify: invalid colormap index `output.png' @ error/colormap-private.h/ConstrainColormapIndex/35.
input.png
output.png
And one question: why the color is inverted?
System Configuration
- Magick.NET version: 7.9.0.1
- Environment (Operating system, version and so on): Windows 7 64bit
- Additional information: install from Nuget, Q16 AnyCPU version with no modification.
Magick.NET 7.8.0 behaves as the same.
In Magick.NET 7.7.0, the produced output.png file can be readable, although negated, and complained by magick identify -verbose.
If I changed
magick.Write("../../output.png", MagickFormat.Png00);
to
magick.Write("../../output.png", MagickFormat.Png8);
it produced correct image, not negated, color_type=3, not complained by identify, in Magick.NET 7.7.0-7.9.0.1
I think the setting Png00 should inherit color_type=3 and produce readable image.
Thanks for the research @t246246 will take a look at it later this week.
This will be resolved in the next release of Magick.NET thanks for reporting this @t246246.