Project

General

Profile

Download (4.38 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / save / SaveRenderer.java @ 7cfeeb63

1

    
2
package org.distorted.examples.save;
3

    
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStream;
7

    
8
import javax.microedition.khronos.egl.EGLConfig;
9
import javax.microedition.khronos.opengles.GL10;
10

    
11
import org.distorted.examples.R;
12

    
13
import org.distorted.library.Distorted;
14
import org.distorted.library.DistortedBitmap;
15
import org.distorted.library.EffectTypes;
16
import org.distorted.library.Float1D;
17
import org.distorted.library.Float2D;
18
import org.distorted.library.Float4D;
19
import org.distorted.library.Interpolator1D;
20

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

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

    
29
class SaveRenderer implements GLSurfaceView.Renderer 
30
{
31
    private GLSurfaceView mView;
32
    private static DistortedBitmap mGirl;
33
    private Float2D pLeft, pRight;
34
    private Float4D sinkRegion;
35
    private static Interpolator1D diSink;
36
    private static Float1D s0;
37
    
38
    private int bmpHeight, bmpWidth;
39
    
40
    private static float boobsSink;
41
    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
   public SaveRenderer(GLSurfaceView v) 
45
      {
46
      mView = v;
47
      
48
      boobsSink  = 1.0f;
49
      
50
      pLeft = new Float2D(132, 264);
51
      pRight= new Float2D(247, 264);
52
      
53
      // Make the boobs bigger
54
      sinkRegion = new Float4D(0,0,60,60);
55
      
56
      s0 = new Float1D(boobsSink);
57
      
58
      diSink = new Interpolator1D(); 
59
      diSink.setCount(0.5f);
60
      diSink.setDuration(0);
61
      diSink.add(s0);
62
      }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
   public static void setSize(float s)
67
     {
68
     boobsSink = s;
69
     s0.set(boobsSink);
70
     }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
   public static void Save()
75
     {
76
     File file;
77
     String filePath;
78
     int lowestNotFound = 1;
79

    
80
     while(true)
81
       {
82
       filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/girl" + lowestNotFound +".png";
83
       file = new File(filePath);
84

    
85
       if( !file.exists() )
86
         {
87
         android.util.Log.e("SAVE", "Saving to "+file.getAbsolutePath());
88
         mGirl.savePNG(file.getAbsolutePath());
89
         break;
90
         }
91
       lowestNotFound++;
92
       }
93
     }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
   
97
   public void onDrawFrame(GL10 glUnused) 
98
      {
99
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
100
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
101
      
102
      mGirl.draw(System.currentTimeMillis());
103
      }
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
    
107
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
108
      { 
109
      mGirl.abortEffects(EffectTypes.MATRIX);
110
      
111
      if( bmpHeight/bmpWidth > height/width )
112
        {
113
        int w = (height*bmpWidth)/bmpHeight;
114
        mGirl.move((width-w)/2 ,0, 0);
115
        mGirl.scale((float)height/bmpHeight);
116
        }
117
      else
118
        {
119
        int h = (width*bmpHeight)/bmpWidth;
120
        mGirl.move(0 ,(height-h)/2, 0);
121
        mGirl.scale((float)width/bmpWidth);
122
        }
123
      
124
      Distorted.onSurfaceChanged(width, height); 
125
      }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
    
129
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
130
      {    
131
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.girl);
132
      Bitmap bitmap;
133
        
134
      try 
135
        {
136
        bitmap = BitmapFactory.decodeStream(is);
137
        } 
138
      finally 
139
        {
140
        try 
141
          {
142
          is.close();
143
          } 
144
        catch(IOException e) { }
145
        }  
146
      
147
      bmpHeight = bitmap.getHeight();
148
      bmpWidth  = bitmap.getWidth();
149
      
150
      mGirl = new DistortedBitmap(bitmap, 30);
151

    
152
      mGirl.sink( diSink, sinkRegion, pLeft );
153
      mGirl.sink( diSink, sinkRegion, pRight);
154

    
155
      try
156
        {
157
        Distorted.onSurfaceCreated(mView.getContext());
158
        }
159
      catch(Exception ex)
160
        {
161
        android.util.Log.e("Renderer", ex.getMessage() );
162
        }
163
      }
164
}
(2-2/3)