CMYK MagickColor strange behaviour

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
zomeo
Posts: 10
Joined: 2018-04-02T02:27:59-07:00
Authentication code: 1152

CMYK MagickColor strange behaviour

Post by zomeo » 2018-04-03T08:00:32-07:00

Hi everyone,

I have a simple Gray image and I want to convert it to CMYK and use the opaque method to fill the rectangle.
My CMYK color should be: C:50 M:9 Y:98 K:61.
The image is here:
https://www.dropbox.com/s/22bq0clwrb3xo ... 0C%29?dl=0

My code:

Code: Select all

MagickImage miPantone1 = new MagickImage(@"E:\CMYK+4SPOT.pdf (PANTONE 371 C)");
miPantone1.Transparent(MagickColors.White);
miPantone1.ColorSpace = ColorSpace.CMYK;
miPantone1.Opaque(MagickColors.Black, new MagickColor(128,23,250,156,255));
miPantone1.Write(@"E:\out.tiff");
I open the TIFF with Photoshop and the box with the following CMYK percentages: C:77 M:99 Y:0 K:4.
I tried every possible combination.
I also tried CMYKColor with bytes and Percentages but the result is always wrong.

I'm using .NET 4 Q8 x64 version.

If I process the same command with magick.exe command line:

Code: Select all

magick "CMYK+4SPOT.pdf (PANTONE 371 C)" -transparent White -set colorspace CMYK -fill cmyk(128,23,250,156) -opaque cmyk(0,0,0,0) out.tiff
the resulting TIFF is OK.

What am I doing wrong?

Thank you,

Denis

User avatar
dlemstra
Posts: 1493
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: CMYK MagickColor strange behaviour

Post by dlemstra » 2018-04-08T10:39:19-07:00

-set colorspace is not the same as .Colorspace. Your command would translate to this:

Code: Select all

using (MagickImage miPantone1 = new MagickImage("CMYK+4SPOT.pdf (PANTONE 371 C)"))
{
    miPantone1.Transparent(MagickColors.White);
    miPantone1.SetAttribute("colorspace", "CMYK");
    miPantone1.Opaque(new MagickColor("cmyk(0,0,0,0)"), new MagickColor("cmyk(128,23,250,156)"));
    miPantone1.Write("out.tiff");
}
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

zomeo
Posts: 10
Joined: 2018-04-02T02:27:59-07:00
Authentication code: 1152

Re: CMYK MagickColor strange behaviour

Post by zomeo » 2018-04-09T02:46:16-07:00

Thank you dlemstra, it works like a charm.

Best regards,

Denis

zomeo
Posts: 10
Joined: 2018-04-02T02:27:59-07:00
Authentication code: 1152

Re: CMYK MagickColor strange behaviour

Post by zomeo » 2018-04-23T00:05:01-07:00

Hello dlemstra,

I did other tests and sometimes it works and sometimes not.
The link to the image:
https://www.dropbox.com/s/6dzz0xrh7fpho ... 0C%29?dl=0

I tried this code:

Code: Select all

using (MagickImage miPantone1 = new MagickImage("CMYK+4SPOT.pdf (PANTONE 371 C)"))
                    {
                        miPantone1.Transparent(MagickColors.White);
                        miPantone1.Write("1.tiff");
                        miPantone1.SetAttribute("colorspace", "CMYK");
                        miPantone1.Write("2.tiff");
                        miPantone1.Opaque(MagickColors.White, new MagickColor("cmyk(128,23,250,156)"));
                        miPantone1.Write("3.tiff");
                    }
The file "1.tiff" is correct. It's a transparent tiff with a black box.
The file "2.tiff" has been modified and the black box became a white box (CMYK 0,0,0,0). It's a strange behaviour because a black box should remain black. But the file is correctly a CMYK file.
For the 3.tiff, the opaque command instead of generating a dark green box (like the PANTONE specification (CMYK(50,9,98,61)) is a violet box (CMYK(77,99,0,4); I used MagickColors.White because of the previous color inversion.

I've also tried to replace MagickColors.White with new MagickColor("cmyk(0,0,0,0)") and in that case the Opaque command does nothing.

What am I doing wrong? How can I obtain a correct dark green box with the correct percentages of CMYK?

I also tried this that seems to work a little well (the 2.tiff is correct now. It remains Black):

Code: Select all

using (MagickImage miPantone1 = new MagickImage("CMYK+4SPOT.pdf (PANTONE 371 C)"))
                    {
                        miPantone1.Transparent(MagickColors.White);
                        miPantone1.Write("1.tiff");
                        miPantone1.ColorSpace = ColorSpace.CMYK;
                        miPantone1.Write("2.tiff");
                        miPantone1.Opaque(MagickColors.Black, new MagickColor("cmyk(128,23,250,156)"));
                        miPantone1.Write("3.tiff");
                    }
but the result of the Spot color is the same.
I also tried to use ColorCMYK as Color, with 0-255 range for colors and with percentages. The resulting color conversion is always the same. It seems that something RGB happens in the behind.

Thank you

Denis

User avatar
dlemstra
Posts: 1493
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: CMYK MagickColor strange behaviour

Post by dlemstra » 2018-04-23T11:08:03-07:00

It appears you found a bug. The second block of code should work. I just pushed a patch to fix this issue. Will try to publish a new release this weekend.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

zomeo
Posts: 10
Joined: 2018-04-02T02:27:59-07:00
Authentication code: 1152

Re: CMYK MagickColor strange behaviour

Post by zomeo » 2018-04-24T00:06:19-07:00

Thank you very much dlemstra.

zomeo
Posts: 10
Joined: 2018-04-02T02:27:59-07:00
Authentication code: 1152

Re: CMYK MagickColor strange behaviour

Post by zomeo » 2018-05-02T03:07:45-07:00

Hello Dirk,

with the latest version the problem is solved.

Thank you,

Denis

Post Reply