diff --git a/library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java b/library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java index c6ade5a6d..8392a5a9a 100644 --- a/library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java +++ b/library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java @@ -100,6 +100,17 @@ public void setGLSurfaceView(final GLSurfaceView view) { mGlSurfaceView.requestRender(); } + /** + * Sets the background color + * + * @param red red color value + * @param green green color value + * @param blue red color value + */ + public void setBackgroundColor(float red, float green, float blue) { + mRenderer.setBackgroundColor(red, green, blue); + } + /** * Request the preview to be rendered again. */ diff --git a/library/src/jp/co/cyberagent/android/gpuimage/GPUImageRenderer.java b/library/src/jp/co/cyberagent/android/gpuimage/GPUImageRenderer.java index fd26a5f32..691550bde 100644 --- a/library/src/jp/co/cyberagent/android/gpuimage/GPUImageRenderer.java +++ b/library/src/jp/co/cyberagent/android/gpuimage/GPUImageRenderer.java @@ -73,6 +73,10 @@ public class GPUImageRenderer implements Renderer, PreviewCallback { private boolean mFlipVertical; private GPUImage.ScaleType mScaleType = GPUImage.ScaleType.CENTER_CROP; + private float mBackgroundRed = 0; + private float mBackgroundGreen = 0; + private float mBackgroundBlue = 0; + public GPUImageRenderer(final GPUImageFilter filter) { mFilter = filter; mRunOnDraw = new LinkedList(); @@ -91,10 +95,8 @@ public GPUImageRenderer(final GPUImageFilter filter) { @Override public void onSurfaceCreated(final GL10 unused, final EGLConfig config) { - GLES20.glDisable(GL10.GL_DITHER); - GLES20.glClearColor(0,0,0,0); - GLES20.glEnable(GL10.GL_CULL_FACE); - GLES20.glEnable(GL10.GL_DEPTH_TEST); + GLES20.glClearColor(mBackgroundRed, mBackgroundGreen, mBackgroundBlue, 1); + GLES20.glDisable(GLES20.GL_DEPTH_TEST); mFilter.init(); } @@ -122,6 +124,19 @@ public void onDrawFrame(final GL10 gl) { } } + /** + * Sets the background color + * + * @param red red color value + * @param green green color value + * @param blue red color value + */ + public void setBackgroundColor(float red, float green, float blue) { + mBackgroundRed = red; + mBackgroundGreen = green; + mBackgroundBlue = blue; + } + private void runAll(Queue queue) { synchronized (queue) { while (!queue.isEmpty()) { diff --git a/library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java b/library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java index 05b15fcf7..cc6a02472 100644 --- a/library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java +++ b/library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java @@ -19,8 +19,9 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.graphics.drawable.Drawable; import android.media.MediaScannerConnection; -import android.graphics.PixelFormat; import android.net.Uri; import android.opengl.GLES20; import android.opengl.GLSurfaceView; @@ -57,9 +58,6 @@ public GPUImageView(Context context, AttributeSet attrs) { private void init(Context context, AttributeSet attrs) { mGLSurfaceView = new GPUImageGLSurfaceView(context, attrs); - mGLSurfaceView.setZOrderOnTop(true); - mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); - mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT); addView(mGLSurfaceView); mGPUImage = new GPUImage(getContext()); mGPUImage.setGLSurfaceView(mGLSurfaceView); @@ -98,6 +96,17 @@ public GPUImage getGPUImage() { return mGPUImage; } + /** + * Sets the background color + * + * @param red red color value + * @param green green color value + * @param blue red color value + */ + public void setBackgroundColor(float red, float green, float blue) { + mGPUImage.setBackgroundColor(red, green, blue); + } + // TODO Should be an xml attribute. But then GPUImage can not be distributed as .jar anymore. public void setRatio(float ratio) { mRatio = ratio;