iOS濾鏡實現之LOMO(美圖秀秀經典LOMO),ioslomo

來源:互聯網
上載者:User

iOS濾鏡實現之LOMO(美圖秀秀經典LOMO),ioslomo

  LOMO追求鮮豔色彩,隨意、自由的態度,是一種經常使用的濾鏡,今天介紹一下iOS 中LOMO濾鏡的實現

首先它有3張輸入映像

1.我們要處理的映像。即我們要應用LOMO濾鏡的映像

2      

3

在gpuimage中多張輸入映像的濾鏡需要自己寫。在這裡我參照本身提供的GPUImageTwoInputFilter,自己寫了GPUImageThreeInputFilter,用於接收3張輸入映像的濾鏡。它們都是通過濾鏡組的繼承來實現,多重濾鏡。

  

  片段著色器

NSString *const kFWLomofiShaderString = SHADER_STRING( precision lowp float;  varying highp vec2 textureCoordinate;  uniform sampler2D inputImageTexture; uniform sampler2D inputImageTexture2; uniform sampler2D inputImageTexture3;  void main() {          vec3 texel = texture2D(inputImageTexture, textureCoordinate).rgb;//擷取要處理映像的rgb值向量          vec2 red = vec2(texel.r, 0.16666);     vec2 green = vec2(texel.g, 0.5);     vec2 blue = vec2(texel.b, 0.83333);//使要處理的映像和柔光混合,產生新的像素          texel.rgb = vec3(                      texture2D(inputImageTexture2, red).r,                      texture2D(inputImageTexture2, green).g,                      texture2D(inputImageTexture2, blue).b);//前面產生新的像素再與第二個輸入映像的像素進行混合     //使用第三個映像作為暗角模板與前面的像素混合     vec2 tc = (2.0 * textureCoordinate) - 1.0;     float d = dot(tc, tc);     vec2 lookup = vec2(d, texel.r);     texel.r = texture2D(inputImageTexture3, lookup).r;     lookup.y = texel.g;     texel.g = texture2D(inputImageTexture3, lookup).g;     lookup.y = texel.b;     texel.b    = texture2D(inputImageTexture3, lookup).b;
//產生最終的LOMO效果
gl_FragColor = vec4(texel,1.0); } );

 

 

@implementation FWLomofiFilter- (id)init{    if (!(self = [super init]))    {        return nil;    }        FWFilter6 *filter = [[FWFilter6 alloc] init];    [self addFilter:filter];//設定第二個輸入映像    UIImage *image = [UIImage imageNamed:@"lomoMap"];    imageSource1 = [[GPUImagePicture alloc] initWithImage:image];    [imageSource1 addTarget:filter atTextureLocation:1];    [imageSource1 processImage];
//設定第三個輸入映像
UIImage *image1 = [UIImage imageNamed:@"vignetteMap"]; imageSource2 = [[GPUImagePicture alloc] initWithImage:image1]; [imageSource2 addTarget:filter atTextureLocation:2]; [imageSource2 processImage]; self.initialFilters = [NSArray arrayWithObjects:filter, nil]; self.terminalFilter = filter; return self; }

 

 

+ (UIImage *)applyLomofiFilter:(UIImage *)image

{

    FWLomofiFilter *filter = [[FWLomofiFilter alloc] init];

    [filter forceProcessingAtSize:image.size];

//第一個輸入映像

   GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image];

    [pic addTarget:filter];

    

    [pic processImage];

    [filter useNextFrameForImageCapture];

//得到

    return [filter imageFromCurrentFramebuffer];

}

 

原圖

 

lomo

 

 完整代碼可以在本人的GITHUB上下載源碼!

 

下面是廢話

不善言辭的人進部落格園首頁就這麼難,我得寫多少廢話才能進?這篇可以嗎? 不管文字多少,你上網查查ios實現LOMO濾鏡的源碼,本濾鏡純自己琢磨,在上一代GPUImage中我通過1個多月的摸索,將多映像濾鏡實現的。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.