Project

General

Profile

« Previous | Next » 

Revision 43bda3db

Added by Leszek Koltunski over 7 years ago

New 'Blur' App. Actual BLUR effect, of course, does not work.

View differences:

src/main/AndroidManifest.xml
43 43
        <activity android:name=".wind.WindActivity"/>
44 44
        <activity android:name=".aroundtheworld.AroundTheWorldActivity"/>
45 45
        <activity android:name=".mirror.MirrorActivity"/>
46
        <activity android:name=".blur.BlurActivity"/>
46 47
    </application>
47 48
</manifest>
src/main/java/org/distorted/examples/TableOfContents.java
61 61
import org.distorted.examples.flag.FlagActivity;
62 62
import org.distorted.examples.wind.WindActivity;
63 63
import org.distorted.examples.mirror.MirrorActivity;
64
import org.distorted.examples.blur.BlurActivity;
64 65

  
65 66
///////////////////////////////////////////////////////////////////////////////////////////////////
66 67

  
......
326 327
      activityMapping.put(i++, MirrorActivity.class);
327 328
   }
328 329

  
330
   {
331
      final Map<String, Object> item = new HashMap<>();
332
      item.put(ITEM_IMAGE, R.drawable.icon_example_blur);
333
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_blur));
334
      item.put(ITEM_SUBTITLE, getText(R.string.example_blur_subtitle));
335
      data.add(item);
336
      activityMapping.put(i++, BlurActivity.class);
337
   }
338

  
329 339
   final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
330 340
   setListAdapter(dataAdapter);  
331 341
      
src/main/java/org/distorted/examples/blur/BlurActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.blur;
21

  
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.widget.SeekBar;
26
import android.widget.SeekBar.OnSeekBarChangeListener;
27
import android.widget.TextView;
28

  
29
import org.distorted.examples.R;
30
import org.distorted.library.Distorted;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
public class BlurActivity extends Activity  implements OnSeekBarChangeListener
35
{
36
    private TextView textBlur;
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
    
40
    @Override
41
    protected void onCreate(Bundle icicle) 
42
      {
43
      super.onCreate(icicle);
44
      
45
      setContentView(R.layout.blurlayout);
46

  
47
      textBlur = (TextView)findViewById(R.id.blurText);
48

  
49
      SeekBar bar = (SeekBar)findViewById(R.id.blurSeek);
50

  
51
      bar.setOnSeekBarChangeListener(this);
52
      bar.setProgress(50);
53
      }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
    
57
    @Override
58
    protected void onPause() 
59
      {
60
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.blurSurfaceView);
61
      view.onPause();
62
      
63
      super.onPause();
64
      }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    @Override
69
    protected void onResume() 
70
      {
71
      super.onResume();
72
      
73
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.blurSurfaceView);
74
      view.onResume();
75
      }
76
 
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
    
79
    @Override
80
    protected void onDestroy() 
81
      {
82
      Distorted.onDestroy();  
83
      super.onDestroy();
84
      }
85
   
86
///////////////////////////////////////////////////////////////////
87
    
88
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
89
      {
90
      BlurSurfaceView view = (BlurSurfaceView) this.findViewById(R.id.blurSurfaceView);
91

  
92
      switch (bar.getId()) 
93
        {
94
        case R.id.blurSeek: view.getRenderer().setBlur(progress);
95
                            textBlur.setText(getString(R.string.blur_placeholder,progress));
96
                            break;
97
        }
98
      }
99

  
100
///////////////////////////////////////////////////////////////////
101

  
102
    public void onStartTrackingTouch(SeekBar bar) { }
103
    
104
///////////////////////////////////////////////////////////////////
105

  
106
    public void onStopTrackingTouch(SeekBar bar)  { }
107
     
108
}
src/main/java/org/distorted/examples/blur/BlurRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.blur;
21

  
22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24
import android.opengl.GLES20;
25
import android.opengl.GLSurfaceView;
26

  
27
import org.distorted.examples.R;
28
import org.distorted.library.Distorted;
29
import org.distorted.library.DistortedEffects;
30
import org.distorted.library.DistortedFramebuffer;
31
import org.distorted.library.DistortedTexture;
32
import org.distorted.library.EffectTypes;
33
import org.distorted.library.MeshFlat;
34
import org.distorted.library.type.Dynamic1D;
35
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static2D;
37
import org.distorted.library.type.Static3D;
38

  
39
import java.io.IOException;
40
import java.io.InputStream;
41

  
42
import javax.microedition.khronos.egl.EGLConfig;
43
import javax.microedition.khronos.opengles.GL10;
44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
class BlurRenderer implements GLSurfaceView.Renderer
48
{
49
    private GLSurfaceView mView;
50
    private DistortedTexture mTexture;
51
    private DistortedEffects mEffects;
52
    private DistortedFramebuffer mScreen;
53
    private MeshFlat mMesh;
54
    private Static1D mRadiusSta;
55
    private int bmpHeight, bmpWidth;
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
   BlurRenderer(GLSurfaceView v)
60
      {
61
      mView    = v;
62
      mMesh    = new MeshFlat(1,1);
63
      mEffects = new DistortedEffects();
64
      mScreen  = new DistortedFramebuffer(0);
65

  
66
      mRadiusSta = new Static1D(5);
67
      Dynamic1D radiusDyn = new Dynamic1D();
68
      radiusDyn.add(mRadiusSta);
69

  
70
      mEffects.blur(radiusDyn, new Static2D(0,0));
71
      }
72

  
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

  
75
   void setBlur(int blur)
76
     {      
77
     mRadiusSta.set(blur);
78
     }
79

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81
   
82
   public void onDrawFrame(GL10 glUnused) 
83
      {
84
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
85
      mScreen.renderTo(mTexture, mMesh, mEffects, System.currentTimeMillis() );
86
      }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
    
90
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
91
      { 
92
      mEffects.abortEffects(EffectTypes.MATRIX);
93
      
94
      if( (float)bmpHeight/bmpWidth > (float)height/width )
95
        {
96
        int w = (height*bmpWidth)/bmpHeight;
97
        float factor = (float)height/bmpHeight;
98

  
99
        mEffects.move( new Static3D((width-w)/2,0,0) );
100
        mEffects.scale(factor);
101
        }
102
      else
103
        {
104
        int h = (width*bmpHeight)/bmpWidth;
105
        float factor = (float)width/bmpWidth;
106

  
107
        mEffects.move( new Static3D(0,(height-h)/2,0) );
108
        mEffects.scale(factor);
109
        }
110
      
111
      mScreen.resize(width, height);
112
      }
113

  
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115
    
116
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
117
      {
118
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
119

  
120
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
121
      Bitmap bitmap;
122
        
123
      try 
124
        {
125
        bitmap = BitmapFactory.decodeStream(is);
126
        } 
127
      finally 
128
        {
129
        try 
130
          {
131
          is.close();
132
          } 
133
        catch(IOException e) { }
134
        }  
135
      
136
      bmpHeight = bitmap.getHeight();
137
      bmpWidth  = bitmap.getWidth();
138

  
139
      mTexture = new DistortedTexture(bmpWidth,bmpHeight);
140
      mTexture.setTexture(bitmap);
141

  
142
      try
143
        {
144
        Distorted.onCreate(mView.getContext());
145
        }
146
      catch(Exception ex)
147
        {
148
        android.util.Log.e("Renderer", ex.getMessage() );
149
        }
150
      }
151
}
src/main/java/org/distorted/examples/blur/BlurSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.blur;
21

  
22
import android.content.Context;
23
import android.opengl.GLSurfaceView;
24
import android.util.AttributeSet;
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
class BlurSurfaceView extends GLSurfaceView
29
{
30
  private BlurRenderer mRenderer;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
  public BlurSurfaceView(Context c, AttributeSet attrs)
35
      {
36
      super(c, attrs);
37

  
38
      if(!isInEditMode())
39
        {
40
        setEGLContextClientVersion(2);
41
        mRenderer = new BlurRenderer(this);
42
        setRenderer(mRenderer);
43
        }
44
      }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  BlurRenderer getRenderer()
49
    {
50
    return mRenderer;
51
    }
52
}
53

  
src/main/java/org/distorted/examples/girl/GirlSurfaceView.java
34 34
  public GirlSurfaceView(Context c, AttributeSet attrs) 
35 35
      {
36 36
      super(c, attrs);
37
     
38
      setEGLContextClientVersion(2);
39
      mRenderer = new GirlRenderer(this);
40
      setRenderer(mRenderer);
37

  
38
      if(!isInEditMode())
39
        {
40
        setEGLContextClientVersion(2);
41
        mRenderer = new GirlRenderer(this);
42
        setRenderer(mRenderer);
43
        }
41 44
      }
42 45

  
43 46
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/blurlayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:orientation="vertical" >
6

  
7
    <org.distorted.examples.blur.BlurSurfaceView
8
        android:id="@+id/blurSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="1" />
12

  
13
    <LinearLayout
14
        android:id="@+id/linearLayout1"
15
        android:layout_width="fill_parent"
16
        android:layout_height="wrap_content"
17
        android:gravity="center|fill_horizontal"
18
        android:orientation="horizontal" >
19

  
20
        <TextView
21
                android:id="@+id/blurText"
22
                android:layout_width="150dp"
23
                android:layout_height="wrap_content"
24
                android:layout_weight="0.5"
25
                android:gravity="center_vertical|center"
26
                android:text="@string/blur"
27
                android:textAppearance="?android:attr/textAppearanceMedium" />
28

  
29
        <SeekBar
30
                android:id="@+id/blurSeek"
31
                android:layout_width="fill_parent"
32
                android:layout_height="wrap_content"
33
                android:layout_weight="1"
34
                android:paddingLeft="15dp"
35
                android:paddingRight="10dp" />
36

  
37
    </LinearLayout>
38

  
39
</LinearLayout>
src/main/res/values/strings.xml
13 13
    <string name="saturation">Saturation</string>
14 14
    <string name="contrast">Contrast</string>
15 15
    <string name="swirl">Swirl</string>
16
    <string name="blur">Blur</string>
16 17

  
17 18
    <string name="continu">Continue</string>
18 19
    <string name="rows">Rows</string>
......
73 74
    <string name="x_placeholder">X: %1$d</string>
74 75
    <string name="y_placeholder">Y: %1$d</string>
75 76
    <string name="wind_placeholder">Wind: %1$d</string>
77
    <string name="blur_placeholder">Blur: %1$d</string>
76 78

  
77 79
    <string name="example_monalisa">Mona Lisa</string>  
78 80
    <string name="example_monalisa_subtitle">The basics of Distortions.</string>
......
128 130
    <string name="example_aroundtheworld_subtitle">Combine several effects to change facial features.</string>
129 131
    <string name="example_mirror">Mirror</string>
130 132
    <string name="example_mirror_subtitle">Ping-pong between offscreen buffers to achieve the \'infinite mirror\' effect.</string>
133
    <string name="example_blur">Blur</string>
134
    <string name="example_blur_subtitle">Postprocessing effect: Blur.</string>
131 135

  
132 136
    <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
133 137
    <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>

Also available in: Unified diff