<2022-03-17 Thu>
ImageMagick
中的number_channels
成员(一)在ImageMagick
中number_channels
成员出现频率有点高,经调试发现ImageMagick
中图片对象初始化时通过调用OpenPixelCache()
然后在InitializePixelChannelMap()
中设置number_channels
的值。这个函数的内部大量使用了GraphicsMagick
中没有类型PixelChannel
和PixelTrait
,不太好把它给搬到GraphicsMagick
中。
查看PixelChannel
的定义发现了它的一个特点是:虽然它是enum
类型,但每个成员都被指派了具体的值,且发现有多个成员共用一个值的情况。以此参照仍然没有在GraphicsMagick
中找到类似定义,PixelChannel
的定义:
typedef enum
{
UndefinedPixelChannel = 0,
RedPixelChannel = 0,
CyanPixelChannel = 0,
GrayPixelChannel = 0,
LPixelChannel = 0,
LabelPixelChannel = 0,
YPixelChannel = 0,
aPixelChannel = 1,
GreenPixelChannel = 1,
MagentaPixelChannel = 1,
CbPixelChannel = 1,
bPixelChannel = 2,
BluePixelChannel = 2,
YellowPixelChannel = 2,
CrPixelChannel = 2,
BlackPixelChannel = 3,
AlphaPixelChannel = 4,
IndexPixelChannel = 5,
ReadMaskPixelChannel = 6,
WriteMaskPixelChannel = 7,
MetaPixelChannel = 8,
CompositeMaskPixelChannel = 9,
IntensityPixelChannel = MaxPixelChannels, /* ???? */
CompositePixelChannel = MaxPixelChannels, /* ???? */
SyncPixelChannel = MaxPixelChannels+1 /* not a real channel */
} PixelChannel; /* must correspond to ChannelType */
我模仿ImageMagick
的InitializePixelChannelMap()
函数写了calc_image_number_channels()
,虽然number_channels
的值对于同一张测试图片bg1a.jpg
来说均为3
,但是在IM
中值3
显示正确,而在GM
中3 + 1
才能正确,所以我在ComputeResizeImage()
中将calc_image_number_channels()
的返回值加上了1
:
number_channels=(cl_uint) calc_image_number_channels(image)+1;
这只是临时方案,估计下面要更改抄过来的kernel
函数。
见commit
:calc number_channels, but need to plus 1 to get correct result。