├── .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 | 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 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 |