use of java.util.concurrent.Semaphore in project StickerCamera by Skykai521.
the class GPUImageView method capture.
/**
* Capture the current image with the size as it is displayed and retrieve it as Bitmap.
* @return current output as Bitmap
* @throws InterruptedException
*/
public Bitmap capture() throws InterruptedException {
final Semaphore waiter = new Semaphore(0);
final int width = mGLSurfaceView.getMeasuredWidth();
final int height = mGLSurfaceView.getMeasuredHeight();
// Take picture on OpenGL thread
final int[] pixelMirroredArray = new int[width * height];
mGPUImage.runOnGLThread(new Runnable() {
@Override
public void run() {
final IntBuffer pixelBuffer = IntBuffer.allocate(width * height);
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
int[] pixelArray = pixelBuffer.array();
// Convert upside down mirror-reversed image to right-side up normal image.
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j];
}
}
waiter.release();
}
});
requestRender();
waiter.acquire();
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray));
return bitmap;
}
use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.
the class CameraFunctionalTest method setUp.
protected void setUp() throws Exception {
final Semaphore sem = new Semaphore(0);
mLooperThread = new Thread() {
@Override
public void run() {
Log.v(TAG, "starting looper");
Looper.prepare();
mHandler = new Handler();
sem.release();
Looper.loop();
Log.v(TAG, "quit looper");
}
};
mLooperThread.start();
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to start the looper.");
}
getActivity();
super.setUp();
mCameraTestHelper = new CameraTestHelper();
}
use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.
the class CameraFunctionalTest method runOnLooper.
private void runOnLooper(final Runnable command) throws InterruptedException {
final Semaphore sem = new Semaphore(0);
mHandler.post(new Runnable() {
@Override
public void run() {
try {
command.run();
} finally {
sem.release();
}
}
});
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to run the command on the looper.");
}
}
use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.
the class CameraPairwiseTest method runOnLooper.
private void runOnLooper(final Runnable command) throws InterruptedException {
final Semaphore sem = new Semaphore(0);
mHandler.post(new Runnable() {
@Override
public void run() {
try {
command.run();
} finally {
sem.release();
}
}
});
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to run the command on the looper.");
}
}
use of java.util.concurrent.Semaphore in project android_frameworks_base by ParanoidAndroid.
the class CameraPairwiseTest method setUp.
protected void setUp() throws Exception {
final Semaphore sem = new Semaphore(0);
mLooperThread = new Thread() {
@Override
public void run() {
Log.v(TAG, "starting looper");
Looper.prepare();
mHandler = new Handler();
sem.release();
Looper.loop();
Log.v(TAG, "quit looper");
}
};
mLooperThread.start();
if (!sem.tryAcquire(WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) {
fail("Failed to start the looper.");
}
getActivity();
super.setUp();
mCameraTestHelper = new CameraTestHelper();
}
Aggregations