Skip to content

Commit

Permalink
add GPUImageFilterGroup setBackground and fix bug for cats-oss#395
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhiyong committed Jul 22, 2021
1 parent ceea576 commit e929601
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-beta04'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ ext {
// apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle'
// apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle'

apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle'
//apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public class GPUImageFilterGroup extends GPUImageFilter {
private final FloatBuffer glTextureBuffer;
private final FloatBuffer glTextureFlipBuffer;

private float mBackgroundRed;
private float mBackgroundGreen;
private float mBackgroundBlue;

/**
* Instantiates a new GPUImageFilterGroup with no filters.
*/
Expand Down Expand Up @@ -196,12 +200,12 @@ public void onDraw(final int textureId, final FloatBuffer cubeBuffer,
boolean isNotLast = i < size - 1;
if (isNotLast) {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffers[i]);
GLES20.glClearColor(0, 0, 0, 0);
GLES20.glClearColor(mBackgroundRed, mBackgroundGreen, mBackgroundBlue, 1);
}

if (i == 0) {
if (i == size - 1) {
filter.onDraw(previousTexture, cubeBuffer, textureBuffer);
} else if (i == size - 1) {
} else if (i == 0) {
filter.onDraw(previousTexture, glCubeBuffer, (size % 2 == 0) ? glTextureFlipBuffer : glTextureBuffer);
} else {
filter.onDraw(previousTexture, glCubeBuffer, glTextureBuffer);
Expand Down Expand Up @@ -252,4 +256,10 @@ public void updateMergedFilters() {
mergedFilters.add(filter);
}
}

public void setBackgroundColor(float red, float green, float blue) {
mBackgroundRed = red;
mBackgroundGreen = green;
mBackgroundBlue = blue;
}
}
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
android:name=".activity.CameraActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activity.ImageActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
</application>

</manifest>
Binary file added sample/src/main/assets/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.widget.SeekBar
import android.widget.SeekBar.OnSeekBarChangeListener
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import jp.co.cyberagent.android.gpuimage.GPUImage
import jp.co.cyberagent.android.gpuimage.GPUImageView
import jp.co.cyberagent.android.gpuimage.filter.GPUImageFilter
import jp.co.cyberagent.android.gpuimage.sample.GPUImageFilterTools
Expand All @@ -39,6 +40,8 @@ class GalleryActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gallery)

gpuImageView.setScaleType(GPUImage.ScaleType.CENTER_INSIDE)

seekBar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
filterAdjuster?.adjust(progress)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package jp.co.cyberagent.android.gpuimage.sample.activity

import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import jp.co.cyberagent.android.gpuimage.GPUImage
import jp.co.cyberagent.android.gpuimage.GPUImageView
import jp.co.cyberagent.android.gpuimage.filter.*
import jp.co.cyberagent.android.gpuimage.sample.R

/*
* Copyright (C) 2018 CyberAgent, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class ImageActivity : AppCompatActivity() {

private val gpuImage: GPUImageView by lazy { findViewById<GPUImageView>(R.id.gpu_image) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image)
gpuImage.setScaleType(GPUImage.ScaleType.CENTER_INSIDE)
gpuImage.filter = GPUImageFilterGroup(listOf(GPUImageBrightnessFilter(),
GPUImageSaturationFilter(),
GPUImageWhiteBalanceFilter(),
GPUImageSharpenFilter())).apply {
setBackgroundColor(0.27f, 0.27f, 0.27f)
}
gpuImage.setImage(Uri.parse("file:///android_asset/image.png"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.button_gallery).setOnClickListener {
startActivity(Intent(this, GalleryActivity::class.java))
}

findViewById<View>(R.id.button_image).setOnClickListener {
startActivity(Intent(this,ImageActivity::class.java))
}

findViewById<View>(R.id.button_camera).setOnClickListener {
if (!hasCameraPermission() || !hasStoragePermission()) {
ActivityCompat.requestPermissions(
Expand Down
12 changes: 12 additions & 0 deletions sample/src/main/res/layout/activity_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<jp.co.cyberagent.android.gpuimage.GPUImageView
android:id="@+id/gpu_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
9 changes: 9 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/button_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:drawableTop="@android:drawable/ic_menu_gallery"
android:text="ImageGroupFilter"
tools:ignore="HardcodedText" />

<Button
android:id="@+id/button_gallery"
android:layout_width="wrap_content"
Expand Down

0 comments on commit e929601

Please sign in to comment.