8000 Fixed heavy cpu usage in getBitmapWithFilterApplied · metacortex/android-gpuimage@ffc81ed · GitHub
[go: up one dir, main page]

Skip to content

Commit ffc81ed

Browse files
committed
Fixed heavy cpu usage in getBitmapWithFilterApplied
1 parent fe83f48 commit ffc81ed

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,18 @@ public Bitmap capture() throws InterruptedException {
291291
final int height = mGLSurfaceView.getMeasuredHeight();
292292

293293
// Take picture on OpenGL thread
294-
final IntBuffer pixelMirroredBuffer = IntBuffer.allocate(width * height);
294+
final int[] pixelMirroredArray = new int[width * height];
295295
mGPUImage.runOnGLThread(new Runnable() {
296296
@Override
297297
public void run() {
298298
final IntBuffer pixelBuffer = IntBuffer.allocate(width * height);
299299
GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, pixelBuffer);
300+
int[] pixelArray = pixelBuffer.array();
300301

301302
// Convert upside down mirror-reversed image to right-side up normal image.
302303
for (int i = 0; i < height; i++) {
303304
for (int j = 0; j < width; j++) {
304-
pixelMirroredBuffer.put((height - i - 1) * width + j, pixelBuffer.get(i * width + j));
305+
pixelMirroredArray[(height - i - 1) * width + j] = pixelArray[i * width + j];
305306
}
306307
}
307308
waiter.release();
@@ -311,7 +312,7 @@ public void run() {
311312
waiter.acquire();
312313

313314
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
314-
bitmap.copyPixelsFromBuffer(pixelMirroredBuffer);
315+
bitmap.copyPixelsFromBuffer(IntBuffer.wrap(pixelMirroredArray));
315316
return bitmap;
316317
}
317318

library/src/jp/co/cyberagent/android/gpuimage/PixelBuffer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,21 @@ private int getConfigAttrib(final EGLConfig config, final int attribute) {
189189
}
190190

191191
private void convertToBitmap() {
192+
int[] iat = new int[mWidth * mHeight];
192193
IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
193-
IntBuffer ibt = IntBuffer.allocate(mWidth * mHeight);
194194
mGL.glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, ib);
195+
int[] ia = ib.array();
195196

196197
// Convert upside down mirror-reversed image to right-side up normal
197198
// image.
198199
for (int i = 0; i < mHeight; i++) {
199200
for (int j = 0; j < mWidth; j++) {
200-
ibt.put((mHeight - i - 1) * mWidth + j, ib.get(i * mWidth + j));
201+
iat[(mHeight - i - 1) * mWidth + j] = ia[i * mWidth + j];
201202
}
202203
}
204+
203205

204206
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
205-
mBitmap.copyPixelsFromBuffer(ibt);
207+
mBitmap.copyPixelsFromBuffer(IntBuffer.wrap(iat));
206208
}
207209
}

0 commit comments

Comments
 (0)
0