cpuimage 开源之
2018-06-17 21:19:38来源:未知 阅读 ()
前年学习opengl做的一个小东西。
原本计划将gpuimage 的算法一个一个转写成cpu版本 c,c++ 版本。
gpuimage 项目参考:
https://github.com/BradLarson/GPUImage
https://github.com/BradLarson/GPUImage2
https://github.com/CyberAgent/android-gpuimage
后来工作琐事太多,这个事情就搁置了。
今天翻出来,从c++改为c代码,
没有经过验证各个算法的正确性,回头发现再修正吧。
贴上头文件,
把绝大部分gpuimage的算法都用cpu的处理思路重新写了下,做一点基础优化。
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <stdbool.h> typedef struct { //色阶最小值 int levelMinimum; //色阶中间值 int levelMiddle; //色阶最大值 int levelMaximum; //最小输出值 int minOutput; //最大输出值 int maxOutput; //是否应用 bool Enable; }cpuLevelParams; void rgb2yiq(unsigned char *R, unsigned char * G, unsigned char * B, short *Y, short * I, short * Q); void yiq2rgb(short *Y, short * I, short * Q, unsigned char *R, unsigned char * G, unsigned char * B); void rgb2hsv(const unsigned char *R, const unsigned char *G, const unsigned char *B, unsigned char *H, unsigned char *S, unsigned char *V); void hsv2rgb(const unsigned char *H, const unsigned char *S, const unsigned char *V, unsigned char *R, unsigned char *G, unsigned char *B); void rgb2ycbcr(unsigned char R, unsigned char G, unsigned char B, unsigned char * y, unsigned char * cb, unsigned char * cr); void ycbcr2rgb(unsigned char y, unsigned char Cb, unsigned char Cr, unsigned char * R, unsigned char * G, unsigned char * B); //--------------------------Color adjustments-------------------------- void CPUImageGrayscaleFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride); // float redAdjustment = 1.0f, float greenAdjustment = 1.0f, float blueAdjustment = 1.0f void CPUImageRGBFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float redAdjustment, float greenAdjustment, float blueAdjustment); // float thresholdMultiplier = 1.0f void CPUImageAverageLuminanceThresholdFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float thresholdMultiplier); void CPUImageAverageColor(unsigned char* Input, int Width, int Height, int Stride, unsigned char * AverageR, unsigned char * AverageG, unsigned char * AverageB, unsigned char * AverageA); void CPUImageLuminosity(unsigned char* Input, int Width, int Height, int Stride, unsigned char * Luminance); // float intensity = 1.0f void CPUImageColorMatrixFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float* colorMatrix, float intensity); //int intensity = 100 void CPUImageSepiaFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, int intensity); // unsigned char colorToReplaceR = 0, unsigned char colorToReplaceG = 160, unsigned char colorToReplaceB = 0, float thresholdSensitivity = 0.2f, float smoothing = 0.1f void CPUImageChromaKeyFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, unsigned char colorToReplaceR, unsigned char colorToReplaceG, unsigned char colorToReplaceB, float thresholdSensitivity, float smoothing); // int intensity = 100 void CPUImageLookupFilter(unsigned char* Input, unsigned char* Output, unsigned char* lookupTable, int Width, int Height, int Stride, int intensity); // float saturation = 1.0 void CPUImageSaturationFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float saturation); // float gamma = 1.0f void CPUImageGammaFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float gamma); // float contrast = 1.0f void CPUImageContrastFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float contrast); //float exposure = 0.0f void CPUImageExposureFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float exposure); //int brightness = 0.0f void CPUImageBrightnessFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, int brightness); //unsigned char firstColorR = 0, unsigned char firstColorG = 0, unsigned char firstColorB = 0.5 * 255, unsigned char secondColorR = 1.0f * 255, unsigned char secondColorG = 0, unsigned char secondColorB = 0, int intensity = 100 void CPUImageFalseColorFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, unsigned char firstColorR, unsigned char firstColorG, unsigned char firstColorB, unsigned char secondColorR, unsigned char secondColorG, unsigned char secondColorB, int intensity); // float distance = 0.3, float slope = 0, int intensity = 100 void CPUImageHazeFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float distance, float slope, int intensity); // float opacity = 1.0f void CPUImageOpacityFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float opacity); void CPUImageLevelsFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, cpuLevelParams *redLevelParams, cpuLevelParams *greenLevelParams, cpuLevelParams *blueLevelParams); // float hueAdjust = 90.0f void CPUImageHueFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float hueAdjust); // float shadowTintR = 1.0f, float shadowTintG = 0.0f, float shadowTintB = 0.0f, float highlightTintR = 0.0f, float highlightTintG = 0.0f, float highlightTintB = 1.0f, float shadowTintIntensity = 0.0f, float highlightTintIntensity = 0.0f void CPUImageHighlightShadowTintFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float shadowTintR, float shadowTintG, float shadowTintB, float highlightTintR, float highlightTintG, float highlightTintB, float shadowTintIntensity, float highlightTintIntensity); // float shadows = 0.0f, float highlights = 1.0f void CPUImageHighlightShadowFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float shadows, float highlights); // unsigned char filterColorR = 0.6 * 255, unsigned char filterColorG = 0.45 * 255, unsigned char filterColorB = 0.3 * 255, int intensity = 100 void CPUImageMonochromeFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, unsigned char filterColorR, unsigned char filterColorG, unsigned char filterColorB, int intensity); void CPUImageColorInvertFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride); // unsigned char colorAlpha = 255 void CPUImageSolidColorGenerator(unsigned char* Output, int Width, int Height, int Stride, unsigned char colorR, unsigned char colorG, unsigned char colorB, unsigned char colorAlpha); // unsigned char threshold = 127 void CPUImageLuminanceThresholdFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, unsigned char threshold); // float temperature = 5000, float tint = 0 void CPUImageWhiteBalanceFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float temperature, float tint); //float vibrance = 1.2 void CPUImageVibranceFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float vibrance); // float skinToneAdjust = 0.3f, float skinHue = 0.05f, float skinHueThreshold = 80.0f, float maxHueShift = 0.25f, float maxSaturationShift = 0.4f, int upperSkinToneColor = 0 void CPUImageSkinToneFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float skinToneAdjust, float skinHue, float skinHueThreshold, float maxHueShift, float maxSaturationShift, int upperSkinToneColor); //float fraction = 0.05f void CPUImageAutoLevel(const unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float fraction); //--------------------------Color adjustments-------------------------- //--------------------------Image processing-------------------------- void CPUImageGaussianBlurFilter(unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float GaussianSigma); // float GaussianSigma = 4, int intensity = 100 void CPUImageUnsharpMaskFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float GaussianSigma, int intensity); //int Radius = 3 void CPUImageBoxBlurFilter(unsigned char *Input, unsigned char *Output, int Width, int Height, int Stride, int Radius); // float Radius = 4, int sharpness = 1, int intensity = 100 void CPUImageSharpenFilter(unsigned char* Input, unsigned char* Output, int Width, int Height, int Stride, float Radius, int sharpness, int intensity); void CPUImageResamplingFilter(unsigned char* Input, unsigned int Width, unsigned int Height, unsigned int Stride, unsigned char* Output, int newWidth, int newHeight, int dstStride); void CPUImageCropFilter(const unsigned char *Input, int Width, int Height, int srcStride, unsigned char *Output, int cropX, int cropY, int dstWidth, int dstHeight, int dstStride); //--------------------------Image processing--------------------------
授人以鱼不如授人以渔,发出来,权当抛砖引玉吧。
项目地址:
https://github.com/cpuimage/cpuimage
哪天心血来潮,用omp优化,用simd优化,嗯会有时间的。
也许哪天翻翻硬盘,又翻出一些老古董了。
这是刚学图像算法时候做的练习,代码风格渣,思路烂,不喜请喷。
若有其他相关问题或者需求也可以邮件联系俺探讨。
邮箱地址是:
gaozhihan@vip.qq.com
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 开源项目SMSS开发指南(二)——基于libevent的线程池 2020-01-11
- 个人项目开源之c++基于epoll实现高并发游戏盒子(服务端+客 2019-11-28
- Qt开源编辑器qsciscintilla的一些用法 2019-08-16
- 开源C++版本CGI库CGICC入门 2018-12-06
- 基于C++ Qt实现的红色警戒3修改器(Github开源) 2018-11-20
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash