| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1543 人关注过本帖
标题:利用neon指令集优化C++代码
只看楼主 加入收藏
jieweijasson
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2018-1-14
收藏
 问题点数:0 回复次数:0 
利用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
搜索更多相关主题的帖子: image int RED for break 
2018-01-14 18:54
快速回复:利用neon指令集优化C++代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.068313 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved