Skip to content

Commit 6150a64

Browse files
committed
second round of abstraction
Signed-off-by: Umair Khan <[email protected]>
1 parent b3955f4 commit 6150a64

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

src/in/omerjerk/processing/video/android/Capture.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
package in.omerjerk.processing.video.android;
22

33
import java.io.IOException;
4-
import java.nio.IntBuffer;
54
import java.util.ArrayList;
65
import java.util.List;
76

87
import android.graphics.SurfaceTexture;
98
import android.hardware.Camera;
109
import android.hardware.Camera.Size;
11-
import android.opengl.GLES20;
12-
import android.opengl.GLSurfaceView;
1310
import android.os.Handler;
1411
import android.os.Message;
1512
import android.util.Log;
1613
import processing.core.PApplet;
17-
import processing.opengl.PGraphicsOpenGL;
1814

1915
@SuppressWarnings("deprecation")
2016
public class Capture extends VideoBase implements CameraHandlerCallback {
@@ -36,27 +32,7 @@ public Capture(PApplet parent) {
3632

3733
public Capture(final PApplet parent, int width, int height) {
3834
super(parent);
39-
this.parent = parent;
40-
if (width == -1 || height == -1) {
41-
//TODO: Temp hack. Needs to be handled intelligently.
42-
width = 720;
43-
height = 1280;
44-
}
45-
init(width, height, ARGB);
4635

47-
glView = (GLSurfaceView) parent.getSurfaceView();
48-
pg = (PGraphicsOpenGL)parent.g;
49-
// customTexture = new Texture(pg, width, height);
50-
// customTexture.invertedY(true);
51-
glView.queueEvent(new Runnable() {
52-
@Override
53-
public void run() {
54-
createSurfaceTexture();
55-
prepareFrameBuffers();
56-
}
57-
});
58-
// pg.setCache(this, customTexture);
59-
activity = parent.getActivity();
6036
activity.runOnUiThread(new Runnable() {
6137
@Override
6238
public void run() {
@@ -83,22 +59,6 @@ public void start() {
8359
CameraHandler.MSG_START_PREVIEW));
8460
}
8561

86-
@Override
87-
public void loadPixels() {
88-
super.loadPixels();
89-
//It's ultra slow right now
90-
91-
if (pixelBuffer == null) {
92-
pixelBuffer = IntBuffer.allocate(width * height);
93-
}
94-
pixelBuffer.position(0);
95-
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffers.get(0));
96-
GLES20.glViewport(0, 0, width, height);
97-
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
98-
pixelBuffer.position(0);
99-
pixelBuffer.get(Capture.this.pixels);
100-
}
101-
10262
@Override
10363
public void onPause() {
10464
log("pause called");

src/in/omerjerk/processing/video/android/VideoBase.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,30 @@ public static void log(String log) {
5252

5353
public VideoBase(PApplet parent) {
5454
super();
55+
this.parent = parent;
56+
if (width == -1 || height == -1) {
57+
//TODO: Temp hack. Needs to be handled intelligently.
58+
width = 720;
59+
height = 1280;
60+
}
61+
init(width, height, ARGB);
62+
5563
parent.registerMethod("pause", this);
5664
parent.registerMethod("resume", this);
65+
66+
glView = (GLSurfaceView) parent.getSurfaceView();
67+
pg = (PGraphicsOpenGL)parent.g;
68+
// customTexture = new Texture(pg, width, height);
69+
// customTexture.invertedY(true);
70+
glView.queueEvent(new Runnable() {
71+
@Override
72+
public void run() {
73+
createSurfaceTexture();
74+
prepareFrameBuffers();
75+
}
76+
});
77+
// pg.setCache(this, customTexture);
78+
activity = parent.getActivity();
5779
}
5880

5981
public boolean available() {
@@ -196,4 +218,20 @@ public void getImage(boolean loadPixels) {
196218
this.setLoaded(false);
197219
}
198220
}
221+
222+
@Override
223+
public void loadPixels() {
224+
super.loadPixels();
225+
//It's ultra slow right now
226+
227+
if (pixelBuffer == null) {
228+
pixelBuffer = IntBuffer.allocate(width * height);
229+
}
230+
pixelBuffer.position(0);
231+
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffers.get(0));
232+
GLES20.glViewport(0, 0, width, height);
233+
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
234+
pixelBuffer.position(0);
235+
pixelBuffer.get(this.pixels);
236+
}
199237
}

0 commit comments

Comments
 (0)