Page 1 of 1

Speed optimization (ReadBlob + Gamma)

Posted: 2007-09-26T08:19:33-07:00
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

Re: Speed optimization (ReadBlob + Gamma)

Posted: 2007-09-26T08:36:04-07:00
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.

Re: Speed optimization (ReadBlob + Gamma)

Posted: 2007-09-26T08:44:32-07:00
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?

Re: Speed optimization (ReadBlob + Gamma)

Posted: 2007-09-26T09:06:34-07:00
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.