8000 Use onInitialized instead of old way. Replace tabs with spaces. · metacortex/android-gpuimage@51cec0b · GitHub
[go: up one dir, main page]

Skip to content

Commit 51cec0b

Browse files
author
Patrick Boos
committed
Use onInitialized instead of old way. Replace tabs with spaces.
1 parent 39f28bb commit 51cec0b

File tree

5 files changed

+121
-121
lines changed

5 files changed

+121
-121
lines changed

library/src/jp/co/cyberagent/android/gpuimage/GPUImageExposureFilter.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@
2323
*/
2424
public class GPUImageExposureFilter extends GPUImageFilter {
2525
public static final String EXPOSURE_FRAGMENT_SHADER = "" +
26-
" varying highp vec2 textureCoordinate;\n" +
27-
" \n" +
28-
" uniform sampler2D inputImageTexture;\n" +
29-
" uniform highp float exposure;\n" +
30-
" \n" +
31-
" void main()\n" +
32-
" {\n" +
33-
" highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
34-
" \n" +
35-
" gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w);\n" +
36-
" } ";
26+
" varying highp vec2 textureCoordinate;\n" +
27+
" \n" +
28+
" uniform sampler2D inputImageTexture;\n" +
29+
" uniform highp float exposure;\n" +
30+
" \n" +
31+
" void main()\n" +
32+
" {\n" +
33+
" highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
34+
" \n" +
35+
" gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w);\n" +
36+
" } ";
3737

3838
private int mExposureLocation;
3939
private float mExposure;
40-
private boolean mIsInitialized = false;
4140

4241
public GPUImageExposureFilter() {
4342
this(1.0f);
@@ -52,14 +51,16 @@ public GPUImageExposureFilter(final float exposure) {
5251
public void onInit() {
5352
super.onInit();
5453
mExposureLocation = GLES20.glGetUniformLocation(getProgram(), "exposure");
55-
mIsInitialized = true;
54+
}
55+
56+
@Override
57+
public void onInitialized() {
58+
super.onInitialized();
5659
setExposure(mExposure);
5760
}
5861

5962
public void setExposure(final float exposure) {
6063
mExposure = exposure;
61-
if (mIsInitialized) {
62-
setFloat(mExposureLocation, mExposure);
63-
}
64+
setFloat(mExposureLocation, mExposure);
6465
}
6566
}

library/src/jp/co/cyberagent/android/gpuimage/GPUImageHighlightShadowFilter.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,30 @@
2525
*/
2626
public class GPUImageHighlightShadowFilter extends GPUImageFilter {
2727
public static final String HIGHLIGHT_SHADOW_FRAGMENT_SHADER = "" +
28-
" uniform sampler2D inputImageTexture;\n" +
29-
" varying highp vec2 textureCoordinate;\n" +
30-
" \n" +
31-
" uniform lowp float shadows;\n" +
32-
" uniform lowp float highlights;\n" +
33-
" \n" +
34-
" const mediump vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3);\n" +
35-
" \n" +
36-
" void main()\n" +
37-
" {\n" +
38-
" lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);\n" +
39-
" mediump float luminance = dot(source.rgb, luminanceWeighting);\n" +
40-
" \n" +
41-
" mediump float shadow = clamp((pow(luminance, 1.0/(shadows+1.0)) + (-0.76)*pow(luminance, 2.0/(shadows+1.0))) - luminance, 0.0, 1.0);\n" +
42-
" mediump float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);\n" +
43-
" lowp vec3 result = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));\n" +
44-
" \n" +
45-
" gl_FragColor = vec4(result.rgb, source.a);\n" +
46-
" }";
28+
" uniform sampler2D inputImageTexture;\n" +
29+
" varying highp vec2 textureCoordinate;\n" +
30+
" \n" +
31+
" uniform lowp float shadows;\n" +
32+
" uniform lowp float highlights;\n" +
33+
" \n" +
34+
" const mediump vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3);\n" +
35+
" \n" +
36+
" void main()\n" +
37+
" {\n" +
38+
" lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);\n" +
39+
" mediump float luminance = dot(source.rgb, luminanceWeighting);\n" +
40+
" \n" +
41+
" mediump float shadow = clamp((pow(luminance, 1.0/(shadows+1.0)) + (-0.76)*pow(luminance, 2.0/(shadows+1.0))) - luminance, 0.0, 1.0);\n" +
42+
" mediump float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);\n" +
43+
" lowp vec3 result = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));\n" +
44+
" \n" +
45+
" gl_FragColor = vec4(result.rgb, source.a);\n" +
46+
" }";
4747

4848
private int mShadowsLocation;
4949
private float mShadows;
5050
private int mHighlightsLocation;
5151
private float mHighlights;
52-
private boolean mIsInitialized = false;
5352

5453
public GPUImageHighlightShadowFilter() {
5554
this(0.0f, 1.0f);
@@ -66,22 +65,22 @@ public void onInit() {
6665
super.onInit();
6766
mHighlightsLocation = GLES20.glGetUniformLocation(getProgram(), "highlights");
6867
mShadowsLocation = GLES20.glGetUniformLocation(getProgram(), "shadows");
69-
mIsInitialized = true;
68+
}
69+
70+
@Override
71+
public void onInitialized() {
72+
super.onInitialized();
7073
setHighlights(mHighlights);
7174
setShadows(mShadows);
7275
}
7376

7477
public void setHighlights(final float highlights) {
75-
mHighlights = highlights;
76-
if (mIsInitialized) {
77-
setFloat(mHighlightsLocation, mHighlights);
78-
}
78+
mHighlights = highlights;
79+
setFloat(mHighlightsLocation, mHighlights);
7980
}
8081

8182
public void setShadows(final float shadows) {
8283
mShadows = shadows;
83-
if (mIsInitialized) {
84-
setFloat(mShadowsLocation, mShadows);
85-
}
84+
setFloat(mShadowsLocation, mShadows);
8685
}
8786
}

library/src/jp/co/cyberagent/android/gpuimage/GPUImageMonochromeFilter.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,40 @@
2525
*/
2626
public class GPUImageMonochromeFilter extends GPUImageFilter {
2727
public static final String MONOCHROME_FRAGMENT_SHADER = "" +
28-
" precision lowp float;\n" +
29-
" \n" +
30-
" varying highp vec2 textureCoordinate;\n" +
31-
" \n" +
32-
" uniform sampler2D inputImageTexture;\n" +
33-
" uniform float intensity;\n" +
34-
" uniform vec3 filterColor;\n" +
35-
" \n" +
36-
" const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
37-
" \n" +
38-
" void main()\n" +
39-
" {\n" +
40-
" //desat, then apply overlay blend\n" +
41-
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
42-
" float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
43-
" \n" +
44-
" lowp vec4 desat = vec4(vec3(luminance), 1.0);\n" +
45-
" \n" +
46-
" //overlay\n" +
47-
" lowp vec4 outputColor = vec4(\n" +
48-
" (desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))),\n" +
49-
" (desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))),\n" +
50-
" (desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))),\n" +
51-
" 1.0\n" +
52-
" );\n" +
53-
" \n" +
54-
" //which is better, or are they equal?\n" +
55-
" gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a);\n" +
56-
" }";
28+
" precision lowp float;\n" +
29+
" \n" +
30+< E377 /span>
" varying highp vec2 textureCoordinate;\n" +
31+
" \n" +
32+
" uniform sampler2D inputImageTexture;\n" +
33+
" uniform float intensity;\n" +
34+
" uniform vec3 filterColor;\n" +
35+
" \n" +
36+
" const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
37+
" \n" +
38+
" void main()\n" +
39+
" {\n" +
40+
" //desat, then apply overlay blend\n" +
41+
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
42+
" float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
43+
" \n" +
44+
" lowp vec4 desat = vec4(vec3(luminance), 1.0);\n" +
45+
" \n" +
46+
" //overlay\n" +
47+
" lowp vec4 outputColor = vec4(\n" +
48+
" (desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))),\n" +
49+
" (desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))),\n" +
50+
" (desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))),\n" +
51+
" 1.0\n" +
52+
" );\n" +
53+
" \n" +
54+
" //which is better, or are they equal?\n" +
55+
" gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a);\n" +
56+
" }";
5757

5858
private int mIntensityLocation;
5959
private float mIntensity;
6060
private int mFilterColorLocation;
6161
private float[] mColor;
62-
private boolean mIsInitialized = false;
6362

6463
public GPUImageMonochromeFilter() {
6564
this(1.0f, new float[] {0.6f, 0.45f, 0.3f, 1.0f});
@@ -76,17 +75,18 @@ public void onInit() {
7675
super.onInit();
7776
mIntensityLocation = GLES20.glGetUniformLocation(getProgram(), "intensity");
7877
mFilterColorLocation = GLES20.glGetUniformLocation(getProgram(), "filterColor");
79-
mIsInitialized = true;
80-
78+
}
79+
80+
@Override
81+
public void onInitialized() {
82+
super.onInitialized();
8183
setIntensity(1.0f);
8284
setColor(new float[]{ 0.6f, 0.45f, 0.3f, 1.f });
8385
}
84-
86+
8587
public void setIntensity(final float intensity) {
8688
mIntensity = intensity;
87-
if (mIsInitialized) {
88-
setFloat(mIntensityLocation, mIntensity);
89-
}
89+
setFloat(mIntensityLocation, mIntensity);
9090
}
9191

9292
public void setColor(final float[] color) {
@@ -96,8 +96,6 @@ public void setColor(final float[] color) {
9696
}
9797

9898
public void setColorRed(final float red, final float green, final float blue) {
99-
if (mIsInitialized) {
100-
setFloatVec3(mFilterColorLocation, new float[]{ red, green, blue });
101-
}
99+
setFloatVec3(mFilterColorLocation, new float[]{ red, green, blue });
102100
}
103101
}

library/src/jp/co/cyberagent/android/gpuimage/GPUImageOpacityFilter.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@
2424
*/
2525
public class GPUImageOpacityFilter extends GPUImageFilter {
2626
public static final String OPACITY_FRAGMENT_SHADER = "" +
27-
" varying highp vec2 textureCoordinate;\n" +
28-
" \n" +
29-
" uniform sampler2D inputImageTexture;\n" +
30-
" uniform lowp float opacity;\n" +
31-
" \n" +
32-
" void main()\n" +
33-
" {\n" +
34-
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
35-
" \n" +
36-
" gl_FragColor = vec4(textureColor.rgb, textureColor.a * opacity);\n" +
37-
" }\n";
27+
" varying highp vec2 textureCoordinate;\n" +
28+
" \n" +
29+
" uniform sampler2D inputImageTexture;\n" +
30+
" uniform lowp float opacity;\n" +
31+
" \n" +
32+
" void main()\n" +
33+
" {\n" +
34+
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
35+
" \n" +
36+
" gl_FragColor = vec4(textureColor.rgb, textureColor.a * opacity);\n" +
37+
" }\n";
3838

3939
private int mOpacityLocation;
4040
private float mOpacity;
41-
private boolean mIsInitialized = false;
4241

4342
public GPUImageOpacityFilter() {
4443
this(1.0f);
@@ -53,14 +52,16 @@ public GPUImageOpacityFilter(final float opacity) {
5352
public void onInit() {
5453
super.onInit();
5554
mOpacityLocation = GLES20.glGetUniformLocation(getProgram(), "opacity");
56-
mIsInitialized = true;
55+
}
56+
57+
@Override
58+
public void onInitialized() {
59+
super.onInitialized();
5760
setOpacity(mOpacity);
5861
}
5962

6063
public void setOpacity(final float opacity) {
6164
mOpacity = opacity;
62-
if (mIsInitialized) {
63-
setFloat(mOpacityLocation, mOpacity);
64-
}
65+
setFloat(mOpacityLocation, mOpacity);
6566
}
6667
}

library/src/jp/co/cyberagent/android/gpuimage/GPUImageSaturationFilter.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,26 @@
2323
*/
2424
public class GPUImageSaturationFilter extends GPUImageFilter {
2525
public static final String SATURATION_FRAGMENT_SHADER = "" +
26-
" varying highp vec2 textureCoordinate;\n" +
27-
" \n" +
28-
" uniform sampler2D inputImageTexture;\n" +
29-
" uniform lowp float saturation;\n" +
30-
" \n" +
31-
" // Values from \"Graphics Shaders: Theory and Practice\" by Bailey and Cunningham\n" +
32-
" const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
33-
" \n" +
34-
" void main()\n" +
35-
" {\n" +
36-
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
37-
" lowp float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
38-
" lowp vec3 greyScaleColor = vec3(luminance);\n" +
39-
" \n" +
40-
" gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);\n" +
41-
" \n" +
42-
" }";
26+
" varying highp vec2 textureCoordinate;\n" +
27+
" \n" +
28+
" uniform sampler2D inputImageTexture;\n" +
29+
" uniform lowp float saturation;\n" +
30+
" \n" +
31+
" // Values from \"Graphics Shaders: Theory and Practice\" by Bailey and Cunningham\n" +
32+
" const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
33+
" \n" +
34+
" void main()\n" +
35+
" {\n" +
36+
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
37+
" lowp float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
38+
" lowp vec3 greyScaleColor = vec3(luminance);\n" +
39+
" \n" +
40+
" gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);\n" +
41+
" \n" +
42+
" }";
4343

4444
private int mSaturationLocation;
4545
private float mSaturation;
46-
private boolean mIsInitialized = false;
4746

4847
public GPUImageSaturationFilter() {
4948
this(1.0f);
@@ -58,14 +57,16 @@ public GPUImageSaturationFilter(final float saturation) {
5857
public void onInit() {
5958
super.onInit();
6059
mSaturationLocation = GLES20.glGetUniformLocation(getProgram(), "saturation");
61-
mIsInitialized = true;
60+
}
61+
62+
@Override
63+
public void onInitialized() {
64+
super.onInitialized();
6265
setSaturation(mSaturation);
6366
}
6467

6568
public void setSaturation(final float saturation) {
6669
mSaturation = saturation;
67-
if (mIsInitialized) {
68-
setFloat(mSaturationLocation, mSaturation);
69-
}
70+
setFloat(mSaturationLocation, mSaturation);
7071
}
7172
}

0 commit comments

Comments
 (0)
0