Possible a bug with BitDepth() method

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
VasyaIvonov2
Posts: 21
Joined: 2019-10-29T07:03:33-07:00
Authentication code: 1152

Possible a bug with BitDepth() method

Post by VasyaIvonov2 »

Hi!

I found that method BitDepth of class MagickImage is always returns 1.
Example:

Code: Select all

                magIm = new MagickImage();
                magIm.Ping(path);
                int bitDepth = magIm.Depth;//8
                var ls = magIm.Channels.ToList(); //R G B B (it is a CMYK image)
                int a1 = magIm.BitDepth(Channels.CMYK);//1
                int a2 = magIm.BitDepth(Channels.RGB);//1
                int a3 = magIm.BitDepth(Channels.Blue);//1
What purpose of that method? Did it return values as intended?

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

Re: Possible a bug with BitDepth() method

Post by dlemstra »

You are pinging the image, what happens when you read it instead?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

VasyaIvonov2
Posts: 21
Joined: 2019-10-29T07:03:33-07:00
Authentication code: 1152

Re: Possible a bug with BitDepth() method

Post by VasyaIvonov2 »

dlemstra wrote:
2019-12-17T15:49:14-07:00
You are pinging the image, what happens when you read it instead?
If I read image a1, a2, a3 are 8, as expected. But I must ping image, not read it.
May be someone knows how to get bitspersample for image through pinging? Now I use such crunch code:

Code: Select all

int bitDepth = magIm.Depth;
                ColorType type = magIm.ColorType;
                bool isCMYK = magIm.ColorSpace == ColorSpace.CMYK;
                if (type == ColorType.TrueColor)
                    bitDepth *= 3;
                else if (type == ColorType.TrueColorAlpha)
                    bitDepth *= 4;
                else if (isCMYK && type == ColorType.ColorSeparation)
                    bitDepth *= 4;
                else if (isCMYK && type == ColorType.ColorSeparationAlpha)
                    bitDepth *= 5;

User avatar
magick
Site Admin
Posts: 11149
Joined: 2003-05-31T11:32:55-07:00

Re: Possible a bug with BitDepth() method

Post by magick »

Pinging an image is designed for performance but the trade off is that the image pixels are not read. Without the pixels, its impossible to compute the image depth.

VasyaIvonov2
Posts: 21
Joined: 2019-10-29T07:03:33-07:00
Authentication code: 1152

Re: Possible a bug with BitDepth() method

Post by VasyaIvonov2 »

magick wrote:
2019-12-18T05:34:07-07:00
Pinging an image is designed for performance but the trade off is that the image pixels are not read. Without the pixels, its impossible to compute the image depth.
It is sad, but is it impossible to read just one pixel to know exact BitDepth

User avatar
magick
Site Admin
Posts: 11149
Joined: 2003-05-31T11:32:55-07:00

Re: Possible a bug with BitDepth() method

Post by magick »

It is possible, use ReadImage(). But no, there is no way with PingImage(). PingImage() is specifically designed for performance which requires we only return specific metadata. Even if we could read just one pixel, we could not reliably return the bit depth of the image unless it was coded in the metadata. Assume the first pixel is sRGB(0,0,0). The bit depth based on that single pixel is 1. However, for this example, if we processed the remaining pixels we discover that the actual bit depth is 8.

Post Reply