├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── ben
│ │ └── android
│ │ └── nativegpuimage
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── ben
│ │ │ └── android
│ │ │ └── nativegpuimage
│ │ │ ├── Camera1Loader.kt
│ │ │ ├── Camera2Loader.kt
│ │ │ ├── CameraActivity.kt
│ │ │ ├── CameraLoader.kt
│ │ │ ├── FBOActivity.java
│ │ │ ├── GPUImageFilterTools.kt
│ │ │ ├── ImageActivity.kt
│ │ │ ├── ImageExt.kt
│ │ │ ├── MainActivity.java
│ │ │ ├── ShowBitmapActivity.kt
│ │ │ ├── ViewExt.kt
│ │ │ └── adapter
│ │ │ └── ImageAdapter.java
│ └── res
│ │ ├── drawable-nodpi
│ │ ├── lookup_amatorka.png
│ │ ├── photo1.jpg
│ │ ├── photo2.jpg
│ │ ├── photo3.jpg
│ │ ├── photo4.jpg
│ │ └── photo5.jpg
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_camera_enhance_black_24dp.xml
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ ├── activity_camera.xml
│ │ ├── activity_fbo.xml
│ │ ├── activity_image.xml
│ │ ├── activity_main.xml
│ │ ├── activity_show_bitmap.xml
│ │ ├── capture_dialog_layout.xml
│ │ └── item_image_layout.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── network_security_config.xml
│ └── test
│ └── java
│ └── com
│ └── ben
│ └── android
│ └── nativegpuimage
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── CMakeLists.txt
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── ben
│ │ └── android
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── ben
│ │ │ └── android
│ │ │ └── library
│ │ │ ├── EGPEnvironmentListener.java
│ │ │ ├── NGP.java
│ │ │ ├── NGPConfigure.java
│ │ │ ├── NGPExecutors.java
│ │ │ ├── NGPFilterListener.java
│ │ │ ├── NGPListener.java
│ │ │ ├── NGPNativeBridge.java
│ │ │ ├── NGPSurfaceView.java
│ │ │ ├── RenderBuilder.java
│ │ │ ├── RenderManager.java
│ │ │ ├── Result.java
│ │ │ ├── filter
│ │ │ ├── DilationFilter.java
│ │ │ ├── GPUImage3x3ConvolutionFilter.java
│ │ │ ├── GPUImage3x3TextureSamplingFilter.java
│ │ │ ├── GPUImageAddBlendFilter.java
│ │ │ ├── GPUImageAlphaBlendFilter.java
│ │ │ ├── GPUImageBrightnessFilter.java
│ │ │ ├── GPUImageContrastFilter.java
│ │ │ ├── GPUImageCrosshatchFilter.java
│ │ │ ├── GPUImageDirectionalSobelEdgeDetectionFilter.java
│ │ │ ├── GPUImageDissolveBlendFilter.java
│ │ │ ├── GPUImageDivideBlendFilter.java
│ │ │ ├── GPUImageEmbossFilter.java
│ │ │ ├── GPUImageExclusionBlendFilter.java
│ │ │ ├── GPUImageExposureFilter.java
│ │ │ ├── GPUImageFalseColorFilter.java
│ │ │ ├── GPUImageGammaFilter.java
│ │ │ ├── GPUImageGrayscaleFilter.java
│ │ │ ├── GPUImageHalftoneFilter.java
│ │ │ ├── GPUImageHazeFilter.java
│ │ │ ├── GPUImageHighlightShadowFilter.java
│ │ │ ├── GPUImageHueFilter.java
│ │ │ ├── GPUImageLevelsFilter.java
│ │ │ ├── GPUImageLuminanceFilter.java
│ │ │ ├── GPUImageLuminanceThresholdFilter.java
│ │ │ ├── GPUImageMixBlendFilter.java
│ │ │ ├── GPUImageMonochromeFilter.java
│ │ │ ├── GPUImageRGBDilationFilter.java
│ │ │ ├── GPUImageRGBFilter.java
│ │ │ ├── GPUImageSaturationFilter.java
│ │ │ ├── GPUImageSharpenFilter.java
│ │ │ ├── GPUImageSketchFilter.java
│ │ │ ├── GPUImageSobelEdgeDetectionFilter.java
│ │ │ ├── GPUImageSobelThresholdFilter.java
│ │ │ ├── GPUImageSolarizeFilter.java
│ │ │ ├── GPUImageThresholdEdgeDetectionFilter.java
│ │ │ ├── GPUImageToonFilter.java
│ │ │ ├── GPUImageTwoInputFilter.java
│ │ │ ├── GPUImageVibranceFilter.java
│ │ │ ├── GPUImageVignetteFilter.java
│ │ │ ├── GPUImageWeakPixelInclusionFilter.java
│ │ │ ├── GPUImageWhiteBalanceFilter.java
│ │ │ ├── GaussianBlurFilter.java
│ │ │ ├── NativeFilter.java
│ │ │ ├── PixelationFilter.java
│ │ │ └── ZoomBlurFilter.java
│ │ │ ├── jni
│ │ │ ├── NativeObject.java
│ │ │ └── annotations
│ │ │ │ └── UsedByNativeCode.java
│ │ │ ├── load
│ │ │ ├── engine
│ │ │ │ ├── Resource.java
│ │ │ │ ├── ResourceFetcherGenerator.java
│ │ │ │ └── ResourceGenerator.java
│ │ │ └── fetcher
│ │ │ │ ├── ContentLengthInputStream.java
│ │ │ │ ├── DataFetcher.java
│ │ │ │ ├── FileFetcher.java
│ │ │ │ ├── HttpException.java
│ │ │ │ ├── HttpUrlFetcher.java
│ │ │ │ ├── MemoryFetcher.java
│ │ │ │ └── ResourceFetcher.java
│ │ │ ├── render
│ │ │ ├── Render.java
│ │ │ ├── RenderFetcherGenerator.java
│ │ │ └── RenderGenerator.java
│ │ │ └── util
│ │ │ ├── FilterTools.java
│ │ │ ├── FilterType.java
│ │ │ ├── NGPListenerTools.java
│ │ │ ├── Rotation.java
│ │ │ └── ScaleType.java
│ ├── jni
│ │ ├── api
│ │ │ ├── CMakeLists.txt
│ │ │ ├── android_gl_bridge.cpp
│ │ │ ├── android_gl_bridge.hpp
│ │ │ ├── android_native_filter.cpp
│ │ │ └── android_native_filter.hpp
│ │ ├── filter
│ │ │ ├── CMakeLists.txt
│ │ │ ├── gpu_image_3x3_convolution_filter.cpp
│ │ │ ├── gpu_image_3x3_convolution_filter.hpp
│ │ │ ├── gpu_image_3x3_texture_sampling_filter.cpp
│ │ │ ├── gpu_image_3x3_texture_sampling_filter.hpp
│ │ │ ├── gpu_image_add_blend_filter.cpp
│ │ │ ├── gpu_image_add_blend_filter.hpp
│ │ │ ├── gpu_image_alpha_blend_filter.cpp
│ │ │ ├── gpu_image_alpha_blend_filter.hpp
│ │ │ ├── gpu_image_brightness_filter.cpp
│ │ │ ├── gpu_image_brightness_filter.hpp
│ │ │ ├── gpu_image_contrast_filter.cpp
│ │ │ ├── gpu_image_contrast_filter.hpp
│ │ │ ├── gpu_image_crosshatch_filter.cpp
│ │ │ ├── gpu_image_crosshatch_filter.hpp
│ │ │ ├── gpu_image_dilation_filter.cpp
│ │ │ ├── gpu_image_dilation_filter.hpp
│ │ │ ├── gpu_image_directional_sobel_edge_detection_filter.cpp
│ │ │ ├── gpu_image_directional_sobel_edge_detection_filter.hpp
│ │ │ ├── gpu_image_dissolve_blend_filter.cpp
│ │ │ ├── gpu_image_dissolve_blend_filter.hpp
│ │ │ ├── gpu_image_divide_blend_filter.cpp
│ │ │ ├── gpu_image_divide_blend_filter.hpp
│ │ │ ├── gpu_image_emboss_filter.cpp
│ │ │ ├── gpu_image_emboss_filter.hpp
│ │ │ ├── gpu_image_exclusion_blend_filter.cpp
│ │ │ ├── gpu_image_exclusion_blend_filter.hpp
│ │ │ ├── gpu_image_exposure_filter.cpp
│ │ │ ├── gpu_image_exposure_filter.hpp
│ │ │ ├── gpu_image_false_color_filter.cpp
│ │ │ ├── gpu_image_false_color_filter.hpp
│ │ │ ├── gpu_image_filter.cpp
│ │ │ ├── gpu_image_filter.hpp
│ │ │ ├── gpu_image_filter_group.cpp
│ │ │ ├── gpu_image_filter_group.hpp
│ │ │ ├── gpu_image_gamma_filter.cpp
│ │ │ ├── gpu_image_gamma_filter.hpp
│ │ │ ├── gpu_image_gaussian_blur_filter.cpp
│ │ │ ├── gpu_image_gaussian_blur_filter.hpp
│ │ │ ├── gpu_image_grayscale_filter.cpp
│ │ │ ├── gpu_image_grayscale_filter.hpp
│ │ │ ├── gpu_image_halftone_filter.cpp
│ │ │ ├── gpu_image_halftone_filter.hpp
│ │ │ ├── gpu_image_haze_filter.cpp
│ │ │ ├── gpu_image_haze_filter.hpp
│ │ │ ├── gpu_image_highlight_shadow_filter.cpp
│ │ │ ├── gpu_image_highlight_shadow_filter.hpp
│ │ │ ├── gpu_image_hue_filter.cpp
│ │ │ ├── gpu_image_hue_filter.hpp
│ │ │ ├── gpu_image_levels_filter.cpp
│ │ │ ├── gpu_image_levels_filter.hpp
│ │ │ ├── gpu_image_luminance_filter.cpp
│ │ │ ├── gpu_image_luminance_filter.hpp
│ │ │ ├── gpu_image_luminance_threshold_filter.cpp
│ │ │ ├── gpu_image_luminance_threshold_filter.hpp
│ │ │ ├── gpu_image_mix_blend_filter.cpp
│ │ │ ├── gpu_image_mix_blend_filter.hpp
│ │ │ ├── gpu_image_monochrome_filter.cpp
│ │ │ ├── gpu_image_monochrome_filter.hpp
│ │ │ ├── gpu_image_pixelation_filter.cpp
│ │ │ ├── gpu_image_pixelation_filter.hpp
│ │ │ ├── gpu_image_rgb_dilation_filter.cpp
│ │ │ ├── gpu_image_rgb_dilation_filter.hpp
│ │ │ ├── gpu_image_rgb_filter.cpp
│ │ │ ├── gpu_image_rgb_filter.hpp
│ │ │ ├── gpu_image_saturation_filter.cpp
│ │ │ ├── gpu_image_saturation_filter.hpp
│ │ │ ├── gpu_image_sharpen_filter.cpp
│ │ │ ├── gpu_image_sharpen_filter.hpp
│ │ │ ├── gpu_image_sketch_filter.cpp
│ │ │ ├── gpu_image_sketch_filter.hpp
│ │ │ ├── gpu_image_sobel_edge_detection_filter.cpp
│ │ │ ├── gpu_image_sobel_edge_detection_filter.hpp
│ │ │ ├── gpu_image_sobel_threshold_filter.cpp
│ │ │ ├── gpu_image_sobel_threshold_filter.hpp
│ │ │ ├── gpu_image_solarize_filter.cpp
│ │ │ ├── gpu_image_solarize_filter.hpp
│ │ │ ├── gpu_image_threshold_edge_detection_filter.cpp
│ │ │ ├── gpu_image_threshold_edge_detection_filter.hpp
│ │ │ ├── gpu_image_toon_filter.cpp
│ │ │ ├── gpu_image_toon_filter.hpp
│ │ │ ├── gpu_image_two_input_filter.cpp
│ │ │ ├── gpu_image_two_input_filter.hpp
│ │ │ ├── gpu_image_two_pass_filter.cpp
│ │ │ ├── gpu_image_two_pass_filter.hpp
│ │ │ ├── gpu_image_two_pass_texture_sampling_filter.cpp
│ │ │ ├── gpu_image_two_pass_texture_sampling_filter.hpp
│ │ │ ├── gpu_image_vibrance_filter.cpp
│ │ │ ├── gpu_image_vibrance_filter.hpp
│ │ │ ├── gpu_image_vignette_filter.cpp
│ │ │ ├── gpu_image_vignette_filter.hpp
│ │ │ ├── gpu_image_weak_pixel_inclusion_filter.cpp
│ │ │ ├── gpu_image_weak_pixel_inclusion_filter.hpp
│ │ │ ├── gpu_image_white_balance_filter.cpp
│ │ │ ├── gpu_image_white_balance_filter.hpp
│ │ │ ├── gpu_image_zoom_blur_filter.cpp
│ │ │ └── gpu_image_zoom_blur_filter.hpp
│ │ ├── global_native_class_ptr.cpp
│ │ ├── global_native_class_ptr.hpp
│ │ ├── gpu_image_render.cpp
│ │ ├── gpu_image_render.hpp
│ │ ├── include
│ │ │ ├── jni
│ │ │ │ ├── ByteArray.cpp
│ │ │ │ ├── ByteArray.h
│ │ │ │ ├── CMakeLists.txt
│ │ │ │ ├── ClassRegistry.cpp
│ │ │ │ ├── ClassRegistry.h
│ │ │ │ ├── JavaClass.cpp
│ │ │ │ ├── JavaClass.h
│ │ │ │ ├── JavaClassUtils.cpp
│ │ │ │ ├── JavaClassUtils.h
│ │ │ │ ├── JavaExceptionUtils.cpp
│ │ │ │ ├── JavaExceptionUtils.h
│ │ │ │ ├── JavaString.cpp
│ │ │ │ ├── JavaString.h
│ │ │ │ ├── JavaStringArray.cpp
│ │ │ │ ├── JavaStringArray.h
│ │ │ │ ├── JavaThreadUtils.cpp
│ │ │ │ ├── JavaThreadUtils.h
│ │ │ │ ├── JniGlobalRef.h
│ │ │ │ ├── JniHelpers.cpp
│ │ │ │ ├── JniHelpers.h
│ │ │ │ ├── JniHelpersCommon.h
│ │ │ │ ├── JniLocalRef.h
│ │ │ │ ├── JniTypes.h
│ │ │ │ ├── JniWeakGlobalRef.h
│ │ │ │ ├── NativeObject.cpp
│ │ │ │ ├── NativeObject.h
│ │ │ │ ├── ScopedPtr.h
│ │ │ │ ├── ShortArray.cpp
│ │ │ │ ├── ShortArray.h
│ │ │ │ └── logger.hpp
│ │ │ ├── libyuv.h
│ │ │ ├── libyuv
│ │ │ │ ├── basic_types.h
│ │ │ │ ├── compare.h
│ │ │ │ ├── compare_row.h
│ │ │ │ ├── convert.h
│ │ │ │ ├── convert_argb.h
│ │ │ │ ├── convert_from.h
│ │ │ │ ├── convert_from_argb.h
│ │ │ │ ├── cpu_id.h
│ │ │ │ ├── macros_msa.h
│ │ │ │ ├── mjpeg_decoder.h
│ │ │ │ ├── planar_functions.h
│ │ │ │ ├── rotate.h
│ │ │ │ ├── rotate_argb.h
│ │ │ │ ├── rotate_row.h
│ │ │ │ ├── row.h
│ │ │ │ ├── scale.h
│ │ │ │ ├── scale_argb.h
│ │ │ │ ├── scale_row.h
│ │ │ │ ├── version.h
│ │ │ │ └── video_common.h
│ │ │ ├── queue.c
│ │ │ └── queue.h
│ │ ├── libcommon
│ │ │ └── native_exception.hpp
│ │ ├── main.cpp
│ │ └── util
│ │ │ ├── filter_tools.hpp
│ │ │ ├── filter_type.hpp
│ │ │ ├── jni_util.hpp
│ │ │ ├── open_gl_util.hpp
│ │ │ ├── rotation.hpp
│ │ │ ├── scale_type.hpp
│ │ │ └── textur_rotation_util.hpp
│ ├── jniLibs
│ │ ├── arm64-v8a
│ │ │ └── libyuv.so
│ │ ├── armeabi
│ │ │ └── libyuv.so
│ │ ├── mips
│ │ │ └── libyuv.so
│ │ ├── mips64
│ │ │ └── libyuv.so
│ │ ├── x86
│ │ │ └── libyuv.so
│ │ └── x86_64
│ │ │ └── libyuv.so
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── ben
│ └── android
│ └── library
│ └── ExampleUnitTest.java
├── photos
├── photo1.jpg
├── photo2.jpg
├── photo3.jpg
├── photo4.jpg
└── photo5.jpg
├── screen
├── capture1.gif
├── capture2.gif
├── capture3.jpg
└── capture4.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 28
7 | defaultConfig {
8 | applicationId "com.ben.android.nativegpuimage"
9 | minSdkVersion 15
10 | targetSdkVersion 28
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | implementation 'com.android.support:appcompat-v7:28.0.0'
26 | implementation "com.android.support:cardview-v7:28.0.0"
27 | implementation "com.android.support:design:28.0.0"
28 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
29 | testImplementation 'junit:junit:4.12'
30 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
31 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32 |
33 | implementation project(':library')
34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35 | implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.47'
36 |
37 | implementation 'com.github.bumptech.glide:glide:4.9.0'
38 | }
39 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/ben/android/nativegpuimage/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.nativegpuimage;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ben.android.nativegpuimage", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ben/android/nativegpuimage/CameraLoader.kt:
--------------------------------------------------------------------------------
1 | package jp.co.cyberagent.android.gpuimage.sample.utils
2 |
3 |
4 | abstract class CameraLoader {
5 |
6 | protected var onPreviewFrame: ((data: ByteArray, width: Int, height: Int) -> Unit)? = null
7 |
8 | abstract fun onResume(width: Int, height: Int)
9 |
10 | abstract fun onPause()
11 |
12 | abstract fun switchCamera()
13 |
14 | abstract fun getCameraOrientation(): Int
15 |
16 | abstract fun hasMultipleCamera(): Boolean
17 |
18 | fun setOnPreviewFrameListener(onPreviewFrame: (data: ByteArray, width: Int, height: Int) -> Unit) {
19 | this.onPreviewFrame = onPreviewFrame
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ben/android/nativegpuimage/ImageExt.kt:
--------------------------------------------------------------------------------
1 | package com.ben.android.nativegpuimage
2 |
3 | import android.graphics.ImageFormat
4 | import android.media.Image
5 | import android.os.Build
6 | import android.support.annotation.RequiresApi
7 |
8 | @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
9 | fun Image.generateNV21Data(): ByteArray {
10 | val crop = cropRect
11 | val format = format
12 | val width = crop.width()
13 | val height = crop.height()
14 | val planes = planes
15 | val data = ByteArray(width * height * ImageFormat.getBitsPerPixel(format) / 8)
16 | val rowData = ByteArray(planes[0].rowStride)
17 | var channelOffset = 0
18 | var outputStride = 1
19 | for (i in planes.indices) {
20 | when (i) {
21 | 0 -> {
22 | channelOffset = 0
23 | outputStride = 1
24 | }
25 | 1 -> {
26 | channelOffset = width * height + 1
27 | outputStride = 2
28 | }
29 | 2 -> {
30 | channelOffset = width * height
31 | outputStride = 2
32 | }
33 | }
34 | val buffer = planes[i].buffer
35 | val rowStride = planes[i].rowStride
36 | val pixelStride = planes[i].pixelStride
37 | val shift = if (i == 0) 0 else 1
38 | val w = width shr shift
39 | val h = height shr shift
40 | buffer.position(rowStride * (crop.top shr shift) + pixelStride * (crop.left shr shift))
41 | for (row in 0 until h) {
42 | val length: Int
43 | if (pixelStride == 1 && outputStride == 1) {
44 | length = w
45 | buffer.get(data, channelOffset, length)
46 | channelOffset += length
47 | } else {
48 | length = (w - 1) * pixelStride + 1
49 | buffer.get(rowData, 0, length)
50 | for (col in 0 until w) {
51 | data[channelOffset] = rowData[col * pixelStride]
52 | channelOffset += outputStride
53 | }
54 | }
55 | if (row < h - 1) {
56 | buffer.position(buffer.position() + rowStride - length)
57 | }
58 | }
59 | }
60 | return data
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ben/android/nativegpuimage/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.nativegpuimage;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | import com.ben.android.library.NGP;
9 | import com.ben.android.library.NGPExecutors;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 | NGP.initialize(this);
18 |
19 | NGPExecutors.execute(new Runnable() {
20 | @Override
21 | public void run() {
22 | NGP.get().clearCache();
23 | }
24 | });
25 | }
26 |
27 | public void fboTest(View view) {
28 | startActivity(new Intent(this, ImageActivity.class));
29 | }
30 |
31 | public void showRenderBitmap(View view) {
32 | startActivity(new Intent(this, ShowBitmapActivity.class));
33 | }
34 |
35 | public void cameraRender(View view) {
36 | startActivity(new Intent(this, CameraActivity.class));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ben/android/nativegpuimage/ViewExt.kt:
--------------------------------------------------------------------------------
1 | package com.ben.android.nativegpuimage
2 |
3 | import android.support.v4.view.ViewCompat
4 | import android.view.View
5 |
6 | inline fun View.doOnLayout(crossinline action: (view: View) -> Unit) {
7 | if (ViewCompat.isLaidOut(this) && !isLayoutRequested) {
8 | action(this)
9 | } else {
10 | doOnNextLayout { action(it) }
11 | }
12 | }
13 |
14 | inline fun View.doOnNextLayout(crossinline action: (view: View) -> Unit) {
15 | addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
16 | override fun onLayoutChange(
17 | view: View,
18 | left: Int,
19 | top: Int,
20 | right: Int,
21 | bottom: Int,
22 | oldLeft: Int,
23 | oldTop: Int,
24 | oldRight: Int,
25 | oldBottom: Int
26 | ) {
27 | view.removeOnLayoutChangeListener(this)
28 | action(view)
29 | }
30 | })
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/lookup_amatorka.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/lookup_amatorka.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/photo1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/photo1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/photo2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/photo2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/photo3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/photo3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/photo4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/photo4.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-nodpi/photo5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/drawable-nodpi/photo5.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_camera_enhance_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
15 |
16 |
29 |
30 |
40 |
41 |
48 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fbo.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
15 |
16 |
28 |
29 |
36 |
37 |
42 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_show_bitmap.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/capture_dialog_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_image_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
15 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F44336
4 | #FF5722
5 | #673AB7
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NativeGPUImage
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/test/java/com/ben/android/nativegpuimage/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.nativegpuimage;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.31'
5 |
6 | repositories {
7 | google()
8 | jcenter()
9 |
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.4.2'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | maven { url "https://jitpack.io" }
24 |
25 | }
26 | }
27 |
28 | task clean(type: Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Sep 12 13:36:55 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 |
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | externalNativeBuild {
16 | cmake {
17 | arguments "-DANDROID_ARM_NEON=TRUE"
18 | cppFlags "-fexceptions -std=c++11"
19 | }
20 | }
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 | externalNativeBuild {
30 | cmake {
31 | path file('CMakeLists.txt')
32 | }
33 | }
34 |
35 | }
36 |
37 | dependencies {
38 | implementation fileTree(dir: 'libs', include: ['*.jar'])
39 | implementation 'com.android.support:appcompat-v7:28.0.0'
40 | testImplementation 'junit:junit:4.12'
41 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
42 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
43 | }
44 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/ben/android/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.ben.android.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/EGPEnvironmentListener.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/10/14
7 | */
8 | public interface EGPEnvironmentListener {
9 | void onCreateEGLFinish();
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/NGPConfigure.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/11
9 | */
10 | public class NGPConfigure {
11 | private Context context;
12 | private String cacheDir;
13 |
14 |
15 | public NGPConfigure(ConfigurBuilder configurBuilder) {
16 | this.context = configurBuilder.context;
17 | this.cacheDir = configurBuilder.cacheDir;
18 | }
19 |
20 | public Context getContext() {
21 | return context;
22 | }
23 |
24 | public String getCacheDir() {
25 | return cacheDir;
26 | }
27 |
28 | public void setCacheDir(String cacheDir) {
29 | this.cacheDir = cacheDir;
30 | }
31 |
32 | public static class ConfigurBuilder {
33 | private Context context;
34 | private String cacheDir;
35 |
36 | public ConfigurBuilder context(Context context) {
37 | this.context = context;
38 | return this;
39 | }
40 |
41 | public ConfigurBuilder cacheDir(String cacheDir) {
42 | this.cacheDir = cacheDir;
43 | return this;
44 | }
45 |
46 | public NGPConfigure build() {
47 | return new NGPConfigure(this);
48 | }
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/NGPFilterListener.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import com.ben.android.library.render.Render;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/10
9 | */
10 | public interface NGPFilterListener {
11 | Render.UpgradRender apply(Render.UpgradRender render, int position);
12 | }
13 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/NGPListener.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/10/9
7 | */
8 | public interface NGPListener {
9 | void onRenderStart();
10 |
11 | void onRenderFinish();
12 |
13 | void onRender(Result result);
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/NGPSurfaceView.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.SurfaceHolder;
6 | import android.view.SurfaceView;
7 | import android.widget.FrameLayout;
8 |
9 | /**
10 | * @author @zhangchuan622@gmail.com
11 | * @version 1.0
12 | * @create 2019/9/22
13 | */
14 | public class NGPSurfaceView extends FrameLayout implements SurfaceHolder.Callback {
15 | protected SurfaceView mSurfaceView;
16 | protected boolean isCreteGL = false;
17 | private EGPEnvironmentListener EGPEnvironmentListener;
18 |
19 | public void setEGPEnvironmentListener(EGPEnvironmentListener EGPEnvironmentListener) {
20 | this.EGPEnvironmentListener = EGPEnvironmentListener;
21 | }
22 |
23 | public NGPSurfaceView(Context context) {
24 | super(context);
25 | }
26 |
27 | public NGPSurfaceView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 |
30 | }
31 |
32 | public void initialize(){
33 | initialize(null);
34 | }
35 | public void initialize(EGPEnvironmentListener EGPEnvironmentListener){
36 | this.EGPEnvironmentListener = EGPEnvironmentListener;
37 | mSurfaceView = new SurfaceView(getContext());
38 | this.addView(mSurfaceView);
39 | mSurfaceView.getHolder().addCallback(this);
40 | }
41 |
42 | @Override
43 | public void surfaceCreated(final SurfaceHolder holder) {
44 | NGPNativeBridge.nativeSurfaceCreated(holder.getSurface());
45 | isCreteGL = true;
46 | if (EGPEnvironmentListener !=null) EGPEnvironmentListener.onCreateEGLFinish();
47 | }
48 |
49 | @Override
50 | public void surfaceChanged(SurfaceHolder holder, int format, final int w, final int h) {
51 | NGPNativeBridge.nativeSurfaceChanged(w, h);
52 | NGPNativeBridge.nativeRequestRender();
53 | }
54 |
55 | @Override
56 | public void surfaceDestroyed(SurfaceHolder holder) {
57 | NGPNativeBridge.nativeDestorySurfaceGL();
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/Result.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.text.TextUtils;
8 |
9 | import com.ben.android.library.filter.NativeFilter;
10 |
11 | import java.io.File;
12 |
13 | /**
14 | * @author @zhangchuan622@gmail.com
15 | * @version 1.0
16 | * @create 2019/10/10
17 | */
18 | public class Result {
19 | @Nullable
20 | private Bitmap bitmap;
21 | @NonNull
22 | private String path;
23 | private NativeFilter filter;
24 | private String filterName;
25 |
26 | private Result(NativeFilter filter, String filterName, @NonNull String path, @Nullable Bitmap bitmap ) {
27 | this.bitmap = bitmap;
28 | this.path = path;
29 | this.filter = filter;
30 | this.filterName = filterName;
31 | }
32 |
33 | public Bitmap getBitmap() {
34 | return TextUtils.isEmpty(path) ? bitmap : BitmapFactory.decodeFile(path);
35 | }
36 |
37 | @NonNull
38 | public String getPath() {
39 | return path;
40 | }
41 |
42 | public NativeFilter getFilter() {
43 | return filter;
44 | }
45 |
46 | public String getFilterName() {
47 | return filterName;
48 | }
49 |
50 | public static Result obtain(NativeFilter filter,String filterName,File file) {
51 | return new Result(filter,filterName,file.getPath(),null);
52 | }
53 | public static Result obtain(NativeFilter filter,String filterName,Bitmap bitmap) {
54 | return new Result(filter, filterName, null, bitmap);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/DilationFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.IntRange;
4 |
5 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
6 | import com.ben.android.library.util.FilterType;
7 |
8 | /**
9 | * @author @zhangchuan622@gmail.com
10 | * @version 1.0
11 | * @create 2019/9/24
12 | */
13 | public class DilationFilter extends NativeFilter {
14 | /**
15 | * Acceptable values for dilationRadius, which sets the distance in pixels to sample out from the center,
16 | * are 1, 2, 3, and 4.
17 | */
18 | private int radius;
19 |
20 | @SuppressWarnings("UnusedDeclaration")
21 | @UsedByNativeCode
22 | public int getRadius() {
23 | return radius;
24 | }
25 | @SuppressWarnings("UnusedDeclaration")
26 | @UsedByNativeCode
27 | public void setRadius(@IntRange(from = 1,to = 4) int radius) {
28 | this.radius = radius;
29 | }
30 |
31 | public DilationFilter() {
32 | this(1);
33 | }
34 |
35 | public DilationFilter(int radius) {
36 | super(FilterType.DILATION.ordinal());
37 | this.radius = radius;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImage3x3TextureSamplingFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/9/27
7 | */
8 | public class GPUImage3x3TextureSamplingFilter extends NativeFilter {
9 | private float texelWidth;
10 | private float texelHeight;
11 | private float lineSize = 1.0f;
12 |
13 | public GPUImage3x3TextureSamplingFilter(int filterType) {
14 | super(filterType);
15 | }
16 |
17 | public float getTexelWidth() {
18 | return texelWidth;
19 | }
20 |
21 | public void setTexelWidth(float texelWidth) {
22 | this.texelWidth = texelWidth;
23 | }
24 |
25 | public float getTexelHeight() {
26 | return texelHeight;
27 | }
28 |
29 | public void setTexelHeight(float texelHeight) {
30 | this.texelHeight = texelHeight;
31 | }
32 |
33 | public float getLineSize() {
34 | return lineSize;
35 | }
36 |
37 | public void setLineSize(float lineSize) {
38 | this.lineSize = lineSize;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageAddBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/28
11 | */
12 | public class GPUImageAddBlendFilter extends GPUImageTwoInputFilter {
13 | public GPUImageAddBlendFilter() {
14 | this(FilterType.BLEND_ADD.ordinal(), null);
15 | }
16 | public GPUImageAddBlendFilter(Bitmap bitmap) {
17 | this(FilterType.BLEND_ADD.ordinal(), bitmap);
18 | }
19 |
20 | public GPUImageAddBlendFilter(int filterType, Bitmap bitmap) {
21 | super(filterType, bitmap);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageAlphaBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/29
11 | */
12 | public class GPUImageAlphaBlendFilter extends GPUImageMixBlendFilter {
13 | public GPUImageAlphaBlendFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageAlphaBlendFilter(float mix) {
18 | this(null, mix);
19 | }
20 |
21 | public GPUImageAlphaBlendFilter(Bitmap bitmap) {
22 | this(bitmap, 1.0f);
23 | }
24 |
25 |
26 | public GPUImageAlphaBlendFilter(Bitmap bitmap, float alpha) {
27 | super(FilterType.BLEND_ALPHA.ordinal(), bitmap, alpha);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageBrightnessFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageBrightnessFilter extends NativeFilter {
11 | private float brightness;
12 |
13 | public GPUImageBrightnessFilter() {
14 | this(0.0f);
15 | }
16 |
17 | public GPUImageBrightnessFilter(float brightness) {
18 | super(FilterType.BRIGHTNESS.ordinal());
19 | this.brightness = brightness;
20 | }
21 |
22 | public float getBrightness() {
23 | return brightness;
24 | }
25 |
26 | public void setBrightness(float brightness) {
27 | this.brightness = brightness;
28 | }
29 |
30 | @Override
31 | public String toString() {
32 | return "GPUImageBrightnessFilter{" +
33 | "brightness=" + brightness +
34 | '}';
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageContrastFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageContrastFilter extends NativeFilter{
11 | private float contrast;
12 |
13 | public GPUImageContrastFilter() {
14 | this(1.2f);
15 | }
16 |
17 | public GPUImageContrastFilter(float contrast) {
18 | super(FilterType.CONTRAST.ordinal());
19 | this.contrast = contrast;
20 | }
21 |
22 | public float getContrast() {
23 | return contrast;
24 | }
25 |
26 | public void setContrast(float contrast) {
27 | this.contrast = contrast;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageCrosshatchFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageCrosshatchFilter extends NativeFilter {
11 | private float crossHatchSpacing;
12 | private float lineWidth;
13 |
14 | public GPUImageCrosshatchFilter() {
15 | this(0.03f, 0.003f);
16 | }
17 |
18 | public GPUImageCrosshatchFilter(float crossHatchSpacing, float lineWidth) {
19 | super(FilterType.CROSSHATCH.ordinal());
20 | this.crossHatchSpacing = crossHatchSpacing;
21 | this.lineWidth = lineWidth;
22 | }
23 |
24 | public float getCrossHatchSpacing() {
25 | return crossHatchSpacing;
26 | }
27 |
28 | public void setCrossHatchSpacing(float crossHatchSpacing) {
29 | this.crossHatchSpacing = crossHatchSpacing;
30 | }
31 |
32 | public float getLineWidth() {
33 | return lineWidth;
34 | }
35 |
36 | public void setLineWidth(float lineWidth) {
37 | this.lineWidth = lineWidth;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageDirectionalSobelEdgeDetectionFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/9/29
7 | */
8 | public class GPUImageDirectionalSobelEdgeDetectionFilter extends GPUImage3x3TextureSamplingFilter {
9 |
10 | public GPUImageDirectionalSobelEdgeDetectionFilter(int filterType) {
11 | super(filterType);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageDissolveBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/29
11 | */
12 | public class GPUImageDissolveBlendFilter extends GPUImageMixBlendFilter{
13 | public GPUImageDissolveBlendFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageDissolveBlendFilter(float mix) {
18 | this(null, mix);
19 | }
20 |
21 | public GPUImageDissolveBlendFilter(Bitmap bitmap) {
22 | this(bitmap, 1.0f);
23 | }
24 |
25 |
26 | public GPUImageDissolveBlendFilter(Bitmap bitmap, float alpha) {
27 | super(FilterType.BLEND_ALPHA.ordinal(), bitmap, alpha);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageDivideBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/29
11 | */
12 | public class GPUImageDivideBlendFilter extends GPUImageTwoInputFilter {
13 | public GPUImageDivideBlendFilter() {
14 | this(null);
15 | }
16 |
17 | public GPUImageDivideBlendFilter(Bitmap bitmap) {
18 | super(FilterType.BLEND_DIVIDE.ordinal(), bitmap);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageEmbossFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageEmbossFilter extends GPUImage3x3ConvolutionFilter {
11 | private float intensity;
12 |
13 | public GPUImageEmbossFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageEmbossFilter(float intensity) {
18 | super(FilterType.EMBOSS.ordinal());
19 | this.intensity = intensity;
20 | }
21 |
22 | public float getIntensity() {
23 | return intensity;
24 | }
25 |
26 | public void setIntensity(float intensity) {
27 | this.intensity = intensity;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageExclusionBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageExclusionBlendFilter extends GPUImageTwoInputFilter {
11 | public GPUImageExclusionBlendFilter() {
12 | super(FilterType.BLEND_EXCLUSION.ordinal(),null);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageExposureFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageExposureFilter extends NativeFilter{
11 | private float exposure;
12 |
13 | public GPUImageExposureFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageExposureFilter(float exposure) {
18 | super(FilterType.EXPOSURE.ordinal());
19 | this.exposure = exposure;
20 | }
21 |
22 | public float getExposure() {
23 | return exposure;
24 | }
25 |
26 | public void setExposure(float exposure) {
27 | this.exposure = exposure;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageFalseColorFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageFalseColorFilter extends NativeFilter {
11 | private float firstRed, firstGreen, firstBlue, secondRed, secondGreen, secondBlue;
12 |
13 | public GPUImageFalseColorFilter() {
14 | this(0f, 0f, 0.5f, 1f, 0f, 0f);
15 | }
16 |
17 | public GPUImageFalseColorFilter(float firstRed, float firstGreen, float firstBlue, float secondRed, float secondGreen, float secondBlue) {
18 | super(FilterType.FALSE_COLOR.ordinal());
19 | this.firstRed = firstRed;
20 | this.firstGreen = firstGreen;
21 | this.firstBlue = firstBlue;
22 | this.secondRed = secondRed;
23 | this.secondGreen = secondGreen;
24 | this.secondBlue = secondBlue;
25 | }
26 |
27 | public float getFirstRed() {
28 | return firstRed;
29 | }
30 |
31 | public void setFirstRed(float firstRed) {
32 | this.firstRed = firstRed;
33 | }
34 |
35 | public float getFirstGreen() {
36 | return firstGreen;
37 | }
38 |
39 | public void setFirstGreen(float firstGreen) {
40 | this.firstGreen = firstGreen;
41 | }
42 |
43 | public float getFirstBlue() {
44 | return firstBlue;
45 | }
46 |
47 | public void setFirstBlue(float firstBlue) {
48 | this.firstBlue = firstBlue;
49 | }
50 |
51 | public float getSecondRed() {
52 | return secondRed;
53 | }
54 |
55 | public void setSecondRed(float secondRed) {
56 | this.secondRed = secondRed;
57 | }
58 |
59 | public float getSecondGreen() {
60 | return secondGreen;
61 | }
62 |
63 | public void setSecondGreen(float secondGreen) {
64 | this.secondGreen = secondGreen;
65 | }
66 |
67 | public float getSecondBlue() {
68 | return secondBlue;
69 | }
70 |
71 | public void setSecondBlue(float secondBlue) {
72 | this.secondBlue = secondBlue;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageGammaFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageGammaFilter extends NativeFilter {
11 | private float gamma;
12 |
13 | public GPUImageGammaFilter() {
14 | this(1.2f);
15 | }
16 | public GPUImageGammaFilter(float gamma) {
17 | super(FilterType.GAMMA.ordinal());
18 | this.gamma = gamma;
19 | }
20 |
21 | public float getGamma() {
22 | return gamma;
23 | }
24 |
25 | public void setGamma(float gamma) {
26 | this.gamma = gamma;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageGrayscaleFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageGrayscaleFilter extends NativeFilter {
11 | public GPUImageGrayscaleFilter() {
12 | super(FilterType.GRAYSCALE.ordinal());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageHalftoneFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageHalftoneFilter extends NativeFilter {
11 | private float fractionalWidthOfAPixel;
12 |
13 | public GPUImageHalftoneFilter() {
14 | this(0.01f);
15 | }
16 |
17 | public GPUImageHalftoneFilter(float fractionalWidthOfAPixel) {
18 | super(FilterType.HALFTONE.ordinal());
19 | this.fractionalWidthOfAPixel = fractionalWidthOfAPixel;
20 | }
21 |
22 | public float getFractionalWidthOfAPixel() {
23 | return fractionalWidthOfAPixel;
24 | }
25 |
26 | public void setFractionalWidthOfAPixel(float fractionalWidthOfAPixel) {
27 | this.fractionalWidthOfAPixel = fractionalWidthOfAPixel;
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageHazeFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageHazeFilter extends NativeFilter {
13 | private float distance;
14 | private float slope;
15 |
16 | public GPUImageHazeFilter() {
17 | this(0.2f, 0.0f);
18 | }
19 |
20 | public GPUImageHazeFilter(@FloatRange(from = -0.3f, to = 0.3f) float distance, @FloatRange(from = -0.3f, to = 0.3f) float slope) {
21 | super(FilterType.HAZE.ordinal());
22 | this.distance = distance;
23 | this.slope = slope;
24 | }
25 |
26 | public float getDistance() {
27 | return distance;
28 | }
29 |
30 | public void setDistance(float distance) {
31 | this.distance = distance;
32 | }
33 |
34 | public float getSlope() {
35 | return slope;
36 | }
37 |
38 | public void setSlope(float slope) {
39 | this.slope = slope;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageHighlightShadowFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageHighlightShadowFilter extends NativeFilter {
13 | private float shadows;
14 | private float highlights;
15 |
16 | public GPUImageHighlightShadowFilter() {
17 | this(0.0f, 1.0f);
18 | }
19 |
20 | public GPUImageHighlightShadowFilter(@FloatRange(from = 0.0f,to = 1.0f) float shadows, @FloatRange(from = 0.0f,to = 1.0f)float highlights) {
21 | super(FilterType.HIGHLIGHT_SHADOW.ordinal());
22 | this.shadows = shadows;
23 | this.highlights = highlights;
24 | }
25 |
26 | public float getShadows() {
27 | return shadows;
28 | }
29 |
30 | public void setShadows(float shadows) {
31 | this.shadows = shadows;
32 | }
33 |
34 | public float getHighlights() {
35 | return highlights;
36 | }
37 |
38 | public void setHighlights(float highlights) {
39 | this.highlights = highlights;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageHueFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageHueFilter extends NativeFilter {
11 | private float hue;
12 |
13 | public GPUImageHueFilter() {
14 | this(90.0f);
15 | }
16 |
17 | public GPUImageHueFilter(float hue) {
18 | super(FilterType.HUE.ordinal());
19 | this.hue = hue;
20 | }
21 |
22 | public float getHue() {
23 | return hue;
24 | }
25 |
26 | public void setHue(float hue) {
27 | this.hue = hue;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageLuminanceFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageLuminanceFilter extends NativeFilter {
11 | public GPUImageLuminanceFilter() {
12 | super(FilterType.LUMINANCE.ordinal());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageLuminanceThresholdFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageLuminanceThresholdFilter extends NativeFilter {
13 | private float threshold;
14 |
15 | public GPUImageLuminanceThresholdFilter() {
16 | this(0.5f);
17 | }
18 |
19 | public GPUImageLuminanceThresholdFilter(@FloatRange(from = 0.0f,to = 1.0f) float threshold) {
20 | super(FilterType.LUMINANCE_THRESHSOLD.ordinal());
21 | this.threshold = threshold;
22 | }
23 |
24 | public float getThreshold() {
25 | return threshold;
26 | }
27 |
28 | public void setThreshold(float threshold) {
29 | this.threshold = threshold;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageMixBlendFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageMixBlendFilter extends GPUImageTwoInputFilter{
11 | private float mix;
12 |
13 | public GPUImageMixBlendFilter(float mix) {
14 | this.mix = mix;
15 | }
16 |
17 | public GPUImageMixBlendFilter(int filterType, Bitmap bitmap, float mix) {
18 | super(filterType, bitmap);
19 | this.mix = mix;
20 | }
21 |
22 | public float getMix() {
23 | return mix;
24 | }
25 |
26 | public void setMix(float mix) {
27 | this.mix = mix;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageMonochromeFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageMonochromeFilter extends NativeFilter {
11 | private float intensity;
12 | private float v1,v2, v3;
13 | public GPUImageMonochromeFilter() {
14 | this(1.0f, new float[]{0.6f, 0.45f, 0.3f, 1.0f});
15 | }
16 |
17 | public GPUImageMonochromeFilter(float intensity) {
18 | this(intensity, new float[]{0.6f, 0.45f, 0.3f, 1.0f});
19 | }
20 |
21 | /**
22 | * @param intensity
23 | * @param color color[0] is red,color[1] is green,color[2] is blue.
24 | */
25 | public GPUImageMonochromeFilter(final float intensity, final float[] color) {
26 | super(FilterType.MONOCHROME.ordinal());
27 | this.intensity = intensity;
28 | if (color != null && color.length == 3) {
29 | this.v1 = color[0];
30 | this.v2 = color[1];
31 | this.v3 = color[2];
32 | }
33 | }
34 |
35 | public float getIntensity() {
36 | return intensity;
37 | }
38 |
39 | public void setIntensity(float intensity) {
40 | this.intensity = intensity;
41 | }
42 |
43 | public float getV1() {
44 | return v1;
45 | }
46 |
47 | public void setV1(float v1) {
48 | this.v1 = v1;
49 | }
50 |
51 | public float getV2() {
52 | return v2;
53 | }
54 |
55 | public void setV2(float v2) {
56 | this.v2 = v2;
57 | }
58 |
59 | public float getV3() {
60 | return v3;
61 | }
62 |
63 | public void setV3(float v3) {
64 | this.v3 = v3;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageRGBDilationFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.IntRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageRGBDilationFilter extends NativeFilter {
13 | private int radius;
14 |
15 | public GPUImageRGBDilationFilter() {
16 | this(1);
17 | }
18 |
19 | public GPUImageRGBDilationFilter(@IntRange(from = 0,to = 4) int radius) {
20 | super(FilterType.RGB_DILATION.ordinal());
21 | this.radius = radius;
22 | }
23 |
24 | public int getRadius() {
25 | return radius;
26 | }
27 |
28 | public void setRadius(int radius) {
29 | this.radius = radius;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageRGBFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageRGBFilter extends NativeFilter {
11 | private float red;
12 | private float green;
13 | private float blue;
14 |
15 | public GPUImageRGBFilter() {
16 | this(1.0f, 1.0f, 1.0f);
17 | }
18 |
19 | public GPUImageRGBFilter(float red, float green, float blue) {
20 | super(FilterType.RGB.ordinal());
21 | this.red = red;
22 | this.green = green;
23 | this.blue = blue;
24 | }
25 |
26 | public float getRed() {
27 | return red;
28 | }
29 |
30 | public void setRed(float red) {
31 | this.red = red;
32 | }
33 |
34 | public float getGreen() {
35 | return green;
36 | }
37 |
38 | public void setGreen(float green) {
39 | this.green = green;
40 | }
41 |
42 | public float getBlue() {
43 | return blue;
44 | }
45 |
46 | public void setBlue(float blue) {
47 | this.blue = blue;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSaturationFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageSaturationFilter extends NativeFilter{
11 | private float saturation;
12 |
13 | public GPUImageSaturationFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageSaturationFilter(float saturation) {
18 | super(FilterType.SATURATION.ordinal());
19 | this.saturation = saturation;
20 | }
21 |
22 | public float getSaturation() {
23 | return saturation;
24 | }
25 |
26 | public void setSaturation(float saturation) {
27 | this.saturation = saturation;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSharpenFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageSharpenFilter extends NativeFilter {
13 | private float sharpness;
14 |
15 | public GPUImageSharpenFilter() {
16 | this(0.0f);
17 | }
18 |
19 | public GPUImageSharpenFilter(@FloatRange(from = -4.0f, to = 4.0f) float sharpness) {
20 | super(FilterType.SHARPEN.ordinal());
21 | this.sharpness = sharpness;
22 | }
23 |
24 | public float getSharpness() {
25 | return sharpness;
26 | }
27 |
28 | public void setSharpness(float sharpness) {
29 | this.sharpness = sharpness;
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSketchFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/8
9 | */
10 | public class GPUImageSketchFilter extends NativeFilter {
11 | public GPUImageSketchFilter() {
12 | super(FilterType.SKETCH.ordinal());
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSobelEdgeDetectionFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageSobelEdgeDetectionFilter extends NativeFilter{
11 | private float size;
12 |
13 | public GPUImageSobelEdgeDetectionFilter() {
14 | this(1.0f);
15 | }
16 |
17 | public GPUImageSobelEdgeDetectionFilter(float size) {
18 | super(FilterType.SOBEL_EDGE_DETECTION.ordinal());
19 | this.size = size;
20 | }
21 |
22 | public float getSize() {
23 | return size;
24 | }
25 |
26 | public void setSize(float size) {
27 | this.size = size;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSobelThresholdFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageSobelThresholdFilter extends GPUImage3x3TextureSamplingFilter {
13 | private float threshold;
14 |
15 | public GPUImageSobelThresholdFilter() {
16 | this(0.9f);
17 | }
18 |
19 | public GPUImageSobelThresholdFilter(float threshold) {
20 | super(FilterType.SOBEL_THRESHOLD.ordinal());
21 | this.threshold = threshold;
22 | }
23 |
24 | public float getThreshold() {
25 | return threshold;
26 | }
27 |
28 | public void setThreshold(float threshold) {
29 | this.threshold = threshold;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageSolarizeFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageSolarizeFilter extends NativeFilter {
13 | private float threshold;
14 |
15 | public GPUImageSolarizeFilter() {
16 | this(0.5f);
17 | }
18 |
19 | public GPUImageSolarizeFilter(@FloatRange(from = 0.0f,to = 1.0f) float threshold) {
20 | super(FilterType.SOLARIZE.ordinal());
21 | this.threshold = threshold;
22 | }
23 |
24 | public float getThreshold() {
25 | return threshold;
26 | }
27 |
28 | public void setThreshold(float threshold) {
29 | this.threshold = threshold;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageThresholdEdgeDetectionFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.support.annotation.FloatRange;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/10/8
11 | */
12 | public class GPUImageThresholdEdgeDetectionFilter extends NativeFilter {
13 | private float size;
14 | private float threshold;
15 |
16 | public GPUImageThresholdEdgeDetectionFilter() {
17 | this(0.9f, 0.9f);
18 | }
19 |
20 | public GPUImageThresholdEdgeDetectionFilter(@FloatRange(from = 0.0f,to = 5.0f) float size, float threshold) {
21 | super(FilterType.THRESHOLD_EDGE_DETECTION.ordinal());
22 | this.size = size;
23 | this.threshold = threshold;
24 | }
25 |
26 | public float getSize() {
27 | return size;
28 | }
29 |
30 | public void setSize(float size) {
31 | this.size = size;
32 | }
33 |
34 | public float getThreshold() {
35 | return threshold;
36 | }
37 |
38 | public void setThreshold(float threshold) {
39 | this.threshold = threshold;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageToonFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/29
9 | */
10 | public class GPUImageToonFilter extends GPUImage3x3TextureSamplingFilter {
11 | private float threshold;
12 | private float quantizationLevels;
13 |
14 | public GPUImageToonFilter() {
15 | this(0.2f, 10.0f);
16 | }
17 |
18 | public GPUImageToonFilter(float threshold, float quantizationLevels) {
19 | super(FilterType.TOON.ordinal());
20 | this.threshold = threshold;
21 | this.quantizationLevels = quantizationLevels;
22 | }
23 |
24 | public float getThreshold() {
25 | return threshold;
26 | }
27 |
28 | public void setThreshold(float threshold) {
29 | this.threshold = threshold;
30 | }
31 |
32 | public float getQuantizationLevels() {
33 | return quantizationLevels;
34 | }
35 |
36 | public void setQuantizationLevels(float quantizationLevels) {
37 | this.quantizationLevels = quantizationLevels;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageTwoInputFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 |
6 | import com.ben.android.library.R;
7 | import com.ben.android.library.util.FilterType;
8 |
9 | /**
10 | * @author @zhangchuan622@gmail.com
11 | * @version 1.0
12 | * @create 2019/9/28
13 | */
14 | public class GPUImageTwoInputFilter extends NativeFilter{
15 | private Bitmap bitmap;
16 |
17 | public GPUImageTwoInputFilter() {
18 | this(-1,null);
19 | }
20 | public GPUImageTwoInputFilter(int filterType, Bitmap bitmap) {
21 | super(filterType);
22 | this.bitmap = bitmap;
23 | }
24 |
25 | public Bitmap getBitmap() {
26 | return bitmap;
27 | }
28 |
29 | public void setBitmap(Bitmap bitmap) {
30 | this.bitmap = bitmap;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageVibranceFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/28
9 | */
10 | public class GPUImageVibranceFilter extends NativeFilter {
11 | private float vibrance;
12 |
13 | public GPUImageVibranceFilter() {
14 | this(0f);
15 | }
16 |
17 | public GPUImageVibranceFilter(float vibrance) {
18 | super(FilterType.VIBRANCE.ordinal());
19 | this.vibrance = vibrance;
20 | }
21 |
22 | public float getVibrance() {
23 | return vibrance;
24 | }
25 |
26 | public void setVibrance(float vibrance) {
27 | this.vibrance = vibrance;
28 | }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageVignetteFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.PointF;
4 |
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/27
11 | */
12 | public class GPUImageVignetteFilter extends NativeFilter {
13 | private float vignetteCenterX;
14 | private float vignetteCenterY;
15 | private float[] vignetteColor;
16 | private float vignetteStart;
17 | private float vignetteEnd;
18 |
19 | public GPUImageVignetteFilter() {
20 | this(new PointF(), new float[]{0.0f, 0.0f, 0.0f}, 0.3f, 0.75f);
21 | }
22 |
23 | public GPUImageVignetteFilter(PointF vignetteCenter, float[] vignetteColor, float vignetteStart, float vignetteEnd) {
24 | super(FilterType.VIGNETTE.ordinal());
25 | this.vignetteCenterX = vignetteCenter.x;
26 | this.vignetteCenterY = vignetteCenter.y;
27 | this.vignetteColor = vignetteColor;
28 | this.vignetteStart = vignetteStart;
29 | this.vignetteEnd = vignetteEnd;
30 | }
31 |
32 | public float getVignetteCenterX() {
33 | return vignetteCenterX;
34 | }
35 |
36 | public void setVignetteCenterX(float vignetteCenterX) {
37 | this.vignetteCenterX = vignetteCenterX;
38 | }
39 |
40 | public float getVignetteCenterY() {
41 | return vignetteCenterY;
42 | }
43 |
44 | public void setVignetteCenterY(float vignetteCenterY) {
45 | this.vignetteCenterY = vignetteCenterY;
46 | }
47 |
48 | public float[] getVignetteColor() {
49 | return vignetteColor;
50 | }
51 |
52 | public void setVignetteColor(float[] vignetteColor) {
53 | this.vignetteColor = vignetteColor;
54 | }
55 |
56 | public float getVignetteStart() {
57 | return vignetteStart;
58 | }
59 |
60 | public void setVignetteStart(float vignetteStart) {
61 | this.vignetteStart = vignetteStart;
62 | }
63 |
64 | public float getVignetteEnd() {
65 | return vignetteEnd;
66 | }
67 |
68 | public void setVignetteEnd(float vignetteEnd) {
69 | this.vignetteEnd = vignetteEnd;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageWeakPixelInclusionFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/27
9 | */
10 | public class GPUImageWeakPixelInclusionFilter extends GPUImage3x3TextureSamplingFilter{
11 |
12 | public GPUImageWeakPixelInclusionFilter() {
13 | this(FilterType.WEAK_PIXEL_INCLUSION.ordinal());
14 | }
15 |
16 | public GPUImageWeakPixelInclusionFilter(int filterType) {
17 | super(filterType);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GPUImageWhiteBalanceFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.util.FilterType;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/9/26
9 | */
10 | public class GPUImageWhiteBalanceFilter extends NativeFilter {
11 | private float temperature;
12 | private float tint;
13 |
14 | public GPUImageWhiteBalanceFilter() {
15 | this(5000.0f, 0.0f);
16 | }
17 |
18 | public GPUImageWhiteBalanceFilter(float temperature, float tint) {
19 | super(FilterType.WHITE_BALANCE.ordinal());
20 | this.temperature = temperature;
21 | this.tint = tint;
22 | }
23 |
24 | public float getTemperature() {
25 | return temperature;
26 | }
27 |
28 | public void setTemperature(float temperature) {
29 | this.temperature = temperature;
30 | }
31 |
32 | public float getTint() {
33 | return tint;
34 | }
35 |
36 | public void setTint(float tint) {
37 | this.tint = tint;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/GaussianBlurFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.jni.NativeObject;
4 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
5 | import com.ben.android.library.util.FilterType;
6 |
7 | /**
8 | * @author @zhangchuan622@gmail.com
9 | * @version 1.0
10 | * @create 2019/9/21
11 | */
12 | public class GaussianBlurFilter extends NativeFilter {
13 | private float blurSize;
14 |
15 | public GaussianBlurFilter() {
16 | this(10f);
17 | }
18 |
19 | public GaussianBlurFilter(float blurSize) {
20 | super(FilterType.GAUSSIAN_BLUR.ordinal());
21 | this.blurSize = blurSize;
22 | }
23 |
24 | @SuppressWarnings("UnusedDeclaration")
25 | @UsedByNativeCode
26 | public float getBlurSize() {
27 | return blurSize;
28 | }
29 |
30 | @SuppressWarnings("UnusedDeclaration")
31 | @UsedByNativeCode
32 | public void setBlurSize(float blurSize) {
33 | this.blurSize = blurSize;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/NativeFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.jni.NativeObject;
4 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/9/24
10 | */
11 | public class NativeFilter extends NativeObject {
12 | protected int filterType;
13 |
14 | public NativeFilter() {
15 | this(-1);
16 | }
17 | public NativeFilter(int filterType) {
18 | this.filterType = filterType;
19 | }
20 |
21 | @SuppressWarnings("UnusedDeclaration")
22 | @UsedByNativeCode
23 | public int getFilterType() {
24 | return filterType;
25 | }
26 |
27 | @SuppressWarnings("UnusedDeclaration")
28 | @UsedByNativeCode
29 | public void setFilterType(int filterType) {
30 | this.filterType = filterType;
31 | }
32 |
33 | @Override
34 | public void destroy() {
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/PixelationFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
4 | import com.ben.android.library.util.FilterType;
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/9/24
10 | */
11 | public class PixelationFilter extends NativeFilter{
12 | private float pixel;
13 |
14 | @SuppressWarnings("UnusedDeclaration")
15 | @UsedByNativeCode
16 | public float getPixel() {
17 | return pixel;
18 | }
19 | @SuppressWarnings("UnusedDeclaration")
20 | @UsedByNativeCode
21 | public void setPixel(float pixel) {
22 | this.pixel = pixel;
23 | }
24 | public PixelationFilter() {
25 | this(1.0f);
26 | }
27 |
28 | public PixelationFilter(float pixel) {
29 | super(FilterType.PIXELATION.ordinal());
30 | this.pixel = pixel;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/filter/ZoomBlurFilter.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.filter;
2 |
3 | import android.graphics.PointF;
4 |
5 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
6 | import com.ben.android.library.util.FilterType;
7 |
8 | /**
9 | * @author @zhangchuan622@gmail.com
10 | * @version 1.0
11 | * @create 2019/9/24
12 | */
13 | public class ZoomBlurFilter extends NativeFilter {
14 | private float pointXF;
15 | private float pointYF;
16 | private float blurSize;
17 |
18 | public ZoomBlurFilter() {
19 | this(null);
20 | }
21 | public ZoomBlurFilter(PointF pointF) {
22 | this(null, 0);
23 | }
24 | public ZoomBlurFilter(PointF pointF,float blurSize) {
25 | super(FilterType.ZOOM_BLUR.ordinal());
26 | if (pointF != null) {
27 | this.pointXF = pointF.x;
28 | this.pointYF = pointF.y;
29 | }
30 | this.blurSize = blurSize;
31 | }
32 |
33 |
34 | @SuppressWarnings("UnusedDeclaration")
35 | @UsedByNativeCode
36 | public float getPointXF() {
37 | return pointXF;
38 | }
39 |
40 | @SuppressWarnings("UnusedDeclaration")
41 | @UsedByNativeCode
42 | public void setPointXF(float pointXF) {
43 | this.pointXF = pointXF;
44 | }
45 | @SuppressWarnings("UnusedDeclaration")
46 | @UsedByNativeCode
47 | public float getPointYF() {
48 | return pointYF;
49 | }
50 |
51 | @SuppressWarnings("UnusedDeclaration")
52 | @UsedByNativeCode
53 | public void setPointYF(float pointYF) {
54 | this.pointYF = pointYF;
55 | }
56 | @SuppressWarnings("UnusedDeclaration")
57 | @UsedByNativeCode
58 | public float getBlurSize() {
59 | return blurSize;
60 | }
61 | @SuppressWarnings("UnusedDeclaration")
62 | @UsedByNativeCode
63 | public void setBlurSize(float blurSize) {
64 | this.blurSize = blurSize;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/jni/NativeObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | package com.ben.android.library.jni;
23 |
24 |
25 | import com.ben.android.library.jni.annotations.UsedByNativeCode;
26 |
27 | public abstract class NativeObject {
28 | /**
29 | * Field used to store a pointer to the native instance allocated on the heap.
30 | * Don't modify this value directly, or else you risk causing segfaults or
31 | * leaking memory.
32 | */
33 | @SuppressWarnings("UnusedDeclaration")
34 | @UsedByNativeCode
35 | protected long nPtr;
36 |
37 | /**
38 | * This method is used to invoke C++ destructors and free native resources,
39 | * and normally you want to declare it as native
in your subclass.
40 | * The native implementation should, in turn, simply invoke the base class'
41 | * destroy()
method. For more information, see the documentation
42 | * in the NativeObject.h header file.
43 | */
44 | public abstract void destroy();
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/jni/annotations/UsedByNativeCode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | package com.ben.android.library.jni.annotations;
23 |
24 | /**
25 | * Annotation which indicates that a piece of seemingly-unused Java code
26 | * is actually being referenced by native code via JNI. Since annotations
27 | * cannot subclass each other, this should be used in combination with
28 | */
29 | public @interface UsedByNativeCode {}
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/engine/Resource.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.engine;
2 |
3 | import android.graphics.Bitmap;
4 |
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/10/9
10 | */
11 | public class Resource {
12 | private Bitmap bitmap;
13 | private int position;
14 |
15 | private Resource(Bitmap bitmap, int position) {
16 | this.bitmap = bitmap;
17 | this.position = position;
18 | }
19 |
20 | public static Resource obtain(Bitmap src, int position){
21 | return new Resource(src,position);
22 | }
23 |
24 | public Bitmap getBitmap() {
25 | return bitmap;
26 | }
27 |
28 | public int getPosition() {
29 | return position;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/engine/ResourceFetcherGenerator.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.engine;
2 |
3 | import android.graphics.Bitmap;
4 | import android.support.annotation.Nullable;
5 |
6 | import com.ben.android.library.load.fetcher.DataFetcher;
7 |
8 | import java.util.concurrent.Callable;
9 |
10 | import javax.sql.DataSource;
11 |
12 | /**
13 | * @author @zhangchuan622@gmail.com
14 | * @version 1.0
15 | * @create 2019/10/9
16 | */
17 | public interface ResourceFetcherGenerator extends Runnable, Callable {
18 |
19 | interface FetcherReadyCallback {
20 |
21 | void onDataFetcherReady(Resource resource);
22 |
23 | void onDataFetcherFailed( Exception e);
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/fetcher/DataFetcher.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.fetcher;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/10/9
10 | */
11 | public interface DataFetcher {
12 | interface DataCallback {
13 | void onDataReady(@Nullable T data);
14 | void onLoadFailed(@NonNull Exception e);
15 | }
16 | void loadData(DataCallback super T> callback);
17 |
18 | T loadData();
19 | }
20 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/fetcher/FileFetcher.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.fetcher;
2 |
3 | import android.util.Log;
4 |
5 | import java.io.File;
6 | import java.io.FileInputStream;
7 | import java.io.FileNotFoundException;
8 | import java.io.InputStream;
9 |
10 | /**
11 | * @author @zhangchuan622@gmail.com
12 | * @version 1.0
13 | * @create 2019/10/9
14 | */
15 | public class FileFetcher implements DataFetcher{
16 | private static final String TAG = FileFetcher.class.getSimpleName();
17 | private File file;
18 |
19 | public FileFetcher(String url) {
20 | this(new File(url));
21 | }
22 |
23 | public FileFetcher(File file) {
24 | this.file = file;
25 | }
26 |
27 | @Override
28 | public void loadData(DataCallback super InputStream> callback) {
29 | try {
30 | callback.onDataReady(new FileInputStream(file));
31 | } catch (FileNotFoundException e) {
32 | if (Log.isLoggable(TAG, Log.DEBUG)) {
33 | Log.d(TAG, "file not found ["+file.getPath()+"]", e);
34 | }
35 | callback.onLoadFailed(e);
36 | }
37 | }
38 |
39 | @Override
40 | public InputStream loadData() {
41 | try {
42 | return new FileInputStream(file);
43 | } catch (FileNotFoundException e) {
44 | if (Log.isLoggable(TAG, Log.DEBUG)) {
45 | Log.d(TAG, "file not found ["+file.getPath()+"]", e);
46 | }
47 | }
48 | return null;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/fetcher/HttpException.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.fetcher;
2 |
3 | import android.support.annotation.Nullable;
4 |
5 | import java.io.IOException;
6 |
7 | public class HttpException extends IOException {
8 | private static final long serialVersionUID = 1L;
9 |
10 | public static final int UNKNOWN = -1;
11 | private final int statusCode;
12 |
13 | public HttpException(int statusCode) {
14 | this("Http request failed with status code: " + statusCode, statusCode);
15 | }
16 |
17 | public HttpException(String message) {
18 | this(message, UNKNOWN);
19 | }
20 |
21 | public HttpException(String message, int statusCode) {
22 | this(message, statusCode, null /*cause*/);
23 | }
24 |
25 | public HttpException(String message, int statusCode, @Nullable Throwable cause) {
26 | super(message, cause);
27 | this.statusCode = statusCode;
28 | }
29 |
30 | /**
31 | * Returns the http status code, or {@link #UNKNOWN} if the request failed without providing
32 | * a status code.
33 | */
34 | public int getStatusCode() {
35 | return statusCode;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/fetcher/MemoryFetcher.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.fetcher;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 |
7 |
8 | /**
9 | * @author @zhangchuan622@gmail.com
10 | * @version 1.0
11 | * @create 2019/10/10
12 | */
13 | public class MemoryFetcher implements DataFetcher {
14 | private Bitmap bitmap;
15 |
16 | public MemoryFetcher(Bitmap bitmap) {
17 | this.bitmap = bitmap;
18 | }
19 |
20 | @Override
21 | public void loadData(DataCallback super Bitmap> callback) {
22 | try {
23 | callback.onDataReady(bitmap);
24 | } catch (Exception e) {
25 | callback.onLoadFailed(e);
26 | }
27 |
28 | }
29 |
30 | @Override
31 | public Bitmap loadData() {
32 | return bitmap;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/load/fetcher/ResourceFetcher.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.load.fetcher;
2 |
3 | import android.content.res.Resources;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 |
7 |
8 |
9 | /**
10 | * @author @zhangchuan622@gmail.com
11 | * @version 1.0
12 | * @create 2019/10/10
13 | */
14 | public class ResourceFetcher implements DataFetcher {
15 | private Resources resource;
16 | private int resId;
17 |
18 | public ResourceFetcher(Resources resource, int resId) {
19 | this.resource = resource;
20 | this.resId = resId;
21 | }
22 |
23 | @Override
24 | public void loadData(DataCallback super Bitmap> callback) {
25 | try {
26 | callback.onDataReady(BitmapFactory.decodeResource(resource, resId));
27 | } catch (Exception e) {
28 | callback.onLoadFailed(e);
29 | }
30 |
31 | }
32 |
33 | @Override
34 | public Bitmap loadData() {
35 | return BitmapFactory.decodeResource(resource, resId);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/render/Render.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.render;
2 |
3 | import com.ben.android.library.filter.NativeFilter;
4 | import com.ben.android.library.load.engine.Resource;
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/10/9
10 | */
11 | public class Render {
12 | private NativeFilter filter;
13 | private Resource resource;
14 |
15 | private Render(NativeFilter filter, Resource resource) {
16 | this.filter = filter;
17 | this.resource = resource;
18 | }
19 |
20 | public NativeFilter getFilter() {
21 | return filter;
22 | }
23 |
24 | public void setFilter(NativeFilter filter) {
25 | this.filter = filter;
26 | }
27 |
28 |
29 | public Resource getResource() {
30 | return resource;
31 | }
32 |
33 | public void setResource(Resource resource) {
34 | this.resource = resource;
35 | }
36 |
37 | public static Render obtain(Resource resource, NativeFilter filter) {
38 | return new Render(filter, resource);
39 | }
40 |
41 |
42 | public static class UpgradRender {
43 | private NativeFilter filter;
44 |
45 | private UpgradRender(NativeFilter filter) {
46 | this.filter = filter;
47 | }
48 |
49 | public NativeFilter getFilter() {
50 | return filter;
51 | }
52 |
53 | public void setFilter(NativeFilter filter) {
54 | this.filter = filter;
55 | }
56 |
57 | public static UpgradRender obtain(Render render) {
58 | return obtain(render.getFilter());
59 | } public static UpgradRender obtain(NativeFilter filter) {
60 | return new UpgradRender(filter);
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/render/RenderFetcherGenerator.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.render;
2 |
3 | import android.graphics.Bitmap;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 |
7 | import com.ben.android.library.Result;
8 |
9 | import java.io.File;
10 |
11 | /**
12 | * @author @zhangchuan622@gmail.com
13 | * @version 1.0
14 | * @create 2019/10/9
15 | */
16 | public interface RenderFetcherGenerator extends Runnable {
17 | interface RenderFetcherCallback{
18 | void onRenderReady(@Nullable Result result);
19 | void onRenderFailed(@NonNull Exception e);
20 | }
21 | void put(Render render);
22 |
23 | void stop();
24 |
25 | void activ();
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/util/FilterTools.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.util;
2 |
3 | import com.ben.android.library.filter.NativeFilter;
4 |
5 | /**
6 | * @author @zhangchuan622@gmail.com
7 | * @version 1.0
8 | * @create 2019/10/12
9 | */
10 | public class FilterTools {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/util/NGPListenerTools.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.util;
2 |
3 | import com.ben.android.library.NGPListener;
4 | import com.ben.android.library.Result;
5 |
6 | /**
7 | * @author @zhangchuan622@gmail.com
8 | * @version 1.0
9 | * @create 2019/10/14
10 | */
11 | public class NGPListenerTools {
12 | public static void callRenderStart(NGPListener listener){
13 | if (listener != null) {
14 | listener.onRenderStart();
15 | }
16 |
17 | }
18 |
19 | public static void callRenderFinish(NGPListener listener){
20 | if (listener != null) {
21 | listener.onRenderFinish();
22 | }
23 | }
24 |
25 | public static void callRenderComplete(NGPListener listener,Result result){
26 | if (listener != null) {
27 | listener.onRender(result);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/util/Rotation.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.util;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/10/11
7 | */
8 | public enum Rotation {
9 | NORMAL(0), ROTATION_90(90), ROTATION_180(180), ROTATION_270(270);
10 | private int value;
11 |
12 | public static int getValue(Rotation rotation) {
13 | for (Rotation item : values()) {
14 | if (item == rotation) {
15 | return item.value;
16 | }
17 | }
18 | return 0;
19 | }
20 |
21 | Rotation(int value) {
22 | this.value = value;
23 | }}
24 |
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ben/android/library/util/ScaleType.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library.util;
2 |
3 | /**
4 | * @author @zhangchuan622@gmail.com
5 | * @version 1.0
6 | * @create 2019/10/11
7 | */
8 | public enum ScaleType {
9 | CENTER_INSIDE, CENTER_CROP
10 | }
11 |
--------------------------------------------------------------------------------
/library/src/main/jni/api/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # API
2 | file(GLOB API_SOURCE "*.cpp*")
3 | message("file ${API_SOURCE}")
4 | add_library(libapi
5 | ${API_SOURCE}
6 | )
7 |
8 | target_link_libraries(libapi
9 | android
10 | )
11 |
12 |
--------------------------------------------------------------------------------
/library/src/main/jni/api/android_native_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/25.
3 | //
4 |
5 | #include "android_native_filter.hpp"
6 |
7 | ben::ngp::NativeFilter::NativeFilter() {}
8 |
9 | ben::ngp::NativeFilter::NativeFilter(JNIEnv *env) : JavaClass(env) {
10 | initialize(env);
11 | merge(this);
12 | }
13 |
14 | void ben::ngp::NativeFilter::initialize(JNIEnv *env) {
15 | setClass(env);
16 | cacheField(env, "filterType", kTypeInt);
17 | cacheConstructor(env);
18 | cacheMethod(env, "getFilterType", kTypeInt, NULL);
19 | cacheMethod(env, "setFilterType", kTypeVoid, kTypeInt, NULL);
20 | }
21 |
22 | void ben::ngp::NativeFilter::mapFields() {
23 | mapField("filterType", kTypeFloat, &filterType);
24 | }
25 |
26 | const char *ben::ngp::NativeFilter::getCanonicalName() const {
27 | return JAVA_NATIVE_FILTER;
28 | }
29 |
30 | int ben::ngp::NativeFilter::getFilterType() const {
31 | return filterType;
32 | }
33 |
34 | void ben::ngp::NativeFilter::setFilterType(int filterType) {
35 | NativeFilter::filterType = filterType;
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/main/jni/api/android_native_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/25.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_ANDROID_NATIVE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_ANDROID_NATIVE_FILTER_HPP
7 | #include "../include/jni/JniHelpers.h"
8 | #include "../util/filter_type.hpp"
9 | #define JAVA_NATIVE_FILTER "com/ben/android/library/filter/NativeFilter"
10 |
11 | using namespace ben::jni;
12 | namespace ben{
13 | namespace ngp{
14 | class NativeFilter : public JavaClass{
15 | private:
16 | int filterType;
17 | public:
18 | NativeFilter();
19 |
20 | NativeFilter(JNIEnv *env);
21 |
22 | void initialize(JNIEnv *env) override;
23 |
24 | void mapFields() override;
25 |
26 | const char *getCanonicalName() const override;
27 |
28 | public:
29 | int getFilterType() const;
30 |
31 | void setFilterType(int filterType);
32 | };
33 | }
34 | }
35 | #endif //NATIVEGPUIMAGE_ANDROID_NATIVE_FILTER_HPP
36 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # filter
2 | file(GLOB FILTER_SOURCE "*.cpp*")
3 | message("file ${FILTER_SOURCE}")
4 | add_library(libfilter
5 | ${FILTER_SOURCE}
6 | )
7 |
8 | target_link_libraries(libfilter
9 | GLESv2
10 | EGL
11 | android
12 | )
13 |
14 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_add_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/28.
3 | //
4 |
5 | #include "gpu_image_add_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageAddBlendFilter::GPUImageAddBlendFilter()
8 | : GPUImageTwoInputFilter(ADD_BLEND_FRAGMENT_SHADER) {
9 |
10 | }
11 |
12 | ben::ngp::GPUImageAddBlendFilter::GPUImageAddBlendFilter(JNIEnv *env) : GPUImageTwoInputFilter(
13 | ADD_BLEND_FRAGMENT_SHADER, env) {
14 | initialize(env);
15 | }
16 |
17 | void ben::ngp::GPUImageAddBlendFilter::initialize(JNIEnv *env) {
18 | GPUImageTwoInputFilter::initialize(env);
19 | }
20 |
21 | void ben::ngp::GPUImageAddBlendFilter::mapFields() {
22 | GPUImageTwoInputFilter::mapFields();
23 | }
24 |
25 | const char *ben::ngp::GPUImageAddBlendFilter::getCanonicalName() const {
26 | return JAVA_ADD_BLEND_FILTER;
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_alpha_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_alpha_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageAlphaBlendFilter::GPUImageAlphaBlendFilter(float mix, JNIEnv *env)
8 | : GPUImageMixBlendFilter(ALPHA_BLEND_FRAGMENT_SHADER, env, mix) {
9 | initialize(env);
10 |
11 | }
12 |
13 | ben::ngp::GPUImageAlphaBlendFilter::GPUImageAlphaBlendFilter(JNIEnv *env)
14 | : GPUImageMixBlendFilter(ALPHA_BLEND_FRAGMENT_SHADER, env) {
15 | initialize(env);
16 | }
17 |
18 | void ben::ngp::GPUImageAlphaBlendFilter::initialize(JNIEnv *env) {
19 | GPUImageMixBlendFilter::initialize(env);
20 | }
21 |
22 | void ben::ngp::GPUImageAlphaBlendFilter::mapFields() {
23 | GPUImageMixBlendFilter::mapFields();
24 | }
25 |
26 | const char *ben::ngp::GPUImageAlphaBlendFilter::getCanonicalName() const {
27 | return JAVA_ALPHA_BLEND_FILTER;
28 | }
29 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_alpha_blend_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_ALPHA_BLEND_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_ALPHA_BLEND_FILTER_HPP
7 |
8 | #include "gpu_image_mix_blend_filter.hpp"
9 | #define JAVA_ALPHA_BLEND_FILTER "com/ben/android/library/filter/GPUImageAlphaBlendFilter"
10 | static char *ALPHA_BLEND_FRAGMENT_SHADER = GET_STR(
11 | varying highp vec2 textureCoordinate;
12 | varying highp vec2 textureCoordinate2;
13 |
14 | uniform sampler2D inputImageTexture;
15 | uniform sampler2D inputImageTexture2;
16 |
17 | uniform lowp float mixturePercent;
18 |
19 | void main()
20 | {
21 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
22 | lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);
23 |
24 | gl_FragColor = vec4(mix(textureColor.rgb, textureColor2.rgb, textureColor2.a * mixturePercent), textureColor.a);
25 | }
26 | );
27 | namespace ben{
28 | namespace ngp{
29 | class GPUImageAlphaBlendFilter:public GPUImageMixBlendFilter {
30 | public:
31 | GPUImageAlphaBlendFilter(JNIEnv *env);
32 | GPUImageAlphaBlendFilter(float mix,JNIEnv *env);
33 |
34 | virtual void initialize(JNIEnv *env);
35 |
36 | virtual void mapFields();
37 |
38 | virtual const char *getCanonicalName() const;
39 | };
40 | }
41 | }
42 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_ALPHA_BLEND_FILTER_HPP
43 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_brightness_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_brightness_filter.hpp"
6 |
7 | ben::ngp::GPUImageBrightnessFilter::GPUImageBrightnessFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, BRIGHTNESS_FRAGMENT_SHADER,env) {
8 | initialize(env);
9 | this->brightness = 0.0f;
10 | }
11 |
12 | ben::ngp::GPUImageBrightnessFilter::GPUImageBrightnessFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, BRIGHTNESS_FRAGMENT_SHADER) {
13 | this->brightness = 0.0f;
14 | }
15 |
16 | void ben::ngp::GPUImageBrightnessFilter::initialize(JNIEnv *env) {
17 | GPUImageFilter::initialize(env);
18 | cacheField(env, "brightness", kTypeFloat);
19 | cacheConstructor(env);
20 | cacheMethod(env, "getBrightness", kTypeFloat, NULL);
21 | cacheMethod(env, "setBrightness", kTypeVoid, kTypeFloat, NULL);
22 | merge(this);
23 | }
24 |
25 | void ben::ngp::GPUImageBrightnessFilter::mapFields() {
26 | GPUImageFilter::mapFields();
27 | mapField("brightness", kTypeFloat, &brightness);
28 | }
29 |
30 | const char *ben::ngp::GPUImageBrightnessFilter::getCanonicalName() const {
31 | return JAVA_BRIGHTNESS_FILTER;
32 | }
33 |
34 | void ben::ngp::GPUImageBrightnessFilter::onInit() {
35 | GPUImageFilter::onInit();
36 | brightnessLocation = glGetUniformLocation(getGlProgId(), "brightness");
37 | }
38 |
39 | void ben::ngp::GPUImageBrightnessFilter::onInitialized() {
40 | GPUImageFilter::onInitialized();
41 | setBrightness(brightness);
42 | }
43 |
44 | void ben::ngp::GPUImageBrightnessFilter::setBrightness(float brightness) {
45 | GPUImageBrightnessFilter::brightness = brightness;
46 | setFloat(this->brightnessLocation, this->brightness);
47 | }
48 |
49 | float ben::ngp::GPUImageBrightnessFilter::getBrightness() const {
50 | return brightness;
51 | }
52 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_brightness_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_BRIGHTNESS_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_BRIGHTNESS_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #define JAVA_BRIGHTNESS_FILTER "com/ben/android/library/filter/GPUImageBrightnessFilter"
10 | static char *BRIGHTNESS_FRAGMENT_SHADER = GET_STR(
11 | varying highp vec2 textureCoordinate;
12 |
13 | uniform sampler2D inputImageTexture;
14 | uniform lowp float brightness;
15 |
16 | void main()
17 | {
18 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
19 |
20 | gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);
21 | }
22 | );
23 |
24 | namespace ben{
25 | namespace ngp{
26 | class GPUImageBrightnessFilter:public GPUImageFilter{
27 | private:
28 | int brightnessLocation;
29 | float brightness;
30 | public:
31 | GPUImageBrightnessFilter();
32 |
33 | GPUImageBrightnessFilter(JNIEnv *env);
34 |
35 | virtual void initialize(JNIEnv *env);
36 |
37 | virtual void mapFields();
38 |
39 | virtual const char *getCanonicalName() const;
40 |
41 | virtual void onInit();
42 |
43 | virtual void onInitialized();
44 |
45 | void setBrightness(float brightness);
46 |
47 | float getBrightness() const;
48 | };
49 | }
50 | }
51 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_BRIGHTNESS_FILTER_HPP
52 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_contrast_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_contrast_filter.hpp"
6 |
7 | ben::ngp::GPUImageContrastFilter::GPUImageContrastFilter(): GPUImageFilter(NO_FILTER_VERTEX_SHADER, CONTRAST_FRAGMENT_SHADER) {
8 | this->contrast = 1.2f;
9 | }
10 |
11 | ben::ngp::GPUImageContrastFilter::GPUImageContrastFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, CONTRAST_FRAGMENT_SHADER,env) {
12 | initialize(env);
13 | this->contrast = 1.2f;
14 | }
15 |
16 | void ben::ngp::GPUImageContrastFilter::setContrast(float contrast) {
17 | GPUImageContrastFilter::contrast = contrast;
18 | setFloat(contrastLocation, this->contrast);
19 | }
20 |
21 | void ben::ngp::GPUImageContrastFilter::initialize(JNIEnv *env) {
22 | GPUImageFilter::initialize(env);
23 | cacheField(env, "contrast", kTypeFloat);
24 | cacheConstructor(env);
25 | cacheMethod(env, "getContrast", kTypeFloat, NULL);
26 | cacheMethod(env, "setContrast", kTypeVoid, kTypeFloat, NULL);
27 | merge(this);
28 |
29 | }
30 |
31 | void ben::ngp::GPUImageContrastFilter::mapFields() {
32 | GPUImageFilter::mapFields();
33 | mapField("contrast", kTypeFloat, &contrast);
34 | }
35 |
36 | const char *ben::ngp::GPUImageContrastFilter::getCanonicalName() const {
37 | return JAVA_CONTRAST_FILTER;
38 | }
39 |
40 | void ben::ngp::GPUImageContrastFilter::onInit() {
41 | GPUImageFilter::onInit();
42 | contrastLocation = glGetUniformLocation(getGlProgId(), "contrast");
43 | }
44 |
45 | void ben::ngp::GPUImageContrastFilter::onInitialized() {
46 | GPUImageFilter::onInitialized();
47 | setContrast(contrast);
48 | }
49 |
50 |
51 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_contrast_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_CONTRAST_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_CONTRAST_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #include "../include/jni/JniHelpersCommon.h"
10 |
11 | #define JAVA_CONTRAST_FILTER "com/ben/android/library/filter/GPUImageContrastFilter"
12 | static char *CONTRAST_FRAGMENT_SHADER = GET_STR(
13 | varying highp vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 | uniform lowp float contrast;
17 |
18 | void main()
19 | {
20 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
21 |
22 | gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);
23 | }
24 | );
25 | namespace ben{
26 | namespace ngp{
27 | class GPUImageContrastFilter:public GPUImageFilter{
28 | private:
29 | int contrastLocation;
30 | float contrast;
31 | public:
32 | GPUImageContrastFilter();
33 |
34 | GPUImageContrastFilter(JNIEnv *env);
35 |
36 | virtual void initialize(JNIEnv *env);
37 |
38 | virtual void mapFields();
39 |
40 | virtual const char *getCanonicalName() const;
41 |
42 | virtual void onInit();
43 |
44 | virtual void onInitialized();
45 |
46 | void setContrast(float contrast);
47 | };
48 | }
49 | }
50 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_CONTRAST_FILTER_HPP
51 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_dilation_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/20.
3 | //
4 |
5 | #include "gpu_image_dilation_filter.hpp"
6 |
7 | ben::ngp::GPUImageDilationFilter::GPUImageDilationFilter(JNIEnv *env)
8 | : GPUImageTwoPassTextureSamplingFilter(VERTEX_SHADER_2, FRAGMENT_SHADER_2, VERTEX_SHADER_2,
9 | FRAGMENT_SHADER_2, env) {
10 | //必须在构造函数执行完以后才可以进行JNI操作
11 | initialize(env);
12 |
13 | }
14 |
15 | ben::ngp::GPUImageDilationFilter::GPUImageDilationFilter()
16 | : GPUImageTwoPassTextureSamplingFilter(VERTEX_SHADER_2, FRAGMENT_SHADER_2, VERTEX_SHADER_2,
17 | FRAGMENT_SHADER_2) {
18 |
19 | }
20 |
21 | ben::ngp::GPUImageDilationFilter::GPUImageDilationFilter(int radius)
22 | : GPUImageTwoPassTextureSamplingFilter(VERTEX_SHADER_2, FRAGMENT_SHADER_2, VERTEX_SHADER_2,
23 | FRAGMENT_SHADER_2) {
24 |
25 | }
26 |
27 | const char *ben::ngp::GPUImageDilationFilter::getCanonicalName() const {
28 | return JAVA_DILATION_FILTER;
29 | }
30 |
31 | void ben::ngp::GPUImageDilationFilter::initialize(JNIEnv *env) {
32 | GPUImageFilter::initialize(env);
33 | cacheField(env, "radius", kTypeInt);
34 | cacheConstructor(env);
35 | cacheMethod(env, "getRadius", kTypeInt, NULL);
36 | cacheMethod(env, "setRadius", kTypeVoid, kTypeInt, NULL);
37 | merge(this);
38 | }
39 |
40 | void ben::ngp::GPUImageDilationFilter::mapFields() {
41 | GPUImageFilter::mapFields();
42 | mapField("radius", kTypeFloat, &radius);
43 |
44 | }
45 |
46 | int ben::ngp::GPUImageDilationFilter::getRadius() const {
47 | return radius;
48 | }
49 |
50 | void ben::ngp::GPUImageDilationFilter::setRadius(int radius) {
51 | GPUImageDilationFilter::radius = radius;
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_directional_sobel_edge_detection_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_directional_sobel_edge_detection_filter.hpp"
6 |
7 | ben::ngp::GPUImageDirectionalSobelEdgeDetectionFilter::GPUImageDirectionalSobelEdgeDetectionFilter(
8 | JNIEnv *env) : GPUImage3x3TextureSamplingFilter(env,DIRECTIONAL_SOBEL_EDGE_DETECTION_FRAGMENT_SHADER) {
9 | initialize(env);
10 | }
11 |
12 | void ben::ngp::GPUImageDirectionalSobelEdgeDetectionFilter::initialize(JNIEnv *env) {
13 | GPUImage3x3TextureSamplingFilter::initialize(env);
14 | }
15 |
16 | void ben::ngp::GPUImageDirectionalSobelEdgeDetectionFilter::mapFields() {
17 | GPUImage3x3TextureSamplingFilter::mapFields();
18 | }
19 |
20 | const char *ben::ngp::GPUImageDirectionalSobelEdgeDetectionFilter::getCanonicalName() const {
21 | return JAVA_DIRECTIONAL_SOBEL_EDGE_DETECTION_FILTER;
22 | }
23 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_dissolve_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_dissolve_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageDissolveBlendFilter::GPUImageDissolveBlendFilter(JNIEnv *env)
8 | : GPUImageMixBlendFilter(DISSOLVE_BLEND_FRAGMENT_SHADER, env) {
9 | initialize(env);
10 | }
11 |
12 | ben::ngp::GPUImageDissolveBlendFilter::GPUImageDissolveBlendFilter(float mix, JNIEnv *env)
13 | : GPUImageMixBlendFilter(DISSOLVE_BLEND_FRAGMENT_SHADER, env, mix) {
14 | initialize(env);
15 | }
16 |
17 | void ben::ngp::GPUImageDissolveBlendFilter::initialize(JNIEnv *env) {
18 | GPUImageMixBlendFilter::initialize(env);
19 | }
20 |
21 | void ben::ngp::GPUImageDissolveBlendFilter::mapFields() {
22 | GPUImageMixBlendFilter::mapFields();
23 | }
24 |
25 | const char *ben::ngp::GPUImageDissolveBlendFilter::getCanonicalName() const {
26 | return JAVA_DISSOLVE_BLEND_FILTER;
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_dissolve_blend_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_DISSOLVE_BLEND_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_DISSOLVE_BLEND_FILTER_HPP
7 |
8 | #include "gpu_image_mix_blend_filter.hpp"
9 | #define JAVA_DISSOLVE_BLEND_FILTER "com/ben/android/library/filter/GPUImageDissolveBlendFilter"
10 | static char *DISSOLVE_BLEND_FRAGMENT_SHADER = GET_STR(
11 | varying highp vec2 textureCoordinate;
12 | varying highp vec2 textureCoordinate2;
13 |
14 | uniform sampler2D inputImageTexture;
15 | uniform sampler2D inputImageTexture2;
16 | uniform lowp float mixturePercent;
17 |
18 | void main()
19 | {
20 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
21 | lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);
22 |
23 | gl_FragColor = mix(textureColor, textureColor2, mixturePercent);
24 | }
25 | );
26 | namespace ben{
27 | namespace ngp{
28 | class GPUImageDissolveBlendFilter:public GPUImageMixBlendFilter {
29 | public:
30 | GPUImageDissolveBlendFilter(JNIEnv *env);
31 | GPUImageDissolveBlendFilter(float mix,JNIEnv *env);
32 | public:
33 | virtual void initialize(JNIEnv *env);
34 |
35 | virtual void mapFields();
36 |
37 | virtual const char *getCanonicalName() const;
38 | };
39 | }
40 | }
41 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_DISSOLVE_BLEND_FILTER_HPP
42 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_divide_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_divide_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageDivideBlendFilter::GPUImageDivideBlendFilter(JNIEnv *env)
8 | : GPUImageTwoInputFilter(DIVIDE_BLEND_FRAGMENT_SHADER, env) {
9 | initialize(env);
10 | }
11 |
12 | const char *ben::ngp::GPUImageDivideBlendFilter::getCanonicalName() const {
13 | return JAVA_DIVIDE_BLEND_FILTER;
14 | }
15 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_emboss_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_emboss_filter.hpp"
6 | #include "../include/jni/JniHelpersCommon.h"
7 |
8 | ben::ngp::GPUImageEmbossFilter::GPUImageEmbossFilter() {
9 | this->intensity = 1.0f;
10 | }
11 |
12 | ben::ngp::GPUImageEmbossFilter::GPUImageEmbossFilter(JNIEnv *env) : GPUImage3x3ConvolutionFilter(
13 | env) {
14 | initialize(env);
15 | this->intensity = 1.0f;
16 | }
17 |
18 | void ben::ngp::GPUImageEmbossFilter::initialize(JNIEnv *env) {
19 | GPUImage3x3ConvolutionFilter::initialize(env);
20 | cacheField(env, "intensity", kTypeFloat);
21 | cacheConstructor(env);
22 | cacheMethod(env, "getIntensity", kTypeFloat, NULL);
23 | cacheMethod(env, "setIntensity", kTypeVoid, kTypeFloat, NULL);
24 | merge(this);
25 | }
26 |
27 | void ben::ngp::GPUImageEmbossFilter::mapFields() {
28 | GPUImage3x3ConvolutionFilter::mapFields();
29 | mapField("intensity", kTypeFloat, &intensity);
30 | }
31 |
32 | const char *ben::ngp::GPUImageEmbossFilter::getCanonicalName() const {
33 | return JAVA_EMBOSS_FILTER;
34 | }
35 |
36 | void ben::ngp::GPUImageEmbossFilter::onInit() {
37 | GPUImage3x3ConvolutionFilter::onInit();
38 | }
39 |
40 | void ben::ngp::GPUImageEmbossFilter::onInitialized() {
41 | GPUImage3x3ConvolutionFilter::onInitialized();
42 | setIntensity(intensity);
43 | }
44 |
45 | void ben::ngp::GPUImageEmbossFilter::setIntensity(float intensity) {
46 | GPUImageEmbossFilter::intensity = intensity;
47 | setConvolutionKernel(new float[9]{
48 | intensity * (-2.0f), -intensity, 0.0f,
49 | -intensity, 1.0f, intensity,
50 | 0.0f, intensity, intensity * 2.0f,
51 | });
52 | }
53 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_emboss_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_EMBOSS_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_EMBOSS_FILTER_HPP
7 |
8 | #include "gpu_image_3x3_convolution_filter.hpp"
9 |
10 | #define JAVA_EMBOSS_FILTER "com/ben/android/library/filter/GPUImageEmbossFilter"
11 |
12 | namespace ben{
13 | namespace ngp{
14 | class GPUImageEmbossFilter:public GPUImage3x3ConvolutionFilter {
15 | private:
16 | float intensity;
17 |
18 | public:
19 | GPUImageEmbossFilter();
20 | GPUImageEmbossFilter(JNIEnv *env);
21 |
22 | virtual void onInit();
23 |
24 | virtual void onInitialized();
25 |
26 | virtual void initialize(JNIEnv *env);
27 |
28 | virtual void mapFields();
29 |
30 | virtual const char *getCanonicalName() const;
31 |
32 | void setIntensity(float intensity);
33 | };
34 | }
35 | }
36 |
37 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_EMBOSS_FILTER_HPP
38 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_exclusion_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_exclusion_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageExclusionBlendFilter::GPUImageExclusionBlendFilter() : GPUImageTwoInputFilter(
8 | EXCLUSION_BLEND_FRAGMENT_SHADER) {
9 |
10 | }
11 |
12 | ben::ngp::GPUImageExclusionBlendFilter::GPUImageExclusionBlendFilter(JNIEnv *env)
13 | : GPUImageTwoInputFilter(EXCLUSION_BLEND_FRAGMENT_SHADER, env) {
14 | initialize(env);
15 | }
16 |
17 | const char *ben::ngp::GPUImageExclusionBlendFilter::getCanonicalName() const {
18 | return JAVA_EXCLUSION_BLEND_FILTER;
19 | }
20 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_exclusion_blend_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_EXCLUSION_BLEND_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_EXCLUSION_BLEND_FILTER_HPP
7 |
8 | #include "gpu_image_two_input_filter.hpp"
9 | #define JAVA_EXCLUSION_BLEND_FILTER "com/ben/android/library/filter/GPUImageExclusionBlendFilter"
10 | static char *EXCLUSION_BLEND_FRAGMENT_SHADER = GET_STR(
11 | varying highp vec2 textureCoordinate;
12 | varying highp vec2 textureCoordinate2;
13 |
14 | uniform sampler2D inputImageTexture;
15 | uniform sampler2D inputImageTexture2;
16 |
17 | void main()
18 | {
19 | mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);
20 | mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);
21 |
22 | // Dca = (Sca.Da + Dca.Sa - 2.Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa)
23 |
24 | gl_FragColor = vec4((overlay.rgb * base.a + base.rgb * overlay.a - 2.0 * overlay.rgb * base.rgb) + overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a), base.a);
25 | }
26 | );
27 | namespace ben{
28 | namespace ngp{
29 | class GPUImageExclusionBlendFilter:public GPUImageTwoInputFilter{
30 | public:
31 | GPUImageExclusionBlendFilter();
32 | GPUImageExclusionBlendFilter(JNIEnv *env);
33 |
34 | virtual const char *getCanonicalName() const;
35 | };
36 | }
37 | }
38 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_EXCLUSION_BLEND_FILTER_HPP
39 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_exposure_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_exposure_filter.hpp"
6 |
7 | ben::ngp::GPUImageExposureFilter::GPUImageExposureFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, EXPOSURE_FRAGMENT_SHADER) {
8 | this->exposure = 1.0f;
9 | }
10 |
11 | ben::ngp::GPUImageExposureFilter::GPUImageExposureFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, EXPOSURE_FRAGMENT_SHADER,env) {
12 | initialize(env);
13 | this->exposure = 1.0f;
14 | }
15 |
16 | void ben::ngp::GPUImageExposureFilter::initialize(JNIEnv *env) {
17 | GPUImageFilter::initialize(env);
18 | cacheField(env, "exposure", kTypeFloat);
19 | cacheConstructor(env);
20 | cacheMethod(env, "getExposure", kTypeFloat, NULL);
21 | cacheMethod(env, "setExposure", kTypeVoid, kTypeFloat, NULL);
22 | merge(this);
23 |
24 | }
25 |
26 | void ben::ngp::GPUImageExposureFilter::mapFields() {
27 | GPUImageFilter::mapFields();
28 | mapField("exposure", kTypeFloat, &exposure);
29 | }
30 |
31 | const char *ben::ngp::GPUImageExposureFilter::getCanonicalName() const {
32 | return JAVA_EXPOSURE_FILTER;
33 | }
34 |
35 | void ben::ngp::GPUImageExposureFilter::onInit() {
36 | GPUImageFilter::onInit();
37 | exposureLocation = glGetUniformLocation(getGlProgId(), "exposure");
38 | }
39 |
40 | void ben::ngp::GPUImageExposureFilter::onInitialized() {
41 | GPUImageFilter::onInitialized();
42 | setExposure(exposure);
43 | }
44 |
45 | void ben::ngp::GPUImageExposureFilter::setExposure(float exposure) {
46 | GPUImageExposureFilter::exposure = exposure;
47 | setFloat(exposureLocation, this->exposure);
48 | }
49 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_exposure_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_EXPOSURE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_EXPOSURE_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 |
10 | #define JAVA_EXPOSURE_FILTER "com/ben/android/library/filter/GPUImageExposureFilter"
11 | static char *EXPOSURE_FRAGMENT_SHADER = GET_STR(
12 | varying
13 | highp
14 | vec2 textureCoordinate;
15 |
16 | uniform
17 | sampler2D inputImageTexture;
18 | uniform
19 | highp float exposure;
20 |
21 | void main() {
22 | highp
23 | vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
24 |
25 | gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w);
26 | }
27 | );
28 | namespace ben {
29 | namespace ngp {
30 | class GPUImageExposureFilter : public GPUImageFilter {
31 | private:
32 | int exposureLocation;
33 | float exposure;
34 | public:
35 | GPUImageExposureFilter();
36 |
37 | GPUImageExposureFilter(JNIEnv *env);
38 |
39 | virtual void onInit();
40 |
41 | virtual void onInitialized();
42 |
43 | virtual void initialize(JNIEnv *env);
44 |
45 | virtual void mapFields();
46 |
47 | virtual const char *getCanonicalName() const;
48 |
49 | void setExposure(float exposure);
50 | };
51 | }
52 | }
53 |
54 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_EXPOSURE_FILTER_HPP
55 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_gamma_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_gamma_filter.hpp"
6 |
7 | ben::ngp::GPUImageGammaFilter::GPUImageGammaFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, GAMMA_FRAGMENT_SHADER) {
8 | this->gamma = 1.2f;
9 | }
10 |
11 | ben::ngp::GPUImageGammaFilter::GPUImageGammaFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, GAMMA_FRAGMENT_SHADER,env) {
12 |
13 | initialize(env);
14 | this->gamma = 1.2f;
15 |
16 | }
17 |
18 | void ben::ngp::GPUImageGammaFilter::initialize(JNIEnv *env) {
19 | GPUImageFilter::initialize(env);
20 | cacheField(env, "gamma", kTypeFloat);
21 | cacheConstructor(env);
22 | cacheMethod(env, "getGamma", kTypeFloat, NULL);
23 | cacheMethod(env, "setGamma", kTypeVoid, kTypeFloat, NULL);
24 | merge(this);
25 | }
26 |
27 | void ben::ngp::GPUImageGammaFilter::mapFields() {
28 | GPUImageFilter::mapFields();
29 | mapField("gamma", kTypeFloat, &gamma);
30 | }
31 |
32 | const char *ben::ngp::GPUImageGammaFilter::getCanonicalName() const {
33 | return JAVA_GAMMA_FILTER;
34 | }
35 |
36 | void ben::ngp::GPUImageGammaFilter::setGamma(float gamma) {
37 | GPUImageGammaFilter::gamma = gamma;
38 | setFloat(gammaLocation, this->gamma);
39 | }
40 |
41 | void ben::ngp::GPUImageGammaFilter::onInit() {
42 | GPUImageFilter::onInit();
43 | gammaLocation = glGetUniformLocation(getGlProgId(), "gamma");
44 | }
45 |
46 | void ben::ngp::GPUImageGammaFilter::onInitialized() {
47 | GPUImageFilter::onInitialized();
48 | setGamma(gamma);
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_gamma_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_GAMMA_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_GAMMA_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #define JAVA_GAMMA_FILTER "com/ben/android/library/filter/GPUImageGammaFilter"
10 | static char *GAMMA_FRAGMENT_SHADER = GET_STR(
11 | varying
12 | highp
13 | vec2 textureCoordinate;
14 |
15 | uniform
16 | sampler2D inputImageTexture;
17 | uniform
18 | lowp float gamma;
19 |
20 | void main() {
21 | lowp
22 | vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
23 |
24 | gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w);
25 | }
26 | );
27 | namespace ben {
28 | namespace ngp {
29 | class GPUImageGammaFilter : public GPUImageFilter {
30 | private:
31 | int gammaLocation;
32 | float gamma;
33 | public:
34 | GPUImageGammaFilter();
35 |
36 | GPUImageGammaFilter(JNIEnv *env);
37 |
38 | virtual void onInit();
39 |
40 | virtual void onInitialized();
41 |
42 | public:
43 | virtual void initialize(JNIEnv *env);
44 |
45 | virtual void mapFields();
46 |
47 | virtual const char *getCanonicalName() const;
48 |
49 | void setGamma(float gamma);
50 | };
51 | }
52 | }
53 |
54 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_GAMMA_FILTER_HPP
55 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_grayscale_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_grayscale_filter.hpp"
6 |
7 | ben::ngp::GPUImageGrayscaleFilter::GPUImageGrayscaleFilter() : GPUImageFilter(NO_FILTER_VERTEX_SHADER, GRAYSCALE_FRAGMENT_SHADER){}
8 | ben::ngp::GPUImageGrayscaleFilter::GPUImageGrayscaleFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, GRAYSCALE_FRAGMENT_SHADER,env) {
9 | initialize(env);
10 | }
11 |
12 | void ben::ngp::GPUImageGrayscaleFilter::initialize(JNIEnv *env) {
13 | GPUImageFilter::initialize(env);
14 | }
15 |
16 | void ben::ngp::GPUImageGrayscaleFilter::mapFields() {
17 | GPUImageFilter::mapFields();
18 | }
19 |
20 | const char *ben::ngp::GPUImageGrayscaleFilter::getCanonicalName() const {
21 | return JAVA_GRAYSCALE_FILTER;
22 | }
23 |
24 |
25 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_grayscale_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_GRAYSCALE_FILTER_HPP
5 | #define NATIVEGPUIMAGE_GPU_IMAGE_GRAYSCALE_FILTER_HPP
6 |
7 | #include "gpu_image_filter.hpp"
8 | #define JAVA_GRAYSCALE_FILTER "com/ben/android/library/filter/GPUImageGrayscaleFilter"
9 | static char *GRAYSCALE_FRAGMENT_SHADER = GET_STR(
10 | precision highp float;
11 |
12 | varying vec2 textureCoordinate;
13 |
14 | uniform sampler2D inputImageTexture;
15 |
16 | const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
17 |
18 | void main()
19 | {
20 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
21 | float luminance = dot(textureColor.rgb, W);
22 |
23 | gl_FragColor = vec4(vec3(luminance), textureColor.a);
24 | }
25 | );
26 | namespace ben{
27 | namespace ngp{
28 | class GPUImageGrayscaleFilter:public GPUImageFilter {
29 | public:
30 | GPUImageGrayscaleFilter();
31 |
32 | GPUImageGrayscaleFilter(JNIEnv *env);
33 |
34 | virtual void initialize(JNIEnv *env);
35 |
36 | virtual void mapFields();
37 |
38 | virtual const char *getCanonicalName() const;
39 | };
40 | }
41 | }
42 |
43 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_GRAYSCALE_FILTER_HPP
44 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_halftone_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_halftone_filter.hpp"
6 |
7 | ben::ngp::GPUImageHalftoneFilter::GPUImageHalftoneFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, HALFTONE_FRAGMENT_SHADER) {}
8 |
9 | ben::ngp::GPUImageHalftoneFilter::GPUImageHalftoneFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, HALFTONE_FRAGMENT_SHADER,env) {
10 | initialize(env);
11 | }
12 |
13 | void ben::ngp::GPUImageHalftoneFilter::initialize(JNIEnv *env) {
14 | GPUImageFilter::initialize(env);
15 | cacheField(env, "fractionalWidthOfAPixel", kTypeFloat);
16 | cacheConstructor(env);
17 | cacheMethod(env, "getFractionalWidthOfAPixel", kTypeFloat, NULL);
18 | cacheMethod(env, "setFractionalWidthOfAPixel", kTypeVoid, kTypeFloat, NULL);
19 | merge(this);
20 | }
21 |
22 | void ben::ngp::GPUImageHalftoneFilter::mapFields() {
23 | GPUImageFilter::mapFields();
24 | mapField("fractionalWidthOfAPixel", kTypeFloat, &fractionalWidthOfAPixel);
25 | }
26 |
27 | const char *ben::ngp::GPUImageHalftoneFilter::getCanonicalName() const {
28 | return JAVA_HALFTONE_FILTER;
29 | }
30 |
31 | void ben::ngp::GPUImageHalftoneFilter::onInit() {
32 | GPUImageFilter::onInit();
33 | fractionalWidthOfPixelLocation = glGetUniformLocation(getGlProgId(), "fractionalWidthOfPixel");
34 | aspectRatioLocation = glGetUniformLocation(getGlProgId(), "aspectRatio");
35 | }
36 |
37 | void ben::ngp::GPUImageHalftoneFilter::onInitialized() {
38 | GPUImageFilter::onInitialized();
39 | setFractionalWidthOfAPixel(fractionalWidthOfAPixel);
40 | setAspectRatio(aspectRatio);
41 | }
42 |
43 | void ben::ngp::GPUImageHalftoneFilter::setFractionalWidthOfAPixel(float fractionalWidthOfAPixel) {
44 | GPUImageHalftoneFilter::fractionalWidthOfAPixel = fractionalWidthOfAPixel;
45 | setFloat(fractionalWidthOfPixelLocation, this->fractionalWidthOfAPixel);
46 | }
47 |
48 | void ben::ngp::GPUImageHalftoneFilter::setAspectRatio(float aspectRatio) {
49 | GPUImageHalftoneFilter::aspectRatio = aspectRatio;
50 | setFloat(aspectRatioLocation, this->aspectRatio);
51 | }
52 |
53 | void ben::ngp::GPUImageHalftoneFilter::onOutputSizeChanged(int width, int height) {
54 | GPUImageFilter::onOutputSizeChanged(width, height);
55 | setAspectRatio((float) height / (float) width);
56 | }
57 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_haze_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_haze_filter.hpp"
6 |
7 | ben::ngp::GPUImageHazeFilter::GPUImageHazeFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, HAZE_FRAGMENT_SHADER) {}
8 |
9 | ben::ngp::GPUImageHazeFilter::GPUImageHazeFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, HAZE_FRAGMENT_SHADER,env) {
10 | initialize(env);
11 | }
12 |
13 | void ben::ngp::GPUImageHazeFilter::initialize(JNIEnv *env) {
14 | GPUImageFilter::initialize(env);
15 | cacheField(env, "distance", kTypeFloat);
16 | cacheField(env, "slope", kTypeFloat);
17 | cacheConstructor(env);
18 | cacheMethod(env, "getDistance", kTypeFloat, NULL);
19 | cacheMethod(env, "setDistance", kTypeVoid, kTypeFloat, NULL);
20 | cacheMethod(env, "getSlope", kTypeFloat, NULL);
21 | cacheMethod(env, "setSlope", kTypeVoid, kTypeFloat, NULL);
22 | merge(this);
23 | }
24 |
25 | void ben::ngp::GPUImageHazeFilter::mapFields() {
26 | GPUImageFilter::mapFields();
27 | mapField("distance", kTypeFloat, &distance);
28 | mapField("slope", kTypeFloat, &slope);
29 | }
30 |
31 | const char *ben::ngp::GPUImageHazeFilter::getCanonicalName() const {
32 | return JAVA_HAZE_FILTER;
33 | }
34 |
35 | void ben::ngp::GPUImageHazeFilter::onInit() {
36 | GPUImageFilter::onInit();
37 | distanceLocation = glGetUniformLocation(getGlProgId(), "distance");
38 | slopeLocation = glGetUniformLocation(getGlProgId(), "slope");
39 | }
40 |
41 | void ben::ngp::GPUImageHazeFilter::onInitialized() {
42 | GPUImageFilter::onInitialized();
43 | setDistance(distance);
44 | setSlope(slope);
45 | }
46 |
47 | void ben::ngp::GPUImageHazeFilter::setDistance(float distance) {
48 | GPUImageHazeFilter::distance = distance;
49 | setFloat(distanceLocation, distance);
50 | }
51 |
52 | void ben::ngp::GPUImageHazeFilter::setSlope(float slope) {
53 | GPUImageHazeFilter::slope = slope;
54 | setFloat(slopeLocation, slope);
55 | }
56 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_haze_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_HAZE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_HAZE_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #include "../include/jni/JniHelpersCommon.h"
10 |
11 | #define JAVA_HAZE_FILTER "com/ben/android/library/filter/GPUImageHazeFilter"
12 | static char *HAZE_FRAGMENT_SHADER = GET_STR(
13 | varying highp vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 |
17 | uniform lowp float distance;
18 | uniform highp float slope;
19 |
20 | void main()
21 | {
22 | //todo reconsider precision modifiers
23 | highp vec4 color = vec4(1.0);//todo reimplement as a parameter
24 |
25 | highp float d = textureCoordinate.y * slope + distance;
26 |
27 | highp vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply
28 |
29 | c = (c - d * color) / (1.0 -d);
30 |
31 | gl_FragColor = c; //consider using premultiply(c);
32 | }
33 | );
34 | namespace ben{
35 | namespace ngp{
36 | class GPUImageHazeFilter:public GPUImageFilter{
37 | private:
38 | float distance;
39 | int distanceLocation;
40 | float slope;
41 | int slopeLocation;
42 | public:
43 | GPUImageHazeFilter();
44 |
45 | GPUImageHazeFilter(JNIEnv *env);
46 |
47 | virtual void initialize(JNIEnv *env);
48 |
49 | virtual void mapFields();
50 |
51 | virtual const char *getCanonicalName() const;
52 |
53 | virtual void onInit();
54 |
55 | virtual void onInitialized();
56 |
57 | void setDistance(float distance);
58 |
59 | void setSlope(float slope);
60 | };
61 | }
62 | }
63 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_HAZE_FILTER_HPP
64 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_highlight_shadow_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_highlight_shadow_filter.hpp"
6 |
7 | ben::ngp::GPUImageHighlightShadowFilter::GPUImageHighlightShadowFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, HIGHLIGHT_SHADOW_FRAGMENT_SHADER) {}
8 |
9 | ben::ngp::GPUImageHighlightShadowFilter::GPUImageHighlightShadowFilter(JNIEnv *env)
10 | : GPUImageFilter(NO_FILTER_VERTEX_SHADER, HIGHLIGHT_SHADOW_FRAGMENT_SHADER,env) {
11 | initialize(env);
12 | }
13 |
14 | void ben::ngp::GPUImageHighlightShadowFilter::initialize(JNIEnv *env) {
15 | GPUImageFilter::initialize(env);
16 | cacheField(env, "shadows", kTypeFloat);
17 | cacheField(env, "highlights", kTypeFloat);
18 | cacheConstructor(env);
19 | cacheMethod(env, "getShadows", kTypeFloat, NULL);
20 | cacheMethod(env, "setShadows", kTypeVoid, kTypeFloat, NULL);
21 | cacheMethod(env, "getHighlights", kTypeFloat, NULL);
22 | cacheMethod(env, "setHighlights", kTypeVoid, kTypeFloat, NULL);
23 | merge(this);
24 | }
25 |
26 | void ben::ngp::GPUImageHighlightShadowFilter::mapFields() {
27 | GPUImageFilter::mapFields();
28 | mapField("shadows", kTypeFloat, &shadows);
29 | mapField("highlights", kTypeFloat, &highlights);
30 | }
31 |
32 | const char *ben::ngp::GPUImageHighlightShadowFilter::getCanonicalName() const {
33 | return JAVA_HIGHLIGHT_SHADOW_FILTER;
34 | }
35 |
36 | void ben::ngp::GPUImageHighlightShadowFilter::onInit() {
37 | GPUImageFilter::onInit();
38 | highlightsLocation = glGetUniformLocation(getGlProgId(), "highlights");
39 | shadowsLocation = glGetUniformLocation(getGlProgId(), "shadows");
40 | }
41 |
42 | void ben::ngp::GPUImageHighlightShadowFilter::onInitialized() {
43 | GPUImageFilter::onInitialized();
44 | setHighlights(highlights);
45 | setShadows(shadows);
46 | }
47 |
48 | void ben::ngp::GPUImageHighlightShadowFilter::setShadows(float shadows) {
49 | GPUImageHighlightShadowFilter::shadows = shadows;
50 | setFloat(shadowsLocation, this->shadows);
51 | }
52 |
53 | void ben::ngp::GPUImageHighlightShadowFilter::setHighlights(float highlights) {
54 | GPUImageHighlightShadowFilter::highlights = highlights;
55 | setFloat(highlightsLocation, this->highlights);
56 | }
57 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_hue_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_hue_filter.hpp"
6 |
7 | ben::ngp::GPUImageHueFilter::GPUImageHueFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, HUE_FRAGMENT_SHADER,env) {
8 | initialize(env);
9 | this->hue = 90.0f;
10 | }
11 |
12 | ben::ngp::GPUImageHueFilter::GPUImageHueFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, HUE_FRAGMENT_SHADER) {
13 | this->hue = 90.0f;
14 | }
15 |
16 | void ben::ngp::GPUImageHueFilter::initialize(JNIEnv *env) {
17 | GPUImageFilter::initialize(env);
18 | cacheField(env, "hue", kTypeFloat);
19 | cacheConstructor(env);
20 | cacheMethod(env, "getHue", kTypeFloat, NULL);
21 | cacheMethod(env, "setHue", kTypeVoid, kTypeFloat, NULL);
22 | merge(this);
23 | }
24 |
25 | void ben::ngp::GPUImageHueFilter::mapFields() {
26 | GPUImageFilter::mapFields();
27 | mapField("hue", kTypeFloat, &hue);
28 | }
29 |
30 | const char *ben::ngp::GPUImageHueFilter::getCanonicalName() const {
31 | return JAVA_HUE_FILTER;
32 | }
33 |
34 | void ben::ngp::GPUImageHueFilter::onInit() {
35 | GPUImageFilter::onInit();
36 | hueLocation = glGetUniformLocation(getGlProgId(), "hueAdjust");
37 | }
38 |
39 | void ben::ngp::GPUImageHueFilter::onInitialized() {
40 | GPUImageFilter::onInitialized();
41 | setHue(hue);
42 | }
43 |
44 | void ben::ngp::GPUImageHueFilter::setHue(float hue) {
45 | GPUImageHueFilter::hue = hue;
46 | float hueAdjust = ((int)this->hue % 360) * (float)3.14159265358979323846 / 180.0f;
47 | setFloat(hueLocation, hueAdjust);
48 | }
49 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_luminance_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_luminance_filter.hpp"
6 |
7 | ben::ngp::GPUImageLuminanceFilter::GPUImageLuminanceFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, LUMINANCE_FRAGMENT_SHADER,env) {
8 | initialize(env);
9 | }
10 |
11 | const char *ben::ngp::GPUImageLuminanceFilter::getCanonicalName() const {
12 | return JAVA_LUMINANCE_FILTER;
13 | }
14 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_luminance_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #define JAVA_LUMINANCE_FILTER "com/ben/android/library/filter/GPUImageLuminanceFilter"
10 | static char *LUMINANCE_FRAGMENT_SHADER = GET_STR(
11 | precision highp float;
12 |
13 | varying vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 |
17 | // Values from \Graphics Shaders: Theory and Practice\ by Bailey and Cunningham
18 | const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
19 |
20 | void main()
21 | {
22 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
23 | float luminance = dot(textureColor.rgb, W);
24 |
25 | gl_FragColor = vec4(vec3(luminance), textureColor.a);
26 | }
27 | );
28 | namespace ben{
29 | namespace ngp{
30 | class GPUImageLuminanceFilter:public GPUImageFilter{
31 | public:
32 | GPUImageLuminanceFilter(JNIEnv *env);
33 |
34 | const char *getCanonicalName() const override;
35 | };
36 | }
37 | }
38 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_FILTER_HPP
39 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_luminance_threshold_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_luminance_threshold_filter.hpp"
6 |
7 | ben::ngp::GPUImageLuminanceThresholdFilter::GPUImageLuminanceThresholdFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, LUMINANCE_THRESHOLD_FRAGMENT_SHADER) {}
8 |
9 | ben::ngp::GPUImageLuminanceThresholdFilter::GPUImageLuminanceThresholdFilter(JNIEnv *env)
10 | : GPUImageFilter(NO_FILTER_VERTEX_SHADER, LUMINANCE_THRESHOLD_FRAGMENT_SHADER,env) {
11 | initialize(env);
12 | }
13 |
14 | void ben::ngp::GPUImageLuminanceThresholdFilter::initialize(JNIEnv *env) {
15 | GPUImageFilter::initialize(env);
16 | cacheField(env, "threshold", kTypeFloat);
17 | cacheConstructor(env);
18 | cacheMethod(env, "getThreshold", kTypeFloat, NULL);
19 | cacheMethod(env, "setThreshold", kTypeVoid, kTypeFloat, NULL);
20 | merge(this);
21 | }
22 |
23 | void ben::ngp::GPUImageLuminanceThresholdFilter::mapFields() {
24 | GPUImageFilter::mapFields();
25 | mapField("threshold", kTypeFloat, &threshold);
26 | }
27 |
28 | const char *ben::ngp::GPUImageLuminanceThresholdFilter::getCanonicalName() const {
29 | return JAVA_LUMINANCE_THRESHOLD_FILTER;
30 | }
31 |
32 | void ben::ngp::GPUImageLuminanceThresholdFilter::onInit() {
33 | GPUImageFilter::onInit();
34 | uniformThresholdLocation = glGetUniformLocation(getGlProgId(), "threshold");
35 | }
36 |
37 | void ben::ngp::GPUImageLuminanceThresholdFilter::onInitialized() {
38 | GPUImageFilter::onInitialized();
39 | setThreshold(threshold);
40 | }
41 |
42 | void ben::ngp::GPUImageLuminanceThresholdFilter::setThreshold(float threshold) {
43 | GPUImageLuminanceThresholdFilter::threshold = threshold;
44 | setFloat(uniformThresholdLocation, threshold);
45 | }
46 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_luminance_threshold_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_THRESHOLD_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_THRESHOLD_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #include "../include/jni/JniHelpersCommon.h"
10 |
11 | #define JAVA_LUMINANCE_THRESHOLD_FILTER "com/ben/android/library/filter/GPUImageLuminanceThresholdFilter"
12 | static char *LUMINANCE_THRESHOLD_FRAGMENT_SHADER = GET_STR(
13 | varying highp vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 | uniform highp float threshold;
17 |
18 | const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
19 |
20 | void main()
21 | {
22 | highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
23 | highp float luminance = dot(textureColor.rgb, W);
24 | highp float thresholdResult = step(threshold, luminance);
25 |
26 | gl_FragColor = vec4(vec3(thresholdResult), textureColor.w);
27 | }
28 | );
29 | namespace ben{
30 | namespace ngp{
31 | class GPUImageLuminanceThresholdFilter:public GPUImageFilter{
32 | private:
33 | int uniformThresholdLocation;
34 | float threshold;
35 | public:
36 | GPUImageLuminanceThresholdFilter();
37 |
38 | GPUImageLuminanceThresholdFilter(JNIEnv *env);
39 |
40 | virtual void initialize(JNIEnv *env);
41 |
42 | virtual void mapFields();
43 |
44 | virtual const char *getCanonicalName() const;
45 |
46 | virtual void onInit();
47 |
48 | virtual void onInitialized();
49 |
50 | void setThreshold(float threshold);
51 | };
52 | }
53 | }
54 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_LUMINANCE_THRESHOLD_FILTER_HPP
55 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_mix_blend_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_mix_blend_filter.hpp"
6 |
7 | ben::ngp::GPUImageMixBlendFilter::GPUImageMixBlendFilter(char *fragmentShader, JNIEnv *env)
8 | : GPUImageTwoInputFilter(fragmentShader, env) {}
9 |
10 | ben::ngp::GPUImageMixBlendFilter::GPUImageMixBlendFilter(char *fragmentShader, JNIEnv *env,
11 | float mix) : GPUImageTwoInputFilter(
12 | fragmentShader, env) {
13 | initialize(env);
14 | this->mix = mix;
15 | }
16 |
17 | void ben::ngp::GPUImageMixBlendFilter::onInit() {
18 | GPUImageTwoInputFilter::onInit();
19 | mixLocation = glGetUniformLocation(getGlProgId(), "mixturePercent");
20 | }
21 |
22 | void ben::ngp::GPUImageMixBlendFilter::onInitialized() {
23 | GPUImageTwoInputFilter::onInitialized();
24 | setMix(mix);
25 | }
26 |
27 | void ben::ngp::GPUImageMixBlendFilter::setMix(float mix) {
28 | GPUImageMixBlendFilter::mix = mix;
29 | setFloat(mixLocation, this->mix);
30 | }
31 |
32 | void ben::ngp::GPUImageMixBlendFilter::initialize(JNIEnv *env) {
33 | GPUImageTwoInputFilter::initialize(env);
34 | cacheField(env, "mix", kTypeFloat);
35 | cacheConstructor(env);
36 | cacheMethod(env, "getMix", kTypeFloat, NULL);
37 | cacheMethod(env, "setMix", kTypeVoid, kTypeFloat, NULL);
38 | merge(this);
39 | }
40 |
41 | void ben::ngp::GPUImageMixBlendFilter::mapFields() {
42 | GPUImageTwoInputFilter::mapFields();
43 | mapField("mix", kTypeFloat, &mix);
44 | }
45 |
46 | const char *ben::ngp::GPUImageMixBlendFilter::getCanonicalName() const {
47 | //don't register
48 | return JAVA_MIX_BLEND_FILTER;
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_mix_blend_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_MIX_BLEND_FILTER_HPP
5 | #define NATIVEGPUIMAGE_GPU_IMAGE_MIX_BLEND_FILTER_HPP
6 |
7 | #include "gpu_image_two_input_filter.hpp"
8 |
9 | #define JAVA_MIX_BLEND_FILTER "com/ben/android/library/filter/GPUImageMixBlendFilter"
10 | namespace ben {
11 | namespace ngp {
12 | class GPUImageMixBlendFilter : public GPUImageTwoInputFilter {
13 | private:
14 | int mixLocation;
15 | float mix;
16 | public:
17 | GPUImageMixBlendFilter(char *fragmentShader, JNIEnv *env);
18 |
19 | GPUImageMixBlendFilter(char *fragmentShader, JNIEnv *env, float mix);
20 |
21 | virtual void initialize(JNIEnv *env);
22 |
23 | virtual void mapFields();
24 |
25 | virtual const char *getCanonicalName() const;
26 |
27 | virtual void onInit();
28 |
29 | virtual void onInitialized();
30 |
31 | void setMix(float mix);
32 |
33 | };
34 | }
35 | }
36 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_MIX_BLEND_FILTER_HPP
37 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_rgb_dilation_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_rgb_dilation_filter.hpp"
6 |
7 | ben::ngp::GPUImageRGBDilationFilter::GPUImageRGBDilationFilter(JNIEnv *env)
8 | : GPUImageTwoPassTextureSamplingFilter(RGB_DILATION_VERTEX_SHADER_1, RGB_DILATION_FRAGMENT_SHADER_1,
9 | RGB_DILATION_VERTEX_SHADER_1, RGB_DILATION_FRAGMENT_SHADER_1, env) {
10 | initialize(env);
11 | }
12 |
13 | const char *ben::ngp::GPUImageRGBDilationFilter::getCanonicalName() const {
14 | return JAVA_RGB_DILATION_FILTER;
15 | }
16 |
17 | void ben::ngp::GPUImageRGBDilationFilter::initialize(JNIEnv *env) {
18 | GPUImageFilter::initialize(env);
19 | cacheField(env, "radius", kTypeInt);
20 | cacheConstructor(env);
21 | cacheMethod(env, "getRadius", kTypeInt, NULL);
22 | cacheMethod(env, "setRadius", kTypeVoid, kTypeInt, NULL);
23 | merge(this);
24 | }
25 |
26 | void ben::ngp::GPUImageRGBDilationFilter::mapFields() {
27 | GPUImageFilter::mapFields();
28 | mapField("radius", kTypeInt, &radius);
29 | }
30 |
31 | int ben::ngp::GPUImageRGBDilationFilter::getRadius() const {
32 | return radius;
33 | }
34 |
35 | void ben::ngp::GPUImageRGBDilationFilter::switchShader() {
36 | clearFilter();
37 | switch (radius) {
38 | case 0:
39 | case 1:
40 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_1, RGB_DILATION_FRAGMENT_SHADER_1));
41 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_1, RGB_DILATION_FRAGMENT_SHADER_1));
42 | case 2:
43 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_2, RGB_DILATION_FRAGMENT_SHADER_2));
44 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_2, RGB_DILATION_FRAGMENT_SHADER_2));
45 | case 3:
46 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_3, RGB_DILATION_FRAGMENT_SHADER_3));
47 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_3, RGB_DILATION_FRAGMENT_SHADER_3));
48 | default:
49 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_4, RGB_DILATION_FRAGMENT_SHADER_4));
50 | addFilter(new GPUImageFilter(RGB_DILATION_VERTEX_SHADER_4, RGB_DILATION_FRAGMENT_SHADER_4));
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_rgb_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_RGB_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_RGB_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #define JAVA_RGB_FILTER "com/ben/android/library/filter/GPUImageRGBFilter"
10 | static char *RGB_FRAGMENT_SHADER = GET_STR(
11 | varying highp vec2 textureCoordinate;
12 |
13 | uniform sampler2D inputImageTexture;
14 | uniform highp float red;
15 | uniform highp float green;
16 | uniform highp float blue;
17 |
18 | void main()
19 | {
20 | highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
21 |
22 | gl_FragColor = vec4(textureColor.r * red, textureColor.g * green, textureColor.b * blue, 1.0);
23 | }
24 | );
25 | namespace ben{
26 | namespace ngp{
27 | class GPUImageRGBFilter:public GPUImageFilter{
28 | private:
29 | int redLocation;
30 | float red;
31 | int greenLocation;
32 | float green;
33 | int blueLocation;
34 | float blue;
35 | public:
36 | GPUImageRGBFilter();
37 |
38 | GPUImageRGBFilter(JNIEnv *env);
39 |
40 | virtual void initialize(JNIEnv *env);
41 |
42 | virtual void mapFields();
43 |
44 | virtual const char *getCanonicalName() const;
45 |
46 | virtual void onInit();
47 |
48 | virtual void onInitialized();
49 |
50 | void setRed(float red);
51 |
52 | void setGreen(float green);
53 |
54 | void setBlue(float blue);
55 | };
56 | }
57 | }
58 |
59 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_RGB_FILTER_HPP
60 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_saturation_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_saturation_filter.hpp"
6 |
7 |
8 | ben::ngp::GPUImageSaturationFilter::GPUImageSaturationFilter() : GPUImageFilter(
9 | NO_FILTER_VERTEX_SHADER, SATURATION_FRAGMENT_SHADER) {
10 | this->saturation = 1.0f;
11 | }
12 |
13 | ben::ngp::GPUImageSaturationFilter::GPUImageSaturationFilter(JNIEnv *env) : GPUImageFilter(
14 | NO_FILTER_VERTEX_SHADER, SATURATION_FRAGMENT_SHADER, env) {
15 | initialize(env);
16 | this->saturation = 1.0f;
17 | }
18 |
19 | void ben::ngp::GPUImageSaturationFilter::onInit() {
20 | GPUImageFilter::onInit();
21 | saturationLocation = glGetUniformLocation(getGlProgId(), "saturation");
22 | }
23 |
24 | void ben::ngp::GPUImageSaturationFilter::onInitialized() {
25 | GPUImageFilter::onInitialized();
26 | setSaturation(saturation);
27 | }
28 |
29 |
30 | void ben::ngp::GPUImageSaturationFilter::initialize(JNIEnv *env) {
31 | GPUImageFilter::initialize(env);
32 | cacheField(env, "saturation", kTypeFloat);
33 | cacheConstructor(env);
34 | cacheMethod(env, "getSaturation", kTypeFloat, NULL);
35 | cacheMethod(env, "setSaturation", kTypeVoid, kTypeFloat, NULL);
36 | merge(this);
37 |
38 | }
39 |
40 | void ben::ngp::GPUImageSaturationFilter::mapFields() {
41 | GPUImageFilter::mapFields();
42 | mapField("saturation", kTypeFloat, &saturation);
43 | }
44 |
45 | const char *ben::ngp::GPUImageSaturationFilter::getCanonicalName() const {
46 | return JAVA_SATURATION_FILTER;
47 | }
48 |
49 | void ben::ngp::GPUImageSaturationFilter::setSaturation(float saturation) {
50 | GPUImageSaturationFilter::saturation = saturation;
51 | setFloat(saturationLocation, this->saturation);
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_saturation_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_SATURATION_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_SATURATION_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #include "../include/jni/JniHelpersCommon.h"
10 |
11 | #define JAVA_SATURATION_FILTER "com/ben/android/library/filter/GPUImageSaturationFilter"
12 | static char *SATURATION_FRAGMENT_SHADER = GET_STR(
13 | varying highp vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 | uniform lowp float saturation;
17 |
18 | // Values from \Graphics Shaders: Theory and Practice\ by Bailey and Cunningham
19 | const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);
20 |
21 | void main()
22 | {
23 | lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
24 | lowp float luminance = dot(textureColor.rgb, luminanceWeighting);
25 | lowp vec3 greyScaleColor = vec3(luminance);
26 |
27 | gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);
28 |
29 | }
30 | );
31 | namespace ben{
32 | namespace ngp{
33 | class GPUImageSaturationFilter:public GPUImageFilter{
34 | private:
35 | int saturationLocation;
36 | float saturation;
37 | public:
38 | GPUImageSaturationFilter();
39 |
40 | GPUImageSaturationFilter(JNIEnv *env);
41 |
42 | virtual void onInit();
43 |
44 | virtual void onInitialized();
45 |
46 | virtual void initialize(JNIEnv *env);
47 |
48 | virtual void mapFields();
49 |
50 | virtual const char *getCanonicalName() const;
51 |
52 | void setSaturation(float saturation);
53 | };
54 | }
55 | }
56 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_SATURATION_FILTER_HPP
57 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_sharpen_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_sharpen_filter.hpp"
6 |
7 | ben::ngp::GPUImageSharpenFilter::GPUImageSharpenFilter():GPUImageFilter(SHARPEN_VERTEX_SHADER, SHARPEN_FRAGMENT_SHADER) {
8 | }
9 |
10 | ben::ngp::GPUImageSharpenFilter::GPUImageSharpenFilter(JNIEnv *env) : GPUImageFilter(SHARPEN_VERTEX_SHADER, SHARPEN_FRAGMENT_SHADER,env) {
11 | initialize(env);
12 | }
13 |
14 | void ben::ngp::GPUImageSharpenFilter::initialize(JNIEnv *env) {
15 | GPUImageFilter::initialize(env);
16 | cacheField(env, "sharpness", kTypeFloat);
17 | cacheConstructor(env);
18 | cacheMethod(env, "getSharpness", kTypeFloat, NULL);
19 | cacheMethod(env, "setSharpness", kTypeVoid, kTypeFloat, NULL);
20 | merge(this);
21 | }
22 |
23 | void ben::ngp::GPUImageSharpenFilter::mapFields() {
24 | GPUImageFilter::mapFields();
25 | mapField("sharpness", kTypeFloat, &sharpness);
26 | }
27 |
28 | const char *ben::ngp::GPUImageSharpenFilter::getCanonicalName() const {
29 | return JAVA_SHARPEN_FILTER;
30 | }
31 |
32 | void ben::ngp::GPUImageSharpenFilter::onInit() {
33 | GPUImageFilter::onInit();
34 | sharpnessLocation = glGetUniformLocation(getGlProgId(), "sharpness");
35 | imageWidthFactorLocation = glGetUniformLocation(getGlProgId(), "imageWidthFactor");
36 | imageHeightFactorLocation = glGetUniformLocation(getGlProgId(), "imageHeightFactor");
37 | }
38 |
39 | void ben::ngp::GPUImageSharpenFilter::onInitialized() {
40 | GPUImageFilter::onInitialized();
41 | setSharpness(sharpness);
42 | }
43 |
44 | void ben::ngp::GPUImageSharpenFilter::setSharpness(float sharpness) {
45 | GPUImageSharpenFilter::sharpness = sharpness;
46 | setFloat(sharpnessLocation, this->sharpness);
47 | }
48 |
49 | void ben::ngp::GPUImageSharpenFilter::onOutputSizeChanged(int width, int height) {
50 | GPUImageFilter::onOutputSizeChanged(width, height);
51 | setFloat(imageWidthFactorLocation, 1.0f / width);
52 | setFloat(imageHeightFactorLocation, 1.0f / height);
53 | }
54 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_sketch_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_sketch_filter.hpp"
6 | #include "gpu_image_grayscale_filter.hpp"
7 | #include "gpu_image_3x3_texture_sampling_filter.hpp"
8 |
9 | ben::ngp::GPUImageSketchFilter::GPUImageSketchFilter():GPUImageFilterGroup() {}
10 |
11 | ben::ngp::GPUImageSketchFilter::GPUImageSketchFilter(JNIEnv *env) : GPUImageFilterGroup(env) {
12 | initialize(env);
13 | addFilter(new GPUImageGrayscaleFilter());
14 | addFilter(new GPUImage3x3TextureSamplingFilter(SKETCH_FRAGMENT_SHADER));
15 | }
16 |
17 | const char *ben::ngp::GPUImageSketchFilter::getCanonicalName() const {
18 | return JAVA_SKETCH_FILTER;
19 | }
20 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_sobel_edge_detection_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/29.
3 | //
4 |
5 | #include "gpu_image_sobel_edge_detection_filter.hpp"
6 |
7 | ben::ngp::GPUImageSobelEdgeDetectionFilter::GPUImageSobelEdgeDetectionFilter(JNIEnv *env):GPUImageFilterGroup(env){
8 | initialize(env);
9 | addFilter(new GPUImageGrayscaleFilter());
10 | addFilter(new GPUImage3x3TextureSamplingFilter(SOBEL_EDGE_DETECTION_SOURCE));
11 | }
12 |
13 | const char *ben::ngp::GPUImageSobelEdgeDetectionFilter::getCanonicalName() const {
14 | return JAVA_SOBEL_EDGE_DETECTION_FILTER;
15 | }
16 |
17 | void ben::ngp::GPUImageSobelEdgeDetectionFilter::setSize(float size) {
18 | GPUImageSobelEdgeDetectionFilter::size = size;
19 | GPUImage3x3TextureSamplingFilter *filter = dynamic_cast(getFilters()[1]);
20 | filter->setLineSize(size);
21 | }
22 |
23 | void ben::ngp::GPUImageSobelEdgeDetectionFilter::initialize(JNIEnv *env) {
24 | GPUImageFilter::initialize(env);
25 | cacheField(env, "size", kTypeFloat);
26 | cacheConstructor(env);
27 | cacheMethod(env, "getSize", kTypeFloat, NULL);
28 | cacheMethod(env, "setSize", kTypeVoid, kTypeFloat, NULL);
29 | merge(this);
30 | }
31 |
32 | void ben::ngp::GPUImageSobelEdgeDetectionFilter::mapFields() {
33 | GPUImageFilter::mapFields();
34 | mapField("size", kTypeFloat, &size);
35 | }
36 |
37 | float ben::ngp::GPUImageSobelEdgeDetectionFilter::getSize() const {
38 | return size;
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_sobel_threshold_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_sobel_threshold_filter.hpp"
6 |
7 | ben::ngp::GPUImageSobelThresholdFilter::GPUImageSobelThresholdFilter():GPUImage3x3TextureSamplingFilter(SOBEL_THRESHOLD_EDGE_DETECTION) {
8 | this->threshold = 0.9f;
9 | }
10 |
11 | ben::ngp::GPUImageSobelThresholdFilter::GPUImageSobelThresholdFilter(JNIEnv *env)
12 | : GPUImage3x3TextureSamplingFilter(env,SOBEL_THRESHOLD_EDGE_DETECTION) {
13 | initialize(env);
14 | this->threshold = 0.9f;
15 | }
16 |
17 | void ben::ngp::GPUImageSobelThresholdFilter::initialize(JNIEnv *env) {
18 | GPUImage3x3TextureSamplingFilter::initialize(env);
19 | cacheField(env, "threshold", kTypeFloat);
20 | cacheConstructor(env);
21 | cacheMethod(env, "getThreshold", kTypeFloat, NULL);
22 | cacheMethod(env, "setThreshold", kTypeVoid, kTypeFloat, NULL);
23 | merge(this);
24 | }
25 |
26 | void ben::ngp::GPUImageSobelThresholdFilter::mapFields() {
27 | GPUImage3x3TextureSamplingFilter::mapFields();
28 | mapField("threshold", kTypeFloat, &threshold);
29 | }
30 |
31 | const char *ben::ngp::GPUImageSobelThresholdFilter::getCanonicalName() const {
32 | return JAVA_SOBEL_THRESHOLD_FILTER;
33 | }
34 |
35 | void ben::ngp::GPUImageSobelThresholdFilter::onInit() {
36 | GPUImage3x3TextureSamplingFilter::onInit();
37 | uniformThresholdLocation = glGetUniformLocation(getGlProgId(), "threshold");
38 |
39 | }
40 |
41 | void ben::ngp::GPUImageSobelThresholdFilter::onInitialized() {
42 | GPUImage3x3TextureSamplingFilter::onInitialized();
43 | setThreshold(threshold);
44 | }
45 |
46 | void ben::ngp::GPUImageSobelThresholdFilter::setThreshold(float threshold) {
47 | GPUImageSobelThresholdFilter::threshold = threshold;
48 | setFloat(uniformThresholdLocation, threshold);
49 | }
50 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_solarize_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #include "gpu_image_solarize_filter.hpp"
6 |
7 | ben::ngp::GPUImageSolarizeFilter::GPUImageSolarizeFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, SOLATIZE_FRAGMENT_SHADER) {}
8 |
9 | ben::ngp::GPUImageSolarizeFilter::GPUImageSolarizeFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, SOLATIZE_FRAGMENT_SHADER,env) {
10 | initialize(env);
11 | }
12 |
13 | void ben::ngp::GPUImageSolarizeFilter::initialize(JNIEnv *env) {
14 | GPUImageFilter::initialize(env);
15 | cacheField(env, "threshold", kTypeFloat);
16 | cacheConstructor(env);
17 | cacheMethod(env, "getThreshold", kTypeFloat, NULL);
18 | cacheMethod(env, "setThreshold", kTypeVoid, kTypeFloat, NULL);
19 | merge(this);
20 | }
21 |
22 | void ben::ngp::GPUImageSolarizeFilter::mapFields() {
23 | GPUImageFilter::mapFields();
24 | mapField("threshold", kTypeFloat, &threshold);
25 | }
26 |
27 | const char *ben::ngp::GPUImageSolarizeFilter::getCanonicalName() const {
28 | return JAVA_SOLARIZE_FILTER;
29 | }
30 |
31 | void ben::ngp::GPUImageSolarizeFilter::onInit() {
32 | GPUImageFilter::onInit();
33 | uniformThresholdLocation = glGetUniformLocation(getGlProgId(), "threshold");
34 | }
35 |
36 | void ben::ngp::GPUImageSolarizeFilter::onInitialized() {
37 | GPUImageFilter::onInitialized();
38 | setThreshold(threshold);
39 | }
40 |
41 | void ben::ngp::GPUImageSolarizeFilter::setThreshold(float threshold) {
42 | GPUImageSolarizeFilter::threshold = threshold;
43 | setFloat(uniformThresholdLocation, threshold);
44 | }
45 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_solarize_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_SOLARIZE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_SOLARIZE_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 | #include "../include/jni/JniHelpersCommon.h"
10 |
11 | #define JAVA_SOLARIZE_FILTER "com/ben/android/library/filter/GPUImageSolarizeFilter"
12 | static char *SOLATIZE_FRAGMENT_SHADER = GET_STR(
13 | varying highp vec2 textureCoordinate;
14 |
15 | uniform sampler2D inputImageTexture;
16 | uniform highp float threshold;
17 |
18 | const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);
19 |
20 | void main()
21 | {
22 | highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
23 | highp float luminance = dot(textureColor.rgb, W);
24 | highp float thresholdResult = step(luminance, threshold);
25 | highp vec3 finalColor = abs(thresholdResult - textureColor.rgb);
26 |
27 | gl_FragColor = vec4(finalColor, textureColor.w);
28 | }
29 | );
30 | namespace ben{
31 | namespace ngp{
32 | class GPUImageSolarizeFilter:public GPUImageFilter{
33 | private:
34 | int uniformThresholdLocation;
35 | float threshold;
36 | public:
37 | GPUImageSolarizeFilter();
38 |
39 | GPUImageSolarizeFilter(JNIEnv *env);
40 |
41 | virtual void initialize(JNIEnv *env);
42 |
43 | virtual void mapFields();
44 |
45 | virtual const char *getCanonicalName() const;
46 |
47 | virtual void onInit();
48 |
49 | virtual void onInitialized();
50 |
51 | void setThreshold(float threshold);
52 | };
53 | }
54 | }
55 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_SOLARIZE_FILTER_HPP
56 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_threshold_edge_detection_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/10/8.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_THRESHOLD_EDGE_DETECTION_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_THRESHOLD_EDGE_DETECTION_FILTER_HPP
7 |
8 | #include "gpu_image_filter_group.hpp"
9 | #define JAVA_THRESHOLD_EDGE_DETECTION_FILTER "com/ben/android/library/filter/GPUImageThresholdEdgeDetectionFilter"
10 | namespace ben{
11 | namespace ngp{
12 | class GPUImageThresholdEdgeDetectionFilter:public GPUImageFilterGroup{
13 | private:
14 | float size;
15 | float threshold;
16 | public:
17 | GPUImageThresholdEdgeDetectionFilter();
18 |
19 | GPUImageThresholdEdgeDetectionFilter(JNIEnv *env);
20 |
21 | virtual void initialize(JNIEnv *env);
22 |
23 | virtual void mapFields();
24 |
25 | virtual const char *getCanonicalName() const;
26 |
27 | float getSize() const;
28 |
29 | void setSize(float size);
30 |
31 | float getThreshold() const;
32 |
33 | void setThreshold(float threshold);
34 |
35 | };
36 | }
37 | }
38 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_THRESHOLD_EDGE_DETECTION_FILTER_HPP
39 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_two_pass_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/17.
3 | //
4 |
5 | #include "gpu_image_two_pass_filter.hpp"
6 |
7 | ben::ngp::GPUImageTwoPassFilter::GPUImageTwoPassFilter(char *firstVertexShader,
8 | char *firstFragmentShader,
9 | char *secondVertexShader,
10 | char *secondFragmentShader) {
11 | addFilter(new GPUImageFilter(firstVertexShader, firstFragmentShader));
12 | addFilter(new GPUImageFilter(secondVertexShader, secondFragmentShader));
13 | }
14 |
15 | const char *ben::ngp::GPUImageTwoPassFilter::getCanonicalName() const {
16 | return GPUImageFilterGroup::getCanonicalName();
17 | }
18 |
19 | ben::ngp::GPUImageTwoPassFilter::GPUImageTwoPassFilter(char *firstVertexShader,
20 | char *firstFragmentShader,
21 | char *secondVertexShader,
22 | char *secondFragmentShader, JNIEnv *env):GPUImageFilterGroup(env){
23 | addFilter(new GPUImageFilter(firstVertexShader, firstFragmentShader));
24 | addFilter(new GPUImageFilter(secondVertexShader, secondFragmentShader));
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_two_pass_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/17.
3 | //
4 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_FILTER_HPP
5 | #define NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_FILTER_HPP
6 |
7 | #include "gpu_image_filter_group.hpp"
8 |
9 | namespace ben {
10 | namespace ngp {
11 | class GPUImageTwoPassFilter : public GPUImageFilterGroup {
12 | public:
13 | GPUImageTwoPassFilter(char *firstVertexShader, char *firstFragmentShader,
14 | char *secondVertexShader, char *secondFragmentShader,JNIEnv *env);
15 |
16 | GPUImageTwoPassFilter(char *firstVertexShader, char *firstFragmentShader,
17 | char *secondVertexShader, char *secondFragmentShader);
18 |
19 | public:
20 | virtual const char *getCanonicalName() const override;
21 | };
22 | }
23 | }
24 |
25 |
26 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_FILTER_HPP
27 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_two_pass_texture_sampling_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/17.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_TEXTURE_SAMPLING_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_TEXTURE_SAMPLING_FILTER_HPP
7 |
8 | #include "gpu_image_two_pass_filter.hpp"
9 |
10 | namespace ben {
11 | namespace ngp {
12 | class GPUImageTwoPassTextureSamplingFilter : public GPUImageTwoPassFilter {
13 | public:
14 | GPUImageTwoPassTextureSamplingFilter(char *firstVertexShader, char *firstFragmentShader,
15 | char *secondVertexShader,
16 | char *secondFragmentShader,
17 | JNIEnv *env);
18 | GPUImageTwoPassTextureSamplingFilter(char *firstVertexShader, char *firstFragmentShader,
19 | char *secondVertexShader,
20 | char *secondFragmentShader);
21 |
22 | void onOutputSizeChanged(int width, int height) override ;
23 |
24 | void onInit() override ;
25 |
26 | virtual float getVerticalTexelOffsetRatio();
27 |
28 | virtual float getHorizontalTexelOffsetRatio();
29 |
30 | void initTexelOffsets();
31 |
32 | public:
33 | virtual const char *getCanonicalName() const override;
34 | };
35 | }
36 | }
37 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_TWO_PASS_TEXTURE_SAMPLING_FILTER_HPP
38 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_vibrance_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/28.
3 | //
4 |
5 | #include "gpu_image_vibrance_filter.hpp"
6 |
7 | ben::ngp::GPUImageVibranceFilter::GPUImageVibranceFilter():GPUImageFilter(NO_FILTER_VERTEX_SHADER, VIBRANCE_FRAGMENT_SHADER) {
8 | this->vibrance = 0.0f;
9 | }
10 |
11 | ben::ngp::GPUImageVibranceFilter::GPUImageVibranceFilter(JNIEnv *env) : GPUImageFilter(NO_FILTER_VERTEX_SHADER, VIBRANCE_FRAGMENT_SHADER,env) {
12 | initialize(env);
13 | this->vibrance = 0.0f;
14 |
15 | }
16 | void ben::ngp::GPUImageVibranceFilter::onInit() {
17 | GPUImageFilter::onInit();
18 | vibranceLocation = glGetUniformLocation(getGlProgId(), "vibrance");
19 | }
20 |
21 | void ben::ngp::GPUImageVibranceFilter::onInitialized() {
22 | GPUImageFilter::onInitialized();
23 | setVibrance(vibrance);
24 | }
25 |
26 |
27 | void ben::ngp::GPUImageVibranceFilter::initialize(JNIEnv *env) {
28 | GPUImageFilter::initialize(env);
29 | cacheField(env, "vibrance", kTypeFloat);
30 | cacheConstructor(env);
31 | cacheMethod(env, "getVibrance", kTypeFloat, NULL);
32 | cacheMethod(env, "setVibrance", kTypeVoid, kTypeFloat, NULL);
33 | merge(this);
34 | }
35 |
36 | void ben::ngp::GPUImageVibranceFilter::mapFields() {
37 | GPUImageFilter::mapFields();
38 | mapField("vibrance", kTypeFloat, &vibrance);
39 | }
40 |
41 | const char *ben::ngp::GPUImageVibranceFilter::getCanonicalName() const {
42 | return JAVA_VIBRANCE_FILTER;
43 | }
44 |
45 | void ben::ngp::GPUImageVibranceFilter::setVibrance(float vibrance) {
46 | GPUImageVibranceFilter::vibrance = vibrance;
47 | if (isInitialized()) {
48 | setFloat(vibranceLocation, vibrance);
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_vibrance_filter.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/28.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_GPU_IMAGE_VIBRANCE_FILTER_HPP
6 | #define NATIVEGPUIMAGE_GPU_IMAGE_VIBRANCE_FILTER_HPP
7 |
8 | #include "gpu_image_filter.hpp"
9 |
10 | #define JAVA_VIBRANCE_FILTER "com/ben/android/library/filter/GPUImageVibranceFilter"
11 |
12 | static char *VIBRANCE_FRAGMENT_SHADER = GET_STR(
13 | varying
14 | highp
15 | vec2 textureCoordinate;
16 |
17 | uniform
18 | sampler2D inputImageTexture;
19 | uniform
20 | lowp float vibrance;
21 |
22 | void main() {
23 | lowp
24 | vec4 color = texture2D(inputImageTexture, textureCoordinate);
25 | lowp float average = (color.r + color.g + color.b) / 3.0;
26 | lowp float mx = max(color.r, max(color.g, color.b));
27 | lowp float amt = (mx - average) * (-vibrance * 3.0);
28 | color.rgb = mix(color.rgb, vec3(mx), amt);
29 | gl_FragColor = color;
30 | }
31 | );
32 | namespace ben {
33 | namespace ngp {
34 | class GPUImageVibranceFilter : public GPUImageFilter {
35 | private:
36 | int vibranceLocation;
37 | float vibrance;
38 | public:
39 | GPUImageVibranceFilter();
40 |
41 | GPUImageVibranceFilter(JNIEnv *env);
42 |
43 | virtual void onInit();
44 |
45 | virtual void onInitialized();
46 |
47 | public:
48 | virtual void initialize(JNIEnv *env);
49 |
50 | virtual void mapFields();
51 |
52 | virtual const char *getCanonicalName() const;
53 |
54 | void setVibrance(float vibrance);
55 | };
56 | }
57 | }
58 | #endif //NATIVEGPUIMAGE_GPU_IMAGE_VIBRANCE_FILTER_HPP
59 |
--------------------------------------------------------------------------------
/library/src/main/jni/filter/gpu_image_weak_pixel_inclusion_filter.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/27.
3 | //
4 |
5 | #include "gpu_image_weak_pixel_inclusion_filter.hpp"
6 |
7 | ben::ngp::GPUImageWeakPixelInclusionFilter::GPUImageWeakPixelInclusionFilter()
8 | : GPUImage3x3TextureSamplingFilter(WEAKPIXEL_FRAGMENT_SHADER) {}
9 |
10 | ben::ngp::GPUImageWeakPixelInclusionFilter::GPUImageWeakPixelInclusionFilter(JNIEnv *env)
11 | : GPUImage3x3TextureSamplingFilter(env, WEAKPIXEL_FRAGMENT_SHADER) {}
12 |
13 | void ben::ngp::GPUImageWeakPixelInclusionFilter::initialize(JNIEnv *env) {
14 | GPUImage3x3TextureSamplingFilter::initialize(env);
15 | }
16 |
17 | void ben::ngp::GPUImageWeakPixelInclusionFilter::mapFields() {
18 | GPUImage3x3TextureSamplingFilter::mapFields();
19 | }
20 |
21 | const char *ben::ngp::GPUImageWeakPixelInclusionFilter::getCanonicalName() const {
22 | return JAVA_WEAK_PIXEL_INCLUSION_FILTER;
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/jni/global_native_class_ptr.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/18.
3 | //
4 | #include "global_native_class_ptr.hpp"
5 | ClassRegistry *classRegistryPtr = new ClassRegistry();
6 |
--------------------------------------------------------------------------------
/library/src/main/jni/global_native_class_ptr.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/18.
3 | //
4 | #pragma once
5 | #ifndef LIVE_GLOBAL_NATIVE_CLASS_PTR_HPP
6 | #define LIVE_GLOBAL_NATIVE_CLASS_PTR_HPP
7 |
8 | #include "include/jni/JniHelpers.h"
9 | using namespace ben::jni;
10 | namespace ben{
11 | namespace ngp{
12 | extern ClassRegistry *classRegistryPtr;;
13 | }
14 | }
15 | #endif //LIVE_GLOBAL_NATIVE_CLASS_PTR_HPP
16 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | file(GLOB JNI_SOURCE "*.cpp")
2 | message("file ${JNI_SOURCE}")
3 | add_library(libjni
4 | ${JNI_SOURCE}
5 | )
6 |
7 | target_link_libraries(libjni)
8 |
9 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JavaExceptionUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #ifndef __JavaExceptionUtils_h__
23 | #define __JavaExceptionUtils_h__
24 |
25 | #include "JniHelpersCommon.h"
26 | #include "JniLocalRef.h"
27 |
28 | namespace ben {
29 | namespace jni {
30 |
31 | class JavaExceptionUtils {
32 | private:
33 | // Direct instantiation not allowed
34 | JavaExceptionUtils() {}
35 | JavaExceptionUtils(const JavaExceptionUtils&) {}
36 | virtual ~JavaExceptionUtils() {}
37 |
38 | public:
39 | static EXPORT JniLocalRef newThrowable(JNIEnv *env, const char *message, ...);
40 |
41 | static EXPORT void checkException(JNIEnv *env);
42 | static EXPORT void checkExceptionAndClear(JNIEnv *env);
43 | static EXPORT void throwException(JNIEnv *env, const char *message, ...);
44 | static EXPORT void throwRuntimeException(JNIEnv *env, const char *message, ...);
45 | static EXPORT void throwExceptionOfType(JNIEnv *env, const char *exception_class_name, const char *message, ...);
46 |
47 | protected:
48 | static EXPORT void throwExceptionOfType(JNIEnv *env, const char *exception_class_name, const char *message, va_list arguments);
49 | };
50 | }
51 | }
52 |
53 | #endif // __JavaExceptionUtils_h__
54 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JavaString.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #include "JavaString.h"
23 | #include "JavaExceptionUtils.h"
24 |
25 | namespace ben {
26 | namespace jni {
27 |
28 | JavaString::JavaString() {
29 | _value = "";
30 | }
31 |
32 | JavaString::JavaString(const std::string &string) {
33 | _value = string;
34 | }
35 |
36 | JavaString::JavaString(JNIEnv *env, jstring javaString) {
37 | set(env, javaString);
38 | }
39 |
40 | const std::string& JavaString::get() const {
41 | return _value;
42 | }
43 |
44 | JniLocalRef JavaString::toJavaString(JNIEnv *env) const {
45 | return env->NewStringUTF(_value.c_str());
46 | }
47 |
48 | void JavaString::set(const char *value) {
49 | _value = value;
50 | }
51 |
52 | void JavaString::set(const std::string &value) {
53 | _value = value;
54 | }
55 |
56 | void JavaString::set(JNIEnv *env, jstring javaString) {
57 | if (javaString == NULL) {
58 | return;
59 | }
60 |
61 | const char *string = env->GetStringUTFChars(javaString, 0);
62 | JavaExceptionUtils::checkException(env);
63 | if (string == NULL) {
64 | return;
65 | }
66 |
67 | _value = string;
68 | env->ReleaseStringUTFChars(javaString, string);
69 | JavaExceptionUtils::checkException(env);
70 | }
71 |
72 |
73 | } // namespace jni
74 | } // namespace ben
75 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JavaString.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #ifndef __JavaStringUtils_h__
23 | #define __JavaStringUtils_h__
24 |
25 | #include "JniHelpersCommon.h"
26 | #include "JniLocalRef.h"
27 | #include
28 |
29 | namespace ben {
30 | namespace jni {
31 |
32 | #if WIN32
33 | // TODO: This is a MSVC thing, should refactor to use PIMPL instead (ugh)
34 | template class EXPORT std::basic_string, std::allocator>;
35 | #endif
36 |
37 | class EXPORT JavaString {
38 | public:
39 | JavaString();
40 | JavaString(const std::string &string);
41 | JavaString(JNIEnv *env, jstring javaString);
42 | virtual ~JavaString() {}
43 |
44 | const std::string& get() const;
45 | const std::string& operator*() const { return get(); }
46 |
47 | JniLocalRef toJavaString(JNIEnv *env) const;
48 |
49 | void set(const char *value);
50 | void operator=(const char *value) { set(value); }
51 | void set(const std::string &value);
52 | void operator=(const std::string &value) { set(value); }
53 | void set(JNIEnv *env, jstring javaString);
54 |
55 | public:
56 | std::string _value;
57 | };
58 |
59 | } // namespace jni
60 | } // namespace ben
61 |
62 | #endif // __JavaStringUtils_h__
63 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JavaThreadUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #ifndef __JavaThreadUtils_h__
23 | #define __JavaThreadUtils_h__
24 |
25 | #include "JniHelpersCommon.h"
26 | #include
27 |
28 | namespace ben {
29 | namespace jni {
30 |
31 | class JavaThreadUtils {
32 | private:
33 | // Direct instantiation not allowed
34 | JavaThreadUtils() {}
35 | JavaThreadUtils(const JavaThreadUtils&) {}
36 | virtual ~JavaThreadUtils() {}
37 |
38 | public:
39 | static EXPORT JavaVM* getJavaVM();
40 | static EXPORT JNIEnv* initialize(JavaVM* jvm);
41 | static EXPORT JNIEnv* getEnvForCurrentThread();
42 | static EXPORT JNIEnv* getEnvForCurrentThread(JavaVM *jvm);
43 | static EXPORT JNIEnv* attachCurrentThreadToJVM(const char* thread_name);
44 | static EXPORT JNIEnv* attachCurrentThreadAsDaemonToJVM(const char* thread_name);
45 | static EXPORT void detatchCurrentThreadFromJVM();
46 | };
47 |
48 | } // namespace jni
49 | } // namespace ben
50 |
51 | #endif // __JavaThreadUtils_h__
52 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JniGlobalRef.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #ifndef __JniGlobalRef_h__
23 | #define __JniGlobalRef_h__
24 |
25 | #include "JniHelpersCommon.h"
26 | #include "JavaThreadUtils.h"
27 | #include "JniLocalRef.h"
28 |
29 | namespace ben {
30 | namespace jni {
31 |
32 | // RAII helper to maintain global references automatically.
33 | template
34 | class EXPORT JniGlobalRef {
35 | public:
36 | JniGlobalRef() : _obj(NULL) {}
37 | JniGlobalRef(const JniGlobalRef &ref) : _obj(NULL) { set(ref.get()); }
38 | JniGlobalRef(const JniLocalRef &ref) : _obj(NULL) { set(ref.get()); }
39 |
40 | ~JniGlobalRef() { set(NULL); }
41 |
42 | JniType get() const { return _obj; }
43 |
44 | void set(JniType obj) {
45 | JNIEnv *env = NULL;
46 | if (_obj || obj) {
47 | env = JavaThreadUtils::getEnvForCurrentThread();
48 | }
49 | if (_obj) {
50 | if (env) {
51 | env->DeleteGlobalRef(_obj);
52 | }
53 | _obj = NULL;
54 | }
55 | if (obj && env) {
56 | _obj = (JniType)env->NewGlobalRef(obj);
57 | }
58 | }
59 |
60 | operator JniType() const { return _obj; }
61 |
62 | void operator=(const JniLocalRef &ref) { set(ref.get()); }
63 |
64 | private:
65 | JniType _obj;
66 | };
67 |
68 | } // namespace jni
69 | } // namespace ben
70 |
71 | #endif // __JniGlobalRef_h__
72 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JniHelpers.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #include "JniHelpers.h"
23 | extern ben::jni::ClassRegistry registry;
24 | using namespace ben::jni;
25 |
26 | JNIEnv* jniHelpersInitialize(JavaVM *jvm) {
27 | return JavaThreadUtils::initialize(jvm);
28 | }
29 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/JniHelpers.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*
3 | * Copyright (c) 2014 Spotify AB
4 | *
5 | * Licensed to the Apache Software Foundation (ASF) under one
6 | * or more contributor license agreements. See the NOTICE file
7 | * distributed with this work for additional information
8 | * regarding copyright ownership. The ASF licenses this file
9 | * to you under the Apache License, Version 2.0 (the
10 | * "License"); you may not use this file except in compliance
11 | * with the License. You may obtain a copy of the License at
12 | *
13 | * http://www.apache.org/licenses/LICENSE-2.0
14 | *
15 | * Unless required by applicable law or agreed to in writing,
16 | * software distributed under the License is distributed on an
17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 | * KIND, either express or implied. See the License for the
19 | * specific language governing permissions and limitations
20 | * under the License.
21 | */
22 |
23 | #ifndef __JniHelpers_h__
24 | #define __JniHelpers_h__
25 |
26 | #include "JniHelpersCommon.h"
27 |
28 | #include "ByteArray.h"
29 | #include "JavaClass.h"
30 | #include "ClassRegistry.h"
31 | #include "JavaClassUtils.h"
32 | #include "JavaExceptionUtils.h"
33 | #include "JavaString.h"
34 | #include "JavaThreadUtils.h"
35 | #include "JniGlobalRef.h"
36 | #include "JniLocalRef.h"
37 | #include "NativeObject.h"
38 | #include "ShortArray.h"
39 | #include "JavaStringArray.h"
40 | #include
41 | #include
42 | EXPORT JNIEnv *jniHelpersInitialize(JavaVM *jvm);
43 | EXPORT JNIEnv *JniCurrentEnv(JavaVM *jvm);
44 |
45 | #endif // __JniHelpers_h__
46 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/ScopedPtr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 Spotify AB
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 |
22 | #ifndef __ScopedPtr_h__
23 | #define __ScopedPtr_h__
24 |
25 | namespace ben {
26 | namespace jni {
27 |
28 | /**
29 | * @brief Scoped pointer class
30 | *
31 | * Under normal circumstances it would be preferable to use the scoped
32 | * pointer provided by stl::scoped_ptr, or even boost, however both of
33 | * these libraries are a bit problematic under Android. Since we only
34 | * need the most basic implementation of a scoped pointer, re-inventing
35 | * the wheel is ok (in small doses).
36 | */
37 | template
38 | class ScopedPtr {
39 | public:
40 | ScopedPtr() : _obj(NULL) {}
41 | ScopedPtr(Type *object) : _obj(NULL) { set(object); }
42 | ScopedPtr(const ScopedPtr &ref) : _obj(NULL) { set(ref.get()); }
43 |
44 | ~ScopedPtr() { set(NULL); }
45 |
46 | Type *get() const { return _obj; }
47 |
48 | void set(Type *object) {
49 | if (_obj) {
50 | delete _obj;
51 | }
52 | _obj = object;
53 | }
54 |
55 | Type *leak() {
56 | Type result = _obj;
57 | _obj = NULL;
58 | return result;
59 | }
60 |
61 | private:
62 | Type *_obj;
63 | };
64 |
65 | } // namespace jni
66 | } // namespace ben
67 |
68 | #endif // __ScopedPtr_h__
69 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/jni/logger.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | #pragma once
3 | //
4 | // Created by ben622 on 2019/7/31.
5 | //
6 | #ifndef LOGGER_HEAD
7 | #define LOGGER_HEAD
8 |
9 | #include
10 | #define PRINT_TAG "benlive"
11 | #define EMAIL "zhuanchuan622@gmail.com"
12 | #define LOGI(FORMAT, ...) __android_log_print(ANDROID_LOG_VERBOSE,PRINT_TAG,FORMAT,__VA_ARGS__)
13 | #define LOGE(FORMAT, ...) __android_log_print(ANDROID_LOG_ERROR,PRINT_TAG,FORMAT,__VA_ARGS__)
14 |
15 | #endif //LOGGER_HEAD
16 |
17 | */
18 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/libyuv.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_H_
12 | #define INCLUDE_LIBYUV_H_
13 |
14 | #include "libyuv/basic_types.h"
15 | #include "libyuv/compare.h"
16 | #include "libyuv/convert.h"
17 | #include "libyuv/convert_argb.h"
18 | #include "libyuv/convert_from.h"
19 | #include "libyuv/convert_from_argb.h"
20 | #include "libyuv/cpu_id.h"
21 | #include "libyuv/mjpeg_decoder.h"
22 | #include "libyuv/planar_functions.h"
23 | #include "libyuv/rotate.h"
24 | #include "libyuv/rotate_argb.h"
25 | #include "libyuv/row.h"
26 | #include "libyuv/scale.h"
27 | #include "libyuv/scale_argb.h"
28 | #include "libyuv/scale_row.h"
29 | #include "libyuv/version.h"
30 | #include "libyuv/video_common.h"
31 |
32 | #endif // INCLUDE_LIBYUV_H_
33 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/libyuv/rotate_argb.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_ROTATE_ARGB_H_
12 | #define INCLUDE_LIBYUV_ROTATE_ARGB_H_
13 |
14 | #include "basic_types.h"
15 | #include "rotate.h" // For RotationMode.
16 |
17 | #ifdef __cplusplus
18 | namespace libyuv {
19 | extern "C" {
20 | #endif
21 |
22 | // Rotate ARGB frame
23 | LIBYUV_API
24 | int ARGBRotate(const uint8_t* src_argb,
25 | int src_stride_argb,
26 | uint8_t* dst_argb,
27 | int dst_stride_argb,
28 | int src_width,
29 | int src_height,
30 | enum RotationMode mode);
31 |
32 | #ifdef __cplusplus
33 | } // extern "C"
34 | } // namespace libyuv
35 | #endif
36 |
37 | #endif // INCLUDE_LIBYUV_ROTATE_ARGB_H_
38 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/libyuv/version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3 | *
4 | * Use of this source code is governed by a BSD-style license
5 | * that can be found in the LICENSE file in the root of the source
6 | * tree. An additional intellectual property rights grant can be found
7 | * in the file PATENTS. All contributing project authors may
8 | * be found in the AUTHORS file in the root of the source tree.
9 | */
10 |
11 | #ifndef INCLUDE_LIBYUV_VERSION_H_
12 | #define INCLUDE_LIBYUV_VERSION_H_
13 |
14 | #define LIBYUV_VERSION 1724
15 |
16 | #endif // INCLUDE_LIBYUV_VERSION_H_
17 |
--------------------------------------------------------------------------------
/library/src/main/jni/include/queue.h:
--------------------------------------------------------------------------------
1 | #ifndef _QUQEUE_H
2 | #define _QUQEUE_H
3 | // 新建“双向链表”。成功,返回表头;否则,返回NULL
4 | extern int create_queue();
5 | // 撤销“双向链表”。成功,返回0;否则,返回-1
6 | extern int destroy_queue();
7 | // “双向链表是否为空”。为空的话返回1;否则,返回0。
8 | extern int queue_is_empty();
9 | // 返回“双向链表的大小”
10 | extern int queue_size();
11 | // 获取“双向链表中第index位置的元素”。成功,返回节点指针;否则,返回NULL。
12 | extern void* queue_get(int index);
13 | // 获取“双向链表中第1个元素”。成功,返回节点指针;否则,返回NULL。
14 | extern void* queue_get_first();
15 | // 获取“双向链表中最后1个元素”。成功,返回节点指针;否则,返回NULL。
16 | extern void* queue_get_last();
17 | // 将“value”插入到index位置。成功,返回0;否则,返回-1。
18 | extern int queue_insert(int index, void *pval);
19 | // 将“value”插入到表头位置。成功,返回0;否则,返回-1。
20 | extern int queue_insert_first(void *pval);
21 | // 将“value”插入到末尾位置。成功,返回0;否则,返回-1。
22 | extern int queue_append_last(void *pval);
23 | // 删除“双向链表中index位置的节点”。成功,返回0;否则,返回-1
24 | extern int queue_delete(int index);
25 | // 删除第一个节点。成功,返回0;否则,返回-1
26 | extern int queue_delete_first();
27 | // 删除组后一个节点。成功,返回0;否则,返回-1
28 | extern int queue_delete_last();
29 | #endif//_QUQEUE_H
30 |
--------------------------------------------------------------------------------
/library/src/main/jni/libcommon/native_exception.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/16.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_NEXCEPTION_HPP
6 | #define NATIVEGPUIMAGE_NEXCEPTION_HPP
7 | #include
8 | #include
9 | using namespace std;
10 |
11 | namespace ben{
12 | namespace common{
13 | class NException : public exception{
14 | public:
15 | NException() {}
16 | NException(char *msg) {}
17 |
18 | };
19 | }
20 | }
21 | #endif //NATIVEGPUIMAGE_NEXCEPTION_HPP
22 |
--------------------------------------------------------------------------------
/library/src/main/jni/util/jni_util.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/17.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_JNI_UTIL_HPP
6 | #define NATIVEGPUIMAGE_JNI_UTIL_HPP
7 |
8 | #include "../global_native_class_ptr.hpp"
9 |
10 | extern ben::jni::ClassRegistry *classRegistryPtr;
11 | namespace ben{
12 | namespace jni{
13 | static const char *GPU_IMAGE_RENDER_CLASS = "com/ben/android/library/NGPSurfaceView";
14 |
15 | template
16 | static TypeName* getNativeClassPtr(const char* className){
17 | JavaClass *nativeClassPtr = const_cast(classRegistryPtr->get(className));
18 | if (!nativeClassPtr) {
19 | LOGE("Can't find class[%s], are you sure you registered in ClassRegister?", className);
20 | return NULL;
21 | }
22 | return dynamic_cast(nativeClassPtr);
23 | }
24 |
25 | template
26 | static TypeName* getNativeInstancePtr(JNIEnv *env, jobject fromObject){
27 | return classRegistryPtr->getNativeInstance(env, fromObject);
28 | }
29 |
30 | }
31 | }
32 |
33 | #endif //NATIVEGPUIMAGE_JNI_UTIL_HPP
34 |
--------------------------------------------------------------------------------
/library/src/main/jni/util/rotation.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/16.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_ROTATION_HPP
6 | #define NATIVEGPUIMAGE_ROTATION_HPP
7 |
8 | #include "../libcommon/native_exception.hpp"
9 | namespace ben {
10 | namespace util {
11 | static enum Rotation {
12 | NORMAL, ROTATION_90, ROTATION_180, ROTATION_270
13 | };
14 |
15 | static int asInt(Rotation rotation) {
16 | switch (rotation) {
17 | case NORMAL:
18 | return 0;
19 | case ROTATION_90:
20 | return 90;
21 | case ROTATION_180:
22 | return 180;
23 | case ROTATION_270:
24 | return 270;
25 | default:
26 | throw ben::common::NException("Unknown Rotation!");
27 | }
28 | }
29 |
30 | static Rotation fromInt(int rotation) {
31 | switch (rotation) {
32 | case 0:
33 | return NORMAL;
34 | case 90:
35 | return ROTATION_90;
36 | case 180:
37 | return ROTATION_180;
38 | case 270:
39 | return ROTATION_270;
40 | case 360:
41 | return NORMAL;
42 | default:
43 | throw ben::common::NException(" is an unknown rotation. Needs to be either 0, 90, 180 or 270!");
44 | }
45 | }
46 | }
47 | }
48 |
49 | #endif //NATIVEGPUIMAGE_ROTATION_HPP
50 |
--------------------------------------------------------------------------------
/library/src/main/jni/util/scale_type.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by ben622 on 2019/9/18.
3 | //
4 |
5 | #ifndef NATIVEGPUIMAGE_SCALE_TYPE_HPP
6 | #define NATIVEGPUIMAGE_SCALE_TYPE_HPP
7 | namespace ben{
8 | namespace util{
9 | enum ScaleType{
10 | CENTER_INSIDE, CENTER_CROP
11 | };
12 | static ScaleType fromScaleValue(int scale) {
13 | switch (scale) {
14 | case 0:
15 | return CENTER_INSIDE;
16 | case 1:
17 | return CENTER_CROP;
18 | default:
19 | throw ben::common::NException(" is an unknown rotation. Needs to be either 0, 90, 180 or 270!");
20 | }
21 | }
22 | }
23 | }
24 | #endif //NATIVEGPUIMAGE_SCALE_TYPE_HPP
25 |
--------------------------------------------------------------------------------
/library/src/main/jniLibs/arm64-v8a/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/arm64-v8a/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/jniLibs/armeabi/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/armeabi/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/jniLibs/mips/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/mips/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/jniLibs/mips64/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/mips64/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/jniLibs/x86/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/x86/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/jniLibs/x86_64/libyuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/library/src/main/jniLibs/x86_64/libyuv.so
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 |
--------------------------------------------------------------------------------
/library/src/test/java/com/ben/android/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.ben.android.library;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/photos/photo1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/photos/photo1.jpg
--------------------------------------------------------------------------------
/photos/photo2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/photos/photo2.jpg
--------------------------------------------------------------------------------
/photos/photo3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/photos/photo3.jpg
--------------------------------------------------------------------------------
/photos/photo4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/photos/photo4.jpg
--------------------------------------------------------------------------------
/photos/photo5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/photos/photo5.jpg
--------------------------------------------------------------------------------
/screen/capture1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/screen/capture1.gif
--------------------------------------------------------------------------------
/screen/capture2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/screen/capture2.gif
--------------------------------------------------------------------------------
/screen/capture3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/screen/capture3.jpg
--------------------------------------------------------------------------------
/screen/capture4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ben622/NativeGPUImage/cc971eae21ecf4eeb4ad1acf16de7499f903c830/screen/capture4.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------