Cpuimage Open Source: cpuimage Open Source

Source: Internet
Author: User

Cpuimage Open Source: cpuimage Open Source

A little thing we learned about opengl the year before.

It was originally planned to convert the gpuimage algorithm into the cpu Version c and c ++ versions one by one.

Gpuimage project reference:

Https://github.com/BradLarson/GPUImage

Https://github.com/BradLarson/GPUImage2

Https://github.com/CyberAgent/android-gpuimage

After that, the task was put on hold because there were too many things at work.

I turned it out today and changed it from c ++ to c code,

If the correctness of each algorithm is not verified, you can modify it later.

Paste the header file,

Write down most gpuimage algorithms with the cpu processing logic and perform some basic optimization.

# Include <math. h> # include <stdio. h> # include <stdlib. h> # include <stdbool. h> typedef struct {// minimum color level int levelMinimum; // intermediate color level int levelMiddle; // maximum color level int levelMaximum; // minimum output value int minOutput; // maximum output value int maxOutput; // whether bool Enable is applied;} 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 HSV 2rgb (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 invalid 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.0 fvoid CPUImageRGBFilter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float redAdjustment, float greenAdjustment, float blueAdjustment); // float thresholdMultiplier = 1.0 fvoid encode (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.0 fvoid 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 placement = 0.2f, float smoothing = 0.1 fvoid CPUImageChromaKeyFilter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, unsigned char colorToReplaceR, unsigned char colorToReplaceG, unsigned char colorToReplaceB, float transform, float smoothing); // int intensity = 100 void encode (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.0 fvoid CPUImageGammaFilter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float gamma); // float contrast = 1.0 fvoid CPUImageContrastFilter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float contrast); // float exposure = 0.0 fvoid CPUImageExposureFilter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float exposure ); // int brightness = 0.0 fvoid 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 encode (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float distance, float slope, int intensity); // float opacity = 1.0 fvoid 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 * blocks); // float duration = 90.0 fvoid CPUImageHueFilter (unsigned char * Input, unsigned char * Output, int Width, Height int, int Stride, float gradient); // float gradient = 1.0f, float shadowTintG = 0.0f, float shadowTintB = 0.0f, float gradient = 0.0f, float highlightTintG = 0.0f, float gradient = 1.0f, float counter = 0.0f, float counter = 0.0 fvoid counter (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float shadowTintR, float shadowTintG, float shadowTintB, float functions, float highlightTintG, float highlightTintB, float functions, float functions); // float shadows = 0.0f, float highlights = 1.0 fvoid functions (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, 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 outputs = 80366f, float maxHueShift = 0.25f, float maxSaturationShift = 0.4f, int outputs = 0 void outputs (unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float values, float skinHue, float values, float maxHueShift, float maxSaturationShift, int values); // float fraction = 0.05 fvoid CPUImageAutoLevel (const unsigned char * Input, unsigned char * Output, int Width, int Height, int Stride, float fraction); // specify Color adjustments attributes // specify 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, Height, int srcStride, unsigned char * Output, int cropX, int cropY, int dstWidth, int dstHeight, int dstStride); // ------------------------ Image processing --------------------------

It is better to teach people to fish than to teach them to fish and send them out.

Project address:

Https://github.com/cpuimage/cpuimage

It may take some time to optimize it with omp and simd.

Maybe one day I flipped through the hard drive and turned out some old antiques.

This is an exercise we did when we first learned about image algorithms. The Code style is scum and the idea is bad. If you don't like it, Please spray it.

 

If you have any other questions or requirements, contact us via email.

The email address is:
Gaozhihan@vip.qq.com

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.