Giter Club home page Giter Club logo

android-gpuimage's Introduction

GPUImage for Android

License Download Maven Central Build Status

Idea from: iOS GPUImage framework

Goal is to have something as similar to GPUImage as possible. Vertex and fragment shaders are exactly the same. That way it makes it easier to port filters from GPUImage iOS to Android.

Requirements

  • Android 2.2 or higher (OpenGL ES 2.0)

Usage

Gradle dependency

repositories {
    mavenCentral()
}

dependencies {
    implementation 'jp.co.cyberagent.android:gpuimage:2.x.x'
}

Sample Code

With preview:

Java:

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);

    Uri imageUri = ...;
    gpuImage = new GPUImage(this);
    gpuImage.setGLSurfaceView((GLSurfaceView) findViewById(R.id.surfaceView));
    gpuImage.setImage(imageUri); // this loads image on the current thread, should be run in a thread
    gpuImage.setFilter(new GPUImageSepiaFilter());

    // Later when image should be saved saved:
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
}

Kotlin:

public override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_gallery)

    val imageUri: Uri = ...
    gpuImage = GPUImage(this)
    gpuImage.setGLSurfaceView(findViewById<GLSurfaceView>(R.id.surfaceView))
    gpuImage.setImage(imageUri) // this loads image on the current thread, should be run in a thread
    gpuImage.setFilter(GPUImageSepiaFilter())

    // Later when image should be saved saved:
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null)
}

Using GPUImageView

<jp.co.cyberagent.android.gpuimage.GPUImageView
    android:id="@+id/gpuimageview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:gpuimage_show_loading="false"
    app:gpuimage_surface_type="texture_view" /> <!-- surface_view or texture_view -->

Java:

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);

    Uri imageUri = ...;
    gpuImageView = findViewById(R.id.gpuimageview);
    gpuImageView.setImage(imageUri); // this loads image on the current thread, should be run in a thread
    gpuImageView.setFilter(new GPUImageSepiaFilter());

    // Later when image should be saved saved:
    gpuImageView.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
}

Kotlin:

public override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_gallery)

    val imageUri: Uri = ...
    gpuImageView = findViewById<GPUImageView>(R.id.gpuimageview)
    gpuImageView.setImage(imageUri) // this loads image on the current thread, should be run in a thread
    gpuImageView.setFilter(GPUImageSepiaFilter())

    // Later when image should be saved saved:
    gpuImageView.saveToPictures("GPUImage", "ImageWithFilter.jpg", null)
}

Without preview:

Java:

public void onCreate(final Bundle savedInstanceState) {
    public void onCreate(final Bundle savedInstanceState) {
    Uri imageUri = ...;
    gpuImage = new GPUImage(context);
    gpuImage.setFilter(new GPUImageSobelEdgeDetection());
    gpuImage.setImage(imageUri);
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null);
}

Kotlin:

public override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_gallery)
    val imageUri: Uri = ...
    gpuImage = GPUImage(this)
    gpuImage.setFilter(GPUImageSepiaFilter())
    gpuImage.setImage(imageUri)
    gpuImage.saveToPictures("GPUImage", "ImageWithFilter.jpg", null)
}

Support status of GPUImage for iOS shaders

  • Saturation
  • Contrast
  • Brightness
  • Levels
  • Exposure
  • RGB
  • RGB Diation
  • Hue
  • White Balance
  • Monochrome
  • False Color
  • Sharpen
  • Unsharp Mask
  • Transform Operation
  • Crop
  • Gamma
  • Highlights and Shadows
  • Haze
  • Sepia Tone
  • Amatorka
  • Miss Etikate
  • Soft Elegance
  • Color Inversion
  • Solarize
  • Vibrance
  • Highlight and Shadow Tint
  • Luminance
  • Luminance Threshold
  • Average Color
  • Average Luminance
  • Average Luminance Threshold
  • Adaptive Threshold
  • Polar Pixellate
  • Pixellate
  • Polka Dot
  • Halftone
  • Crosshatch
  • Sobel Edge Detection
  • Prewitt Edge Detection
  • Canny Edge Detection
  • Threshold Sobel EdgeDetection
  • Harris Corner Detector
  • Noble Corner Detector
  • Shi Tomasi Feature Detector
  • Colour FAST Feature Detector
  • Low Pass Filter
  • High Pass Filter
  • Sketch Filter
  • Threshold Sketch Filter
  • Toon Filter
  • SmoothToon Filter
  • Tilt Shift
  • CGA Colorspace Filter
  • Posterize
  • Convolution 3x3
  • Emboss Filter
  • Laplacian
  • Chroma Keying
  • Kuwahara Filter
  • Kuwahara Radius3 Filter
  • Vignette
  • Gaussian Blur
  • Box Blur
  • Bilateral Blur
  • Motion Blur
  • Zoom Blur
  • iOS Blur
  • Median Filter
  • Swirl Distortion
  • Bulge Distortion
  • Pinch Distortion
  • Sphere Refraction
  • Glass Sphere Refraction
  • Stretch Distortion
  • Dilation
  • Erosion
  • Opening Filter
  • Closing Filter
  • Local Binary Pattern
  • Color Local Binary Pattern
  • Dissolve Blend
  • Chroma Key Blend
  • Add Blend
  • Divide Blend
  • Multiply Blend
  • Overlay Blend
  • Lighten Blend
  • Darken Blend
  • Color Burn Blend
  • Color Dodge Blend
  • Linear Burn Blend
  • Screen Blend
  • Difference Blend
  • Subtract Blend
  • Exclusion Blend
  • HardLight Blend
  • SoftLight Blend
  • Color Blend
  • Hue Blend
  • Saturation Blend
  • Luminosity Blend
  • Normal Blend
  • Source Over Blend
  • Alpha Blend
  • Non Maximum Suppression
  • Thresholded Non Maximum Suppression
  • Directional Non Maximum Suppression
  • Opacity
  • Weak Pixel Inclusion Filter
  • Color Matrix
  • Directional Sobel Edge Detection
  • Lookup
  • Tone Curve (*.acv files)

Others

  • Texture 3x3
  • Gray Scale

Gradle

Make sure that you run the clean target when using maven.

gradle clean assemble

License

Copyright 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.

android-gpuimage's People

Contributors

amachang avatar bearprada avatar charlesbedrosian avatar chihung93 avatar chriszeng87 avatar dichro avatar dotyso avatar hoozh avatar ilfuriano avatar imj007 avatar itome avatar javierpuntonet avatar jonan avatar keheira avatar kettsun0123 avatar leonrd avatar lukesleeman avatar moyuruaizawa avatar mstrengis avatar pboos avatar primary0 avatar ryogak avatar ryohey avatar swcai avatar takasfz avatar ubuntudroid avatar vashisthg avatar wasabeef avatar wsidortsov avatar wysaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-gpuimage's Issues

The blur size of GPUImageBoxBlurFilter seems strange

I use 6 as blur size for GPUImageBoxBlurFilter and found the result image different from GPUImage for iOS using same blur size.

BTW, could you please add GPUImageAdaptiveThresholdFilter in android-gpuimage?

Adding 2 effects simultaneously

hi,
1)Im having a doubt about how to use 2 effects on the same image,if i use the following code,

mGPUimage.setFilter(new GPUImageSepiaFilter());
mGPUimage.setFilter(new GPUImagePosterizeFilter());

the image i get only has the 2nd filter,but not both, how can i fix this?

i checked one older issue where GPUImageFilterGroup is mentioned, i checked the sample but i wasnt able to find how to use it..

Thanks

Compress video so i can send it to my server

Can the library compress a video? GPU Image for iOs do it very fast.
I think they do it with GPUImageMovie. I can't find such class in android library?

It seems Android library doesn't manipulate video? Do you think you will add this feature?
Do you know any other library that can do the job?

video filter

did anyone developed video filter application

Rare NPE when calling getBitmapWithFilterApplied()

I rarely receive a NPE during execution of GPUImage.getBitmapWithFilterApplied(). Hoped I had fixed it with commit 0c43346, but the problem still persists. I've found out, that it in fact only occurs if I've no GLSurfaceView set.

Stacktrace:

07-08 12:17:55.843: E/AndroidRuntime(11370): java.lang.NullPointerException
07-08 12:17:55.843: E/AndroidRuntime(11370):    at jp.co.cyberagent.android.gpuimage.GPUImageFilterGroup.onDraw(GPUImageFilterGroup.java:210)
07-08 12:17:55.843: E/AndroidRuntime(11370):    at jp.co.cyberagent.android.gpuimage.GPUImageRenderer.onDrawFrame(GPUImageRenderer.java:116)
07-08 12:17:55.843: E/AndroidRuntime(11370):    at jp.co.cyberagent.android.gpuimage.PixelBuffer.getBitmap(PixelBuffer.java:121)
07-08 12:17:55.843: E/AndroidRuntime(11370):    at jp.co.cyberagent.android.gpuimage.GPUImage.getBitmapWithFilterApplied(GPUImage.java:288)

How to correctly handle glSurfaceView.onPause(); and onResume();

The docs for GLSurfaceView tell us that we should call onPause() from our activities onPause and onResume() from our activities onResume(). When I do this with my surface view attached to my GPUImage all I can get once the activity has been resumed is a black screen.

I've tried calling requestRender() , setting the image on GPUImage and re-setting the filter, all to no avail.

GPUImageMovieWriter class for video filtering

Hello,

First of all, I would like to thank you for giving us a great library similar to GPUImage framework of iOS, it is much easy task for us after developing application on iOS.

While viewing library, I could not find useful links or samples for editing videos from resource files as well from live camera. If possible, I would like to go through any samples for the same if it is developed. We had worked using GPUImageMovieWriter in iOS for writing filtered videos to albums.

Will be waiting for your response.

Thanks
Jignesh Brahmkhatri

Image stretches and crops

when i open either the gpuimage-sample,or my own project, smaller images just strech and crop wierdly, how to solve that?

Trying CENTER_INSIDE scale type doesnt really work....

1)Original image

130411155624-lamborghini-dubai-police-4-horizontal-gallery 1

2)Auto crop and zoomed image in GpuImageSample project

screenshot_2013-06-28-10-28-09 1

Thanks,

Jeet

Camera preview really slow

Hi!
I'm currently trying to port my iPhone app which use GPUImage, on Android.
I successfully created a GLSurfaceView and can affect it to my GPUImage object.
But the activity is really slow and the preview is laggy.

Is it 'normal'?

Here is my code if it can be helpful:

mCamera = getCameraInstance(); // Method found in the developer guide
if(mCamera == null) {
Toast.makeText(this, "No camera found", Toast.LENGTH_SHORT).show();
onBackPressed();
}
mGPUImage = new GPUImage(this);
mGPUImage.setGLSurfaceView(surfaceView);
mGPUImage.setUpCamera(mCamera, 90, false, frontCAM);
mGPUImage.setScaleType(GPUImage.ScaleType.CENTER_CROP);

Question about persisting changes when switching effects

Hi everyone.

In your example app the bitmap resets to the original when you switch filters. I'm able to persist changes to the bitmap by first exporting changes to a new bitmap and then setting that new bitmap as the image for the GPUImageView.

Bitmap newBitmap = mGPUImage.getBitmapWithFilterApplied();          
mGPUImageView.setImage(newBitmap);

This method takes too much time (almost 1 second to execute) and I assume there must be a more efficient way to do this, maybe by using OpenGL functions. Anybody got an idea how to do this? Any help appreciated.

ScaleType.CENTER_INSIDE in combination with rotation

With an GPUImageView with ScaleType set to CENTER_INSIDE and proprietary dimensions (e.g. 300 x 350 on the screen), the texture coordinates get calculated properly on load of the image, and if rotated by 180 degrees.

However, on 90 and 270 degrees, the image gets distorted, and will be saved this distorted way when calling saveToPictures.

Timing issue with GPUImageView.capture(width, height) leads to black borders / areas

Hi there,

in our setup we displayed a GPUImageView in a preview size and used the capture(width, height) method to stretch it bigger and get the rendered picture in the full output size. During this process, on old devices we could see the GPUImageView being stretched and enlarged. It occasionally also led to some areas on the image being rendered black (borders, or black overlay on the top).

In our setup (I will try to provide a tiny demo setup later), we were able to circumvent this issue by inserting a Thread.sleep for around 100ms in the capture(width, height) method, just after the post to requestLayout and before the request render call.

GPUImageView#capture(int width, int height)

....
post(new Runnable() {
            @Override
            public void run() {
                // Show loading¥
                if(showLoadingView) addView(new LoadingView(getContext()));

                mGLSurfaceView.requestLayout();
            }
        });
        waiter.acquire();

        // fix for timing condition on some devices (Galaxy S2), when upscaling the view
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // Run one render pass
        mGPUImage.runOnGLThread(new Runnable() {
            @Override
            public void run() {
                waiter.release();
            }
        });
        requestRender();
        waiter.acquire();
        Bitmap bitmap = capture();
....

I wondered if you have experienced similar issues before or is there would be another better way to solve this..

Enable transparency

Hi, I'm using this library on my project. I've a GPUImage with GPUImagePixelationFilter and the CENTER_INSIDE ScaleType and I put a .png (with transparency) as an image source. The problem is that the background of the GLSurfaceView is black and I need to set it transparent because I want to show the background of my Layout.

I've been looking on google but have not found any proper solution. Is there any option to get this effect?

Thanks in advance.

GPUImageMonochromeFilter not taking any set values

Hi!
First off, great work on this project!

Now the perceived issue (I'm not 100% sure) and the fix...

In the GPUImageMonochromeFilter your onInitialized method seems to feeds in the default values all the time...I've changed it to:

@OverRide
public void onInitialized() {
super.onInitialized();
setIntensity(mIntensity);
setColor(mColor);
}

and now it seems to change if I change the values in the constructor whereas first it just gave the same result no matter the values...

Hope it actually is an issue and not me being stupid...Otherwise ignore this and accept my apologies...

Build gpuimage library error, help me!

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for jp.co.cyberagent.android.gpuimage:gpuimage-library:apklib:1.0.3
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin com.jayway.maven.plugins.android.generation2:android-maven-plugin @ line 56, column 21
[WARNING]
[WARNING] Some problems were encountered while building the effective model for jp.co.cyberagent.android.gpuimage:gpuimage-sample:apk:1.0.3
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-javadoc-plugin is missing. @ line 44, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] GPUImage for Android
[INFO] GPUImage for Android Library
[INFO] GPUImage Sample
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GPUImage for Android 1.0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ gpuimage-parent ---
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ gpuimage-parent ---
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ gpuimage-parent ---
[INFO] Installing C:\Program Files\android-gpuimage-master\pom.xml to C:\Users\yang_shuai.CCWLAB.m2\repository\jp\co\cyberagent\android\gpuimage\gpuimage-parent\1.0.3\gpuimage-parent-1.0.3.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GPUImage for Android Library 1.0.3
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ gpuimage-library ---
[INFO] Deleting C:\Program Files\android-gpuimage-master\library\target
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ gpuimage-library ---
[INFO]
[INFO] --- android-maven-plugin:3.2.0:generate-sources (default-generate-sources) @ gpuimage-library ---
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] ANDROID-904-002: Found aidl files: Count = 0
[INFO] C:\Program Files\adt-bundle-windows-x86\sdk\platform-tools\aapt.exe [package, -m, -J, C:\Program Files\android-gpuimage-master\library\target\generated-sources\r, -M, C:\Program Files\android-gpuimage-master\library\AndroidManifest.xml, -S, C:\Program Files\android-gpuimage-master\library\res, --auto-add-overlay, -I, C:\Program Files\adt-bundle-windows-x86\sdk\platforms\android-17\android.jar]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ gpuimage-library ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Program Files\android-gpuimage-master\library\src\main\resources
[INFO] skip non existing resourceDirectory C:\Program Files\android-gpuimage-master\library\target\generated-sources\extracted-dependencies\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ gpuimage-library ---
[INFO] Compiling 20 source files to C:\Program Files\android-gpuimage-master\library\target\classes
[INFO]
[INFO] --- android-maven-plugin:3.2.0:ndk-build (default) @ gpuimage-library ---
[INFO] C:\android-ndk-r8d\ndk-build [-C, C:\Program Files\android-gpuimage-master\library, gpuimage-library]
make: Entering directory C:/Program Files/android-gpuimage-master/library' [INFO] C:/android-ndk-r8d/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml make: Nothing to be done forgpuimage-library'.
make: Leaving directory `C:/Program Files/android-gpuimage-master/library'
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] GPUImage for Android .............................. SUCCESS [0.796s]
[INFO] GPUImage for Android Library ...................... FAILURE [3.561s]
[INFO] GPUImage Sample ................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.357s
[INFO] Finished at: Wed Dec 26 14:14:53 CST 2012
[INFO] Final Memory: 11M/21M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.2.0:ndk-build (default) on project gpuimage-library: ANDROID-040-001: Could not execute: Command = cmd.exe /X /C "C:\android-ndk-r8d\ndk-build -C "C:\Program Files\android-gpuimage-master\library" gpuimage-library", Result = 0 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :gpuimage-library

Build armeabi and x86

Currently only armeabi gets deployed with maven. Should deploy both armeabi and x86.

GPUImageTwoPassFilter

I have spent some time trying to implement GPUImageTwoPassFilter. At the current time, it does not quite work. I know I must be very close, though. Although I am very new to OpenGL, I am experienced in Android and iOS, and based it off the iOS implementation.

I open this issue for anyone looking for this class, they can use my implementation as a starting point, because I know I am at least 90% of the way there.

https://gist.github.com/jamieomatthews/5237002#file-gpuimagetwopassfilter-java

Center Inside not working

Hi, in the last develop code capture works perfectly, but now I have another problem.

GPUImageView always crop the image, even setting CENTER_INSIDE in setScaleType at the beginning of the code.

When I capture the image works perfectly, but when I'm viewing the image in GPUImageView is cropped.

Thanks.

Question about Pixelation filter.

Hi all! I have a question about Pixelation filter. I've tried one in gpuimage-sample project, but it seems work not as expected for me. In camera preview this filter scales pixels as rectangles, but when i take a picture and save it to gallery pixels scaled as squares. I'm trying to get pixels scaled as squares both in gallery and camera live preview. Any help on this will be appreciated!

BTW, thanks for great library, it rocks :)

GPUImageGaussianBlurFilter breaks on some devices

I tested the sample project on a HTC Evo 4G Wimax, and when selecting the GPUImageGaussianBlurFilter the view renders only black. (fails with GL error code 1281)

I narrowed it down to the Fragment shader somewhere around these lines:

" sum += texture2D(inputImageTexture, blurCoordinates[1]).rgb * 0.09;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[2]).rgb * 0.12;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[3]).rgb * 0.15;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[4]).rgb * 0.18;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[5]).rgb * 0.15;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[6]).rgb * 0.12;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[7]).rgb * 0.09;\n" +
" sum += texture2D(inputImageTexture, blurCoordinates[8]).rgb * 0.05;\n" +

It works if i just replace these values (for testing) with textureCoordinate and skipping the multiplication with the value.

//BREAKS
sum += texture2D(inputImageTexture, blurCoordinates[2]).rgb * 0.12;

//BREAKS
sum += texture2D(inputImageTexture, textureCoordinate).rgb * 0.12;

//WORKS
sum += texture2D(inputImageTexture, textureCoordinate).rgb;

Here is the GPU Bench output for reference:

font:h2#System#font

SDK:Android unknown
ID:GRJ22
OS name:Linux
OS version:2.6.35.10-ge792f86

font:h2#Device#font

Model:PC36100
Product:htc_supersonic
Board:supersonic
Brand:KDDI

font:h2#CPU#font

Name:armeabi-v7a
Max Freq:998Mhz
Min Freq:245Mhz
Cores:1
Arch:7
BogoMips: 662.40

font:h2#Memory#font

Total:404 Mo
Free:8 Mo

font:h2#Display#font

Width:480px
Height:800px
Density:1.50(254.00|254.00)

font:h2#GPU#font

Vendor:Qualcomm
Driver:OpenGL ES 2.0 1044053
Render:Adreno 200

font:h2#GPU Extensions#font

AMD_compressed_3DC_texture
AMD_compressed_ATC_texture
AMD_performance_monitor
AMD_program_binary_Z400
EXT_texture_filter_anisotropic
EXT_texture_format_BGRA8888
EXT_texture_type_2_10_10_10_REV
OES_compressed_ETC1_RGB8_texture
OES_depth_texture
OES_depth24
OES_EGL_image
OES_element_index_uint
OES_fbo_render_mipmap
OES_fragment_precision_high
OES_get_program_binary
OES_packed_depth_stencil
OES_rgb8_rgba8
OES_standard_derivatives
OES_texture_3D
OES_texture_float
OES_texture_half_float
OES_texture_half_float_linear
OES_texture_npot
OES_vertex_half_float
OES_vertex_type_10_10_10_2
NV_fence
QCOM_driver_control
QCOM_perfmon_global_mode
QCOM_extended_get
QCOM_extended_get2
QCOM_tiled_rendering
QCOM_writeonly_rendering
QCOM_memory_monitor

Building against latest Mac x64 NDK

First of all, awesome project :)

I get the following error when building against the latest NDK using Maven. I'm pretty new to this, so I don't know if this is an issue with my NDK or something else. Any pointers to how I could fix this issue would be great.

[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.5.0:ndk-build (default) on project gpuimage-library: Can not resolve automatically a toolchain to use. Please specify one. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :gpuimage-library

Notes: I specified the NDK in the POM file as it couldn't be found automatically. Might that be related?
Update: Now specified NDK in Path instead, I get the same error. I also updated Maven to 3.0.5 without any more luck. I'm on OS X 10.8.

Update 2: This is because android-gpuimage doesn't build against OS X NDK x64. 32bit NDK worked (although I have encountered another error, but I'll check that before I report it).

Save image in High quality

Hi, I follow your work and I would like to ask you if you had planned to insert the possibility to save the image that you processing in HQ (for example 8 Mpx).
Did you plan to insert this feature ?
Did you have any idea to implement this feature?

Thanks
Paolo

video filter

did anyone developed filtershowcase for video ?

GPUImageSobelEdgeDetection filter chain, is this correct?

I am working on developing the GPUImageTwoPassFilter boiler plate class. I am looking for a good filter to test it on.

I noticed for the SobelEdgeDetection you simply use a filter group. Is it equivalent to chain two filters together as it is to do two passes? If so I would simply not spend all the effort on this, and spend more time porting filters. Otherwise, I will keep working at the GPUImageTwoPassFilter, so expect a pull request soon :)

App crashes when the range changes quickly.

When the sample app is running, if you change the range quickly, sometimes the app will crash. I got the following adb messages:

01-06 13:35:14.462 14995 15045 E AndroidRuntime: FATAL EXCEPTION: GLThread 4239
01-06 13:35:14.462 14995 15045 E AndroidRuntime: java.util.NoSuchElementException
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at java.util.LinkedList.removeFirstImpl(LinkedList.java:689)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at java.util.LinkedList.removeFirst(LinkedList.java:676)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at jp.co.cyberagent.android.gpuimage.GPUImageFilter.runPendingOnDrawTasks(GPUImageFilter.java:127)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at jp.co.cyberagent.android.gpuimage.GPUImageFilter.onDraw(GPUImageFilter.java:102)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at jp.co.cyberagent.android.gpuimage.GPUImageFilterGroup.onDraw(GPUImageFilterGroup.java:158)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at jp.co.cyberagent.android.gpuimage.GPUImageRenderer.onDrawFrame(GPUImageRenderer.java:133)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1487)
01-06 13:35:14.462 14995 15045 E AndroidRuntime: at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1241)
01-06 13:35:14.472 744 1067 W ActivityManager: Force finishing activity jp.co.cyberagent.android.gpuimage.sample/.activity.ActivityCamera
01-06 13:35:14.492 666 15052 I libcamera: int android::CameraHardware::aeAfAwbThread(): previewaeafawb is waiting

Looks like a synchronization issue?

Crash when calling getBitmapWithFilterApplied on Samsung Galaxy Y- Unable to Find Phys Addr for 0

When I call getBitmapWithFilterApplied on a Samsung Galaxy Y the activity will crash. I traced it through in the debugger, and it seems to get to line 195 in PixelBuffer which reads:

    mGL.glReadPixels(0, 0, mWidth, mHeight, GL_RGBA, GL_UNSIGNED_BYTE, ib);

The call to that method never returns and after about 30 seconds something in the OS seems to kill the activity. The only hint is the following line which appears in the log during the call to glReadPixels:

Unable to Find Phys Addr for 0

Process Video in the Background

Is it possible currently to basically show the user an unfiltered stream of video, while running some filters in the background? I thought that getBitmapForMultipleFilters was perfect until I realized that this just applies each filter individually. Is there anyway to get a bitmap image with multiple filters applied to it?

GPUImage.setFilter() needs camera tear down before working properly in live mode

Due to some atm unknown problems with the GPUImage.setFilter() method one has to partially reset the camera before calling it to prevent the preview from hanging. This applies to every usage of the aforementioned method except for using it directly after calling GPUImage.setUpCamera() for the first time.

If you want to change filters multiple times during a live preview, you have to issue the following commands every time when changing the filter:

// release camera
if (camera != null){
   camera.setPreviewCallback(null);
   camera.stopPreview();
   camera.release();
   camera = null;
}

camera = camera.getCameraInstance(); // as defined in the official Android camera tutorials

gpuImage.setUpCamera(camera);
gpuImage.setFilter(new GPUImageSepiaFilter());

As this is a somewhat costly operation it always issues a short lag.

Equivalent for GPUImageTwoInputFilter in iOS.

Hi, I could not find an equivalent for the GPUImageTwoInputFilter that is found in the iOS GPUImage library. Are there plans to include one on the Android version as well? Thank you for the great library.

gradle build library error

FAILURE: Build failed with an exception.

  • Where:
    Build file 'E:\ProjectGitHub\other\android-gpuimage\library\build.gradle' line:
    22

  • What went wrong:
    A problem occurred evaluating project ':library'.

    No such property: sonatypeRepo for class: org.gradle.api.publication.maven.int
    ernal.ant.DefaultGroovyMavenDeployer

I solve it :
// repository(url: sonatypeRepo) {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
// }
// snapshotRepository(url: sonatypeSnapshotRepo) {
// authentication(userName: sonatypeUsername, password: sonatypePassword)
// }

why it happen?

Problems with aspect ratio of GPUImageBulgeDistortionFilter in ScaleType.CENTER_INSIDE

There are a few serious problems with the aspect ratio of GPUImageBulgeDistortionFilter when in ScaleType.CENTER_INSIDE. The bulge distortion is not round, its instead oval and is offset from its center. Finally the oval doesn't bulge properly - it looks .. weird.

After spending half a day with a calculator, graph paper and a printout of the Fragment shader, I've been able to figure out the way the fragment shader code handles the input aspect ratio is just never going to work. In particular the lines:

highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float dist = distance(center, textureCoordinateToUse);
textureCoordinateToUse = textureCoordinate;

are problematic.

Secondly GPUImageBulgeDistortionFilter tries to adjust the aspect ratio in onOutputSizeChanged - however as far as I can tell this method receives the size of the glSurfaceView, not the size of the Image being worked on. The fragment shader needs to receive the aspect ratio of the image, not the surface view to correctly adjust the bulge distortion.

I was able to get it working by modifying the fragment shader code, commenting out onOutputSizedChanged and then manually setting the aspect ratio based on the image size. I doubt this is a scalable solution suitable for including in android-gpuimage but I will attach my code to this issue in the hopes that it will prove useful.

GPUImageLookupFilter not working as expected

Using a lookup bitmap doesn't produce the same results than GPUImage iOS. I looked at the code and seems the same (shame shader code). Attached a bitmap that messes up the image in android but works perfectly in iOS.
mayfair

GPUTwoInputFilter setBitmap rotation error

GPUTwoInputFilter.setBitmap with noRotation make 180º vertical rotation in second texture.

Deleting line 97 in GPUTwoInputFilter solves the problem, but disable all rotations.

I'm sorry about my english.

Equivalent for GPUImageVideoCamera in iOS.

Hi, I could not find an equivalent for the GPUImageVideoCamera that is found in the iOS GPUImage library. Are there plans to include one on the Android version as well? Thank you for the great library.

java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap

0   
java.lang.RuntimeException: An error occured while executing doInBackground()
1   
at android.os.AsyncTask$3.done(AsyncTask.java:299)
2   
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
3   
at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
4   
at java.util.concurrent.FutureTask.run(FutureTask.java:239)
5   
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
6   
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
7   
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
8   
at java.lang.Thread.run(Thread.java:856)
9   
Caused by: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41e89060
10  
at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
11  
at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
12  
at android.graphics.Bitmap.createBitmap(Bitmap.java:617)
13  
at android.graphics.Bitmap.createBitmap(Bitmap.java:514)
14  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.scaleBitmap(GPUImage.java:592)
15  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.loadResizedImage(GPUImage.java:574)
16  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.doInBackground(GPUImage.java:540)
17  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.doInBackground(GPUImage.java:516)
18  
at android.os.AsyncTask$2.call(AsyncTask.java:287)
19  
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
20  
... 4 more
21  
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@41e89060
22  
at android.graphics.Canvas.throwIfRecycled(Canvas.java:1026)
23  
at android.graphics.Canvas.drawBitmap(Canvas.java:1096)
24  
at android.graphics.Bitmap.createBitmap(Bitmap.java:617)
25  
at android.graphics.Bitmap.createBitmap(Bitmap.java:514)
26  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.scaleBitmap(GPUImage.java:592)
27  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.loadResizedImage(GPUImage.java:574)
28  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.doInBackground(GPUImage.java:540)
29  
at jp.co.cyberagent.android.gpuimage.GPUImage$LoadImageTask.doInBackground(GPUImage.java:516)
30  
at android.os.AsyncTask$2.call(AsyncTask.java:287)
31  
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
32  
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
33  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
34  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
35  
at java.lang.Thread.run(Thread.java:856)

From the SDK documentation http://developer.android.com/reference/android/graphics/Bitmap.html#createScaledBitmap(android.graphics.Bitmap, int, int, boolean):

Creates a new bitmap, scaled from an existing bitmap, when possible. If the specified width and height are the same as the current width and height of the source btimap, the source bitmap is returned and now new bitmap is created.

I think this error will be happen when the specified width and height are the same as the current width and height of the source bitmap.

private Bitmap scaleBitmap(Bitmap bitmap) {
            // resize to desired dimensions
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            int[] newSize = getScaleSize(width, height);
            Bitmap workBitmap = Bitmap.createScaledBitmap(bitmap, newSize[0], newSize[1], true);
            bitmap.recycle();
            bitmap = workBitmap;
            System.gc();

            if (mScaleType == ScaleType.CENTER_CROP) {
                // Crop it
                int diffWidth = newSize[0] - mOutputWidth;
                int diffHeight = newSize[1] - mOutputHeight;
                workBitmap = Bitmap.createBitmap(bitmap, diffWidth / 2, diffHeight / 2,
                        newSize[0] - diffWidth, newSize[1] - diffHeight);
                bitmap.recycle();
                bitmap = workBitmap;
            }

            return bitmap;
        }

Should become this:

private Bitmap scaleBitmap(Bitmap bitmap) {
            // resize to desired dimensions
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();
            int[] newSize = getScaleSize(width, height);
            Bitmap workBitmap = Bitmap.createScaledBitmap(bitmap, newSize[0],
                    newSize[1], true);
            if (workBitmap != bitmap) {
                bitmap.recycle();
                bitmap = workBitmap;
            }
            System.gc();

            if (mScaleType == ScaleType.CENTER_CROP) {
                // Crop it
                int diffWidth = newSize[0] - mOutputWidth;
                int diffHeight = newSize[1] - mOutputHeight;
                workBitmap = Bitmap.createBitmap(bitmap, diffWidth / 2,
                        diffHeight / 2, newSize[0] - diffWidth, newSize[1]
                                - diffHeight);
                if (workBitmap != bitmap) {
                    bitmap.recycle();
                    bitmap = workBitmap;
                }
            }

            return bitmap;
        }

getBitmapWithFilterApplied() returns width -1

If I use

GPUImage mGPUImage = new GPUImage(EditActivity.this);
mGPUImage.setFilter(new GPUImageSepiaFilter());
Bitmap bm = mGPUImage.getBitmapWithFilterApplied(bitmap);
imageView.setImageBitmap(bm);

in onCreate there is no problem. But when using it in my seekbar's OnSeekBarChangeListener, getBitmapWithFilterApplied(bitmap) returns width -1. I can't find the problem. Anyone experience this problem?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.