Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectQueueOther.java @ 57dc1301

1 b3618cb5 Leszek Koltunski
package org.distorted.library;
2
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4
5 57dc1301 Leszek Koltunski
import android.graphics.Bitmap;
6
import android.opengl.GLES20;
7
8
import java.io.BufferedOutputStream;
9
import java.io.FileOutputStream;
10
import java.io.IOException;
11
import java.nio.ByteBuffer;
12
import java.nio.ByteOrder;
13
14 71887484 Leszek Koltunski
class EffectQueueOther extends EffectQueue
15 b3618cb5 Leszek Koltunski
  {
16 71887484 Leszek Koltunski
  private static final int NUM_UNIFORMS = 0;
17
  private static final int INDEX = EffectTypes.OTHER.ordinal();
18 2e18813f Leszek Koltunski
  private String[] mFilename;
19 b3618cb5 Leszek Koltunski
20
///////////////////////////////////////////////////////////////////////////////////////////////////
21
22 d07f2950 Leszek Koltunski
  public EffectQueueOther(DistortedObject obj)
23 b3618cb5 Leszek Koltunski
    {
24 71887484 Leszek Koltunski
    super(obj,NUM_UNIFORMS, INDEX );
25 2e18813f Leszek Koltunski
26
    if( mMax[INDEX]>0 )
27
      {
28
      mFilename= new String[mMax[INDEX]];
29
      }
30 b3618cb5 Leszek Koltunski
    }
31
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33
34 71887484 Leszek Koltunski
  protected void moveEffect(int index)
35 b3618cb5 Leszek Koltunski
    {
36 2e18813f Leszek Koltunski
    mFilename[index] = mFilename[index+1];
37 b3618cb5 Leszek Koltunski
    }
38
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40 57dc1301 Leszek Koltunski
// runs on the graphics thread
41 b3618cb5 Leszek Koltunski
42 71887484 Leszek Koltunski
  synchronized void send()
43 b3618cb5 Leszek Koltunski
    {
44 2e18813f Leszek Koltunski
    for(int i=0; i<mNumEffects; i++)
45
      {
46
      if (mType[i] == EffectNames.SAVE_PNG.ordinal() )
47
        {
48 57dc1301 Leszek Koltunski
        ByteBuffer buf = ByteBuffer.allocateDirect( (int)(mObjHalfX * mObjHalfY * 16) );
49
        buf.order(ByteOrder.LITTLE_ENDIAN);
50
        GLES20.glReadPixels(0, 0, (int)(2*mObjHalfX), (int)(2*mObjHalfY) , GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
51
52
        buf.rewind();
53
54
        BufferedOutputStream bos = null;
55
56
        try
57
          {
58
          bos = new BufferedOutputStream(new FileOutputStream(mFilename[i]));
59
          Bitmap bmp = Bitmap.createBitmap( (int)(2*mObjHalfX), (int)(2*mObjHalfY), Bitmap.Config.ARGB_8888);
60
          bmp.copyPixelsFromBuffer(buf);
61
          bmp.compress(Bitmap.CompressFormat.PNG, 90, bos);
62
          bmp.recycle();
63
64
          for(int j=0; j<mNumListeners; j++)
65
            EffectMessageSender.newMessage( mListeners.elementAt(j),
66
                                            EffectMessage.EFFECT_FINISHED,
67
                                           (mID[i]<<EffectTypes.LENGTH)+EffectTypes.OTHER.type,
68
                                            mType[i],
69
                                            mBitmapID);
70
          }
71
        catch(Exception e)
72
          {
73
          for(int j=0; j<mNumListeners; j++)
74
            EffectMessageSender.newMessage( mListeners.elementAt(j),
75
                                            EffectMessage.EFFECT_FAILED,
76
                                           (mID[i]<<EffectTypes.LENGTH)+EffectTypes.OTHER.type,
77
                                            mType[i],
78
                                            mBitmapID);
79
          }
80
        finally
81
          {
82
          if (bos != null)
83
            {
84
            try {bos.close();}
85
            catch(IOException io ) {}
86
            }
87
          }
88
89
        remove(i);
90
        i--;
91
        continue;
92 2e18813f Leszek Koltunski
        }
93
      else if (mType[i] == EffectNames.SAVE_MP4.ordinal() )
94
        {
95
        // TODO: Implement SAVE_MP4 HERE
96
        }
97
      }
98 b3618cb5 Leszek Koltunski
    }
99
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102
  synchronized long add(EffectNames eln, String filename)
103
    {
104 2e18813f Leszek Koltunski
    if( mMax[INDEX]>mNumEffects )
105
      {
106
      mFilename[mNumEffects] = filename;
107
      mInterI[mNumEffects] = null;
108
      mInterP[mNumEffects] = null;
109
110
      return addBase(eln);
111
      }
112
113
    return -1;
114 b3618cb5 Leszek Koltunski
    }
115
  }