2016-03-17 159 views
1

我繼承了一個圖像過濾器應用程序,我試圖更新它。 Apple要求我改變架構以支持64位。在64位手機上,圖像具有垂直黑條(見下文)。 32位電話按預期工作。轉換圖像處理爲64位創建黑色線條

這似乎是舊的代碼假設一個32位系統的問題,但我該如何解決它?

Imgur

我已經收窄到適用的圖像曲線下面的代碼:

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

和計算應在兩種類型的設備的正常工作。

相關問題