Skip to content

Commit d554ac8

Browse files
committed
Allow changing the background color of GPUImageView
1 parent 37580be commit d554ac8

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
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: 18 additions & 1 deletion
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,7 +95,7 @@ public GPUImageRenderer(final GPUImageFilter filter) {
9195

9296
@Override
9397
public void onSurfaceCreated(final GL10 unused, final EGLConfig config) {
94-
GLES20.glClearColor(0, 0, 0, 1);
98+
GLES20.glClearColor(mBackgroundRed, mBackgroundGreen, mBackgroundBlue, 1);
9599
GLES20.glDisable(GLES20.GL_DEPTH_TEST);
96100
mFilter.init();
97101
}
@@ -120,6 +124,19 @@ public void onDrawFrame(final GL10 gl) {
120124
}
121125
}
122126

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+
123140
private void runAll(Queue<Runnable> queue) {
124141
synchronized (queue) {
125142
while (!queue.isEmpty()) {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
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;
2325
import android.net.Uri;
2426
import android.opengl.GLES20;
@@ -94,6 +96,17 @@ public GPUImage getGPUImage() {
9496
return mGPUImage;
9597
}
9698

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+
97110
// TODO Should be an xml attribute. But then GPUImage can not be distributed as .jar anymore.
98111
public void setRatio(float ratio) {
99112
mRatio = ratio;

0 commit comments

Comments
 (0)