cpuimage 開源之

来源:https://www.cnblogs.com/tntmonks/archive/2018/01/30/8387359.html
-Advertisement-
Play Games

前年學習opengl做的一個小東西。 原本計劃將gpuimage 的演算法一個一個轉寫成cpu版本 c,c++ 版本。 gpuimage 項目參考: https://github.com/BradLarson/GPUImage https://github.com/BradLarson/GPUImag ...


前年學習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優化,嗯會有時間的。

也許哪天翻翻硬碟,又翻出一些老古董了。

這是剛學圖像演算法時候做的練習,代碼風格渣,思路爛,不喜請噴。

 

若有其他相關問題或者需求也可以郵件聯繫俺探討。

郵箱地址是: 
[email protected]

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 作為一枚程式猿,我決心也自己搞一下,不為別的,一來為了磨練一下自己的解決問題的能力,而來也為了娛樂一下。像這種任務,最適合的當然是Python,豐富的第三方庫,而且具有膠水語言的特點。 ...
  • 1.os模塊操作 os.getcwd(): # 查看當前所在路徑。 os.listdir(path): # 列舉目錄下的所有文件,返回的是列表類型。 os.path.abspath(path): # 返回path的絕對路徑。 os.path.join(path1,path2,...): # 將pat ...
  • 本節內容: 格式化輸入輸出——Hello World. 表達式if...else 條件語句. 表達式for 迴圈. 表達式while迴圈 and continue. break跳出迴圈. ...
  • #python中不存在單個字元的運算,只有字元串函數 >>> s="www.google.com" >>> s 'www.google.com' >>> s.split('.') #無參數全部切割 ['www', 'google', 'com'] >>> s.split('.',1) #分隔一次 [ ...
  • 1、安裝好個版本jdk 以自己電腦舉例:jdk 1.6 和 jdk 1.8 2、修改環境變數 - JAVA_HOME 本機: 1.6:D:\Java\jdk1.6.0_45 1.8:D:\Java\jdk1.8.0_152 3、修改 Java 控制面板中版本的啟用 【控制面板】-【程式】-【Java ...
  • 使用 getch() 函數,需要先引入 conio.h 頭文件 然而,我使用的是 cygwin 作為編譯環境,找不到 conio.h ,所以只能想辦法找替代方法,或者自己構造一個具有類似功能的函數。 可惜,剛學編程沒多久,一時之間也是沒有想到什麼合適的替代方法,若說自己構造這個函數,這就更難了。 於 ...
  • 1.A 演算法 我們普通的搜索演算法往往複雜度都是指數級,OI中這樣的複雜度無法滿足我們的要求。這時我們一般都會進行一些剪枝優化,但在有些題目中卻可以有更加巧妙的方法——A 演算法。 A 演算法作為一種基礎的啟髮式搜索,它不同於DFS和BFS將所有情況進行遍歷,它能從所有情況中選出較優的再進行遍歷。因此,它 ...
  • 一.使用environ指針輸出環境變數 代碼如下: ~~~~ include include define MAX_INPUT 20 / 引用指針 / extern char environ; int main(int argc, char argv) { char temp = NULL; cha ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...