Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GPUImageFilterGroup when image is center_ Inside mode is invalid to change the background color in GPUImageView #531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,44 @@
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.setBackgroundColor(1f,1f,1f)
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