MagickWand for C,调用 DestroyPixelWands 时出错

发布于 2024-12-03 02:43:17 字数 1700 浏览 0 评论 0原文

我开始在一个简单的 C 程序中使用 ImageMagick 和 MagickWand API。 现在,作为测试,我只是在帧中寻找黑色像素。 这是我的代码:

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;
}

如果我取消注释任何 DestroyPixelWands 调用,我会得到一个断言:

test: wand/pixel-wand.c:283: DestroyPixelWands: Assertion `(*wand)->signature == 0xabacadabUL' failed.

知道为什么会发生这种情况吗?

编辑:

更多调试...即使调用 DestroyPixelWand(pixels[0]); 也会以同样的方式失败...

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 :

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 ?

EDIT :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吹泡泡o 2024-12-10 02:43:17

我怀疑 pixels 不是一个单独的可销毁对象(它只是指向原始 wand 对象的指针),并且您当前的代码没有问题,没有任何代码可以销毁 像素

I suspect that pixels is not a separate destroyable object (it is just a pointer into the original wand object) and that your current code is fine without any code to destroy pixels.

已下线请稍等 2024-12-10 02:43:17

从 ImageMagick 论坛 得到答案:

当与像素迭代器关联时,像素棒是私有的。这
当您销毁像素迭代器时,像素棒也会被销毁。不要
使用 DestroyPixelWands() 作为像素迭代器。

Got the answer from ImageMagick forum :

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文