Speed optimization (ReadBlob + Gamma)

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rigid

Speed optimization (ReadBlob + Gamma)

Post by rigid »

Hi,

I'm doing something like this:

Code: Select all

magick_wand = NewMagickWand();

while(my_image) {
    MagickReadImageBlob(magick_wand, my_image->data, my_image->datasize);

    MagickGammaImageChannel(magick_wand, RedChannel, gamma_r);
    MagickGammaImageChannel(magick_wand, GreenChannel, gamma_g);
    MagickGammaImageChannel(magick_wand, BlueChannel, gamma_b);
        
    MagickGetImagePixels(magick_wand,0, 0,width,height, "RGB", CharPixel, 
                                            my_image->raw_data);

    MagickRemoveImage(magick_wand);

    my_image=my_image->next;
}

DestroyMagickWand(magick_wand);
Now this works fine but it seems awfully slow.

Is there a good way to optimize this?
I read about the Pixel Cache stuff and thought things would get faster when allocating one PixelCache once and then re-use that one for every image. But i guess using MagickCore functions isn't a good idea. I don't even know what exactly takes so long in the above code. I first wanted to ask here before I begin profiling half the ImageMagick code :)

thanks for any suggestions

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

Re: Speed optimization (ReadBlob + Gamma)

Post by magick »

We assume gamma_r, gamma_g, and gamma_b have different values? If not you could use MagickGammaImage() and gamma-correct the image in one pass. Otherwise you would need to write a new method that gamma-corrects an image with different gamma values for each channel in one pass or use some other API that might be more efficient than MagickWand.
rigid

Re: Speed optimization (ReadBlob + Gamma)

Post by rigid »

magick wrote:We assume gamma_r, gamma_g, and gamma_b have different values?
Indeed the values differ.
I don't think the gamma-correction is the bottleneck, it's faster without it, but still too slow (i use 28x7 PNGs for testing).
I suppose there is a lot of overhead in MagickReadImageBlob() ...
Another idea I had is that maybe I can prevent some overhead by setting some options in the MagickWand... So maybe I gain some speed by not having to "autodetect" them?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Speed optimization (ReadBlob + Gamma)

Post by magick »

We cannot think of any options you could tweak in MagickWand to speed up your algorithm other than what we already mentioned. You could try using MagickGetImageBlob() but first setting the image format to "RGB" with MagickSetImageFormat() and the depth to 8. You may need to set the image filename to something like "rgb:image" since its a raw format. It may be more efficient but only testing will tell.
Post Reply