cpuimage 开源之
前年学习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
cpuimage 开源之的更多相关文章
- 开源发丝分割数据集CelebAHairMask-HQ(国庆献礼)
在这个特别日子里,举国欢庆,什么都可以缺席,大礼包不行. 本次开源针对CelebAMask-HQ中发丝部分进行细化的数据集. 该数据集可用于发丝分割等方向的研究和探索. 在过去的一年时间里,疫情改变很 ...
- 【原】Android热更新开源项目Tinker源码解析系列之三:so热更新
本系列将从以下三个方面对Tinker进行源码解析: Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Android热更新开源项目Tinker源码解析系列之二:资源文件热更新 A ...
- 【原】Android热更新开源项目Tinker源码解析系列之一:Dex热更新
[原]Android热更新开源项目Tinker源码解析系列之一:Dex热更新 Tinker是微信的第一个开源项目,主要用于安卓应用bug的热修复和功能的迭代. Tinker github地址:http ...
- 【原】Android热更新开源项目Tinker源码解析系列之二:资源文件热更新
上一篇文章介绍了Dex文件的热更新流程,本文将会分析Tinker中对资源文件的热更新流程. 同Dex,资源文件的热更新同样包括三个部分:资源补丁生成,资源补丁合成及资源补丁加载. 本系列将从以下三个方 ...
- 哪种缓存效果高?开源一个简单的缓存组件j2cache
背景 现在的web系统已经越来越多的应用缓存技术,而且缓存技术确实是能实足的增强系统性能的.我在项目中也开始接触一些缓存的需求. 开始简单的就用jvm(java托管内存)来做缓存,这样对于单个应用服务 ...
- 开源:Taurus.MVC 框架
为什么要创造Taurus.MVC: 记得被上一家公司忽悠去负责公司电商平台的时候,情况是这样的: 项目原版是外包给第三方的,使用:WebForm+NHibernate,代码不堪入目,Bug无限,经常点 ...
- 终于等到你:CYQ.Data V5系列 (ORM数据层)最新版本开源了
前言: 不要问我框架为什么从收费授权转到免费开源,人生没有那么多为什么,这些年我开源的东西并不少,虽然这个是最核心的,看淡了就也没什么了. 群里的网友:太平说: 记得一年前你开源另一个项目的时候我就说 ...
- 开源:ASP.NET Aries 开发框架
前言: 随着岁月的推进,不知不觉已在.NET这领域上战斗了十年了. 青春还没来得急好好感受,却已是步入健忘之秋的老人一枚了. 趁着还有点记忆,得赶紧把硬盘里那私藏的80G除外的东西,和大伙分享分享. ...
- Taurus.MVC 2.2 开源发布:WebAPI 功能增强(请求跨域及Json转换)
背景: 1:有用户反馈了关于跨域请求的问题. 2:有用户反馈了参数获取的问题. 3:JsonHelper的增强. 在综合上面的条件下,有了2.2版本的更新,也因此写了此文. 开源地址: https:/ ...
随机推荐
- 【Java框架型项目从入门到装逼】第六节 - 用ajax请求后台数据
这一节我们来说一下如何用ajax提交请求? 我们先不讲ajax的原理,还是先以实战为主,看一下这个东西到底怎么用的? form表单: <!-- 采用post表单提交 --> <for ...
- 第五章:大数据 の HBase 进阶
本课主题 HBase 读写数据的流程 HBase 性能优化和最住实践 HBase 管理和集群操作 HBase 备份和复制 引言 前一篇 HBase 基础 (HBase 基础) 简单介绍了NoSQL是什 ...
- window10上登录Oracle时提示ORA-12546:Permission denied
在64位的Windows 10上安装了Oracle 10.2.0.4的64位版,遇到不少问题. 虽然可能现在安装这个版本越来越少,还是分享出来,希望能帮助到一些人. 1.安装的过程遇到的问题 在普通用 ...
- 用Vue自己造个组件轮子,以及实践背后带来的思考
前言 首先,向大家说声抱歉.由于之前的井底之蛙,误认为Vue.js还远没有覆盖到二三线城市的互联网小厂里.现在我错了,从我司的前端技术选型之路便可见端倪.以太原为例,已经有不少公司陆续开始采用Vue. ...
- TCP协议详解(一)
Tcp协议作为传输层的重要协议之一,想必每个稍有网络编程知识的人都不会感觉到陌生,三次握手/四次挥手这些基本概念也都是耳熟能详.但是当你们进行具体的网络编程的时候发现有很多事情并没有想象中的那么简单, ...
- WinForm响应式布局设计实践
引言 创建响应式WinForm应用程序并不那么简单. 响应式布局,在此我指的是应用程序在不同屏幕分辨率下的可用性. 对于WinForm应用程序,我们需要明确地根据分辨率来调整控件的大小和重新定位. 虽 ...
- 在React中你真的用对了Ajax吗?
通过AJAX加载初始数据 通过AJAX加载数据是一个很普遍的场景.在React组件中如何通过AJAX请求来加载数据呢?首先,AJAX请求的源URL应该通过props传入:其次,最好在component ...
- VFS四大对象之三 struct dentry
继上一篇文章介绍了inode结构体:继续介绍目录项dentry: http://www.cnblogs.com/linhaostudy/p/7427794.html 三.dentry结构体 目录项:目 ...
- Centos环境下搭建Asp.NET Core环境和安装Jexus
.NET Core2.0出来以后,很多公司开始用于实践生产,其中的原因想必大家都明白,最主要的一下几点. 跨平台,能够部署在Linux和Docker容器中 性能优越,测试时Node的20倍左右 ...
- 从头开始基于Maven搭建SpringMVC+Mybatis项目(3)
接上文内容,本节介绍基于Mybatis的查询和分页功能,并展示一个自定义的分页标签,可重复使用以简化JSP页面的开发. 从头阅读传送门 在上一节中,我们已经使用Maven搭建好了项目的基础结构,包括一 ...