Revision bf2e8f97
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/examples/blur/BlurActivity.java | ||
---|---|---|
33 | 33 |
|
34 | 34 |
public class BlurActivity extends Activity implements OnSeekBarChangeListener |
35 | 35 |
{ |
36 |
private TextView textBlur; |
|
36 |
private TextView textBlur, textHalo, textMove;
|
|
37 | 37 |
|
38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 39 |
|
... | ... | |
42 | 42 |
{ |
43 | 43 |
super.onCreate(icicle); |
44 | 44 |
setContentView(R.layout.blurlayout); |
45 |
|
|
45 | 46 |
textBlur = findViewById(R.id.blurText); |
46 |
SeekBar bar = findViewById(R.id.blurSeek); |
|
47 |
bar.setOnSeekBarChangeListener(this); |
|
48 |
bar.setProgress(50); |
|
47 |
textHalo = findViewById(R.id.haloText); |
|
48 |
textMove = findViewById(R.id.moveText); |
|
49 |
|
|
50 |
SeekBar barB = findViewById(R.id.blurSeek); |
|
51 |
barB.setOnSeekBarChangeListener(this); |
|
52 |
barB.setProgress(50); |
|
53 |
|
|
54 |
SeekBar barH = findViewById(R.id.haloSeek); |
|
55 |
barH.setOnSeekBarChangeListener(this); |
|
56 |
barH.setProgress(50); |
|
57 |
|
|
58 |
SeekBar barM = findViewById(R.id.moveSeek); |
|
59 |
barM.setOnSeekBarChangeListener(this); |
|
60 |
barM.setProgress(50); |
|
49 | 61 |
} |
50 | 62 |
|
51 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
84 | 96 |
{ |
85 | 97 |
BlurSurfaceView view = findViewById(R.id.blurSurfaceView); |
86 | 98 |
|
87 |
if (bar.getId() == R.id.blurSeek)
|
|
99 |
switch( bar.getId() )
|
|
88 | 100 |
{ |
89 |
int level = view.getRenderer().setBlur(progress); |
|
90 |
textBlur.setText(getString(R.string.blur_placeholder,level)); |
|
101 |
case R.id.blurSeek: int l1 = view.getRenderer().setBlur(progress); |
|
102 |
textBlur.setText(getString(R.string.blur_placeholder,l1)); |
|
103 |
break; |
|
104 |
case R.id.haloSeek: int l2 = view.getRenderer().setHalo(progress); |
|
105 |
textHalo.setText(getString(R.string.halo_placeholder,l2)); |
|
106 |
break; |
|
107 |
case R.id.moveSeek: int l3 = view.getRenderer().setMove(progress); |
|
108 |
textMove.setText(getString(R.string.move_placeholder,l3)); |
|
109 |
break; |
|
91 | 110 |
} |
92 | 111 |
} |
93 | 112 |
|
src/main/java/org/distorted/examples/blur/BlurRenderer.java | ||
---|---|---|
24 | 24 |
import android.opengl.GLSurfaceView; |
25 | 25 |
|
26 | 26 |
import org.distorted.examples.R; |
27 |
import org.distorted.library.effect.MatrixEffectMove; |
|
27 | 28 |
import org.distorted.library.effect.MatrixEffectScale; |
28 | 29 |
import org.distorted.library.effect.PostprocessEffectBlur; |
29 | 30 |
import org.distorted.library.main.DistortedLibrary; |
30 | 31 |
import org.distorted.library.main.DistortedEffects; |
31 | 32 |
import org.distorted.library.main.DistortedFramebuffer; |
32 |
import org.distorted.library.main.DistortedNode; |
|
33 | 33 |
import org.distorted.library.main.DistortedScreen; |
34 | 34 |
import org.distorted.library.main.DistortedTexture; |
35 | 35 |
import org.distorted.library.mesh.MeshRectangles; |
... | ... | |
48 | 48 |
class BlurRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener |
49 | 49 |
{ |
50 | 50 |
private final static int SIZE = 500; |
51 |
private final static float PART = 0.5f; |
|
51 | 52 |
|
52 | 53 |
private GLSurfaceView mView; |
53 | 54 |
private DistortedTexture mTexture; |
... | ... | |
56 | 57 |
private DistortedFramebuffer mBuffer; |
57 | 58 |
private MeshRectangles mMesh, mMeshBuffer; |
58 | 59 |
private Static2D mHaloRadiusSta; |
59 |
private Static3D mScale, mBufferScale; |
|
60 |
private Static3D mMove, mScale, mBufferScale;
|
|
60 | 61 |
|
61 | 62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
62 | 63 |
|
... | ... | |
72 | 73 |
Dynamic2D haloAndRadiusDyn = new Dynamic2D(); |
73 | 74 |
haloAndRadiusDyn.add(mHaloRadiusSta); |
74 | 75 |
|
76 |
mMove = new Static3D(0,0,0); |
|
75 | 77 |
mScale= new Static3D(1,1,1); |
76 | 78 |
mBufferScale= new Static3D(1,1,1); |
77 | 79 |
|
78 | 80 |
mBufferEffects = new DistortedEffects(); |
79 | 81 |
mBufferEffects.apply(new MatrixEffectScale(mBufferScale)); |
82 |
mBufferEffects.apply(new PostprocessEffectBlur(haloAndRadiusDyn)); |
|
80 | 83 |
|
81 | 84 |
mEffects = new DistortedEffects(); |
82 |
mEffects.apply( new PostprocessEffectBlur(haloAndRadiusDyn) ); |
|
83 | 85 |
mEffects.apply(new MatrixEffectScale(mScale)); |
86 |
mEffects.apply(new MatrixEffectMove(mMove)); |
|
84 | 87 |
} |
85 | 88 |
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
// 0 --> (SIZE-factor2) * -0.5 |
|
91 |
// 50 --> (SIZE-factor2) * 0.0 |
|
92 |
// 100 --> (SIZE-factor2) * +0.5 |
|
93 |
|
|
94 |
int setMove(int move) |
|
95 |
{ |
|
96 |
float xmove = (1-PART)*SIZE*(move-50)*0.01f; |
|
97 |
mMove.set0(xmove); |
|
98 |
return (int)xmove; |
|
99 |
} |
|
100 |
|
|
101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
102 |
|
|
103 |
int setHalo(int halo) |
|
104 |
{ |
|
105 |
int radius = halo; |
|
106 |
mHaloRadiusSta.set0(radius); |
|
107 |
return radius; |
|
108 |
} |
|
109 |
|
|
86 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 | 111 |
|
88 | 112 |
int setBlur(int blur) |
... | ... | |
106 | 130 |
|
107 | 131 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
108 | 132 |
{ |
109 |
float factor1 = 0.8f* (Math.min(width, height)); |
|
110 |
|
|
133 |
float factor1 = Math.min(width, height); |
|
111 | 134 |
mBufferScale.set( factor1,factor1,factor1 ); |
112 | 135 |
|
113 |
float factor2 = 0.9f*SIZE; |
|
114 |
|
|
136 |
float factor2 = PART*SIZE; |
|
115 | 137 |
mScale.set( factor2,factor2,factor2 ); |
116 | 138 |
|
117 | 139 |
mScreen.resize(width, height); |
... | ... | |
141 | 163 |
mTexture.setTexture(bitmap); |
142 | 164 |
|
143 | 165 |
mScreen.detachAll(); |
166 |
mBuffer.detachAll(); |
|
167 |
|
|
144 | 168 |
mScreen.attach(mBuffer, mBufferEffects, mMeshBuffer); |
145 |
mBuffer.attach(new DistortedNode(mTexture,mEffects,mMesh));
|
|
169 |
mBuffer.attach(mTexture,mEffects,mMesh);
|
|
146 | 170 |
|
147 | 171 |
PostprocessEffectBlur.enable(); |
148 | 172 |
|
src/main/res/layout/blurlayout.xml | ||
---|---|---|
11 | 11 |
android:layout_weight="1" /> |
12 | 12 |
|
13 | 13 |
<LinearLayout |
14 |
android:id="@+id/linearLayout1" |
|
14 |
android:layout_width="fill_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:gravity="center|fill_horizontal" |
|
17 |
android:orientation="horizontal" > |
|
18 |
|
|
19 |
<TextView |
|
20 |
android:id="@+id/haloText" |
|
21 |
android:layout_width="150dp" |
|
22 |
android:layout_height="wrap_content" |
|
23 |
android:layout_weight="0.5" |
|
24 |
android:gravity="center_vertical|center" |
|
25 |
android:text="@string/blur" |
|
26 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
27 |
|
|
28 |
<SeekBar |
|
29 |
android:id="@+id/haloSeek" |
|
30 |
android:layout_width="fill_parent" |
|
31 |
android:layout_height="wrap_content" |
|
32 |
android:layout_weight="1" |
|
33 |
android:paddingLeft="15dp" |
|
34 |
android:paddingRight="10dp" /> |
|
35 |
|
|
36 |
</LinearLayout> |
|
37 |
|
|
38 |
<LinearLayout |
|
15 | 39 |
android:layout_width="fill_parent" |
16 | 40 |
android:layout_height="wrap_content" |
17 | 41 |
android:gravity="center|fill_horizontal" |
... | ... | |
36 | 60 |
|
37 | 61 |
</LinearLayout> |
38 | 62 |
|
63 |
<LinearLayout |
|
64 |
android:layout_width="fill_parent" |
|
65 |
android:layout_height="wrap_content" |
|
66 |
android:gravity="center|fill_horizontal" |
|
67 |
android:orientation="horizontal" > |
|
68 |
|
|
69 |
<TextView |
|
70 |
android:id="@+id/moveText" |
|
71 |
android:layout_width="150dp" |
|
72 |
android:layout_height="wrap_content" |
|
73 |
android:layout_weight="0.5" |
|
74 |
android:gravity="center_vertical|center" |
|
75 |
android:text="@string/blur" |
|
76 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
77 |
|
|
78 |
<SeekBar |
|
79 |
android:id="@+id/moveSeek" |
|
80 |
android:layout_width="fill_parent" |
|
81 |
android:layout_height="wrap_content" |
|
82 |
android:layout_weight="1" |
|
83 |
android:paddingLeft="15dp" |
|
84 |
android:paddingRight="10dp" /> |
|
85 |
|
|
86 |
</LinearLayout> |
|
87 |
|
|
39 | 88 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
117 | 117 |
<string name="near_placeholder">Near: %1$.2f</string> |
118 | 118 |
<string name="wind_placeholder">Wind: %1$d</string> |
119 | 119 |
<string name="blur_placeholder">Blur: %1$d</string> |
120 |
<string name="halo_placeholder">Halo: %1$d</string> |
|
121 |
<string name="move_placeholder">Move: %1$d</string> |
|
120 | 122 |
<string name="glow_radius_placeholder">Radius: %1$d</string> |
121 | 123 |
<string name="glow_alpha_placeholder">Alpha: %1$.2f</string> |
122 | 124 |
<string name="inflate_placeholder">Inflate: %1$.2f</string> |
Also available in: Unified diff
Improve the Blur App to catch the bug where a small part of the Blur (and Glow) halo gets displayed on the other edge of the surface.