1
|
package org.distorted.library;
|
2
|
|
3
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
4
|
|
5
|
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
|
class EffectQueueOther extends EffectQueue
|
15
|
{
|
16
|
private static final int NUM_UNIFORMS = 0;
|
17
|
private static final int INDEX = EffectTypes.OTHER.ordinal();
|
18
|
private String[] mFilename;
|
19
|
|
20
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
21
|
|
22
|
public EffectQueueOther(DistortedObject obj)
|
23
|
{
|
24
|
super(obj,NUM_UNIFORMS, INDEX );
|
25
|
|
26
|
if( mMax[INDEX]>0 )
|
27
|
{
|
28
|
mFilename= new String[mMax[INDEX]];
|
29
|
}
|
30
|
}
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
protected void moveEffect(int index)
|
35
|
{
|
36
|
mFilename[index] = mFilename[index+1];
|
37
|
}
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
// runs on the graphics thread
|
41
|
|
42
|
synchronized void send()
|
43
|
{
|
44
|
for(int i=0; i<mNumEffects; i++)
|
45
|
{
|
46
|
if (mType[i] == EffectNames.SAVE_PNG.ordinal() )
|
47
|
{
|
48
|
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
|
}
|
93
|
else if (mType[i] == EffectNames.SAVE_MP4.ordinal() )
|
94
|
{
|
95
|
// TODO: Implement SAVE_MP4 HERE
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
|
100
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101
|
|
102
|
synchronized long add(EffectNames eln, String filename)
|
103
|
{
|
104
|
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
|
}
|
115
|
}
|