/** * This sets the scale type of GPUImage. This has to be run before setting the image. If image is * set and scale type changed, image needs to be reset. * * @param scaleType The new ScaleType */ public void setScaleType(ScaleType scaleType) { mScaleType = scaleType; mRenderer.setScaleType(scaleType); mRenderer.deleteImage(); mCurrentBitmap = null; requestRender(); }
private int getOutputHeight() { if (mRenderer != null && mRenderer.getFrameHeight() != 0) { return mRenderer.getFrameHeight(); } else if (mCurrentBitmap != null) { return mCurrentBitmap.getHeight(); } else { WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); Display display = windowManager.getDefaultDisplay(); return display.getHeight(); } }
/** * Gets the images for multiple filters on a image. This can be used to quickly get thumbnail * images for filters. <br> * Whenever a new Bitmap is ready, the listener will be called with the bitmap. The order of the * calls to the listener will be the same as the filter order. * * @param bitmap the bitmap on which the filters will be applied * @param filters the filters which will be applied on the bitmap * @param listener the listener on which the results will be notified */ public static void getBitmapForMultipleFilters( final Bitmap bitmap, final List<GPUImageFilter> filters, final ResponseListener<Bitmap> listener) { if (filters.isEmpty()) { return; } GPUImageRenderer renderer = new GPUImageRenderer(filters.get(0)); renderer.setImageBitmap(bitmap, false); PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight()); buffer.setRenderer(renderer); for (GPUImageFilter filter : filters) { renderer.setFilter(filter); listener.response(buffer.getBitmap()); filter.destroy(); } renderer.deleteImage(); buffer.destroy(); }
/** * Sets the up camera to be connected to GPUImage to get a filtered preview. * * @param camera the camera * @param degrees by how many degrees the image should be rotated * @param flipHorizontal if the image should be flipped horizontally * @param flipVertical if the image should be flipped vertically */ public void setUpCamera( final Camera camera, boolean userFront, final boolean flipHorizontal, final boolean flipVertical) { try { mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); Rotation rotation = Rotation.ROTATION_90; if (userFront) { rotation = Rotation.ROTATION_270; } else { rotation = Rotation.ROTATION_90; } mRenderer.setRotationCamera(rotation, flipHorizontal, flipVertical); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) { setUpCameraGingerbread(camera); } else { camera.setPreviewCallback(mRenderer); camera.startPreview(); } } catch (Exception e) { e.printStackTrace(); } }
/** * Runs the given Runnable on the OpenGL thread. * * @param runnable The runnable to be run on the OpenGL thread. */ public void runOnGLThread(Runnable runnable) { mRenderer.runOnDrawEnd(runnable); }
/** * Gets the given bitmap with current filter applied as a Bitmap. * * @param bitmap the bitmap on which the current filter should be applied * @return the bitmap with filter applied */ public Bitmap getBitmapWithFilterApplied(final Bitmap bitmap) { if (mGlSurfaceView != null) { mRenderer.deleteImage(); mRenderer.runOnDraw( new Runnable() { @Override public void run() { synchronized (mFilter) { mFilter.destroy(); mFilter.notify(); } } }); synchronized (mFilter) { requestRender(); try { mFilter.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } GPUImageRenderer renderer = new GPUImageRenderer(mFilter); renderer.setRotation( Rotation.NORMAL, mRenderer.isFlippedHorizontally(), mRenderer.isFlippedVertically()); renderer.setScaleType(mScaleType); PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight()); buffer.setRenderer(renderer); renderer.setImageBitmap(bitmap, false); Bitmap result = buffer.getBitmap(); mFilter.destroy(); renderer.deleteImage(); buffer.destroy(); mRenderer.setFilter(mFilter); if (mCurrentBitmap != null) { mRenderer.setImageBitmap(mCurrentBitmap, false); } requestRender(); return result; }
/** Deletes the current image. */ public void deleteImage() { mRenderer.deleteImage(); mCurrentBitmap = null; requestRender(); }
/** * Sets the rotation of the displayed image. * * @param rotation new rotation */ public void setRotation(Rotation rotation) { mRenderer.setRotation(rotation); }
/** * Sets the image on which the filter should be applied. * * @param bitmap the new image */ public void setImage(final Bitmap bitmap) { mCurrentBitmap = bitmap; mRenderer.setImageBitmap(bitmap, false); requestRender(); }
/** * Sets the filter which should be applied to the image which was (or will be) set by * setImage(...). * * @param filter the new filter */ public void setFilter(final GPUImageFilter filter) { mFilter = filter; mRenderer.setFilter(mFilter); requestRender(); }
@TargetApi(11) private void setUpCameraGingerbread(final Camera camera) { mRenderer.setUpSurfaceTexture(camera); }