Skip to content

Commit 77b1f10

Browse files
committed
Merge pull request cats-oss#213 from jonan/background-color
Allow setting the background color
2 parents 245d050 + d554ac8 commit 77b1f10

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ public void setGLSurfaceView(final GLSurfaceView view) {
100100
mGlSurfaceView.requestRender();
101101
}
102102

103+
/**
104+
* Sets the background color
105+
*
106+
* @param red red color value
107+
* @param green green color value
108+
* @param blue red color value
109+
*/
110+
public void setBackgroundColor(float red, float green, float blue) {
111+
mRenderer.setBackgroundColor(red, green, blue);
112+
}
113+
103114
/**
104115
* Request the preview to be rendered again.
105116
*/

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public class GPUImageRenderer implements Renderer, PreviewCallback {
7373
private boolean mFlipVertical;
7474
private GPUImage.ScaleType mScaleType = GPUImage.ScaleType.CENTER_CROP;
7575

76+
private float mBackgroundRed = 0;
77+
private float mBackgroundGreen = 0;
78+
private float mBackgroundBlue = 0;
79+
7680
public GPUImageRenderer(final GPUImageFilter filter) {
7781
mFilter = filter;
7882
mRunOnDraw = new LinkedList<Runnable>();
@@ -91,10 +95,8 @@ public GPUImageRenderer(final GPUImageFilter filter) {
9195

9296
@Override
9397
public void onSurfaceCreated(final GL10 unused, final EGLConfig config) {
94-
GLES20.glDisable(GL10.GL_DITHER);
95-
GLES20.glClearColor(0,0,0,0);
96-
GLES20.glEnable(GL10.GL_CULL_FACE);
97-
GLES20.glEnable(GL10.GL_DEPTH_TEST);
98+
GLES20.glClearColor(mBackgroundRed, mBackgroundGreen, mBackgroundBlue, 1);
99+
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
98100
mFilter.init();
99101
}
100102

@@ -122,6 +124,19 @@ public void onDrawFrame(final GL10 gl) {
122124
}
123125
}
124126

127+
/**
128+
* Sets the background color
129+
*
130+
* @param red red color value
131+
* @param green green color value
132+
* @param blue red color value
133+
*/
134+
public void setBackgroundColor(float red, float green, float blue) {
135+
mBackgroundRed = red;
136+
mBackgroundGreen = green;
137+
mBackgroundBlue = blue;
138+
}
139+
125140
private void runAll(Queue<Runnable> queue) {
126141
synchronized (queue) {
127142
while (!queue.isEmpty()) {

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import android.content.Context;
2020
import android.graphics.Bitmap;
2121
import android.graphics.Color;
22+
import android.graphics.drawable.ColorDrawable;
23+
import android.graphics.drawable.Drawable;
2224
import android.media.MediaScannerConnection;
23-
import android.graphics.PixelFormat;
2425
import android.net.Uri;
2526
import android.opengl.GLES20;
2627
import android.opengl.GLSurfaceView;
@@ -57,9 +58,6 @@ public GPUImageView(Context context, AttributeSet attrs) {
5758

5859
private void init(Context context, AttributeSet attrs) {
5960
mGLSurfaceView = new GPUImageGLSurfaceView(context, attrs);
60-
mGLSurfaceView.setZOrderOnTop(true);
61-
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
62-
mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
6361
addView(mGLSurfaceView);
6462
mGPUImage = new GPUImage(getContext());
6563
mGPUImage.setGLSurfaceView(mGLSurfaceView);
@@ -98,6 +96,17 @@ public GPUImage getGPUImage() {
9896
return mGPUImage;
9997
}
10098

99+
/**
100+
* Sets the background color
101+
*
102+
* @param red red color value
103+
* @param green green color value
104+
* @param blue red color value
105+
*/
106+
public void setBackgroundColor(float red, float green, float blue) {
107+
mGPUImage.setBackgroundColor(red, green, blue);
108+
}
109+
101110
// TODO Should be an xml attribute. But then GPUImage can not be distributed as .jar anymore.
102111
public void setRatio(float ratio) {
103112
mRatio = ratio;

0 commit comments

Comments
 (0)