This project has moved and is read-only. For the latest updates, please go here.

JPEG-2000 encoder does not respect ColorSpace changes

Dec 21, 2016 at 7:36 PM
Edited Dec 21, 2016 at 8:31 PM
I am unsuccessfully attempting to use Magick.NET to create 8-bit grayscale JPEG-2000 files. The Magick.NET library (version 7.0.3.500-Q8-x86) appears to not respect any changes to the ColorSpace.

The following is the sample code I am using:
using (MagickImage m = new MagickImage(bmp))
{
    m.Format = MagickFormat.Jp2;
    //m.Settings.SetDefine(MagickFormat.Jp2, "colorspace", "gray");
    //m.Settings.ColorSpace = ColorSpace.Gray;
    m.Settings.SetDefine(MagickFormat.Jp2, "quality", "80");
    m.Write(jpeg2000FullPath);
}
Notes: "bmp" is a bitmap created from a 8-bit data array. To set the colorspace, I uncomment one of the above commented-out lines of code.

For comparison, the following command-line ImageMagick command works fine:
convert test.bmp -colorspace gray test.jp2
I have confirmed with exiftool that the command-line tool properly changes the colorspace to Grayscale and number of bands to 1, whereas the Magick.NET code leaves the colorspace as RGB and number of bands as 3.

I've also posted on the ImageMagick forums, where I have unsuccessfully attempted a couple of fixes; see here:

ImageMagick forum - "Users" thread
ImageMagick forum - "Magick.NET" thread
Dec 22, 2016 at 6:51 AM
Edited Dec 22, 2016 at 12:43 PM
Would you mind sharing your test.bmp file so I can use that to reproduce the issue? You can attach it to the issue that you created. Can you try setting m.ColorSpace? That should do the same as -colorspace.
Dec 22, 2016 at 5:00 PM
Done. See here for the issue page.
Dec 26, 2016 at 4:06 PM
I have replied to your issue, hope that will help you.