gpt4 book ai didi

c - MagickWand for C,调用 DestroyPixelWands 时出错

转载 作者:行者123 更新时间:2023-11-30 18:04:52 25 4
gpt4 key购买 nike

我开始在一个简单的 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]); 也会以同样的方式失败...

最佳答案

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

关于c - MagickWand for C,调用 DestroyPixelWands 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7277954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com