Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Drag Distortion Image filter in android?

I am working on custom image filter project. And I came across one challenging task, in which I am supposed to apply distorted filters as can be seen in Funny face effect app. I want to develop first 3 filters as available in Funny Face Effects.

So to implement such an effect I started using GPUImageView GPUImage and in this, it is using seekbar to distort image from the centre. I have achieved Bulge distortion from this. But is there any way I can implement drag filter, where I can distort my image by drag gesture?

We tried to search for any other third party classes other then GPUImage. But we could not find useful stuff.

Our queries are as under:-

1) Is it possible to apply Drag filter using Drag gesture? (Any code snippet or reference appreciable)

2) Any other third party class other than GPU which can help us to get above results.

Thanks in advance!

enter image description here

like image 667
Malik Motani Avatar asked Apr 07 '17 13:04

Malik Motani


1 Answers

One way to achieve it is to use an additional texture to specify to the fragment shader the deformation to apply. You can modify that texture contents from the app as the user touches the image to apply deformations.

GPUImageBulgeDistortionFilter extends GPUImageFilter which is designed to use only one texture.

You'll need to duplicate the texture binding (glBindTexture) and assignation to the fragment shader (glUniform1i) in GPUImageFilter using 1 for the new texture (instead of 0). You'll need also to duplicate glGetUniformLocation and use other name instead of inputImageTexture, for example inputImageTexture2.

Modify the fragment shader at GPUImageBulgeDistortionFilter or create a new class derived from GPUImageBulgeDistortionFilter to add "uniform sampler2D inputImageTexture2;\n" +

Finally add code to use inputImageTexture2 texels to deform data at inputImageTexture in the same fragment shader.

like image 151
user1039663 Avatar answered Oct 12 '22 21:10

user1039663