iOS --- 使用GPUImage實現的簡單濾鏡效果

來源:互聯網
上載者:User

iOS --- 使用GPUImage實現的簡單濾鏡效果

GPUImage 是一個基於 GPU 映像和視頻處理的開源 iOS 架構。由於使用 GPU 來處理映像和視頻,所以速度非常快. 除了速度上的優勢,GPUImage 還提供了很多很棒的影像處理濾鏡,但有時候這些準系統仍然無法滿足實際開發中的需求,GPUImage 還支援自訂濾鏡.

簡單濾鏡
GPUImageSepiaFilter *filter = [[GPUImageSepiaFilter alloc] init];_filteredImage = [filter imageByFilteringImage:_originImage];


GPUImage將大多數的濾鏡效果都做了如上類似的封裝, 因此使用非常簡便. 使用的時候可以直接在GPUImage.h中尋找.

自訂濾鏡

GPUImage的自訂濾鏡需要使用到OpenGL著色語言(GLSL)來編寫Fragment Shader(片段著色器), 且尾碼為.fsh. 至於GLSL的文法等內容, 暫時不多做說明, 以後會單獨補充.

GPUImageFilter *customFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@GPUImageCustomFilter];_filteredImage = [customFilter imageByFilteringImage:_originImage];

GLSL指令檔(GPUImageCustomFilter.fsh)如下:

varying highp vec2 textureCoordinate;uniform sampler2D inputImageTexture;void main(){    lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);    lowp vec4 outputColor;    outputColor.r = (textureColor.r * 0.393) + (textureColor.g * 0.769) + (textureColor.b * 0.189);    outputColor.g = (textureColor.r * 0.349) + (textureColor.g * 0.686) + (textureColor.b * 0.168);    outputColor.b = (textureColor.r * 0.872) + (textureColor.g * 0.534) + (textureColor.b * 0.131);    outputColor.a = 1.0;    gl_FragColor = outputColor;}

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.