Skip to content

Commit

Permalink
Merge pull request cats-oss#213 from jonan/background-color
Browse files Browse the repository at this point in the history
Allow setting the background color
  • Loading branch information
wasabeef committed Feb 16, 2016
2 parents 245d050 + d554ac8 commit 77b1f10
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
11 changes: 11 additions & 0 deletions library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runnable>();
Expand All @@ -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();
}

Expand Down Expand Up @@ -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<Runnable> queue) {
synchronized (queue) {
while (!queue.isEmpty()) {
Expand Down
17 changes: 13 additions & 4 deletions library/src/jp/co/cyberagent/android/gpuimage/GPUImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 77b1f10

Please sign in to comment.