我继承了一个图片过滤器应用,我正在尝试更新它。 Apple要求我改变架构以支持64位。在64位手机上,图像有垂直的黑条(见下文)。 32位手机按预期工作。
似乎这是旧代码假设32位系统的问题,但我该如何解决?
我已将其缩小为以下应用图像曲线的代码:
NSUInteger* currentPixel = _rawBytes;
NSUInteger* lastPixel = (NSUInteger*)((unsigned char*)_rawBytes + _bufferSize);
while(currentPixel < lastPixel)
{
SET_RED_COMPONENT_RGBA(currentPixel, _reds[RED_COMPONENT_RGBA(currentPixel)]);
SET_GREEN_COMPONENT_RGBA(currentPixel, _greens[GREEN_COMPONENT_RGBA(currentPixel)]);
SET_BLUE_COMPONENT_RGBA(currentPixel, _blues[BLUE_COMPONENT_RGBA(currentPixel)]);
++currentPixel;
}
以下是宏定义:
#define ALPHA_COMPONENT_RGBA(pixel) (unsigned char)(*pixel >> 24)
#define BLUE_COMPONENT_RGBA(pixel) (unsigned char)(*pixel >> 16)
#define GREEN_COMPONENT_RGBA(pixel) (unsigned char)(*pixel >> 8)
#define RED_COMPONENT_RGBA(pixel) (unsigned char)(*pixel >> 0)
#define SET_ALPHA_COMPONENT_RGBA(pixel, value) *pixel = (*pixel & 0x00FFFFFF) | ((unsigned long)value << 24)
#define SET_BLUE_COMPONENT_RGBA(pixel, value) *pixel = (*pixel & 0xFF00FFFF) | ((unsigned long)value << 16)
#define SET_GREEN_COMPONENT_RGBA(pixel, value) *pixel = (*pixel & 0xFFFF00FF) | ((unsigned long)value << 8)
#define SET_RED_COMPONENT_RGBA(pixel, value) *pixel = (*pixel & 0xFFFFFF00) | ((unsigned long)value << 0)
#define BLUE_COMPONENT_ARGB(pixel) (unsigned char)(*pixel >> 24)
#define GREEN_COMPONENT_ARGB(pixel) (unsigned char)(*pixel >> 16)
#define RED_COMPONENT_ARGB(pixel) (unsigned char)(*pixel >> 8)
#define ALPHA_COMPONENT_ARGB(pixel) (unsigned char)(*pixel >> 0)
#define SET_BLUE_COMPONENT_ARGB(pixel, value) *pixel = (*pixel & 0x00FFFFFF) | ((unsigned long)value << 24)
#define SET_GREEN_COMPONENT_ARGB(pixel, value) *pixel = (*pixel & 0xFF00FFFF) | ((unsigned long)value << 16)
#define SET_RED_COMPONENT_ARGB(pixel, value) *pixel = (*pixel & 0xFFFF00FF) | ((unsigned long)value << 8)
#define SET_ALPHA_COMPONENT_ARGB(pixel, value) *pixel = (*pixel & 0xFFFFFF00) | ((unsigned long)value << 0)
如何将上述内容更改为32位或64位设备?我需要包含更多代码吗?
答案 0 :(得分:2)
NSUInteger
会更改32位和64位设备之间的大小。它曾经是4个字节;现在它是8.代码假定它使用RGBA数据,每个通道有一个字节,所以8字节指针的增量跳过一半以上的数据。
只要明确大小:
uint32_t * currentPixel = _rawBytes;
uint32_t * lastPixel = (uint32_t *)((unsigned char *)_rawBytes + _bufferSize);
并且计算应该在两种类型的设备上正常工作。