imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by jcupitt »

Hi all,

I'm rewriting an import class for imagemagick7, lots of nice improvements, thank you.

I'd like to be able to call PingImage() and then get the number of channels with GetPixelChannels(image), but this seems to return 0, at least for JPEG images. It seems I can only use GetPixelChannels() after ReadImage().

Is this correct? Is there any way to get the number of channels without decoding the whole image?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by magick »

You could try calling InitializePixelChannelMap(image), before you call GetPixelChannels(). The channel map is initialized when the pixel cache is initialized. The pixel cache is generally not initialized when you are "pinging" an image. Let us know if that works. If so, we will consider adding a patch to initialize the pixel channel map automatically when pinging an image.
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by jcupitt »

It works! And it makes PingBlob() work too.

Thank you very much. I have another question, I'll start a fresh topic.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by dlemstra »

We added a patch so you won't need to do it yourself in the next version: http://git.imagemagick.org/repos/ImageM ... 85e97aa69d
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by jcupitt »

I've found a case when this fails. If I PingImage()/InitializePixelChannelMap(image) on a PDF I see:

image->depth = 16
GetImageType() = 6
GetPixelChannels() = 3

But if I ReadImage() the same file I see:

image->depth = 16
GetImageType() = 7
GetPixelChannels() = 4

I'd obviously like Ping and Read to return the same header so I can allocate memory correctly. Is there some way around this?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.
jcupitt
Posts: 26
Joined: 2011-04-26T05:14:01-07:00
Authentication code: 8675308

Re: imagemagick7, MagickCore: GetPixelChannels(image) not valid after PingImage()?

Post by jcupitt »

Works well here. Thank you very much!
Post Reply