MagickWand C API, error when calling DestroyPixelWands

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
djense2000
Posts: 4
Joined: 2011-09-02T09:28:13-07:00
Authentication code: 8675308

MagickWand C API, error when calling DestroyPixelWands

Post by djense2000 »

I am starting to use ImageMagick and the MagickWand API in a simple C program.
Right now, as a test, I am just looking for black pixels in a frame.
Here is my code :

Code: Select all

    int find_black_pixel(MagickWand *wand) {
        int res = 0;
        PixelIterator * iterator = NewPixelIterator(wand);
        size_t width=MagickGetImageWidth(wand);
        size_t height=MagickGetImageHeight(wand);
        PixelWand ** pixels;
        unsigned long x,y;
        unsigned int alpha;
        unsigned int red, green, blue;
    
        //printf("Width : %d, Height : %d\n", (int)width, (int)height);
    
        for (y=0; y<height; y++) {
            pixels = PixelGetNextIteratorRow(iterator, &width);
            for (x=0; x<width; x++) {
    
                alpha = (unsigned int) (255*PixelGetAlpha(pixels[x]));
                if (alpha == 0)
                    continue;
    
                red = (unsigned int) (255*PixelGetRed(pixels[x]));
                green = (unsigned int) (255*PixelGetGreen(pixels[x]));
                blue = (unsigned int) (255*PixelGetBlue(pixels[x]));
    
                //printf("At %04ld,%04ld, alpha : %d, rgb : %d,%d,%d\n", x,y,alpha, red, green, blue);
    
                if ((red ==0) || (green == 0) || (blue ==0)) {
    
                    res = 1;
                    //DestroyPixelWands(pixels, width);
                    goto finished_find_black_pixel;
                }
    
            }
            //DestroyPixelWands(pixels, (size_t)width);
        }
    
    finished_find_black_pixel:
        DestroyPixelIterator(iterator);
    
        return res;
    }
If I uncomment any of the DestroyPixelWands call, I get an assertion :
test: wand/pixel-wand.c:283: DestroyPixelWands: Assertion `(*wand)->signature == 0xabacadabUL' failed.
Any idea why this is happening ?

The version I use :
$ convert -version
Version: ImageMagick 6.6.2-6 2011-03-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
That's on a Linux (Ubuntu 11.04) machine.

Even calling `DestroyPixelWand(pixels[0]);` makes it fail the same way...

Posted that question on StackOverflow, but did not seem to get much success there...
http://stackoverflow.com/questions/7277 ... pixelwands
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickWand C API, error when calling DestroyPixelWands

Post by magick »

The pixel wands are private when associated with a pixel iterator. The pixel wands are destroyed when you destroy the pixel iterator. Do not use DestroyPixelWands() for a pixel iterator.
djense2000
Posts: 4
Joined: 2011-09-02T09:28:13-07:00
Authentication code: 8675308

Re: MagickWand C API, error when calling DestroyPixelWands

Post by djense2000 »

Got it.

Thanks a lot for the quick reply !!
Post Reply