├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── jarRepositories.xml ├── misc.xml └── runConfigurations.xml ├── LICENSE ├── NBEffects ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── gradle-plugin-mvn-push.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── wufuqi │ │ └── nbeffects │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── wufuqi │ │ │ └── nbeffects │ │ │ ├── Constants.kt │ │ │ ├── NBEffectsImageView.kt │ │ │ ├── OpenGLImageRenderType.kt │ │ │ ├── bean │ │ │ ├── Texture.kt │ │ │ ├── UniformFloat.kt │ │ │ ├── UniformInt.kt │ │ │ ├── UniformInterface.kt │ │ │ ├── Vec2.kt │ │ │ ├── Vec3.kt │ │ │ └── Vec4.kt │ │ │ ├── filter │ │ │ ├── BaseFilter.kt │ │ │ ├── DissolveFilter.kt │ │ │ ├── DynamicBlurTransferFilter.kt │ │ │ ├── GaussBlursFilter.kt │ │ │ ├── GrayFilter.kt │ │ │ ├── MosaicFilter.kt │ │ │ ├── QuarterMirrorFilter.kt │ │ │ ├── RadialBlurFilter.kt │ │ │ ├── RainFilter.kt │ │ │ ├── RendererFilter.kt │ │ │ ├── UnfoldTransferFilter.kt │ │ │ ├── WaterFilter.kt │ │ │ ├── WaveFilter.kt │ │ │ ├── WindowTransferFilter.kt │ │ │ └── ZoomBlurTransferFilter.kt │ │ │ ├── helper │ │ │ └── PendingThreadAider.java │ │ │ ├── pixijs_filter │ │ │ ├── AdjustmentFilter.kt │ │ │ ├── AsciiFilter.kt │ │ │ └── BevelFilter.kt │ │ │ ├── renderer │ │ │ ├── FilterRenderer.kt │ │ │ ├── GLESThread.java │ │ │ ├── GLRender.kt │ │ │ ├── NBGLSurfaceView.kt │ │ │ └── NBTextureView.kt │ │ │ └── utils │ │ │ ├── AppUtils.kt │ │ │ ├── BitmapUtils.kt │ │ │ ├── BufferUtils.kt │ │ │ ├── ResReadUtils.kt │ │ │ ├── ShaderUtils.kt │ │ │ └── TextureUtils.kt │ └── res │ │ └── raw │ │ ├── adjustment_filter_fragment_shader.glsl │ │ ├── ascii_filter_fragment_shader.glsl │ │ ├── base_filter_fragment_shader.glsl │ │ ├── base_filter_vertex_shader.glsl │ │ ├── bevel_filter_fragment_shader.glsl │ │ ├── dissolve_filter_fragment_shader.glsl │ │ ├── dynamic_blur_transfer_filter_fragment_shader.glsl │ │ ├── gauss_blurs_filter_fragment_shader.glsl │ │ ├── gray_filter_fragment_shader.glsl │ │ ├── mosaic_filter_fragment_shader.glsl │ │ ├── quarter_mirror_filter_fragment_shader.glsl │ │ ├── radial_blur_filter_fragment_shader.glsl │ │ ├── rain_filter_fragment_shader.glsl │ │ ├── unfold_transfer_filter_vertex_shader.glsl │ │ ├── water_filter_fragment_shader.glsl │ │ ├── wave_filter_fragment_shader.glsl │ │ ├── window_transfer_filter_fragment_shader.glsl │ │ └── zoom_blur_transfer_filter_fragment_shader.glsl │ └── test │ └── java │ └── cn │ └── wufuqi │ └── nbeffects │ └── ExampleUnitTest.kt ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── cn │ │ └── wufuqi │ │ └── test │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── cn │ │ │ └── wufuqi │ │ │ └── test │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── fj.png │ │ ├── hd.png │ │ ├── ic_launcher_background.xml │ │ └── main.jpg │ │ ├── layout │ │ └── activity_main.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-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── cn │ └── wufuqi │ └── test │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img ├── DissolveFilter.gif ├── DynamicBlurTransferFilter.gif ├── GaussBlursFilter.png ├── GrayFilter.png ├── MosaicFilter.png ├── QuarterMirrorFilter.png ├── RadialBlurFilter.png ├── RainFilter.gif ├── UnfoldTransferFilter.gif ├── WaterFilter.gif ├── WaveFilter.gif ├── WindowTransferFilter.gif └── ZoomBlurTransferFilter.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.aar 4 | *.ap_ 5 | *.aab 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | # Uncomment the following line in case you need and you don't have the release build type files in your app 18 | # release/ 19 | 20 | # Gradle files 21 | .gradle/ 22 | build/ 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Proguard folder generated by Eclipse 28 | proguard/ 29 | 30 | # Log Files 31 | *.log 32 | 33 | # Android Studio Navigation editor temp files 34 | .navigation/ 35 | 36 | # Android Studio captures folder 37 | captures/ 38 | 39 | # IntelliJ 40 | *.iml 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NBEffects/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /NBEffects/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | //apply from: 'gradle-plugin-mvn-push.gradle' 7 | 8 | android { 9 | compileSdkVersion 32 10 | buildToolsVersion "32.0.0" 11 | 12 | defaultConfig { 13 | minSdkVersion 16 14 | targetSdkVersion 32 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | consumerProguardFiles "consumer-rules.pro" 20 | } 21 | 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | compileOptions { 29 | sourceCompatibility JavaVersion.VERSION_1_8 30 | targetCompatibility JavaVersion.VERSION_1_8 31 | } 32 | kotlinOptions { 33 | jvmTarget = '1.8' 34 | } 35 | } 36 | 37 | dependencies { 38 | 39 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 40 | implementation 'androidx.core:core-ktx:1.3.1' 41 | implementation 'androidx.appcompat:appcompat:1.2.0' 42 | implementation 'com.google.android.material:material:1.2.1' 43 | 44 | implementation 'cn.wufuqi:WuKongAnimation:1.0.4' 45 | } -------------------------------------------------------------------------------- /NBEffects/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/NBEffects/consumer-rules.pro -------------------------------------------------------------------------------- /NBEffects/gradle-plugin-mvn-push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Lucas Rocha 3 | * 4 | * This code is largely based on Chris Banes' gradle-mvn-push script. 5 | * 6 | * Copyright (C) 2013 Chris Banes 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * 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, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | apply plugin: 'maven' 22 | apply plugin: 'signing' 23 | 24 | def isReleaseBuild() { 25 | return VERSION_NAME.contains("SNAPSHOT") == false 26 | } 27 | 28 | def getReleaseRepositoryUrl() { 29 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 30 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 31 | } 32 | 33 | def getSnapshotRepositoryUrl() { 34 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 35 | : "https://oss.sonatype.org/content/repositories/snapshots/" 36 | } 37 | 38 | def getRepositoryUsername() { 39 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 40 | } 41 | 42 | def getRepositoryPassword() { 43 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 44 | } 45 | 46 | afterEvaluate { project -> 47 | uploadArchives { 48 | repositories { 49 | mavenDeployer { 50 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 51 | 52 | pom.groupId = GROUP 53 | pom.artifactId = POM_ARTIFACT_ID 54 | pom.version = VERSION_NAME 55 | 56 | repository(url: getReleaseRepositoryUrl()) { 57 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 58 | } 59 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 60 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 61 | } 62 | 63 | pom.project { 64 | name POM_NAME 65 | packaging POM_PACKAGING 66 | description POM_DESCRIPTION 67 | url POM_URL 68 | 69 | scm { 70 | url POM_SCM_URL 71 | connection POM_SCM_CONNECTION 72 | developerConnection POM_SCM_DEV_CONNECTION 73 | } 74 | 75 | licenses { 76 | license { 77 | name POM_LICENCE_NAME 78 | url POM_LICENCE_URL 79 | distribution POM_LICENCE_DIST 80 | } 81 | } 82 | 83 | developers { 84 | developer { 85 | id POM_DEVELOPER_ID 86 | name POM_DEVELOPER_NAME 87 | } 88 | } 89 | } 90 | } 91 | } 92 | } 93 | 94 | signing { 95 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 96 | sign configurations.archives 97 | } 98 | 99 | 100 | // task pluginJavadocs(type: Groovydoc) { 101 | // source = sourceSets.main.groovy.srcDirs 102 | // classpath = sourceSets.main.compileClasspath 103 | // } 104 | // 105 | // task pluginJavadocsJar(type: Jar, dependsOn: pluginJavadocs) { 106 | // classifier = 'javadoc' 107 | // from pluginJavadocs.destinationDir 108 | // } 109 | // 110 | // task pluginSourcesJar(type: Jar) { 111 | // classifier = 'sources' 112 | // from sourceSets.main.allGroovy 113 | // } 114 | 115 | // artifacts { 116 | // archives pluginSourcesJar 117 | // archives pluginJavadocsJar 118 | // } 119 | 120 | 121 | if (project.getPlugins().hasPlugin('com.android.application') || 122 | project.getPlugins().hasPlugin('com.android.library')) { 123 | 124 | task androidJavadocs(type: Javadoc) { 125 | source = android.sourceSets.main.java.source 126 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 127 | excludes = ['**/*.kt'] 128 | } 129 | 130 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 131 | classifier = 'javadoc' 132 | from androidJavadocs.destinationDir 133 | } 134 | 135 | task androidSourcesJar(type: Jar) { 136 | classifier = 'sources' 137 | from android.sourceSets.main.java.source 138 | } 139 | } 140 | 141 | if (JavaVersion.current().isJava8Compatible()) { 142 | allprojects { 143 | tasks.withType(Javadoc) { 144 | options.addStringOption('Xdoclint:none', '-quiet') 145 | } 146 | } 147 | } 148 | 149 | if (JavaVersion.current().isJava9Compatible()) { 150 | allprojects { 151 | tasks.withType(Javadoc) { 152 | options.addBooleanOption('html5', true) 153 | } 154 | } 155 | } 156 | 157 | artifacts { 158 | if (project.getPlugins().hasPlugin('com.android.application') || 159 | project.getPlugins().hasPlugin('com.android.library')) { 160 | archives androidSourcesJar 161 | archives androidJavadocsJar 162 | } 163 | } 164 | 165 | android.libraryVariants.all { variant -> 166 | tasks.androidJavadocs.doFirst { 167 | classpath += files(variant.javaCompileProvider.get().classpath.files.join(File.pathSeparator)) 168 | } 169 | } 170 | } -------------------------------------------------------------------------------- /NBEffects/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 -------------------------------------------------------------------------------- /NBEffects/src/androidTest/java/cn/wufuqi/nbeffects/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("cn.wufuqi.nbeffects.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /NBEffects/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/Constants.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects 2 | 3 | object Constants { 4 | const val BYTES_PER_INT = 4 5 | const val BYTES_PER_FLOAT = 4 6 | const val BYTES_PER_SHORT = 2 7 | 8 | /** 9 | * 顶点坐标 10 | * (x,y,z) 11 | */ 12 | val POSITION_VERTEX = floatArrayOf( 13 | 0f, 0f, 0f, //顶点坐标V0 14 | 1f, 1f, 0f, //顶点坐标V1 15 | -1f, 1f, 0f, //顶点坐标V2 16 | -1f, -1f, 0f, //顶点坐标V3 17 | 1f, -1f, 0f //顶点坐标V4 18 | ) 19 | 20 | /** 21 | * 纹理坐标 22 | * (s,t) 23 | */ 24 | val TEX_VERTEX = floatArrayOf( 25 | 0.5f, 0.5f, //纹理坐标V0 26 | 1f, 0f, //纹理坐标V1 27 | 0f, 0f, //纹理坐标V2 28 | 0f, 1.0f, //纹理坐标V3 29 | 1f, 1.0f //纹理坐标V4 30 | ) 31 | 32 | /** 33 | * 索引 34 | */ 35 | val VERTEX_INDEX = shortArrayOf( 36 | 0, 1, 2, //V0,V1,V2 三个顶点组成一个三角形 37 | 0, 2, 3, //V0,V2,V3 三个顶点组成一个三角形 38 | 0, 3, 4, //V0,V3,V4 三个顶点组成一个三角形 39 | 0, 4, 1 //V0,V4,V1 三个顶点组成一个三角形 40 | ) 41 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/NBEffectsImageView.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.drawable.Drawable 6 | import android.util.AttributeSet 7 | import android.view.View 8 | import android.widget.FrameLayout 9 | import cn.wufuqi.nbeffects.filter.RendererFilter 10 | import cn.wufuqi.nbeffects.renderer.GLRender 11 | import cn.wufuqi.nbeffects.renderer.NBGLSurfaceView 12 | import cn.wufuqi.nbeffects.renderer.NBTextureView 13 | import cn.wufuqi.nbeffects.utils.BitmapUtils 14 | 15 | 16 | class NBEffectsImageView : FrameLayout, GLRender { 17 | 18 | 19 | var renderType = OpenGLImageRenderType.AUTO_NO_BACK 20 | 21 | lateinit var mGLRender: GLRender 22 | 23 | constructor(context: Context) : this(context, null) 24 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) 25 | 26 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( 27 | context, 28 | attrs, 29 | defStyleAttr 30 | ) { 31 | initView(context) 32 | } 33 | 34 | private fun initView(context: Context) { 35 | mGLRender = NBGLSurfaceView(context) 36 | addView(mGLRender as View) 37 | } 38 | 39 | 40 | /** 41 | * 设置渲染类型 42 | * 43 | * OpenGLImageRenderType.FLEX 等高等宽拉伸 44 | * EQUAL_WIDTH 等宽的 45 | * EQUAL_HEIGHT 等高的 46 | * AUTO_NO_BACK 自适应,不留黑边 (默认) 47 | */ 48 | override fun setOpenGLImageRenderType(type: OpenGLImageRenderType) { 49 | renderType = type 50 | mGLRender.setOpenGLImageRenderType(type) 51 | } 52 | 53 | override fun setImageBitmap( 54 | bitmap: Bitmap, 55 | type: OpenGLImageRenderType 56 | ) { 57 | mGLRender.setImageBitmap(bitmap, type) 58 | } 59 | 60 | override fun setImageDrawable( 61 | drawable: Drawable, 62 | type: OpenGLImageRenderType 63 | ) { 64 | setImageBitmap(BitmapUtils.drawableToBitmap(drawable), type) 65 | } 66 | 67 | 68 | override fun setImageRes( 69 | resourceId: Int, 70 | type: OpenGLImageRenderType 71 | ) { 72 | setImageBitmap(BitmapUtils.getBitmap(resourceId)!!, type) 73 | } 74 | 75 | 76 | /** 77 | * 设置滤镜 78 | */ 79 | override fun setFilter(filter: RendererFilter?) { 80 | mGLRender.setFilter(filter) 81 | } 82 | 83 | /** 84 | * 设置true后 view 将会被置顶显示 85 | * 设置false view可能会有黑边 86 | */ 87 | override fun setTranslucent(translucent: Boolean) { 88 | mGLRender.setTranslucent(translucent) 89 | } 90 | 91 | 92 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/OpenGLImageRenderType.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects 2 | 3 | enum class OpenGLImageRenderType { 4 | 5 | /** 6 | * 等高等宽拉伸 7 | */ 8 | FLEX, 9 | 10 | /** 11 | * 等宽的 12 | */ 13 | EQUAL_WIDTH, 14 | 15 | /** 16 | * 等高的 17 | */ 18 | EQUAL_HEIGHT, 19 | 20 | /** 21 | * 自适应 EQUAL_WIDTH 和 EQUAL_HEIGHT 22 | * 不留黑边 23 | */ 24 | AUTO_NO_BACK, 25 | 26 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/Texture.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | import android.graphics.Bitmap 4 | import cn.wufuqi.nbeffects.utils.BitmapUtils 5 | 6 | class Texture : UniformInterface { 7 | var bitmap: Bitmap 8 | 9 | var textureId: Int = 0 10 | 11 | constructor(resId: Int) : this(BitmapUtils.getBitmap(resId)!!) 12 | constructor(bitmap: Bitmap) { 13 | this.bitmap = bitmap 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/UniformFloat.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | data class UniformFloat(var value: Float) : UniformInterface() 4 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/UniformInt.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | data class UniformInt(var value: Int) : UniformInterface() 4 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/UniformInterface.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | abstract class UniformInterface { 4 | var location = 0 5 | open fun toArray(): FloatArray{ 6 | return floatArrayOf() 7 | } 8 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/Vec2.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | data class Vec2(var x: Float, var y: Float): UniformInterface() { 4 | override fun toArray(): FloatArray { 5 | return floatArrayOf(x, y) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/Vec3.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | data class Vec3(var r: Float, var g: Float, var b: Float): UniformInterface() { 4 | override fun toArray(): FloatArray { 5 | return floatArrayOf(r, g, b) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/bean/Vec4.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.bean 2 | 3 | data class Vec4(var r: Float, var g: Float, var b: Float, var a: Float) : UniformInterface() { 4 | override fun toArray(): FloatArray { 5 | return floatArrayOf(r, g, b, a) 6 | } 7 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/BaseFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import android.graphics.Bitmap 4 | import android.opengl.GLES20 5 | import android.opengl.GLES30 6 | import android.opengl.Matrix 7 | import android.os.SystemClock 8 | import android.util.Log 9 | import androidx.annotation.CallSuper 10 | import cn.wufuqi.nbeffects.Constants 11 | import cn.wufuqi.nbeffects.NBEffectsImageView 12 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 13 | import cn.wufuqi.nbeffects.R 14 | import cn.wufuqi.nbeffects.bean.* 15 | import cn.wufuqi.nbeffects.utils.BitmapUtils 16 | import cn.wufuqi.nbeffects.utils.BufferUtils 17 | import cn.wufuqi.nbeffects.utils.ResReadUtils.readResource 18 | import cn.wufuqi.nbeffects.utils.ShaderUtils.linkProgram 19 | import cn.wufuqi.nbeffects.utils.ShaderUtils.loadFragmentShader 20 | import cn.wufuqi.nbeffects.utils.ShaderUtils.loadVertexShader 21 | import cn.wufuqi.nbeffects.utils.TextureUtils.loadTexture 22 | import com.wukonganimation.tween.Tween 23 | import com.wukonganimation.tween.TweenManager 24 | import java.nio.FloatBuffer 25 | import java.nio.ShortBuffer 26 | 27 | /** 28 | * 基本的Filter 29 | */ 30 | open class BaseFilter : RendererFilter { 31 | 32 | companion object { 33 | const val TEXTURE_LOCATION_NAME = "uTextureUnit" 34 | const val TAG = "RendererFilter" 35 | } 36 | 37 | private var mTween: Tween? = null 38 | 39 | private var vertexBuffer: FloatBuffer 40 | private var mTexVertexBuffer: FloatBuffer 41 | 42 | private var mVertexIndexBuffer: ShortBuffer 43 | 44 | var mProgram = 0 45 | 46 | var textureId = 0 47 | 48 | 49 | private var uMatrixLocation = 0 50 | 51 | private val mUniformMap = mutableMapOf() 52 | 53 | /** 54 | * 矩阵 55 | */ 56 | private val mMatrix = FloatArray(16) 57 | 58 | /** 59 | * 顶点着色器 60 | */ 61 | private var mVertexShader: String 62 | 63 | /** 64 | * 片段着色器 65 | */ 66 | private var mFragmentShader: String 67 | 68 | override var bitmap: Bitmap = BitmapUtils.getTransparentBitmap() 69 | 70 | var lastTime = 0L 71 | 72 | var textureCount = 0 73 | 74 | /** 75 | * 加载默认的着色器 76 | */ 77 | constructor() : this( 78 | R.raw.base_filter_vertex_shader, 79 | R.raw.base_filter_fragment_shader 80 | ) 81 | 82 | constructor(fragmentRes: Int) : this( 83 | R.raw.base_filter_vertex_shader, 84 | fragmentRes 85 | ) 86 | 87 | constructor(vertexRes: Int, fragmentRes: Int) : this( 88 | readResource(vertexRes), 89 | readResource(fragmentRes) 90 | ) 91 | 92 | constructor(vertexShader: String, fragmentShader: String) { 93 | mVertexShader = vertexShader 94 | mFragmentShader = fragmentShader 95 | //初始化内存空间 96 | vertexBuffer = BufferUtils.floatBufferUtil(Constants.POSITION_VERTEX) 97 | mTexVertexBuffer = BufferUtils.floatBufferUtil(Constants.TEX_VERTEX) 98 | mVertexIndexBuffer = BufferUtils.shortBufferUtil(Constants.VERTEX_INDEX) 99 | } 100 | 101 | 102 | open fun setupProgram() { 103 | //编译着色器 104 | val vertexShaderId = loadVertexShader(mVertexShader) 105 | val fragmentShaderId = loadFragmentShader(mFragmentShader) 106 | //链接程序片段 107 | mProgram = linkProgram(vertexShaderId, fragmentShaderId) 108 | uMatrixLocation = GLES30.glGetUniformLocation(mProgram, "u_Matrix") 109 | mUniformMap.forEach { v -> 110 | v.value.location = GLES30.glGetUniformLocation(mProgram, v.key) 111 | if (v.value is Texture) { 112 | val texture = v.value as Texture 113 | texture.textureId = loadTexture(texture.bitmap) 114 | } 115 | } 116 | //加载纹理 117 | textureId = loadTexture(bitmap) 118 | 119 | // textureLocation = 120 | } 121 | 122 | 123 | fun setUniform(name: String, value: Float) { 124 | setUniform(name, UniformFloat(value)) 125 | } 126 | 127 | fun setUniform(name: String, value: Int) { 128 | setUniform(name, UniformInt(value)) 129 | } 130 | 131 | fun setUniform(name: String, u: UniformInterface) { 132 | mUniformMap[name] = u 133 | if (u.location == 0) { 134 | u.location = GLES30.glGetUniformLocation(mProgram, name) 135 | } 136 | } 137 | 138 | @CallSuper 139 | override fun onSurfaceCreated() { 140 | //设置背景颜色 141 | // GLES30.glClearColor(0.5f, 0.5f, 0.5f, 0.5f) 142 | //初始化程序对象 143 | setupProgram() 144 | lastTime = SystemClock.uptimeMillis() 145 | } 146 | 147 | @CallSuper 148 | override fun onSurfaceChanged( 149 | width: Int, 150 | height: Int, 151 | bitmapWidth: Int, 152 | bitmapHeight: Int, 153 | renderType: OpenGLImageRenderType, 154 | view: NBEffectsImageView? 155 | ) { 156 | 157 | GLES30.glViewport(0, 0, width, height) 158 | var left = -1f 159 | var right = 1f 160 | var top = 1f 161 | var bottom = -1f 162 | 163 | var currRenderType = renderType 164 | if (currRenderType == OpenGLImageRenderType.AUTO_NO_BACK) { 165 | val realityHeight = ((width.toFloat() / bitmapWidth) * bitmapHeight).toInt() 166 | val ratioHeight = realityHeight.toFloat() / height 167 | currRenderType = 168 | if (ratioHeight >= 1) OpenGLImageRenderType.EQUAL_WIDTH else OpenGLImageRenderType.EQUAL_HEIGHT 169 | } 170 | 171 | 172 | when (currRenderType) { 173 | OpenGLImageRenderType.EQUAL_WIDTH -> { 174 | // 图片真实在手机上的高度 175 | val realityHeight = ((width.toFloat() / bitmapWidth) * bitmapHeight).toInt() 176 | val ratioHeight = realityHeight.toFloat() / height 177 | 178 | top = 1 / ratioHeight 179 | bottom = -1 / ratioHeight 180 | } 181 | OpenGLImageRenderType.EQUAL_HEIGHT -> { 182 | val realityWidth = ((height.toFloat() / bitmapHeight) * bitmapWidth).toInt() 183 | val ratioWidth = realityWidth.toFloat() / width 184 | 185 | right = 1 / ratioWidth 186 | left = -1 / ratioWidth 187 | } 188 | OpenGLImageRenderType.FLEX -> { 189 | left = -1f 190 | right = 1f 191 | top = 1f 192 | bottom = -1f 193 | } 194 | } 195 | setMatrix(left, right, bottom, top) 196 | } 197 | 198 | open fun setMatrix(left: Float, right: Float, bottom: Float, top: Float) { 199 | Matrix.orthoM(mMatrix, 0, left, right, bottom, top, -1f, 1f) 200 | } 201 | 202 | 203 | @CallSuper 204 | override fun onDrawFrame() { 205 | GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT) 206 | // GLES30.glClear(GLES30.GL_ALPHA); 207 | 208 | //使用程序片段 209 | GLES30.glUseProgram(mProgram) 210 | val currTime = SystemClock.uptimeMillis() 211 | //更新属性等信息 212 | onUpdateDrawFrame(currTime - lastTime) 213 | lastTime = currTime 214 | 215 | 216 | 217 | 218 | GLES30.glUniformMatrix4fv(uMatrixLocation, 1, false, mMatrix, 0) 219 | 220 | 221 | 222 | GLES30.glEnableVertexAttribArray(0) 223 | GLES30.glVertexAttribPointer(0, 3, GLES30.GL_FLOAT, false, 0, vertexBuffer) 224 | GLES30.glEnableVertexAttribArray(1) 225 | GLES30.glVertexAttribPointer(1, 2, GLES30.GL_FLOAT, false, 0, mTexVertexBuffer) 226 | GLES30.glActiveTexture(GLES30.GL_TEXTURE0) 227 | //绑定纹理 228 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureId) 229 | // GLES30.glUniform1i(GLES30.glGetUniformLocation(mProgram, TEXTURE_LOCATION_NAME), textureId) 230 | 231 | 232 | // 设置 Uniform 233 | mUniformMap.forEach { v -> 234 | when (val value = v.value) { 235 | is Vec4 -> { 236 | GLES30.glUniform4fv(value.location, 1, value.toArray(), 0) 237 | } 238 | is Vec2 -> { 239 | GLES30.glUniform2fv(value.location, 1, value.toArray(), 0) 240 | } 241 | is Vec3 -> { 242 | GLES30.glUniform3fv(value.location, 1, value.toArray(), 0) 243 | } 244 | is UniformInt -> { 245 | GLES30.glUniform1i(value.location, value.value) 246 | } 247 | is UniformFloat -> { 248 | GLES30.glUniform1f(value.location, value.value) 249 | } 250 | is Texture -> { 251 | GLES30.glActiveTexture(GLES30.GL_TEXTURE0 + value.textureId) 252 | GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, value.textureId) 253 | //绑定纹理 254 | GLES30.glUniform1i(value.location, value.textureId) 255 | } 256 | } 257 | } 258 | 259 | // 绘制 260 | GLES20.glDrawElements( 261 | GLES20.GL_TRIANGLES, 262 | Constants.VERTEX_INDEX.size, 263 | GLES20.GL_UNSIGNED_SHORT, 264 | mVertexIndexBuffer 265 | ) 266 | } 267 | 268 | fun aminFilterValue( 269 | time: Long, 270 | propertyName: String, 271 | propertyValue: Number, 272 | callback: (() -> Unit)? = null 273 | ) { 274 | mTween?.remove() 275 | mTween = TweenManager.builderOne(this) 276 | .to(mutableMapOf(propertyName to propertyValue)) 277 | .time(time) 278 | .on(TweenManager.EVENT_END) { 279 | callback?.invoke() 280 | } 281 | .start() 282 | } 283 | 284 | 285 | open fun onUpdateDrawFrame(dt: Long) {} 286 | 287 | override fun onDestroy() { 288 | mTween?.remove() 289 | mTween = null 290 | GLES30.glDeleteProgram(mProgram) 291 | } 292 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/DissolveFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 溶解的效果 7 | */ 8 | class DissolveFilter : BaseFilter(R.raw.dissolve_filter_fragment_shader) { 9 | 10 | 11 | 12 | /** 13 | * 溶解的值 0-1 14 | */ 15 | var dissolve: Float = 1f 16 | 17 | /** 18 | * 渐入 19 | */ 20 | fun fadeIn(time: Long, callback: (() -> Unit)? = null) { 21 | aminFilterValue(time,"dissolve",1f,callback) 22 | } 23 | 24 | /** 25 | * 渐出 26 | */ 27 | fun fadeOut(time: Long, callback: (() -> Unit)? = null) { 28 | aminFilterValue(time,"dissolve",-0.1f,callback) 29 | } 30 | 31 | /** 32 | * 指定到某个溶解值 33 | */ 34 | fun fadeTo(time: Long, dissolve: Float, callback: (() -> Unit)? = null) { 35 | aminFilterValue(time,"dissolve",dissolve,callback) 36 | } 37 | 38 | override fun onUpdateDrawFrame(dt: Long) { 39 | super.onUpdateDrawFrame(dt) 40 | setUniform("dissolve", 1 - dissolve) 41 | } 42 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/DynamicBlurTransferFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 模糊动画 7 | */ 8 | class DynamicBlurTransferFilter : BaseFilter(R.raw.dynamic_blur_transfer_filter_fragment_shader) { 9 | 10 | /** 11 | * 0 - 1 12 | */ 13 | var transfer = 0f 14 | 15 | 16 | fun transferAmin(time: Long, callback: (() -> Unit)? = null) { 17 | fadeIn(time / 2) { 18 | fadeOut(time / 2, callback) 19 | } 20 | } 21 | 22 | /** 23 | * 渐入 24 | */ 25 | fun fadeIn(time: Long, callback: (() -> Unit)? = null) { 26 | aminFilterValue(time, "transfer", 1f, callback) 27 | } 28 | 29 | /** 30 | * 渐出 31 | */ 32 | fun fadeOut(time: Long, callback: (() -> Unit)? = null) { 33 | aminFilterValue(time, "transfer", 0f, callback) 34 | } 35 | 36 | /** 37 | * 指定到某个溶解值 38 | */ 39 | fun fadeTo(time: Long, transfer: Float, callback: (() -> Unit)? = null) { 40 | aminFilterValue(time, "transfer", transfer, callback) 41 | } 42 | 43 | 44 | override fun onUpdateDrawFrame(dt: Long) { 45 | setUniform("time", 1.414f * transfer) 46 | } 47 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/GaussBlursFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 高斯模糊 7 | */ 8 | class GaussBlursFilter: BaseFilter(R.raw.gauss_blurs_filter_fragment_shader) { 9 | 10 | var blur = 2f 11 | override fun onUpdateDrawFrame(dt: Long) { 12 | setUniform("bluramount", blur) 13 | } 14 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/GrayFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | import cn.wufuqi.nbeffects.bean.Vec3 5 | 6 | /** 7 | * 置灰 8 | */ 9 | class GrayFilter : BaseFilter(R.raw.gray_filter_fragment_shader) { 10 | init { 11 | // 设置灰色滤镜 12 | setUniform("color", Vec3(0.299f, 0.587f, 0.114f)) 13 | } 14 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/MosaicFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.NBEffectsImageView 4 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 5 | import cn.wufuqi.nbeffects.R 6 | import cn.wufuqi.nbeffects.bean.Vec3 7 | 8 | /** 9 | * 方形马赛克 10 | */ 11 | class MosaicFilter : BaseFilter(R.raw.mosaic_filter_fragment_shader) { 12 | 13 | 14 | /** 15 | * 16 | * 方形马赛克的宽高大小 px 17 | * 0 - 屏幕大小 18 | */ 19 | var mosaicSize = 50f 20 | 21 | 22 | override fun onSurfaceChanged( 23 | width: Int, 24 | height: Int, 25 | bitmapWidth: Int, 26 | bitmapHeight: Int, 27 | renderType: OpenGLImageRenderType, 28 | view: NBEffectsImageView? 29 | ) { 30 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType, view) 31 | setUniform("iResolution", Vec3(width.toFloat(), height.toFloat(), 0f)) 32 | } 33 | 34 | override fun onUpdateDrawFrame(dt: Long) { 35 | setUniform("mosaicSize", mosaicSize) 36 | } 37 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/QuarterMirrorFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 显示4个一样的图片 7 | * 8 | */ 9 | class QuarterMirrorFilter : 10 | BaseFilter(R.raw.quarter_mirror_filter_fragment_shader) -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/RadialBlurFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.NBEffectsImageView 4 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 5 | import cn.wufuqi.nbeffects.R 6 | import cn.wufuqi.nbeffects.bean.Vec3 7 | 8 | class RadialBlurFilter : BaseFilter(R.raw.radial_blur_filter_fragment_shader){ 9 | 10 | var center = 5f 11 | 12 | 13 | override fun onSurfaceChanged( 14 | width: Int, 15 | height: Int, 16 | bitmapWidth: Int, 17 | bitmapHeight: Int, 18 | renderType: OpenGLImageRenderType, 19 | view: NBEffectsImageView? 20 | ) { 21 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType,view) 22 | setUniform("iResolution", Vec3(width.toFloat(), height.toFloat(), 0f)) 23 | } 24 | 25 | override fun onUpdateDrawFrame(dt: Long) { 26 | setUniform("iCenter", center) 27 | } 28 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/RainFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import android.graphics.Bitmap 4 | import android.os.SystemClock 5 | import android.util.Log 6 | import cn.wufuqi.nbeffects.NBEffectsImageView 7 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 8 | import cn.wufuqi.nbeffects.R 9 | import cn.wufuqi.nbeffects.bean.Vec2 10 | import cn.wufuqi.nbeffects.bean.Vec3 11 | import cn.wufuqi.nbeffects.utils.BitmapUtils 12 | 13 | /** 14 | * 雨滴效果 15 | */ 16 | class RainFilter : BaseFilter(R.raw.rain_filter_fragment_shader) { 17 | 18 | 19 | var time = 0f 20 | 21 | override var bitmap: Bitmap 22 | get() = super.bitmap 23 | set(value) { 24 | super.bitmap = BitmapUtils.getRotateAndFlipBitmap(value, 180f) 25 | } 26 | 27 | 28 | override fun onSurfaceChanged( 29 | width: Int, 30 | height: Int, 31 | bitmapWidth: Int, 32 | bitmapHeight: Int, 33 | renderType: OpenGLImageRenderType, 34 | view: NBEffectsImageView? 35 | ) { 36 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType,view) 37 | setUniform("iResolution", Vec3(width.toFloat(), height.toFloat(), 0f)) 38 | setUniform("texSize", Vec2(width.toFloat(), height.toFloat())) 39 | } 40 | 41 | 42 | override fun onUpdateDrawFrame(dt: Long) { 43 | if (time >= 20f) { 44 | time = 0.0f 45 | } 46 | time += dt / 800f 47 | setUniform("iTime", time) 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/RendererFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import android.graphics.Bitmap 4 | import cn.wufuqi.nbeffects.NBEffectsImageView 5 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 6 | 7 | interface RendererFilter { 8 | 9 | /** 10 | * bitmap 11 | */ 12 | var bitmap: Bitmap 13 | 14 | /** 15 | * 创建回调 16 | */ 17 | fun onSurfaceCreated() 18 | 19 | /** 20 | * 宽高改变回调 21 | * 22 | * @param width 23 | * @param height 24 | */ 25 | fun onSurfaceChanged( 26 | width: Int, 27 | height: Int, 28 | bitmapWidth: Int, 29 | bitmapHeight: Int, 30 | renderType: OpenGLImageRenderType, 31 | view: NBEffectsImageView? 32 | ) 33 | 34 | /** 35 | * 绘制回调 36 | */ 37 | fun onDrawFrame() 38 | 39 | /** 40 | * 销毁回调 41 | */ 42 | fun onDestroy() 43 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/UnfoldTransferFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 方条 切换动画 7 | */ 8 | class UnfoldTransferFilter : BaseFilter(R.raw.unfold_transfer_filter_vertex_shader) { 9 | 10 | 11 | /** 12 | * 0 - 1 13 | * 0 - 2 14 | */ 15 | var transfer = 0f 16 | 17 | 18 | fun transferAmin(time: Long, callback: (() -> Unit)? = null) { 19 | fadeIn(time / 2) { 20 | fadeOut(time / 2, callback) 21 | } 22 | } 23 | 24 | 25 | /** 26 | * 渐入 27 | */ 28 | fun fadeIn(time: Long, callback: (() -> Unit)? = null) { 29 | aminFilterValue(time, "transfer", 1f, callback) 30 | } 31 | 32 | /** 33 | * 渐出 34 | */ 35 | fun fadeOut(time: Long, callback: (() -> Unit)? = null) { 36 | aminFilterValue(time, "transfer", 0f, callback) 37 | } 38 | 39 | /** 40 | * 指定到某个溶解值 41 | */ 42 | fun fadeTo(time: Long, transfer: Float, callback: (() -> Unit)? = null) { 43 | aminFilterValue(time, "transfer", transfer, callback) 44 | } 45 | 46 | 47 | override fun onUpdateDrawFrame(dt: Long) { 48 | var t = transfer 49 | if (t >= 1) { 50 | t = 0.999f 51 | } 52 | setUniform("time", t) 53 | } 54 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/WaterFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.NBEffectsImageView 4 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 5 | import cn.wufuqi.nbeffects.R 6 | import cn.wufuqi.nbeffects.bean.Vec3 7 | 8 | /** 9 | * 水波纹 10 | */ 11 | class WaterFilter : BaseFilter(R.raw.water_filter_fragment_shader) { 12 | 13 | 14 | var time = 0.0f 15 | var offset = -0.01f 16 | 17 | override fun onSurfaceChanged( 18 | width: Int, 19 | height: Int, 20 | bitmapWidth: Int, 21 | bitmapHeight: Int, 22 | renderType: OpenGLImageRenderType, 23 | view: NBEffectsImageView? 24 | ) { 25 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType, view) 26 | setUniform("iResolution", Vec3(width.toFloat(), height.toFloat(), 0f)) 27 | } 28 | 29 | 30 | override fun setMatrix(left: Float, right: Float, bottom: Float, top: Float) { 31 | super.setMatrix(left - offset, right + offset, bottom - offset, top + offset) 32 | } 33 | 34 | override fun onUpdateDrawFrame(dt: Long) { 35 | if (time >= Float.MAX_VALUE - 1) { 36 | time = 0.0f 37 | } 38 | time += dt / 800f 39 | setUniform("iTime", time) 40 | } 41 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/WaveFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | import cn.wufuqi.nbeffects.bean.Vec2 5 | 6 | /** 7 | * 波浪流动效果 8 | */ 9 | class WaveFilter : BaseFilter(R.raw.wave_filter_fragment_shader) { 10 | 11 | 12 | private var offsetX: Float = 0.2f 13 | private var offsetY: Float = 0.2f 14 | 15 | var time = 0.0f 16 | 17 | init { 18 | setUniform("iOffset", Vec2(offsetX, offsetY)) 19 | } 20 | 21 | 22 | override fun setMatrix(left: Float, right: Float, bottom: Float, top: Float) { 23 | super.setMatrix( 24 | left + offsetX / 10, 25 | right - offsetX / 10, 26 | bottom + offsetY / 10, 27 | top - offsetY / 10 28 | ) 29 | } 30 | 31 | override fun onUpdateDrawFrame(dt: Long) { 32 | if (time >= Float.MAX_VALUE - 1) { 33 | time = 0.0f 34 | } 35 | time += dt / 800f 36 | setUniform("iTime", time) 37 | } 38 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/WindowTransferFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | 6 | /** 7 | * window 方块 切换动画 8 | */ 9 | class WindowTransferFilter : BaseFilter(R.raw.window_transfer_filter_fragment_shader) { 10 | 11 | /** 12 | * 0 - 1 13 | * 0 - 2 14 | */ 15 | var transfer = 0f 16 | 17 | 18 | fun transferAmin(time: Long, callback: (() -> Unit)? = null) { 19 | aminFilterValue(time, "transfer", 2f, callback) 20 | } 21 | 22 | 23 | /** 24 | * 渐入 25 | */ 26 | fun fadeIn(time: Long, callback: (() -> Unit)? = null) { 27 | aminFilterValue(time, "transfer", 1f, callback) 28 | } 29 | 30 | /** 31 | * 渐出 32 | */ 33 | fun fadeOut(time: Long, callback: (() -> Unit)? = null) { 34 | aminFilterValue(time, "transfer", 0f, callback) 35 | } 36 | 37 | /** 38 | * 指定到某个溶解值 39 | */ 40 | fun fadeTo(time: Long, transfer: Float, callback: (() -> Unit)? = null) { 41 | aminFilterValue(time, "transfer", transfer, callback) 42 | } 43 | 44 | 45 | override fun onUpdateDrawFrame(dt: Long) { 46 | setUniform("transfer", 2 * transfer) 47 | } 48 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/filter/ZoomBlurTransferFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | 5 | /** 6 | * 高斯模糊切换动画 7 | */ 8 | class ZoomBlurTransferFilter : BaseFilter(R.raw.zoom_blur_transfer_filter_fragment_shader) { 9 | 10 | /** 11 | * 0 - 1 12 | * 0 - 2 13 | */ 14 | var transfer = 0f 15 | 16 | 17 | fun transferAmin(time: Long, callback: (() -> Unit)? = null) { 18 | aminFilterValue(time, "transfer", 2f, callback) 19 | } 20 | 21 | 22 | /** 23 | * 渐入 24 | */ 25 | fun fadeIn(time: Long, callback: (() -> Unit)? = null) { 26 | aminFilterValue(time, "transfer", 1f, callback) 27 | } 28 | 29 | /** 30 | * 渐出 31 | */ 32 | fun fadeOut(time: Long, callback: (() -> Unit)? = null) { 33 | aminFilterValue(time, "transfer", 0f, callback) 34 | } 35 | 36 | /** 37 | * 指定到某个溶解值 38 | */ 39 | fun fadeTo(time: Long, transfer: Float, callback: (() -> Unit)? = null) { 40 | aminFilterValue(time, "transfer", transfer, callback) 41 | } 42 | 43 | 44 | override fun onUpdateDrawFrame(dt: Long) { 45 | setUniform("time", (Math.PI * 2 * transfer - Math.PI).toFloat()) 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/helper/PendingThreadAider.java: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.helper; 2 | 3 | import java.util.LinkedList; 4 | 5 | 6 | public class PendingThreadAider { 7 | LinkedList mRunOnDraw = new LinkedList(); 8 | 9 | public void runPendings() { 10 | while (!mRunOnDraw.isEmpty()) { 11 | mRunOnDraw.removeFirst().run(); 12 | } 13 | } 14 | 15 | public void addToPending(final Runnable runnable) { 16 | synchronized (mRunOnDraw) { 17 | mRunOnDraw.addLast(runnable); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/pixijs_filter/AdjustmentFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.pixijs_filter 2 | 3 | import cn.wufuqi.nbeffects.R 4 | import cn.wufuqi.nbeffects.filter.BaseFilter 5 | import kotlin.math.max 6 | 7 | 8 | class AdjustmentFilter : BaseFilter(R.raw.adjustment_filter_fragment_shader) { 9 | /** The amount of luminance */ 10 | var gamma = 1f 11 | 12 | /** The amount of saturation */ 13 | var saturation = 1f 14 | 15 | /** The amount of contrast */ 16 | var contrast = 1f 17 | 18 | /** The amount of brightness */ 19 | var brightness = 1f 20 | 21 | /** The amount of red channel */ 22 | var red = 1f 23 | 24 | /** The amount of green channel */ 25 | var green = 1f 26 | 27 | /** The amount of blue channel */ 28 | var blue = 1f 29 | 30 | /** The amount of alpha channel */ 31 | var alpha = 1f 32 | 33 | 34 | override fun onUpdateDrawFrame(dt: Long) { 35 | setUniform("gamma", max(gamma, 0.0001f)) 36 | setUniform("saturation", saturation) 37 | setUniform("contrast", contrast) 38 | setUniform("brightness", brightness) 39 | setUniform("red", red) 40 | setUniform("green", green) 41 | setUniform("blue", blue) 42 | setUniform("alpha", alpha) 43 | } 44 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/pixijs_filter/AsciiFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.pixijs_filter 2 | 3 | import cn.wufuqi.nbeffects.NBEffectsImageView 4 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 5 | import cn.wufuqi.nbeffects.R 6 | import cn.wufuqi.nbeffects.bean.Vec4 7 | import cn.wufuqi.nbeffects.filter.BaseFilter 8 | 9 | class AsciiFilter:BaseFilter(R.raw.ascii_filter_fragment_shader) { 10 | 11 | var size = 8f 12 | 13 | 14 | override fun onSurfaceChanged( 15 | width: Int, 16 | height: Int, 17 | bitmapWidth: Int, 18 | bitmapHeight: Int, 19 | renderType: OpenGLImageRenderType, 20 | view: NBEffectsImageView? 21 | ) { 22 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType,view) 23 | setUniform("filterArea", Vec4(width.toFloat(), height.toFloat(), 0f,0f)) 24 | } 25 | 26 | override fun onUpdateDrawFrame(dt: Long) { 27 | setUniform("pixelSize", size) 28 | } 29 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/pixijs_filter/BevelFilter.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.pixijs_filter 2 | 3 | import android.graphics.Color 4 | import androidx.core.graphics.alpha 5 | import androidx.core.graphics.blue 6 | import androidx.core.graphics.green 7 | import androidx.core.graphics.red 8 | import cn.wufuqi.nbeffects.NBEffectsImageView 9 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 10 | import cn.wufuqi.nbeffects.R 11 | import cn.wufuqi.nbeffects.bean.Vec3 12 | import cn.wufuqi.nbeffects.bean.Vec4 13 | import cn.wufuqi.nbeffects.filter.BaseFilter 14 | import kotlin.math.max 15 | 16 | class BevelFilter : BaseFilter(R.raw.bevel_filter_fragment_shader) { 17 | var lightColor = "#ffffff" 18 | var shadowColor = "#000000" 19 | var transformX = 0f 20 | var transformY = 0f 21 | var lightAlpha = 1f 22 | var shadowAlpha = 1f 23 | 24 | 25 | override fun onSurfaceChanged( 26 | width: Int, 27 | height: Int, 28 | bitmapWidth: Int, 29 | bitmapHeight: Int, 30 | renderType: OpenGLImageRenderType, 31 | view: NBEffectsImageView? 32 | ) { 33 | super.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType, view) 34 | setUniform("filterArea", Vec4(width.toFloat(), height.toFloat(), 0f, 0f)) 35 | } 36 | 37 | override fun onUpdateDrawFrame(dt: Long) { 38 | val lc = Color.parseColor(lightColor) 39 | val sc = Color.parseColor(shadowColor) 40 | 41 | setUniform( 42 | "lightColor", 43 | Vec3(lc.red / 255f, lc.green / 255f, lc.blue / 255f) 44 | ) 45 | setUniform( 46 | "shadowColor", 47 | Vec3(sc.red / 255f, sc.green / 255f, sc.blue / 255f) 48 | ) 49 | setUniform("transformX", transformX) 50 | setUniform("transformY", transformY) 51 | setUniform("lightAlpha", lightAlpha) 52 | setUniform("shadowAlpha", shadowAlpha) 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/renderer/FilterRenderer.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.renderer 2 | 3 | import android.graphics.Bitmap 4 | import android.opengl.GLSurfaceView 5 | import cn.wufuqi.nbeffects.NBEffectsImageView 6 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 7 | import cn.wufuqi.nbeffects.filter.BaseFilter 8 | import cn.wufuqi.nbeffects.filter.RendererFilter 9 | import cn.wufuqi.nbeffects.utils.BitmapUtils 10 | import javax.microedition.khronos.egl.EGLConfig 11 | import javax.microedition.khronos.opengles.GL10 12 | 13 | class FilterRenderer : GLSurfaceView.Renderer { 14 | 15 | 16 | private var mSurfaceWidth = 0 17 | private var mSurfaceHeight: Int = 0 18 | 19 | private var mTargetFilter: RendererFilter = BaseFilter() 20 | 21 | var bitmap: Bitmap = BitmapUtils.getTransparentBitmap() 22 | var renderType = OpenGLImageRenderType.FLEX 23 | 24 | var view: NBEffectsImageView? = null 25 | 26 | var bitmapWidth = bitmap.width 27 | var bitmapHeight = bitmap.width 28 | 29 | fun setImage(bitmap: Bitmap) { 30 | this.bitmap = bitmap 31 | bitmapWidth = bitmap.width 32 | bitmapHeight = bitmap.height 33 | mTargetFilter.bitmap = bitmap 34 | } 35 | 36 | fun setOpenGLImageRenderType(type: OpenGLImageRenderType) { 37 | renderType = type 38 | } 39 | 40 | override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) { 41 | mTargetFilter.onSurfaceCreated() 42 | } 43 | 44 | override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) { 45 | mSurfaceWidth = width 46 | mSurfaceHeight = height 47 | mTargetFilter.onSurfaceChanged(width, height, bitmapWidth, bitmapHeight, renderType,view) 48 | } 49 | 50 | override fun onDrawFrame(gl: GL10?) { 51 | mTargetFilter.onDrawFrame() 52 | } 53 | 54 | fun setFilter(filter: RendererFilter?) { 55 | mTargetFilter.onDestroy() 56 | mTargetFilter = filter ?: BaseFilter() 57 | mTargetFilter.bitmap = bitmap 58 | mTargetFilter.onSurfaceCreated() 59 | mTargetFilter.onSurfaceChanged( 60 | mSurfaceWidth, 61 | mSurfaceHeight, 62 | bitmapWidth, 63 | bitmapHeight, 64 | renderType, 65 | view 66 | ) 67 | } 68 | 69 | fun getFilter():RendererFilter{ 70 | return mTargetFilter 71 | } 72 | 73 | fun destroy(){ 74 | mTargetFilter.onDestroy() 75 | view = null 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/renderer/GLESThread.java: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.renderer; 2 | 3 | import android.graphics.SurfaceTexture; 4 | import android.opengl.GLUtils; 5 | 6 | import java.util.ArrayList; 7 | 8 | import javax.microedition.khronos.egl.EGL10; 9 | import javax.microedition.khronos.egl.EGLConfig; 10 | import javax.microedition.khronos.egl.EGLContext; 11 | import javax.microedition.khronos.egl.EGLDisplay; 12 | import javax.microedition.khronos.egl.EGLSurface; 13 | 14 | import cn.wufuqi.nbeffects.helper.PendingThreadAider; 15 | 16 | public class GLESThread extends Thread { 17 | private static final String TAG = "GLESTVThread"; 18 | private SurfaceTexture mSurfaceTexture; 19 | private EGL10 mEgl; 20 | private EGLDisplay mEglDisplay = EGL10.EGL_NO_DISPLAY;// 显示设备 21 | private EGLSurface mEglSurface = EGL10.EGL_NO_SURFACE; 22 | private EGLContext mEglContext = EGL10.EGL_NO_CONTEXT; 23 | // private GL mGL; 24 | private static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; 25 | private static final int EGL_OPENGL_ES2_BIT = 4; 26 | private FilterRenderer mRenderer; 27 | private PendingThreadAider mPendingThreadAider = new PendingThreadAider(); 28 | private boolean mNeedRenderring = true; 29 | private Object LOCK = new Object(); 30 | private boolean mIsPaused = false; 31 | 32 | private ArrayList mEventQueue = new ArrayList(); 33 | 34 | public GLESThread(SurfaceTexture surface, FilterRenderer renderer) { 35 | mSurfaceTexture = surface; 36 | mRenderer = renderer; 37 | } 38 | 39 | @Override 40 | public void run() { 41 | 42 | initGLESContext(); 43 | mRenderer.onSurfaceCreated(null, null); 44 | while (mNeedRenderring) { 45 | 46 | while (!mEventQueue.isEmpty()) { 47 | Runnable event = mEventQueue.remove(0); 48 | if (event != null) { 49 | event.run(); 50 | } 51 | } 52 | 53 | mPendingThreadAider.runPendings(); 54 | mRenderer.onDrawFrame(null); 55 | mEgl.eglSwapBuffers(mEglDisplay, mEglSurface); 56 | if (mIsPaused) { 57 | pauseWhile(); 58 | } else if (mRendererMode == NBTextureView.RENDERMODE_WHEN_DIRTY) { 59 | pauseWhile(); 60 | } 61 | 62 | 63 | } 64 | destoryGLESContext(); 65 | } 66 | 67 | private void initGLESContext() { 68 | 69 | mEgl = (EGL10) EGLContext.getEGL(); 70 | mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);// 获取显示设备 71 | if (mEglDisplay == EGL10.EGL_NO_DISPLAY) { 72 | throw new RuntimeException("eglGetdisplay failed : " + GLUtils.getEGLErrorString(mEgl.eglGetError())); 73 | } 74 | 75 | int[] version = new int[2]; 76 | if (!mEgl.eglInitialize(mEglDisplay, version)) { 77 | throw new RuntimeException("eglInitialize failed : " + GLUtils.getEGLErrorString(mEgl.eglGetError())); 78 | } 79 | 80 | int[] configAttribs = { // 81 | EGL10.EGL_BUFFER_SIZE, 32, 82 | EGL10.EGL_ALPHA_SIZE, 8, 83 | EGL10.EGL_BLUE_SIZE, 8, 84 | EGL10.EGL_GREEN_SIZE, 8, 85 | EGL10.EGL_RED_SIZE, 8, 86 | EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 87 | EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT, EGL10.EGL_NONE 88 | }; 89 | 90 | int[] numConfigs = new int[1]; 91 | EGLConfig[] configs = new EGLConfig[1]; 92 | if (!mEgl.eglChooseConfig(mEglDisplay, configAttribs, configs, 1, numConfigs)) { 93 | throw new RuntimeException("eglChooseConfig failed : " + GLUtils.getEGLErrorString(mEgl.eglGetError())); 94 | } 95 | 96 | int[] contextAttribs = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE}; 97 | mEglContext = mEgl.eglCreateContext(mEglDisplay, configs[0], EGL10.EGL_NO_CONTEXT, 98 | contextAttribs); 99 | mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, configs[0], mSurfaceTexture, 100 | null 101 | ); 102 | if (mEglSurface == EGL10.EGL_NO_SURFACE || mEglContext == EGL10.EGL_NO_CONTEXT) { 103 | int error = mEgl.eglGetError(); 104 | if (error == EGL10.EGL_BAD_NATIVE_WINDOW) { 105 | throw new RuntimeException("eglCreateWindowSurface returned EGL_BAD_NATIVE_WINDOW. "); 106 | } 107 | throw new RuntimeException("eglCreateWindowSurface failed : " + GLUtils.getEGLErrorString(mEgl.eglGetError())); 108 | } 109 | 110 | if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { 111 | throw new RuntimeException("eglMakeCurrent failed : " + GLUtils.getEGLErrorString(mEgl.eglGetError())); 112 | } 113 | // mGL = mEglContext.getGL(); 114 | } 115 | 116 | private void pauseWhile() { 117 | synchronized (LOCK) { 118 | try { 119 | LOCK.wait(); 120 | } catch (InterruptedException e) { 121 | e.printStackTrace(); 122 | } 123 | } 124 | } 125 | 126 | private void destoryGLESContext() { 127 | mEgl.eglDestroyContext(mEglDisplay, mEglContext); 128 | mEgl.eglDestroySurface(mEglDisplay, mEglSurface); 129 | mEglContext = EGL10.EGL_NO_CONTEXT; 130 | mEglSurface = EGL10.EGL_NO_SURFACE; 131 | } 132 | 133 | public void onPause() { 134 | // mRenderer.onPause(); 135 | mIsPaused = true; 136 | } 137 | 138 | public void onResume() { 139 | // mRenderer.onResume(); 140 | mIsPaused = false; 141 | requestRender(); 142 | } 143 | 144 | public void onSurfaceChanged(final int width, final int height) { 145 | mPendingThreadAider.addToPending(new Runnable() { 146 | 147 | @Override 148 | public void run() { 149 | mRenderer.onSurfaceChanged(null, width, height); 150 | } 151 | }); 152 | } 153 | 154 | private int mRendererMode = NBTextureView.RENDERMODE_CONTINUOUSLY; 155 | 156 | public void setRenderMode(int mode) { 157 | mRendererMode = mode; 158 | } 159 | 160 | public void requestRender() { 161 | synchronized (LOCK) { 162 | LOCK.notifyAll(); 163 | } 164 | } 165 | 166 | public void onDestroy() { 167 | mNeedRenderring = false; 168 | mRenderer.destroy(); 169 | destoryGLESContext(); 170 | } 171 | 172 | public void queueEvent(Runnable r) { 173 | if (r == null) { 174 | throw new IllegalArgumentException("r must not be null"); 175 | } 176 | synchronized (LOCK) { 177 | mEventQueue.add(r); 178 | LOCK.notifyAll(); 179 | } 180 | } 181 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/renderer/GLRender.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.renderer 2 | 3 | import android.graphics.Bitmap 4 | import android.graphics.drawable.Drawable 5 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 6 | import cn.wufuqi.nbeffects.filter.RendererFilter 7 | 8 | interface GLRender { 9 | 10 | /** 11 | * 设置渲染类型 12 | * 13 | * OpenGLImageRenderType.FLEX 等高等宽拉伸 14 | * EQUAL_WIDTH 等宽的 15 | * EQUAL_HEIGHT 等高的 16 | * AUTO_NO_BACK 自适应,不留黑边 (默认) 17 | */ 18 | fun setOpenGLImageRenderType(type: OpenGLImageRenderType) 19 | 20 | fun setImageBitmap( 21 | bitmap: Bitmap, 22 | type: OpenGLImageRenderType = OpenGLImageRenderType.AUTO_NO_BACK 23 | ) 24 | 25 | fun setImageDrawable( 26 | drawable: Drawable, 27 | type: OpenGLImageRenderType = OpenGLImageRenderType.AUTO_NO_BACK 28 | ) 29 | 30 | fun setImageRes( 31 | resourceId: Int, 32 | type: OpenGLImageRenderType = OpenGLImageRenderType.AUTO_NO_BACK 33 | ) 34 | 35 | /** 36 | * 设置滤镜 37 | */ 38 | fun setFilter(filter: RendererFilter?) 39 | 40 | 41 | /** 42 | * 设置true后 view 将会被置顶显示 43 | * 设置false view可能会有黑边 44 | */ 45 | fun setTranslucent(translucent: Boolean) 46 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/renderer/NBGLSurfaceView.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.renderer 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.PixelFormat 6 | import android.graphics.drawable.Drawable 7 | import android.opengl.GLES10 8 | import android.opengl.GLSurfaceView 9 | import android.util.AttributeSet 10 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 11 | import cn.wufuqi.nbeffects.filter.RendererFilter 12 | import cn.wufuqi.nbeffects.utils.BitmapUtils 13 | 14 | class NBGLSurfaceView : GLSurfaceView, GLRender { 15 | 16 | constructor(context: Context) : this(context, null) 17 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { 18 | setupSurfaceView() 19 | } 20 | 21 | private val queueEventRunnableList = mutableListOf() 22 | 23 | 24 | private lateinit var mGLRender: FilterRenderer 25 | 26 | var renderType = OpenGLImageRenderType.AUTO_NO_BACK 27 | 28 | var isAddRender = false 29 | 30 | 31 | /** 32 | * 设置渲染类型 33 | * 34 | * OpenGLImageRenderType.FLEX 等高等宽拉伸 35 | * EQUAL_WIDTH 等宽的 36 | * EQUAL_HEIGHT 等高的 37 | * AUTO_NO_BACK 自适应,不留黑边 (默认) 38 | */ 39 | override fun setOpenGLImageRenderType(type: OpenGLImageRenderType) { 40 | queueEvent { 41 | renderType = type 42 | mGLRender.setOpenGLImageRenderType(type) 43 | mGLRender.setFilter(mGLRender.getFilter()) 44 | } 45 | } 46 | 47 | override fun setImageBitmap( 48 | bitmap: Bitmap, 49 | type: OpenGLImageRenderType 50 | ) { 51 | queueEvent { 52 | mGLRender.setImage(bitmap) 53 | mGLRender.setOpenGLImageRenderType(type) 54 | mGLRender.setFilter(mGLRender.getFilter()) 55 | } 56 | } 57 | 58 | override fun setImageDrawable( 59 | drawable: Drawable, 60 | type: OpenGLImageRenderType 61 | ) { 62 | setImageBitmap(BitmapUtils.drawableToBitmap(drawable), type) 63 | } 64 | 65 | 66 | override fun setImageRes( 67 | resourceId: Int, 68 | type: OpenGLImageRenderType 69 | ) { 70 | setImageBitmap(BitmapUtils.getBitmap(resourceId)!!, type) 71 | } 72 | 73 | 74 | private fun setupSurfaceView() { 75 | //设置版本 76 | setEGLContextClientVersion(3) 77 | 78 | setEGLConfigChooser(8, 8, 8, 8, 16, 0) 79 | // setTranslucent() 80 | mGLRender = FilterRenderer() 81 | 82 | setRenderer(mGLRender) 83 | isAddRender = true 84 | 85 | } 86 | 87 | /** 88 | * 设置滤镜 89 | * 滤镜由于可能存在多种类型 90 | * 这里抽象了一个基础的滤镜类 91 | * queueEvent 92 | * 93 | * @param baseFilter 94 | */ 95 | override fun setFilter(filter: RendererFilter?) { 96 | queueEvent { 97 | mGLRender.setFilter(filter) 98 | requestRender() 99 | } 100 | } 101 | 102 | override fun onAttachedToWindow() { 103 | super.onAttachedToWindow() 104 | requestRender() 105 | } 106 | 107 | override fun onDetachedFromWindow() { 108 | super.onDetachedFromWindow() 109 | mGLRender.destroy() 110 | } 111 | 112 | override fun requestRender() { 113 | try { 114 | queueEvent { 115 | super.requestRender() 116 | } 117 | } catch (e: Exception) { 118 | e.printStackTrace() 119 | } 120 | } 121 | 122 | override fun queueEvent(r: Runnable?) { 123 | if (isAddRender) { 124 | try { 125 | super.requestRender() 126 | } catch (e: Exception) { 127 | queueEventRunnableList.add(r) 128 | e.printStackTrace() 129 | return 130 | } 131 | 132 | queueEventRunnableList.forEach { 133 | super.queueEvent(it) 134 | } 135 | queueEventRunnableList.clear() 136 | super.queueEvent(r) 137 | } else { 138 | queueEventRunnableList.add(r) 139 | } 140 | } 141 | 142 | 143 | /** 144 | * 设置透明背景的方法 145 | * 设置后 会被置顶 146 | */ 147 | override fun setTranslucent(translucent:Boolean){ 148 | holder.setFormat(PixelFormat.TRANSLUCENT) 149 | // 将GLSurfaceView置顶 150 | setZOrderOnTop(translucent) 151 | } 152 | 153 | 154 | 155 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/renderer/NBTextureView.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.renderer 2 | 3 | import android.content.Context 4 | import android.graphics.Bitmap 5 | import android.graphics.SurfaceTexture 6 | import android.graphics.drawable.Drawable 7 | import android.util.AttributeSet 8 | import android.view.TextureView 9 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 10 | import cn.wufuqi.nbeffects.filter.RendererFilter 11 | import cn.wufuqi.nbeffects.utils.BitmapUtils 12 | 13 | class NBTextureView : TextureView, GLRender, TextureView.SurfaceTextureListener { 14 | 15 | 16 | companion object { 17 | const val RENDERMODE_WHEN_DIRTY = 0 18 | const val RENDERMODE_CONTINUOUSLY = 1 19 | } 20 | 21 | var mRendererMode = RENDERMODE_CONTINUOUSLY 22 | 23 | var renderType = OpenGLImageRenderType.AUTO_NO_BACK 24 | private var mGLThread: GLESThread? = null 25 | private val mGLRender: FilterRenderer = FilterRenderer() 26 | 27 | constructor(context: Context) : this(context, null) 28 | constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) 29 | 30 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( 31 | context, 32 | attrs, 33 | defStyleAttr 34 | ) { 35 | initView(context) 36 | } 37 | 38 | private fun initView(context: Context) { 39 | surfaceTextureListener = this 40 | } 41 | 42 | override fun setOpenGLImageRenderType(type: OpenGLImageRenderType) { 43 | queueEvent { 44 | renderType = type 45 | mGLRender.setOpenGLImageRenderType(type) 46 | mGLRender.setFilter(mGLRender.getFilter()) 47 | } 48 | } 49 | 50 | override fun setImageBitmap(bitmap: Bitmap, type: OpenGLImageRenderType) { 51 | queueEvent { 52 | mGLRender.setImage(bitmap) 53 | mGLRender.setOpenGLImageRenderType(type) 54 | mGLRender.setFilter(mGLRender.getFilter()) 55 | } 56 | } 57 | 58 | override fun setImageDrawable(drawable: Drawable, type: OpenGLImageRenderType) { 59 | setImageBitmap(BitmapUtils.drawableToBitmap(drawable), type) 60 | } 61 | 62 | override fun setImageRes(resourceId: Int, type: OpenGLImageRenderType) { 63 | setImageBitmap(BitmapUtils.getBitmap(resourceId)!!, type) 64 | } 65 | 66 | override fun setFilter(filter: RendererFilter?) { 67 | queueEvent { 68 | mGLRender.setFilter(filter) 69 | } 70 | requestRender() 71 | } 72 | 73 | override fun setTranslucent(translucent: Boolean) { 74 | // setZOrderOnTop(translucent) 75 | } 76 | 77 | override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) { 78 | mGLThread = GLESThread( 79 | surface, 80 | mGLRender 81 | ) // 创建一个线程,作为GL线程 82 | 83 | mGLThread!!.setRenderMode(mRendererMode) 84 | mGLThread!!.start() 85 | mGLThread!!.onSurfaceChanged(width, height) 86 | } 87 | 88 | override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) { 89 | mGLThread?.onSurfaceChanged(width, height) 90 | } 91 | 92 | override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean { 93 | mGLThread?.onDestroy() 94 | return false 95 | } 96 | 97 | override fun onSurfaceTextureUpdated(surface: SurfaceTexture) { 98 | 99 | } 100 | 101 | fun queueEvent(r: Runnable?) { 102 | if (mGLThread != null) { 103 | mGLThread!!.queueEvent(r) 104 | } else { 105 | r?.run() 106 | } 107 | } 108 | 109 | 110 | fun setRenderMode(mode: Int) { 111 | mRendererMode = mode 112 | } 113 | 114 | fun requestRender() { 115 | mGLThread?.requestRender() 116 | } 117 | 118 | fun onResume() { 119 | mGLThread?.onResume() 120 | } 121 | 122 | fun onPause() { 123 | mGLThread?.onPause() 124 | } 125 | 126 | fun onDestroy() { 127 | mGLThread?.onDestroy() 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/AppUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | import android.annotation.SuppressLint 4 | import android.app.ActivityManager 5 | import android.app.Application 6 | import android.content.Context 7 | import android.content.pm.PackageManager 8 | import java.lang.reflect.InvocationTargetException 9 | 10 | @SuppressLint("StaticFieldLeak") 11 | object AppUtils { 12 | 13 | private var application: Application? = null 14 | private var context: Context? = null 15 | 16 | /** 反射获取Application */ 17 | @SuppressLint("BlockedPrivateApi", "StaticFieldLeak", "PrivateApi", "DiscouragedPrivateApi") 18 | fun getApplication(): Application? { 19 | if (application != null) { 20 | return application 21 | } 22 | try { 23 | @SuppressLint("PrivateApi") val activityThread = 24 | Class.forName("android.app.ActivityThread") 25 | val at = activityThread.getMethod("currentActivityThread").invoke(null) 26 | val app = activityThread.getMethod("getApplication").invoke(at) 27 | ?: throw NullPointerException("u should init first") 28 | application = app as Application 29 | context = application 30 | return application 31 | } catch (e: NoSuchMethodException) { 32 | e.printStackTrace() 33 | } catch (e: IllegalAccessException) { 34 | e.printStackTrace() 35 | } catch (e: InvocationTargetException) { 36 | e.printStackTrace() 37 | } catch (e: ClassNotFoundException) { 38 | e.printStackTrace() 39 | } 40 | throw NullPointerException("u should init first") 41 | } 42 | 43 | /** 获取Context */ 44 | @SuppressLint("StaticFieldLeak") 45 | fun getContext(): Context? { 46 | return context ?: getApplication() 47 | } 48 | 49 | fun getAppIcon(): Int { 50 | var icon = -1 51 | try { 52 | val packageManager = getContext()?.packageManager 53 | val packageInfo = packageManager?.getPackageInfo( 54 | getContext()?.packageName ?: "", 0 55 | ) 56 | icon = packageInfo?.applicationInfo?.icon ?: -1 57 | } catch (e: PackageManager.NameNotFoundException) { 58 | e.printStackTrace() 59 | } 60 | return icon 61 | } 62 | 63 | 64 | /** 65 | * 获取app的名称 66 | * @param context 67 | * @return 68 | */ 69 | fun getAppName(): String { 70 | var appName = "" 71 | try { 72 | val packageManager = getContext()?.packageManager 73 | val packageInfo = packageManager?.getPackageInfo( 74 | getContext()?.packageName ?: "", 0 75 | ) 76 | val labelRes = packageInfo?.applicationInfo?.labelRes ?: -1 77 | appName = getContext()?.resources?.getString(labelRes) ?: "" 78 | } catch (e: Throwable) { 79 | e.printStackTrace() 80 | } 81 | return appName 82 | } 83 | 84 | /** 85 | * 获取app的名称 86 | * @param context 87 | * @return 88 | */ 89 | fun getPackageName(): String { 90 | return getContext()?.packageName ?: "" 91 | } 92 | 93 | /** 94 | * 用于判断那个应用是处于前台的 95 | */ 96 | private fun getForegroundApp(): String? { 97 | 98 | val activityManager = getContext()!! 99 | .getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager 100 | val runningAppProcesses = activityManager.runningAppProcesses 101 | if (runningAppProcesses.isNullOrEmpty()) { 102 | return null 103 | } 104 | runningAppProcesses.forEach { 105 | if (it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND || it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE) { 106 | return it.processName 107 | } 108 | } 109 | 110 | return null 111 | } 112 | 113 | fun isRunningForeground(): Boolean { 114 | return getForegroundApp() == getPackageName() 115 | } 116 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/BitmapUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | import android.graphics.* 4 | import android.graphics.drawable.Drawable 5 | 6 | object BitmapUtils { 7 | const val TAG = "BitmapUtils" 8 | fun getBitmap(resourceId: Int): Bitmap? { 9 | val options = BitmapFactory.Options() 10 | options.inScaled = false 11 | return BitmapFactory.decodeResource(AppUtils.getContext()!!.resources, resourceId, options) 12 | } 13 | 14 | fun drawableToBitmap(drawable: Drawable): Bitmap { 15 | //获取图片宽度 16 | val width = drawable.intrinsicWidth 17 | //获取图片高度 18 | val height = drawable.intrinsicHeight 19 | //图片位深,PixelFormat.OPAQUE代表没有透明度,RGB_565就是没有透明度的位深,否则就用ARGB_8888。详细见下面图片编码知识。 20 | val config = 21 | if (drawable.opacity != PixelFormat.OPAQUE) Bitmap.Config.ARGB_8888 else Bitmap.Config.RGB_565 22 | //创建一个空的Bitmap 23 | val bitmap = Bitmap.createBitmap(width, height, config) 24 | //在bitmap上创建一个画布 25 | val canvas = Canvas(bitmap) 26 | //设置画布的范围 27 | drawable.setBounds(0, 0, width, height) 28 | //将drawable绘制在canvas上 29 | drawable.draw(canvas) 30 | return bitmap 31 | } 32 | 33 | fun getTransparentBitmap(): Bitmap { 34 | val argb = IntArray(1 * 1) 35 | for (i in argb.indices) { 36 | argb[i] = 0x00FFFFFF.toInt() 37 | } 38 | return Bitmap.createBitmap( 39 | argb, 1, 1, Bitmap.Config.ARGB_8888 40 | ) 41 | } 42 | 43 | // 获得旋转角度之后的位图对象 44 | fun getRotateAndFlipBitmap(bitmap: Bitmap, rotateDegree: Float): Bitmap { 45 | val matrix = Matrix() // 创建操作图片用的矩阵对象 46 | matrix.postRotate(rotateDegree) // 执行图片的旋转动作 47 | matrix.postScale(-1f, 1f) 48 | // 创建并返回旋转后的位图对象 49 | return Bitmap.createBitmap( 50 | bitmap, 0, 0, bitmap.width, 51 | bitmap.height, matrix, false 52 | ) 53 | } 54 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/BufferUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | import cn.wufuqi.nbeffects.Constants 4 | import java.nio.* 5 | 6 | object BufferUtils { 7 | 8 | /** 9 | * 将int[]转成IntBuffer 10 | */ 11 | fun intBufferUtil(arr: IntArray): IntBuffer { 12 | val mBuffer: IntBuffer 13 | // 初始化ByteBuffer,长度为arr数组的长度*4,因为一个int占4个字节 14 | val qbb: ByteBuffer = ByteBuffer.allocateDirect(arr.size * Constants.BYTES_PER_INT) 15 | // 数组排列用nativeOrder 16 | qbb.order(ByteOrder.nativeOrder()) 17 | mBuffer = qbb.asIntBuffer() 18 | mBuffer.put(arr) 19 | mBuffer.position(0) 20 | return mBuffer 21 | } 22 | 23 | 24 | /** 25 | * 将float[]数组转为OpenGl 所需要的FloatBuffer 26 | */ 27 | fun floatBufferUtil(arr: FloatArray): FloatBuffer { 28 | val mBuffer: FloatBuffer 29 | // 初始化ByteBuffer,长度为arr数组的长度*4,因为一个int占4个字节 30 | val qbb = ByteBuffer.allocateDirect(arr.size * Constants.BYTES_PER_FLOAT) 31 | // 数组排列用nativeOrder 32 | qbb.order(ByteOrder.nativeOrder()) 33 | mBuffer = qbb.asFloatBuffer() 34 | mBuffer.put(arr) 35 | mBuffer.position(0) 36 | return mBuffer 37 | } 38 | 39 | 40 | /** 41 | * 将short[]转ShortBuffer 42 | */ 43 | fun shortBufferUtil(arr: ShortArray): ShortBuffer { 44 | val mBuffer: ShortBuffer 45 | // 初始化ByteBuffer,长度为arr数组的长度*2,因为一个short占2个字节 46 | val dlb = ByteBuffer.allocateDirect( // (# of coordinate values * 2 bytes per short) 47 | arr.size * Constants.BYTES_PER_SHORT 48 | ) 49 | dlb.order(ByteOrder.nativeOrder()) 50 | mBuffer = dlb.asShortBuffer() 51 | mBuffer.put(arr) 52 | mBuffer.position(0) 53 | return mBuffer 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/ResReadUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | import android.content.res.Resources 4 | import android.util.Log 5 | import java.io.BufferedReader 6 | import java.io.IOException 7 | import java.io.InputStream 8 | import java.io.InputStreamReader 9 | 10 | object ResReadUtils { 11 | 12 | /** 13 | * 读取资源 14 | * 15 | * @param resourceId 16 | * @return 17 | */ 18 | fun readResource(resourceId: Int): String { 19 | val builder = StringBuilder() 20 | try { 21 | val inputStream: InputStream = 22 | AppUtils.getApplication()!!.resources.openRawResource(resourceId) 23 | val streamReader = InputStreamReader(inputStream) 24 | val bufferedReader = BufferedReader(streamReader) 25 | bufferedReader.readLines().forEach { 26 | builder.append(it) 27 | builder.append("\n") 28 | } 29 | } catch (e: IOException) { 30 | e.printStackTrace() 31 | } catch (e: Resources.NotFoundException) { 32 | e.printStackTrace() 33 | } 34 | return builder.toString() 35 | } 36 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/ShaderUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | 4 | import android.opengl.GLES30.* 5 | import android.util.Log 6 | 7 | 8 | object ShaderUtils { 9 | 10 | /** 11 | * 加载shader 12 | */ 13 | fun loadShader(type: Int, shaderCode: String): Int { 14 | val shaderObjectId = glCreateShader(type) 15 | if (shaderObjectId == 0) { 16 | Log.e("ShaderUtils", "着色器创建失败:$shaderObjectId") 17 | return 0 18 | } 19 | // 添加上面编写的着色器代码并编译它 20 | glShaderSource(shaderObjectId, shaderCode) 21 | glCompileShader(shaderObjectId) 22 | 23 | val compileStatus = intArrayOf(0) 24 | glGetShaderiv(shaderObjectId, GL_COMPILE_STATUS, compileStatus, 0); 25 | if (compileStatus[0] == 0) { 26 | //失败 删除着色器 27 | glDeleteShader(shaderObjectId) 28 | Log.e("ShaderUtils", "着色器编译失败:$shaderCode") 29 | return 0 30 | } 31 | return shaderObjectId 32 | } 33 | 34 | 35 | /** 36 | * 加载顶点着色器 37 | */ 38 | fun loadVertexShader(shaderCode: String): Int { 39 | return loadShader(GL_VERTEX_SHADER, shaderCode) 40 | } 41 | 42 | /** 43 | * 加载片段着色器 44 | */ 45 | fun loadFragmentShader(shaderCode: String): Int { 46 | return loadShader(GL_FRAGMENT_SHADER, shaderCode) 47 | } 48 | 49 | 50 | /** 51 | * shader和 Program 连接起来 52 | */ 53 | fun linkProgram(vertexShaderId: Int, fragmentShaderId: Int): Int { 54 | val programObjectId = glCreateProgram() 55 | if (programObjectId == 0) { 56 | Log.e("ShaderUtils", "OpenGL SE 2 创建Program 失败!") 57 | return 0 58 | } 59 | glAttachShader(programObjectId, vertexShaderId) 60 | glAttachShader(programObjectId, fragmentShaderId) 61 | 62 | glLinkProgram(programObjectId) 63 | val compileStatus = IntArray(1) 64 | glGetProgramiv(programObjectId, GL_LINK_STATUS, compileStatus, 0) 65 | if (compileStatus[0] == 0) { 66 | 67 | val logInfo = glGetProgramInfoLog(programObjectId) 68 | //失败 删除 69 | glDeleteProgram(programObjectId) 70 | Log.e("ShaderUtils", "OpenGL SE 2 连接Program 失败! $programObjectId $vertexShaderId $fragmentShaderId $logInfo") 71 | return 0 72 | } 73 | return programObjectId 74 | } 75 | 76 | /** 77 | * 检测当前Program 是否有效 78 | */ 79 | fun validateProgram(programObjectId: Int): Boolean { 80 | glValidateProgram(programObjectId) 81 | val compileStatus = intArrayOf(0) 82 | glGetProgramiv(programObjectId, GL_VALIDATE_STATUS, compileStatus, 0) 83 | val isValidate = compileStatus[0] != 0 84 | if (!isValidate) { 85 | Log.e("ShaderUtils", "OpenGL SE 2 Program 无效") 86 | } 87 | return isValidate 88 | } 89 | } -------------------------------------------------------------------------------- /NBEffects/src/main/java/cn/wufuqi/nbeffects/utils/TextureUtils.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects.utils 2 | 3 | import android.graphics.Bitmap 4 | import android.graphics.BitmapFactory 5 | import android.opengl.GLES30 6 | import android.opengl.GLES30.* 7 | import android.opengl.GLUtils 8 | import android.util.Log 9 | 10 | 11 | object TextureUtils { 12 | 13 | private const val TAG = "TextureUtils" 14 | 15 | fun loadTexture(resourceId: Int): Int { 16 | return loadTexture(BitmapUtils.getBitmap(resourceId)) 17 | } 18 | 19 | 20 | fun loadTexture(bitmap: Bitmap?): Int { 21 | val textureIds = IntArray(1) 22 | glGenTextures(1, textureIds, 0) 23 | if (textureIds[0] == 0) { 24 | Log.e(TAG, "无法生成一个新的OpenGL textureId对象") 25 | return 0 26 | } 27 | 28 | if (bitmap == null) { 29 | Log.e(BitmapUtils.TAG, "无法绑定bitmap. bitmap is null") 30 | glDeleteTextures(1, textureIds, 0) 31 | return 0 32 | } 33 | 34 | // 绑定纹理到OpenGL 35 | glBindTexture(GL_TEXTURE_2D, textureIds[0]) 36 | 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) 39 | 40 | // 加载bitmap到纹理中 41 | GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0) 42 | 43 | // 生成MIP贴图 44 | glGenerateMipmap(GL_TEXTURE_2D) 45 | 46 | // // 数据如果已经被加载进OpenGL,则可以回收该bitmap 47 | // bitmap.recycle() 48 | 49 | // 取消绑定纹理 50 | glBindTexture(GL_TEXTURE_2D, 0) 51 | 52 | return textureIds[0] 53 | } 54 | 55 | 56 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/adjustment_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | 9 | uniform float gamma; 10 | uniform float contrast; 11 | uniform float saturation; 12 | uniform float brightness; 13 | uniform float red; 14 | uniform float green; 15 | uniform float blue; 16 | uniform float alpha; 17 | 18 | void main(void) 19 | { 20 | vec4 c = texture(uTextureUnit, vTexCoord); 21 | 22 | if (c.a > 0.0) { 23 | c.rgb /= c.a; 24 | 25 | vec3 rgb = pow(c.rgb, vec3(1. / gamma)); 26 | rgb = mix(vec3(.5), mix(vec3(dot(vec3(.2125, .7154, .0721), rgb)), rgb, saturation), contrast); 27 | rgb.r *= red; 28 | rgb.g *= green; 29 | rgb.b *= blue; 30 | c.rgb = rgb * brightness; 31 | 32 | c.rgb *= c.a; 33 | } 34 | 35 | vFragColor = c * alpha; 36 | } 37 | -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/ascii_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | 9 | uniform vec4 filterArea; 10 | uniform float pixelSize; 11 | 12 | vec2 mapCoord( vec2 coord ) 13 | { 14 | coord *= filterArea.xy; 15 | coord += filterArea.zw; 16 | 17 | return coord; 18 | } 19 | 20 | vec2 unmapCoord( vec2 coord ) 21 | { 22 | coord -= filterArea.zw; 23 | coord /= filterArea.xy; 24 | 25 | return coord; 26 | } 27 | 28 | vec2 pixelate(vec2 coord, vec2 size) 29 | { 30 | return floor( coord / size ) * size; 31 | } 32 | 33 | vec2 getMod(vec2 coord, vec2 size) 34 | { 35 | return mod( coord , size) / size; 36 | } 37 | 38 | float character(float n, vec2 p) 39 | { 40 | p = floor(p*vec2(4.0, -4.0) + 2.5); 41 | 42 | if (clamp(p.x, 0.0, 4.0) == p.x) 43 | { 44 | if (clamp(p.y, 0.0, 4.0) == p.y) 45 | { 46 | if (int(mod(n/exp2(p.x + 5.0*p.y), 2.0)) == 1) return 1.0; 47 | } 48 | } 49 | return 0.0; 50 | } 51 | 52 | void main() 53 | { 54 | vec2 coord = mapCoord(vTexCoord); 55 | 56 | // get the rounded color.. 57 | vec2 pixCoord = pixelate(coord, vec2(pixelSize)); 58 | pixCoord = unmapCoord(pixCoord); 59 | 60 | vec4 color = texture(uTextureUnit, pixCoord); 61 | 62 | // determine the character to use 63 | float gray = (color.r + color.g + color.b) / 3.0; 64 | 65 | float n = 65536.0; // . 66 | if (gray > 0.2) n = 65600.0; // : 67 | if (gray > 0.3) n = 332772.0; // * 68 | if (gray > 0.4) n = 15255086.0; // o 69 | if (gray > 0.5) n = 23385164.0; // & 70 | if (gray > 0.6) n = 15252014.0; // 8 71 | if (gray > 0.7) n = 13199452.0; // @ 72 | if (gray > 0.8) n = 11512810.0; // # 73 | 74 | // get the mod.. 75 | vec2 modd = getMod(coord, vec2(pixelSize)); 76 | 77 | vFragColor = color * character( n, vec2(-1.0) + modd * 2.0); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/base_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | void main() { 9 | vFragColor = texture(uTextureUnit,vTexCoord); 10 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/base_filter_vertex_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | layout (location = 0) in vec4 vPosition; 3 | layout (location = 1) in vec2 aTextureCoord; 4 | 5 | uniform mat4 u_Matrix; 6 | 7 | out vec2 vTexCoord; 8 | void main() { 9 | gl_Position = u_Matrix * vPosition; 10 | vTexCoord = aTextureCoord; 11 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/bevel_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform vec4 filterArea; 9 | 10 | uniform float transformX; 11 | uniform float transformY; 12 | uniform vec3 lightColor; 13 | uniform float lightAlpha; 14 | uniform vec3 shadowColor; 15 | uniform float shadowAlpha; 16 | 17 | void main(void) { 18 | vec2 transform = vec2(1.0 / filterArea) * vec2(transformX, transformY); 19 | vec4 color = texture(uTextureUnit, vTexCoord); 20 | float light = texture(uTextureUnit, vTexCoord - transform).a; 21 | float shadow = texture(uTextureUnit, vTexCoord + transform).a; 22 | 23 | color.rgb = mix(color.rgb, lightColor, clamp((color.a - light) * lightAlpha, 0.0, 1.0)); 24 | color.rgb = mix(color.rgb, shadowColor, clamp((color.a - shadow) * shadowAlpha, 0.0, 1.0)); 25 | vFragColor = vec4(color.rgb * color.a, color.a); 26 | } 27 | -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/dissolve_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | 9 | uniform float dissolve; 10 | 11 | void main(void){ 12 | vec4 c = texture(uTextureUnit,vTexCoord); 13 | if(c.g < dissolve) 14 | { 15 | discard; 16 | } 17 | vFragColor = c; 18 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/dynamic_blur_transfer_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform float time; 9 | 10 | #define SAMPLES 10 11 | #define SHARPNESS 4.0 12 | #define SAMPLES_F float(SAMPLES) 13 | #define TAU 6.28318530718 14 | #define HASHSCALE1 443.8975 15 | 16 | float hash13(vec3 p3) 17 | { 18 | p3 = fract(p3 * HASHSCALE1); 19 | p3 += dot(p3, p3.yzx + 19.19); 20 | return fract((p3.x + p3.y) * p3.z); 21 | } 22 | 23 | void main(void){ 24 | float r = 0.05 + 0.05 * sin(time*.2*TAU+4.3); 25 | 26 | float d = (r * 2.0 * vTexCoord.x) / SAMPLES_F; 27 | float lod = log2(max(d / SHARPNESS, 1.0)); 28 | 29 | vec4 colorRead = vec4(0.0, 0.0, 0.0, 0.0); 30 | for (int i = 0; i < SAMPLES; ++i) 31 | { 32 | float fi = float(i); 33 | float rnd = hash13(vec3(vTexCoord.xy, fi)); 34 | float f = (fi + rnd) / SAMPLES_F; 35 | f = (f * 2.0 - 1.0) * r; 36 | colorRead += texture(uTextureUnit, vTexCoord + vec2(f, 0.0), lod); 37 | } 38 | colorRead = colorRead / SAMPLES_F; 39 | vFragColor = colorRead; 40 | 41 | vFragColor.w = 2.25 - time; 42 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/gauss_blurs_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform vec4 color; 9 | uniform float bluramount; 10 | 11 | vec4 draw(vec2 uv) { 12 | return texture(uTextureUnit, uv); 13 | } 14 | 15 | float grid(float var, float size) { 16 | return floor(var*size)/size; 17 | } 18 | 19 | float rand(vec2 co){ 20 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); 21 | } 22 | void mainImage( out vec4 vFragColor, in vec2 vTexCoord ) 23 | { 24 | vec2 uv = vTexCoord.xy; 25 | vec4 blurred_image = vec4(0.); 26 | #define repeats 5. 27 | for (float i = 0.; i < repeats; i++) { 28 | vec2 q = vec2(cos(degrees((i/repeats)*360.)),sin(degrees((i/repeats)*360.))) * (rand(vec2(i,uv.x+uv.y))+bluramount); 29 | vec2 uv2 = uv+(q*bluramount); 30 | blurred_image += draw(uv2)/2.; 31 | q = vec2(cos(degrees((i/repeats)*360.)),sin(degrees((i/repeats)*360.))) * (rand(vec2(i+2.,uv.x+uv.y+24.))+bluramount); 32 | uv2 = uv+(q*bluramount); 33 | blurred_image += draw(uv2)/2.; 34 | } 35 | blurred_image /= repeats; 36 | vFragColor = vec4(blurred_image); 37 | } 38 | void main(void){ 39 | mainImage(vFragColor, vTexCoord.xy); 40 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/gray_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | 5 | uniform vec3 color; 6 | in vec2 vTexCoord; 7 | 8 | //输出 9 | out vec4 vFragColor; 10 | void main() { 11 | vec4 vTextureColor = texture(uTextureUnit,vTexCoord); 12 | float vFilterColor = (color.x * vTextureColor.r + color.y * vTextureColor.g + color.z * vTextureColor.b); 13 | vFragColor = vec4(vFilterColor, vFilterColor, vFilterColor, vTextureColor.a); 14 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/mosaic_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform vec3 iResolution; 9 | uniform float mosaicSize; 10 | uniform vec4 color; 11 | 12 | void main(void){ 13 | vec4 colorRead; 14 | vec2 xy = vec2(vTexCoord.x * iResolution.x, vTexCoord.y * iResolution.y); 15 | vec2 xyMosaic = vec2(floor(xy.x / mosaicSize) * mosaicSize, floor(xy.y / mosaicSize) * mosaicSize); 16 | vec2 xyFloor = vec2(floor(mod(xy.x, mosaicSize)), floor(mod(xy.y, mosaicSize))); 17 | vec2 uvMosaic = vec2(xyMosaic.x / iResolution.x, xyMosaic.y / iResolution.y); 18 | vFragColor = texture( uTextureUnit, uvMosaic); 19 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/quarter_mirror_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | void main() { 9 | vec2 uv = vTexCoord; 10 | if (uv.x <= 0.5) { 11 | uv.x = uv.x * 2.0; 12 | } else { 13 | uv.x = (uv.x - 0.5) * 2.0; 14 | } 15 | if (uv.y <= 0.5) { 16 | uv.y = uv.y * 2.0; 17 | } else { 18 | uv.y = (uv.y - 0.5) * 2.0; 19 | } 20 | vFragColor = texture(uTextureUnit,fract(uv)); 21 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/radial_blur_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform vec3 iResolution; 9 | uniform vec2 iCenter; 10 | 11 | void mainImage( out vec4 vFragColor, in vec2 vTexCoord ) 12 | { 13 | //const float Strength = 0.125; 14 | const float Strength = 0.015; 15 | const int Samples = 64; //multiple of 2 16 | 17 | vec2 uv = vTexCoord.xy; 18 | 19 | vec2 dir = (vTexCoord.xy-iCenter.xy); 20 | 21 | vec4 colorRead = vec4(0.0,0.0,0.0,0.0); 22 | 23 | for (int i = 0; i < Samples; i += 2) //operating at 2 samples for better performance 24 | { 25 | colorRead += texture(uTextureUnit,uv+float(i)/float(Samples)*dir*Strength); 26 | colorRead += texture(uTextureUnit,uv+float(i+1)/float(Samples)*dir*Strength); 27 | } 28 | 29 | vFragColor = colorRead/float(Samples); 30 | } 31 | void main(void){ 32 | mainImage(vFragColor, vTexCoord); 33 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/rain_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | #define S(a, b, t) smoothstep(a, b, t) 3 | precision mediump float; 4 | uniform sampler2D uTextureUnit; 5 | in vec2 vTexCoord; 6 | //输出 7 | out vec4 vFragColor; 8 | 9 | uniform vec3 iResolution; 10 | uniform float iTime; 11 | uniform vec2 texSize; 12 | 13 | vec3 N13(float p) { 14 | // from DAVE HOSKINS 15 | vec3 p3 = fract(vec3(p) * vec3(.1031, .11369, .13787)); 16 | p3 += dot(p3, p3.yzx + 19.19); 17 | return fract(vec3((p3.x + p3.y) * p3.z, (p3.x + p3.z) * p3.y, (p3.y + p3.z) * p3.x)); 18 | } 19 | 20 | vec4 N14(float t) { 21 | return fract(sin(t * vec4(123., 1024., 1456., 264.)) * vec4(6547., 345., 8799., 1564.)); 22 | } 23 | float N(float t) { 24 | return fract(sin(t * 12345.564) * 7658.76); 25 | } 26 | 27 | float Saw(float b, float t) { 28 | return S(0., b, t) * S(1., b, t); 29 | } 30 | 31 | vec2 DropLayer2(vec2 uv, float t) { 32 | vec2 UV = uv; 33 | 34 | uv.y += t * 0.75; 35 | vec2 a = vec2(6., 1.); 36 | vec2 grid = a * 2.; 37 | vec2 id = floor(uv * grid); 38 | 39 | float colShift = N(id.x); 40 | uv.y += colShift; 41 | 42 | id = floor(uv * grid); 43 | vec3 n = N13(id.x * 35.2 + id.y * 2376.1); 44 | vec2 st = fract(uv * grid) - vec2(.5, 0); 45 | 46 | float x = n.x - .5; 47 | 48 | float y = UV.y * 20.; 49 | float wiggle = sin(y + sin(y)); 50 | x += wiggle * (.5 - abs(x)) * (n.z - .5); 51 | x *= .7; 52 | float ti = fract(t + n.z); 53 | y = (Saw(.85, ti) - .5) * .9 + .5; 54 | vec2 p = vec2(x, y); 55 | 56 | float d = length((st - p) * a.yx); 57 | 58 | float mainDrop = S(.4, .0, d); 59 | 60 | float r = sqrt(S(1., y, st.y)); 61 | float cd = abs(st.x - x); 62 | float trail = S(.23 * r, .15 * r * r, cd); 63 | float trailFront = S(-.02, .02, st.y - y); 64 | trail *= trailFront * r * r; 65 | 66 | y = UV.y; 67 | float trail2 = S(.2 * r, .0, cd); 68 | float droplets = max(0., (sin(y * (1. - y) * 120.) - st.y)) * trail2 * trailFront * n.z; 69 | y = fract(y * 10.) + (st.y - .5); 70 | float dd = length(st - vec2(x, y)); 71 | droplets = S(.3, 0., dd); 72 | float m = mainDrop + droplets * r * trailFront; 73 | 74 | //m += st.x>a.y*.45 || st.y>a.x*.165 ? 1.2 : 0.; 75 | return vec2(m, trail); 76 | } 77 | 78 | float StaticDrops(vec2 uv, float t) { 79 | uv *= 40.; 80 | 81 | vec2 id = floor(uv); 82 | uv = fract(uv) - .5; 83 | vec3 n = N13(id.x * 107.45 + id.y * 3543.654); 84 | vec2 p = (n.xy - .5) * .7; 85 | float d = length(uv - p); 86 | 87 | float fade = Saw(.025, fract(t + n.z)); 88 | float c = S(.3, 0., d) * fract(n.z * 10.) * fade; 89 | return c; 90 | } 91 | 92 | vec2 Drops(vec2 uv, float t, float l0, float l1, float l2) { 93 | float s = StaticDrops(uv, t) * l0; 94 | vec2 m1 = DropLayer2(uv, t) * l1; 95 | vec2 m2 = DropLayer2(uv * 1.85, t) * l2; 96 | 97 | float c = s + m1.x + m2.x; 98 | c = S(.3, 1., c); 99 | 100 | return vec2(c, max(m1.y * l0, m2.y * l1)); 101 | } 102 | 103 | void main() 104 | { 105 | vec4 iMouse = vec4(0.0, 0.0, 0.0, 0.0); 106 | vec2 fragCoord = vec2(vTexCoord.x * texSize.x - 0.5 * texSize.x, 0.5 * texSize.y - vTexCoord.y * texSize.y); 107 | vec2 uv = fragCoord.xy / iResolution.y; 108 | vec2 UV = (fragCoord.xy+.5*iResolution.xy) / iResolution.xy; 109 | vec3 M = iMouse.xyz/iResolution.xyz; 110 | float T = iTime+M.x*2.; 111 | 112 | #ifdef HAS_HEART 113 | T = mod(iTime, 102.); 114 | T = mix(T, M.x*102., M.z>0.?1.:0.); 115 | #endif 116 | 117 | float t = T*.2; 118 | 119 | float rainAmount = iMouse.z>0. ? M.y : sin(T*.05)*.3+.7; 120 | 121 | float maxBlur = mix(3., 6., rainAmount); 122 | float minBlur = 2.; 123 | 124 | float story = 0.; 125 | float heart = 0.; 126 | 127 | #ifdef HAS_HEART 128 | story = S(0., 70., T); 129 | 130 | t = min(1., T/70.); // remap drop time so it goes slower when it freezes 131 | t = 1.-t; 132 | t = (1.-t*t)*70.; 133 | 134 | float zoom= mix(.3, 1.2, story); // slowly zoom out 135 | uv *=zoom; 136 | minBlur = 4.+S(.5, 1., story)*3.; // more opaque glass towards the end 137 | maxBlur = 6.+S(.5, 1., story)*1.5; 138 | 139 | vec2 hv = uv-vec2(.0, -.1); // build heart 140 | hv.x *= .5; 141 | float s = S(110., 70., T); // heart gets smaller and fades towards the end 142 | hv.y-=sqrt(abs(hv.x))*.5*s; 143 | heart = length(hv); 144 | heart = S(.4*s, .2*s, heart)*s; 145 | rainAmount = heart; // the rain is where the heart is 146 | 147 | maxBlur-=heart; // inside the heart slighly less foggy 148 | uv *= 1.5; // zoom out a bit more 149 | t *= .25; 150 | #else 151 | float zoom = -cos(T*.2); 152 | uv *= .7+zoom*.3; 153 | #endif 154 | UV = (UV-.5)*(.9+zoom*.1)+.5; 155 | 156 | float staticDrops = S(-.5, 1., rainAmount)*2.; 157 | float layer1 = S(.25, .75, rainAmount); 158 | float layer2 = S(.0, .5, rainAmount); 159 | 160 | vec2 c = Drops(uv, t, staticDrops, layer1, layer2); 161 | #ifdef CHEAP_NORMALS 162 | vec2 n = vec2(dFdx(c.x), dFdy(c.x));// cheap normals (3x cheaper, but 2 times shittier ;)) 163 | #else 164 | vec2 e = vec2(.001, 0.); 165 | float cx = Drops(uv+e, t, staticDrops, layer1, layer2).x; 166 | float cy = Drops(uv+e.yx, t, staticDrops, layer1, layer2).x; 167 | vec2 n = vec2(cx-c.x, cy-c.x); // expensive normals 168 | #endif 169 | 170 | #ifdef HAS_HEART 171 | n *= 1.-S(60., 85., T); 172 | c.y *= 1.-S(80., 100., T)*.8; 173 | #endif 174 | 175 | float focus = mix(maxBlur-c.y, minBlur, S(.1, .2, c.x)); 176 | vec3 col = texture(uTextureUnit, UV+n).rgb; 177 | // vec3 col = texture(uTextureUnit, n).rgb; 178 | // make time sync with first lightnoing 179 | 180 | #ifdef USE_POST_PROCESSING 181 | t = (T+3.)*.5; 182 | float colFade = sin(t*.2)*.5+.5+story; 183 | col *= mix(vec3(1.), vec3(.8, .9, 1.3), colFade); // subtle color shift 184 | float fade = S(0., 10., T); // fade in at the start 185 | float lightning = sin(t*sin(t*10.)); // lighting flicker 186 | lightning *= pow(max(0., sin(t+sin(t))), 10.); // lightning flash 187 | col *= 1.+lightning*fade*mix(1., .1, story*story); // composite lightning 188 | col *= 1.-dot(UV-=.5, UV); // vignette 189 | 190 | #ifdef HAS_HEART 191 | col = mix(pow(col, vec3(1.2)), col, heart); 192 | fade *= S(102., 97., T); 193 | #endif 194 | 195 | col *= fade; // composite start and end fade 196 | #endif 197 | 198 | //col = vec3(heart); 199 | vFragColor = vec4(col, 1.); 200 | // vFragColor = texture(uTextureUnit,vTexCoord); 201 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/unfold_transfer_filter_vertex_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform float time; 9 | 10 | void main() 11 | { 12 | vec4 result = vec4(1.0,1.0,1.0,1.0); 13 | vec2 translate = vec2(vTexCoord.x,vTexCoord.y); 14 | result = texture(uTextureUnit, vTexCoord); 15 | 16 | // Calculate modulo to decide even and odd row 17 | float div = 2.0; 18 | float num = floor(vTexCoord.y * 10.0); 19 | float odd = num - (div * floor(num/div)); 20 | 21 | float t = mod(time,1.0); 22 | 23 | //Only do the odd number 24 | if( odd == 0.0){ 25 | translate.x = translate.x - t; 26 | result = texture(uTextureUnit,translate); 27 | if(translate.x < 0.0){ 28 | discard; 29 | } 30 | } 31 | else{ 32 | translate.x = translate.x + t; 33 | result = texture(uTextureUnit,translate); 34 | if(translate.x > 1.0){ 35 | discard; 36 | } 37 | } 38 | 39 | // Output to screen 40 | vFragColor = result; 41 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/water_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | //输出 6 | uniform float iTime; 7 | uniform vec3 iResolution; 8 | 9 | //输出 10 | out vec4 vFragColor; 11 | 12 | 13 | #define F cos(x-y)*cos(y),sin(x+y)*sin(y) 14 | 15 | vec2 s(vec2 p) 16 | { 17 | float d=iTime*0.2,x=8.*(p.x+d),y=8.*(p.y+d); 18 | return vec2(F); 19 | } 20 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 21 | { 22 | // 换成resolution 23 | vec2 rs = iResolution.xy; 24 | // 换成纹理坐标v_texCoord.xy 25 | vec2 uv = fragCoord; 26 | vec2 q = uv+2./iResolution.x*(s(uv)-s(uv+rs)); 27 | //反转y 28 | //q.y=1.-q.y; 29 | fragColor = texture(uTextureUnit, q); 30 | } 31 | void main() 32 | { 33 | mainImage(vFragColor, vTexCoord.xy); 34 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/wave_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | //输出 6 | uniform float iTime; 7 | uniform vec2 iOffset; 8 | 9 | //输出 10 | out vec4 vFragColor; 11 | 12 | void main() { 13 | vec2 coord = vTexCoord; 14 | coord.x += (sin(coord.y * 30.0 + iTime * 3.0) / 30.0 * iOffset[0]); 15 | coord.y += (sin(coord.x * 30.0 + iTime * 3.0) / 30.0 * iOffset[1]); 16 | vFragColor = texture(uTextureUnit, coord); 17 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/window_transfer_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | 9 | uniform float transfer; 10 | 11 | void main() 12 | { 13 | 14 | float dur = 2.; 15 | float dim = 7.; 16 | vec2 v = vTexCoord; 17 | v.y=1.-v.y; 18 | vec2 x = mod(1.-v.xx, 1./dim)+floor(v*dim)/dim; 19 | float a = .5*(abs(x.x)+abs(x.y)); 20 | float b = fract(transfer/dur); 21 | a=a>b?0.:1.; 22 | bool mt = mod(floor(transfer/dur),2.)==0.; 23 | float cd = a; 24 | if (mt) 25 | { 26 | cd=1.-cd; 27 | } 28 | vec4 colore = vec4(0.5,0.2,0.3, 0.01); 29 | vFragColor = mix(vec4(a),(mix(texture(uTextureUnit, vTexCoord), colore, cd)), 1.); 30 | 31 | } -------------------------------------------------------------------------------- /NBEffects/src/main/res/raw/zoom_blur_transfer_filter_fragment_shader.glsl: -------------------------------------------------------------------------------- 1 | #version 300 es 2 | precision mediump float; 3 | uniform sampler2D uTextureUnit; 4 | in vec2 vTexCoord; 5 | 6 | //输出 7 | out vec4 vFragColor; 8 | uniform float time; 9 | 10 | const float strength = 0.3; 11 | const float PI = 3.141592653589793; 12 | 13 | float Linear_ease(in float begin, in float change, in float duration, in float time) { 14 | return change * time / duration + begin; 15 | } 16 | 17 | float Exponential_easeInOut(in float begin, in float change, in float duration, in float time) { 18 | if (time == 0.0) 19 | return begin; 20 | else if (time == duration) 21 | return begin + change; 22 | time = time / (duration / 2.0); 23 | if (time < 1.0) 24 | return change / 2.0 * pow(2.0, 10.0 * (time - 1.0)) + begin; 25 | return change / 2.0 * (-pow(2.0, -10.0 * (time - 1.0)) + 2.0) + begin; 26 | } 27 | 28 | float Sinusoidal_easeInOut(in float begin, in float change, in float duration, in float time) { 29 | return -change / 2.0 * (cos(PI * time / duration) - 1.0) + begin; 30 | } 31 | 32 | float random(in vec3 scale, in float seed) { 33 | return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed); 34 | } 35 | 36 | vec4 crossFade(in vec2 uv, in float dissolve) { 37 | vec4 colore = vec4(0.0,0.0,0.0,0.0); 38 | return mix(texture(uTextureUnit, uv), colore, dissolve); 39 | } 40 | 41 | void main() 42 | { 43 | float progress = sin(time*0.5) * 0.5 + 0.5; 44 | vec2 center = vec2(Linear_ease(0.5, 0.0, 1.0, progress),0.5); 45 | float dissolve = Exponential_easeInOut(0.0, 1.0, 1.0, progress); 46 | 47 | float strength = Sinusoidal_easeInOut(0.0, strength, 0.5, progress); 48 | 49 | vec4 colorx = vec4(0.0); 50 | float total = 0.0; 51 | vec2 toCenter = center - vTexCoord; 52 | 53 | float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0)*0.5; 54 | 55 | for (float t = 0.0; t <= 20.0; t++) { 56 | float percent = (t + offset) / 20.0; 57 | float weight = 1.0 * (percent - percent * percent); 58 | colorx += crossFade(vTexCoord + toCenter * percent * strength, dissolve) * weight; 59 | total += weight; 60 | } 61 | vFragColor = colorx / total; 62 | } -------------------------------------------------------------------------------- /NBEffects/src/test/java/cn/wufuqi/nbeffects/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.nbeffects 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 一个很牛逼的特效库,如水波纹雨滴实时高斯模糊等 3 | ``` 4 | 5 | 6 | #### 基础功能 7 | 1. 添加依赖 8 | 9 | 请在 build.gradle 下添加依赖。 10 | 11 | ``` 12 | implementation 'cn.wufuqi:NBEffects:1.0.1' 13 | ``` 14 | 15 | 16 | 2. 设置jdk8或更高版本 17 | 18 | 因为本sdk使用了jdk8才能使用的 Lambda 表达式,所以要在 build.gradle 下面配置jdk8或以上版本。 19 | 20 | ``` 21 | android { 22 | .... 23 | 24 | compileOptions { 25 | sourceCompatibility JavaVersion.VERSION_1_8 26 | targetCompatibility JavaVersion.VERSION_1_8 27 | } 28 | 29 | } 30 | ``` 31 | 32 | 3. 使用imageview 33 | 34 | ``` 35 | 39 | ``` 40 | 41 | 或者 42 | 43 | ``` 44 | val iv = NBEffectsImageView(context) 45 | addView(iv) 46 | ``` 47 | 48 | 4. 设置图片 49 | 50 | ``` 51 | img.setImageRes(R.drawable.fj) 52 | img.setImageDrawable(drawable) 53 | img.setImageBitmap(bitmap) 54 | ``` 55 | 56 | 5. 图片展开方式 57 | 58 | ``` 59 | // 默认是 OpenGLImageRenderType.AUTO_NO_BACK 60 | img.setOpenGLImageRenderType(OpenGLImageRenderType.AUTO_NO_BACK) 61 | ``` 62 | 63 | OpenGLImageRenderType 说明: 64 | 65 | ``` 66 | FLEX 等高等宽拉伸 67 | EQUAL_WIDTH 等宽的,高度使用图片的比例自适应 68 | EQUAL_HEIGHT 等高的,宽度使用图片的比例自适应 69 | AUTO_NO_BACK 自适应 EQUAL_WIDTH 和 EQUAL_HEIGHT,不留黑边 70 | ``` 71 | 72 | 73 | 4. 去掉黑边,为了适应EQUAL_WIDTH和EQUAL_HEIGHT 74 | 75 | ``` 76 | //设置之后 就没有背景黑色。但是UI会被显示在最顶部,设置的UI显示顺序不起作用。 77 | img.setTranslucent(true) 78 | ``` 79 | 80 | 81 | 5. 设置过滤器 82 | 83 | 当设置过滤器后,图片将会在显卡重新计算图形。可以重复更换过滤器。 84 | 85 | ``` 86 | // 如果不设置过滤器,默认为:BaseFilter这个过滤器。 87 | img.setFilter(BaseFilter()) 88 | ``` 89 | 90 | 91 | ## 过滤器(Filter)介绍 92 | 93 | 94 | #### DissolveFilter 95 | 演示: 96 | ![DissolveFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/DissolveFilter.gif) 97 | 98 | 使用方式 99 | 100 | ``` 101 | val filter = DissolveFilter() 102 | 103 | //溶解的值 0-1 104 | filter.dissolve = 0 - 1 105 | //渐入 106 | filter.fadeIn(500) 107 | //渐出 108 | filter.fadeOut(500) 109 | //指定到某个值 110 | filter.fadeTo(500) 111 | 112 | img.setFilter(filter) 113 | ``` 114 | 115 | 116 | 117 | #### DynamicBlurTransferFilter 118 | 演示: 119 | ![DynamicBlurTransferFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/DynamicBlurTransferFilter.gif) 120 | 121 | 使用方式 122 | 123 | ``` 124 | val filter = DynamicBlurTransferFilter() 125 | 126 | //值 0-1 127 | filter.transfer = 0 - 1 128 | //渐入 129 | filter.fadeIn(500) 130 | //渐出 131 | filter.fadeOut(500) 132 | //指定到某个值 133 | filter.fadeTo(500) 134 | 135 | img.setFilter(filter) 136 | ``` 137 | 138 | 139 | 140 | #### GaussBlursFilter 141 | 演示: 142 | ![GaussBlursFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/GaussBlursFilter.png) 143 | 144 | 使用方式 145 | 146 | ``` 147 | val filter = GaussBlursFilter() 148 | 149 | filter.blur = 2f //.... 150 | 151 | img.setFilter(filter) 152 | ``` 153 | 154 | 155 | 156 | #### GrayFilter 157 | 演示: 158 | ![GrayFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/GrayFilter.png) 159 | 160 | 使用方式 161 | 162 | ``` 163 | val filter = GrayFilter() 164 | 165 | img.setFilter(filter) 166 | ``` 167 | 168 | 169 | #### MosaicFilter 170 | 演示: 171 | ![MosaicFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/MosaicFilter.png) 172 | 173 | 使用方式 174 | 175 | ``` 176 | val filter = MosaicFilter() 177 | 178 | // 方形马赛克的宽高大小 px 179 | filter.mosaicSize = 2f //0 - 屏幕大小 180 | 181 | img.setFilter(filter) 182 | ``` 183 | 184 | #### QuarterMirrorFilter 185 | 演示: 186 | ![QuarterMirrorFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/QuarterMirrorFilter.png) 187 | 188 | 189 | 使用方式 190 | 191 | ``` 192 | val filter = QuarterMirrorFilter() 193 | 194 | img.setFilter(filter) 195 | ``` 196 | 197 | #### RadialBlurFilter 198 | 演示: 199 | ![RadialBlurFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/RadialBlurFilter.png) 200 | 201 | 使用方式 202 | 203 | ``` 204 | val filter = RadialBlurFilter() 205 | 206 | filter.center = 2f //.... 207 | 208 | img.setFilter(filter) 209 | ``` 210 | 211 | 212 | #### RainFilter 213 | 演示: 214 | ![RainFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/RainFilter.gif) 215 | 216 | 使用方式 217 | 218 | ``` 219 | val filter = RainFilter() 220 | 221 | img.setFilter(filter) 222 | ``` 223 | 224 | 225 | 226 | #### UnfoldTransferFilter 227 | 演示: 228 | ![UnfoldTransferFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/UnfoldTransferFilter.gif) 229 | 230 | 使用方式 231 | 232 | ``` 233 | val filter = UnfoldTransferFilter() 234 | 235 | //值 0-1 236 | filter.transfer = 0 - 1 0 - 2 237 | 238 | filter.transferAmin(500) 239 | //渐入 240 | filter.fadeIn(500) 241 | //渐出 242 | filter.fadeOut(500) 243 | //指定到某个值 244 | filter.fadeTo(500) 245 | 246 | img.setFilter(filter) 247 | ``` 248 | 249 | 250 | 251 | 252 | #### WaterFilter 253 | 演示: 254 | ![WaterFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/WaterFilter.gif) 255 | 256 | 使用方式 257 | 258 | ``` 259 | val filter = WaterFilter() 260 | 261 | img.setFilter(filter) 262 | ``` 263 | 264 | #### WaveFilter 265 | 演示: 266 | ![WaveFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/WaveFilter.gif) 267 | 268 | 使用方式 269 | 270 | ``` 271 | val filter = WaveFilter() 272 | 273 | img.setFilter(filter) 274 | ``` 275 | 276 | 277 | 278 | #### WindowTransferFilter 279 | 演示: 280 | ![WindowTransferFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/WindowTransferFilter.gif) 281 | 282 | 283 | 使用方式 284 | 285 | ``` 286 | val filter = WindowTransferFilter() 287 | 288 | //值 0-1 289 | filter.transfer = 0 - 1 290 | 291 | filter.transferAmin(500) 292 | //渐入 293 | filter.fadeIn(500) 294 | //渐出 295 | filter.fadeOut(500) 296 | //指定到某个值 297 | filter.fadeTo(500) 298 | 299 | img.setFilter(filter) 300 | ``` 301 | 302 | #### ZoomBlurTransferFilter 303 | 演示: 304 | ![ZoomBlurTransferFilter](https://gitlab.com/wufuqi123/NBEffects/-/raw/master/img/ZoomBlurTransferFilter.gif) 305 | 306 | 307 | 使用方式 308 | 309 | ``` 310 | val filter = ZoomBlurTransferFilter() 311 | 312 | //值 0-1 313 | filter.transfer = 0 - 1 314 | 315 | filter.transferAmin(500) 316 | //渐入 317 | filter.fadeIn(500) 318 | //渐出 319 | filter.fadeOut(500) 320 | //指定到某个值 321 | filter.fadeTo(500) 322 | 323 | img.setFilter(filter) 324 | ``` 325 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 32 8 | buildToolsVersion "32.0.0" 9 | 10 | defaultConfig { 11 | applicationId "cn.wufuqi.test" 12 | minSdkVersion 16 13 | targetSdkVersion 32 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | } 34 | 35 | dependencies { 36 | 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 38 | implementation 'androidx.core:core-ktx:1.3.1' 39 | implementation 'androidx.appcompat:appcompat:1.2.0' 40 | implementation 'com.google.android.material:material:1.2.1' 41 | implementation 'androidx.constraintlayout:constraintlayout:2.0.1' 42 | testImplementation 'junit:junit:4.+' 43 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 44 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 45 | 46 | 47 | // implementation 'jp.co.cyberagent.android:gpuimage:2.1.0' 48 | implementation project(path: ':NBEffects') 49 | 50 | implementation 'cn.wufuqi:EasyTimer:1.0.1' 51 | implementation 'cn.wufuqi:WuKongAnimation:1.0.4' 52 | implementation 'com.geyifeng.immersionbar:immersionbar:3.2.2' 53 | } -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /app/src/androidTest/java/cn/wufuqi/test/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.test 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("cn.wufuqi.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/cn/wufuqi/test/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.test 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import android.util.Log 6 | import android.view.Window 7 | import cn.wufuqi.easytimer.EasyTimer 8 | import cn.wufuqi.nbeffects.NBEffectsImageView 9 | import cn.wufuqi.nbeffects.OpenGLImageRenderType 10 | import cn.wufuqi.nbeffects.filter.* 11 | import cn.wufuqi.nbeffects.pixijs_filter.AdjustmentFilter 12 | import cn.wufuqi.nbeffects.pixijs_filter.AsciiFilter 13 | import cn.wufuqi.nbeffects.pixijs_filter.BevelFilter 14 | import com.gyf.immersionbar.ImmersionBar 15 | import com.wukonganimation.tween.TweenManager 16 | 17 | class MainActivity : AppCompatActivity() { 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | requestWindowFeature(Window.FEATURE_NO_TITLE) 21 | setContentView(R.layout.activity_main) 22 | supportActionBar?.hide() 23 | ImmersionBar.with(this) 24 | // .fitsSystemWindows(true) 25 | //状态栏颜色,不写默认透明色 26 | // .statusBarColor("#ffffff") 27 | // .autoStatusBarDarkModeEnable(true, 0.2f) 28 | .transparentStatusBar() //透明状态栏,不写默认透明色 29 | .transparentNavigationBar() 30 | .init() 31 | 32 | 33 | val img = findViewById(R.id.iv_gpu) 34 | img.setImageRes(R.drawable.fj) 35 | 36 | EasyTimer().scheduleOneUI(2000){ 37 | 38 | val t = ZoomBlurTransferFilter() 39 | // t.fadeOut(2000) { 40 | // t.fadeIn(2000) 41 | // } 42 | t.transferAmin(4000) 43 | img.setFilter(t) 44 | } 45 | 46 | img.setTranslucent(true) 47 | 48 | } 49 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/fj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/drawable/fj.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/hd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/drawable/hd.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/main.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/drawable/main.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /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/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NBEffects 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/test/java/cn/wufuqi/test/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package cn.wufuqi.test 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun 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 | buildscript { 3 | ext.kotlin_version = "1.5.10" 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | dependencies { 9 | classpath "com.android.tools.build:gradle:4.2.2" 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | mavenCentral() 21 | jcenter() // Warning: this repository is going to shut down soon 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } -------------------------------------------------------------------------------- /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=-Xmx2048m -Dfile.encoding=UTF-8 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 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Dec 01 12:36:16 CST 2022 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /img/DissolveFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/DissolveFilter.gif -------------------------------------------------------------------------------- /img/DynamicBlurTransferFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/DynamicBlurTransferFilter.gif -------------------------------------------------------------------------------- /img/GaussBlursFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/GaussBlursFilter.png -------------------------------------------------------------------------------- /img/GrayFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/GrayFilter.png -------------------------------------------------------------------------------- /img/MosaicFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/MosaicFilter.png -------------------------------------------------------------------------------- /img/QuarterMirrorFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/QuarterMirrorFilter.png -------------------------------------------------------------------------------- /img/RadialBlurFilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/RadialBlurFilter.png -------------------------------------------------------------------------------- /img/RainFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/RainFilter.gif -------------------------------------------------------------------------------- /img/UnfoldTransferFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/UnfoldTransferFilter.gif -------------------------------------------------------------------------------- /img/WaterFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/WaterFilter.gif -------------------------------------------------------------------------------- /img/WaveFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/WaveFilter.gif -------------------------------------------------------------------------------- /img/WindowTransferFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/WindowTransferFilter.gif -------------------------------------------------------------------------------- /img/ZoomBlurTransferFilter.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wufuqi123/NBEffects/fbd2d7b4312891e15b41d98fb96c1374ccd9324b/img/ZoomBlurTransferFilter.gif -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "NBEffects" 2 | include ':app' 3 | include ':NBEffects' 4 | --------------------------------------------------------------------------------