-
Notifications
You must be signed in to change notification settings - Fork 88
/
ContrastEffect.java
40 lines (34 loc) · 1.25 KB
/
ContrastEffect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.sherazkhilji.videffects;
import android.opengl.GLSurfaceView;
import com.sherazkhilji.videffects.interfaces.ShaderInterface;
/**
* Adjusts the contrast of the video.
*
* @author sheraz.khilji
*/
public class ContrastEffect implements ShaderInterface {
private float contrast;
/**
* Initialize Effect
*
* @param contrast Range should be between 0.1- 2.0 with 1.0 being normal.
*/
public ContrastEffect(float contrast) {
if (contrast < 0.1f)
contrast = 0.1f;
if (contrast > 2.0f)
contrast = 2.0f;
this.contrast = contrast;
}
@Override
public String getShader(GLSurfaceView mGlSurfaceView) {
return "#extension GL_OES_EGL_image_external : require\n"
+ "precision mediump float;\n"
+ "uniform samplerExternalOES sTexture;\n"
+ " float contrast;\n" + "varying vec2 vTextureCoord;\n"
+ "void main() {\n" + " contrast =" + contrast + ";\n"
+ " vec4 color = texture2D(sTexture, vTextureCoord);\n"
+ " color -= 0.5;\n" + " color *= contrast;\n"
+ " color += 0.5;\n" + " gl_FragColor = color;\n" + "}\n";
}
}