dlemstra / Magick.NET

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

1bit PCX conversion fails since 7.3.0 #214

Closed dittodhole closed 6 years ago

dittodhole commented 6 years ago

Coming from 7.0.0.14, I convert a .png-file to 1bit .pcx-file with the following code:

using System;
using System.Drawing;
using ImageMagick;

using (var bitmap = (Bitmap) Bitmap.FromFile(path))
using (var magickImage = new MagickImage(bitmap))
{
  if (magickImage.HasAlpha)
  {
    magickImage.ColorAlpha(new MagickColor(Color.White)); // in later versions MagickColors.White
  }

  var quantizeSettings = new QuantizeSettings
                         {
                           ColorSpace = ColorSpace.GRAY, // in later versions ColorSpace.Gray
                           Colors = 2
                         };
  magickImage.Quantize(quantizeSettings);

  magickImage.ColorType = ColorType.Bilevel;
  magickImage.Depth = 1;
  magickImage.Format = MagickFormat.Pcx;

  var array = magickImage.ToByteArray();
}

Now, inspecting the PXC header of array at offset 3:

Offset Size Description Value
0 1 Manufacturer 10 :heavy_check_mark:
1 1 PCX version number 5 :heavy_check_mark:
2 1 RLE 1 :heavy_check_mark:
3 1 Depth 1 :heavy_check_mark:
... ... ... ...

With 7.3.0 Depth changes to 8:

offset size description value
0 1 Manufacturer 10 :heavy_check_mark:
1 1 PCX version number 5 :heavy_check_mark:
2 1 RLE 1 :heavy_check_mark:
3 1 Depth 8 :shit: :zap: :bomb:
... ... ... ...

What and why has that behavior changed? How can I get the initial behavior back?

Additionally, the output size has changed (WHY??):

Best Andreas

dlemstra commented 6 years ago

Thanks for the detailed report, will try to take a look at it later today.

dlemstra commented 6 years ago

Can you share your input image?

dlemstra commented 6 years ago

I can confirm this is a bug and I will need to figure out how to fix this.

And you don't need to do the call to Quantize. This already happens when you change the ColorType to BiLevel.

dlemstra commented 6 years ago

@dittodhole Can you give it another try with the latest release?

dittodhole commented 6 years ago

@dlemstra Thanks for the ping, I will test the new release this eve.

dittodhole commented 6 years ago

@dlemstra Thanks for the fix - I've validated the new version with various .png-files and checked the actual byte content for 7.0.1 vs 7.4.6 :+1: The actual binary output matches between versions 😄