利用neon指令集优化C++代码
请问怎么用neon指令集优化这段自动对比度算法的代码?跪谢大神#pragma mark 图片处理(自动对比度)
- (UIImage *)autoContrastImage:(UIImage *)image
{
unsigned char* pData = [self.image ARGBData];
unsigned char* p_Data = pData;
int width = self.image.size.width;
int height = self.image.size.height;
const int RED =1;
const int GREEN =2;
const int BLUE =3;
double Low_Cut = 8;
double High_Cut = 8;
int HistRed[256] = {0};
int HistGreen[256] = {0};
int HistBlue[256] = {0};
int HistRGB[256] = {0};
int PixelAmount = width*height;
int isum;
unsigned int iMin_RGB,iMax_RGB,iMinRed,iMaxRed,iMinGreen,iMaxGreen,iMinBlue,iMaxBlue;
//计算各通道直方图
for (int j = 0; j<height; j++)
{
for (int i = 0; i<width; i++)
{
HistRed[pData[RED]] = HistRed[pData[RED]]+1;
HistGreen[pData[GREEN]] = HistGreen[pData[GREEN]]+1;
HistBlue[pData[BLUE]] = HistBlue[pData[BLUE]]+1;
pData += 4;
}
}
//计算各个通道的上下限值
//red
isum = 0;
for (int j=0;j<256;j++){
isum = isum + HistRed[j];
if(isum >= PixelAmount * Low_Cut * 0.01 ){
iMinRed = j;
break;
}
}
isum = 0;
for (int j=255;j>=0;j--){
isum = isum + HistRed[j];
if(isum >= PixelAmount * High_Cut * 0.01 ){
iMaxRed = j;
break;
}
}
//green
isum = 0;
for (int j=0;j<256;j++){
isum = isum + HistGreen[j];
if(isum >= PixelAmount * Low_Cut * 0.01 ){
iMinGreen = j;
break;
}
}
isum = 0;
for (int j=255;j>=0;j--){
isum = isum + HistGreen[j];
if(isum >= PixelAmount * High_Cut * 0.01 ){
iMaxGreen = j;
break;
}
}
//blue
isum = 0;
for (int j=0;j<256;j++){
isum = isum + HistBlue[j];
if (isum >= PixelAmount * Low_Cut * 0.01){
iMinBlue = j;
break;
}
}
isum = 0;
for (int j=255;;j--){
isum = isum + HistBlue[j];
if (isum >= PixelAmount * High_Cut * 0.01){
iMaxBlue = j;
break;
}
}
//获取三个通道下限值的最小值,以及上限值的最大值
iMin_RGB = iMinRed>iMinGreen?iMinGreen:iMinRed;
iMax_RGB = iMaxRed>iMaxGreen?iMaxRed:iMaxGreen;
iMin_RGB = iMin_RGB>iMinBlue?iMinBlue:iMin_RGB;
iMax_RGB = iMax_RGB>iMaxBlue?iMax_RGB:iMaxBlue;
//以新的上下限值,计算隐射表
for (int j=0;j<256;j++){
if(j<=(unsigned int)iMin_RGB)
HistRGB[j]=0;
else if(j>=(unsigned int)iMax_RGB)
HistRGB[j]=255;
else
HistRGB[j]= (255*(j-iMin_RGB))/(iMax_RGB-iMin_RGB);
}
//查表
pData = p_Data;
for (int j=0;j<height;j++)
{
for (int i=0;i<width;i++)
{
pData[RED] = HistRGB[pData[RED]];
pData[GREEN] = HistRGB[pData[GREEN]];
pData[BLUE] = HistRGB[pData[BLUE]];
pData += 4;
}
}
self.image = [UIImage imageWithARGBData:p_Data withSize:self.image.size];
delete p_Data;
p_Data=NULL;
imageView.image = _image;
return _image;
}
@end