├── simple
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── themes.xml
│ │ ├── drawable-hdpi
│ │ │ ├── ic_check.png
│ │ │ ├── ic_add_view.png
│ │ │ ├── ic_uncheck.png
│ │ │ ├── ic_select_effect.png
│ │ │ ├── ic_select_photo.png
│ │ │ └── ic_show_dialog.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_check.png
│ │ │ ├── ic_add_view.png
│ │ │ ├── ic_uncheck.png
│ │ │ ├── ic_select_effect.png
│ │ │ ├── ic_select_photo.png
│ │ │ └── ic_show_dialog.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_check.png
│ │ │ ├── ic_uncheck.png
│ │ │ ├── ic_add_view.png
│ │ │ ├── ic_select_photo.png
│ │ │ ├── ic_show_dialog.png
│ │ │ └── ic_select_effect.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_check.png
│ │ │ ├── ic_add_view.png
│ │ │ ├── ic_uncheck.png
│ │ │ ├── ic_show_dialog.png
│ │ │ ├── ic_select_effect.png
│ │ │ └── ic_select_photo.png
│ │ ├── 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
│ │ ├── drawable
│ │ │ ├── shape_on_surface_bg.xml
│ │ │ ├── selector_checkbox.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── drawable-anydpi
│ │ │ ├── ic_add_view.xml
│ │ │ ├── ic_uncheck.xml
│ │ │ ├── ic_show_dialog.xml
│ │ │ ├── ic_select_photo.xml
│ │ │ ├── ic_check.xml
│ │ │ └── ic_select_effect.xml
│ │ ├── values-night
│ │ │ └── themes.xml
│ │ ├── menu
│ │ │ └── menu_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── java
│ │ └── per
│ │ │ └── goweii
│ │ │ └── visualeffect
│ │ │ └── simple
│ │ │ ├── Ext.kt
│ │ │ ├── DragGestureHelper.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── visualeffect-blur
├── .gitignore
├── proguard-rules.pro
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── per
│ └── goweii
│ └── visualeffect
│ └── blur
│ ├── BlurEffect.kt
│ ├── RSBlurEffect.kt
│ └── FastBlurEffect.kt
├── visualeffect-core
├── .gitignore
├── proguard-rules.pro
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── per
│ └── goweii
│ └── visualeffect
│ └── core
│ ├── VisualEffect.kt
│ ├── GroupVisualEffect.kt
│ ├── ParcelableVisualEffect.kt
│ └── BaseVisualEffect.kt
├── visualeffect-mosaic
├── .gitignore
├── proguard-rules.pro
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── per
│ └── goweii
│ └── visualeffect
│ └── mosaic
│ └── MosaicEffect.kt
├── visualeffect-view
├── .gitignore
├── proguard-rules.pro
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── per
│ └── goweii
│ └── visualeffect
│ └── view
│ ├── ContextExt.kt
│ ├── OutlineBuilder.kt
│ ├── ChildrenVisualEffectFrameLayout.kt
│ ├── BackdropVisualEffectView.kt
│ ├── BackdropVisualEffectFrameLayout.kt
│ ├── OutlineHelper.kt
│ ├── VisualEffectImageView.kt
│ ├── ChildrenVisualEffectHelper.kt
│ └── BackdropVisualEffectHelper.kt
├── visualeffect-watermask
├── .gitignore
├── proguard-rules.pro
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── per
│ └── goweii
│ └── visualeffect
│ └── watermask
│ └── WatermarkEffect.kt
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── .github
├── workflows
│ └── android.yml
└── FUNDING.yml
├── lib-build.gradle
├── gradle.properties
├── README.md
├── gradlew.bat
├── gradlew
└── LICENSE
/simple/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-blur/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-blur/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/visualeffect-core/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-core/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/visualeffect-mosaic/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-mosaic/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/visualeffect-view/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-view/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/visualeffect-watermask/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/visualeffect-watermask/proguard-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea
3 | build
4 | local.properties
5 | *.iml
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/simple/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | VisualEffect
3 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_check.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_check.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_add_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_add_view.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_uncheck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_uncheck.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_add_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_add_view.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_uncheck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_uncheck.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_check.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_uncheck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_uncheck.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_check.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_add_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_add_view.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_add_view.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_add_view.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_uncheck.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_uncheck.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_select_effect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_select_effect.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_select_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_select_photo.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-hdpi/ic_show_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-hdpi/ic_show_dialog.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_select_effect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_select_effect.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_select_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_select_photo.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-mdpi/ic_show_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-mdpi/ic_show_dialog.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_select_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_select_photo.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_show_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_show_dialog.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_show_dialog.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_show_dialog.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xhdpi/ic_select_effect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xhdpi/ic_select_effect.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_select_effect.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_select_effect.png
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-xxhdpi/ic_select_photo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/drawable-xxhdpi/ic_select_photo.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goweii/VisualEffect/HEAD/simple/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/visualeffect-core/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | dependencies {
8 | }
--------------------------------------------------------------------------------
/visualeffect-blur/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | dependencies {
8 | api project(":visualeffect-core")
9 | }
--------------------------------------------------------------------------------
/visualeffect-mosaic/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | dependencies {
8 | api project(":visualeffect-core")
9 | }
--------------------------------------------------------------------------------
/visualeffect-view/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | dependencies {
8 | api project(":visualeffect-core")
9 | }
--------------------------------------------------------------------------------
/visualeffect-blur/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/visualeffect-core/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/visualeffect-mosaic/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/visualeffect-watermask/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.library"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | dependencies {
8 | compileOnly project(":visualeffect-core")
9 | }
--------------------------------------------------------------------------------
/visualeffect-watermask/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = "VisualEffect"
2 | include ':simple'
3 | include ':visualeffect-core'
4 | include ':visualeffect-blur'
5 | include ':visualeffect-mosaic'
6 | include ':visualeffect-watermask'
7 | include ':visualeffect-view'
--------------------------------------------------------------------------------
/simple/src/main/res/drawable/shape_on_surface_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/visualeffect-core/src/main/java/per/goweii/visualeffect/core/VisualEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.core
2 |
3 | import android.graphics.Bitmap
4 |
5 | interface VisualEffect {
6 | fun process(input: Bitmap, output: Bitmap)
7 | fun recycle()
8 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 07 18:59:49 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
7 |
--------------------------------------------------------------------------------
/simple/src/main/java/per/goweii/visualeffect/simple/Ext.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.simple
2 |
3 | inline fun timeCost(block: () -> Unit) : Long {
4 | val start = System.currentTimeMillis()
5 | block()
6 | val end = System.currentTimeMillis()
7 | return end - start
8 | }
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable/selector_checkbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_add_view.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_uncheck.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_show_dialog.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/visualeffect-blur/src/main/java/per/goweii/visualeffect/blur/BlurEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.blur
2 |
3 | import android.os.Parcel
4 | import per.goweii.visualeffect.core.BaseVisualEffect
5 |
6 | abstract class BlurEffect constructor(var radius: Float) : BaseVisualEffect() {
7 | override fun writeToParcel(parcel: Parcel, flags: Int) {
8 | super.writeToParcel(parcel, flags)
9 | parcel.writeFloat(radius)
10 | }
11 |
12 | override fun readFromParcel(parcel: Parcel) {
13 | super.readFromParcel(parcel)
14 | radius = parcel.readFloat()
15 | }
16 | }
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_select_photo.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: set up JDK 11
17 | uses: actions/setup-java@v2
18 | with:
19 | java-version: '11'
20 | distribution: 'temurin'
21 | cache: gradle
22 |
23 | - name: Grant execute permission for gradlew
24 | run: chmod +x gradlew
25 | - name: Build with Gradle
26 | run: ./gradlew build
27 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/ContextExt.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.app.Activity
4 | import android.content.Context
5 | import android.content.ContextWrapper
6 |
7 | fun Context.getActivity(): Activity? {
8 | var context = this
9 | while (true) {
10 | if (context is Activity) {
11 | return context
12 | }
13 | if (context is ContextWrapper) {
14 | val baseContext = context.baseContext
15 | if (baseContext !== context) {
16 | context = baseContext
17 | continue
18 | }
19 | }
20 | return null
21 | }
22 | }
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_check.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: https://goweii.github.io/resource/payment_code/all_qrcode.jpg
14 |
--------------------------------------------------------------------------------
/simple/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
--------------------------------------------------------------------------------
/simple/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/simple/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/lib-build.gradle:
--------------------------------------------------------------------------------
1 | android {
2 | compileSdkVersion android_compile_sdk_version
3 | buildToolsVersion android_build_tools_version
4 |
5 | defaultConfig {
6 | minSdkVersion android_min_sdk_version
7 | targetSdkVersion android_target_sdk_version
8 | versionCode android_version_code
9 | versionName android_version_name
10 |
11 | consumerProguardFiles "proguard-rules.pro"
12 | }
13 |
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
18 | }
19 | }
20 |
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 |
26 | kotlinOptions {
27 | jvmTarget = "1.8"
28 | }
29 | }
30 |
31 | dependencies {
32 | compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
33 | }
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-anydpi/ic_select_effect.xml:
--------------------------------------------------------------------------------
1 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/simple/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/OutlineBuilder.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.graphics.Path
4 | import android.view.View
5 | import java.lang.ref.WeakReference
6 |
7 | abstract class OutlineBuilder {
8 | private var outlineHelperRef: WeakReference? = null
9 |
10 | fun attachToVisualEffectOutlineHelper(outlineHelper: OutlineHelper) {
11 | if (outlineHelperRef == null || outlineHelperRef!!.get() !== outlineHelper) {
12 | outlineHelperRef = WeakReference(outlineHelper)
13 | }
14 | }
15 |
16 | fun detachFromVisualEffectOutlineHelper() {
17 | if (outlineHelperRef != null) {
18 | outlineHelperRef!!.clear()
19 | outlineHelperRef = null
20 | }
21 | }
22 |
23 | fun invalidateOutline() {
24 | outlineHelperRef?.get()?.invalidateOutline()
25 | }
26 |
27 | open fun getSuggestedMinimumWidth(): Int = 0
28 |
29 | open fun getSuggestedMinimumHeight(): Int = 0
30 |
31 | abstract fun buildOutline(view: View, outline: Path)
32 | }
--------------------------------------------------------------------------------
/simple/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/visualeffect-core/src/main/java/per/goweii/visualeffect/core/GroupVisualEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.core
2 |
3 | import android.graphics.Bitmap
4 |
5 | class GroupVisualEffect(vararg visualEffects: VisualEffect) : BaseVisualEffect() {
6 | private val visualEffects = arrayListOf()
7 |
8 | init {
9 | this.visualEffects.addAll(visualEffects)
10 | }
11 |
12 | fun getVisualEffects(): List {
13 | return visualEffects
14 | }
15 |
16 | fun addVisualEffect(visualEffect: VisualEffect) {
17 | visualEffects.add(visualEffect)
18 | }
19 |
20 | fun removeVisualEffect(visualEffect: VisualEffect) {
21 | visualEffects.remove(visualEffect)
22 | }
23 |
24 | override fun doEffect(input: Bitmap, output: Bitmap) {
25 | visualEffects.forEachIndexed { index, visualEffect ->
26 | if (index == 0) {
27 | visualEffect.process(input, output)
28 | } else {
29 | visualEffect.process(output, output)
30 | }
31 | }
32 | }
33 |
34 | override fun recycle() {
35 | super.recycle()
36 | visualEffects.forEach {
37 | it.recycle()
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/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 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VisualEffect
2 |
3 | [](https://github.com/goweii/VisualEffect/actions/workflows/android.yml)
4 |
5 | Used to achieve visual effects in Android, such as Gaussian blur, mosaic, watermark, etc.
6 |
7 | # Preview
8 |
9 | |  |  |  |  |
10 | | ---- | ---- | ---- | ---- |
11 |
12 | # How to Use
13 |
14 | To get a Git project into your build:
15 |
16 | Step 1. Add the JitPack repository
17 |
18 | ```
19 | maven { url 'https://jitpack.io' }
20 | ```
21 |
22 | Step 2. Add the dependency
23 |
24 | [](https://jitpack.io/#goweii/VisualEffect)
25 |
26 | ```
27 | // Core library (must be imported)
28 | implementation "com.github.goweii.VisualEffect:visualeffect-core:$version"
29 | // Effect Library (imported on demand)
30 | implementation "com.github.goweii.VisualEffect:visualeffect-blur:$version"
31 | implementation "com.github.goweii.VisualEffect:visualeffect-mosaic:$version"
32 | implementation "com.github.goweii.VisualEffect:visualeffect-watermask:$version"
33 | // View Library (import on demand)
34 | implementation "com.github.goweii.VisualEffect:visualeffect-view:$version"
35 | ```
36 |
--------------------------------------------------------------------------------
/visualeffect-watermask/src/main/java/per/goweii/visualeffect/watermask/WatermarkEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.watermask
2 |
3 | import android.graphics.Bitmap
4 | import android.graphics.Color
5 | import android.os.Parcel
6 | import per.goweii.visualeffect.core.BaseVisualEffect
7 |
8 | class WatermarkEffect(
9 | var text: String = "",
10 | var textColor: Int = Color.BLACK,
11 | var textSize: Float = 24F
12 | ) : BaseVisualEffect() {
13 | override fun writeToParcel(parcel: Parcel, flags: Int) {
14 | super.writeToParcel(parcel, flags)
15 | parcel.writeString(text)
16 | parcel.writeInt(textColor)
17 | parcel.writeFloat(textSize)
18 | }
19 |
20 | override fun readFromParcel(parcel: Parcel) {
21 | super.readFromParcel(parcel)
22 | text = parcel.readString() ?: ""
23 | textColor = parcel.readInt()
24 | textSize = parcel.readFloat()
25 | }
26 |
27 | override fun doEffect(input: Bitmap, output: Bitmap) {
28 | useCanvas(output, true) { canvas, paint ->
29 | if (input !== output) {
30 | canvas.drawBitmap(input, 0F, 0F, paint)
31 | }
32 | paint.textSize = textSize
33 | paint.color = textColor
34 | canvas.drawText(
35 | text,
36 | output.width - paint.measureText(text),
37 | output.height - paint.fontMetrics.bottom,
38 | paint
39 | )
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/simple/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.application"
3 | id "kotlin-android"
4 | }
5 | apply from: "../lib-build.gradle"
6 |
7 | android {
8 | defaultConfig {
9 | applicationId "per.goweii.visualeffect.simple"
10 | }
11 |
12 | buildFeatures {
13 | viewBinding true
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
26 | implementation "androidx.core:core-ktx:$androidx_core_version"
27 | implementation "androidx.appcompat:appcompat:$androidx_appcompat_version"
28 | implementation "com.google.android.material:material:1.2.1"
29 | implementation "androidx.constraintlayout:constraintlayout:2.0.4"
30 |
31 | implementation project(":visualeffect-core")
32 | implementation project(":visualeffect-view")
33 | implementation project(":visualeffect-blur")
34 | implementation project(":visualeffect-mosaic")
35 | implementation project(":visualeffect-watermask")
36 |
37 | implementation "com.github.chrisbanes:PhotoView:2.0.0"
38 | implementation "com.github.bumptech.glide:glide:4.8.0"
39 | annotationProcessor "com.github.bumptech.glide:compiler:4.8.0"
40 | implementation("com.github.bumptech.glide:okhttp3-integration:4.8.0") {
41 | exclude group: "com.android.support"
42 | }
43 | }
--------------------------------------------------------------------------------
/simple/src/main/java/per/goweii/visualeffect/simple/DragGestureHelper.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.simple
2 |
3 | import android.annotation.SuppressLint
4 | import android.view.GestureDetector
5 | import android.view.MotionEvent
6 | import android.view.View
7 |
8 | @SuppressLint("ClickableViewAccessibility")
9 | class DragGestureHelper private constructor(
10 | private val view: View
11 | ) : GestureDetector.SimpleOnGestureListener() {
12 | companion object {
13 | fun attach(view: View): DragGestureHelper {
14 | return DragGestureHelper(view)
15 | }
16 | }
17 |
18 | private val gestureDetector = GestureDetector(view.context, this)
19 |
20 | private var downX = 0F
21 | private var downY = 0F
22 |
23 | var onDoubleClick: (() -> Unit)? = null
24 |
25 | init {
26 | view.setOnTouchListener { _, event ->
27 | gestureDetector.onTouchEvent(event)
28 | true
29 | }
30 | }
31 |
32 | override fun onDown(e: MotionEvent): Boolean {
33 | downX = view.translationX
34 | downY = view.translationY
35 | return true
36 | }
37 |
38 | override fun onDoubleTap(e: MotionEvent?): Boolean {
39 | return onDoubleClick?.let {
40 | it.invoke()
41 | true
42 | } ?: false
43 | }
44 |
45 | override fun onScroll(
46 | e1: MotionEvent,
47 | e2: MotionEvent,
48 | distanceX: Float,
49 | distanceY: Float
50 | ): Boolean {
51 | val x = (e2.rawX - e1.rawX).toInt()
52 | val y = (e2.rawY - e1.rawY).toInt()
53 | view.apply {
54 | translationX = downX + x
55 | translationY = downY + y
56 | }
57 | return true
58 | }
59 | }
--------------------------------------------------------------------------------
/simple/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/ChildrenVisualEffectFrameLayout.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.graphics.Canvas
6 | import android.os.Parcelable
7 | import android.util.AttributeSet
8 | import android.widget.FrameLayout
9 | import per.goweii.visualeffect.core.VisualEffect
10 |
11 | open class ChildrenVisualEffectFrameLayout @JvmOverloads constructor(
12 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
13 | ) : FrameLayout(context, attrs, defStyleAttr) {
14 | private val visualEffectHelper by lazy {
15 | ChildrenVisualEffectHelper(this)
16 | }
17 |
18 | var visualEffect: VisualEffect?
19 | get() = visualEffectHelper.visualEffect
20 | set(value) {
21 | visualEffectHelper.visualEffect = value
22 | }
23 | var simpleSize: Float
24 | get() = visualEffectHelper.simpleSize
25 | set(value) {
26 | visualEffectHelper.simpleSize = value
27 | }
28 | var isShowDebugInfo: Boolean
29 | get() = visualEffectHelper.isShowDebugInfo
30 | set(value) {
31 | visualEffectHelper.isShowDebugInfo = value
32 | }
33 | val isRendering get() = visualEffectHelper.isRendering
34 |
35 | override fun draw(canvas: Canvas) {
36 | visualEffectHelper.draw(canvas) {
37 | super.draw(it)
38 | }
39 | }
40 |
41 | override fun onRestoreInstanceState(state: Parcelable?) {
42 | visualEffectHelper.onRestoreInstanceState(state) {
43 | super.onRestoreInstanceState(it)
44 | }
45 | }
46 |
47 | override fun onSaveInstanceState(): Parcelable {
48 | return visualEffectHelper.onSaveInstanceState {
49 | super.onSaveInstanceState()
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/visualeffect-core/src/main/java/per/goweii/visualeffect/core/ParcelableVisualEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.core
2 |
3 | import android.content.Context
4 | import android.os.Parcel
5 | import android.os.Parcelable
6 |
7 | abstract class ParcelableVisualEffect : VisualEffect, Parcelable {
8 | open fun readFromParcel(parcel: Parcel) {
9 | }
10 |
11 | override fun writeToParcel(parcel: Parcel, flags: Int) {
12 | parcel.writeString(javaClass.name)
13 | }
14 |
15 | override fun describeContents(): Int {
16 | return 0
17 | }
18 |
19 | companion object {
20 | @JvmField
21 | val CREATOR = object : Parcelable.Creator {
22 | override fun createFromParcel(parcel: Parcel): ParcelableVisualEffect? {
23 | val className = parcel.readString()
24 | if (className.isNullOrEmpty()) return null
25 | val visualEffect = createVisualEffectByClassName(className) ?: return null
26 | visualEffect.readFromParcel(parcel)
27 | return visualEffect
28 | }
29 |
30 | override fun newArray(size: Int): Array {
31 | return arrayOfNulls(size)
32 | }
33 |
34 | private fun createVisualEffectByClassName(className: String?): ParcelableVisualEffect? {
35 | className ?: return null
36 | var cls: Class<*>? = null
37 | try {
38 | cls = Class.forName(className)
39 | } catch (e: Exception) {
40 | }
41 | cls ?: return null
42 | try {
43 | val c = cls.getConstructor()
44 | return c.newInstance() as ParcelableVisualEffect
45 | } catch (e: Exception) {
46 | }
47 | try {
48 | val c = cls.getConstructor(Context::class.java)
49 | return c.newInstance() as ParcelableVisualEffect
50 | } catch (e: Exception) {
51 | }
52 | return null
53 | }
54 | }
55 | }
56 |
57 | }
--------------------------------------------------------------------------------
/visualeffect-core/src/main/java/per/goweii/visualeffect/core/BaseVisualEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.core
2 |
3 | import android.graphics.Bitmap
4 | import android.graphics.Canvas
5 | import android.graphics.Paint
6 | import android.graphics.PaintFlagsDrawFilter
7 |
8 | abstract class BaseVisualEffect : ParcelableVisualEffect() {
9 | private val canvas = Canvas()
10 | private val paint = Paint()
11 | private val antiAliasDrawFilter =
12 | PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG or Paint.FILTER_BITMAP_FLAG)
13 |
14 | override fun process(input: Bitmap, output: Bitmap) {
15 | if (input === output) {
16 | doEffect(input, output)
17 | } else {
18 | if (input.width != output.width || input.height != output.height) {
19 | copyBitmap(input, output, false)
20 | doEffect(output, output)
21 | } else {
22 | doEffect(input, output)
23 | }
24 | }
25 | }
26 |
27 | override fun recycle() {
28 | canvas.drawFilter = null
29 | canvas.setBitmap(null)
30 | paint.reset()
31 | }
32 |
33 | protected abstract fun doEffect(input: Bitmap, output: Bitmap)
34 |
35 | @Suppress("SameParameterValue")
36 | protected fun copyBitmap(input: Bitmap, output: Bitmap, antiAlias: Boolean) {
37 | useCanvas(output, antiAlias) { canvas, paint ->
38 | canvas.scale(
39 | output.width.toFloat() / input.width.toFloat(),
40 | output.height.toFloat() / input.height.toFloat()
41 | )
42 | canvas.drawBitmap(input, 0F, 0F, paint)
43 | }
44 | }
45 |
46 | protected fun useCanvas(
47 | bitmap: Bitmap,
48 | isAntiAlias: Boolean = false,
49 | action: (canvas: Canvas, paint: Paint) -> Unit
50 | ) {
51 | val canvas = this.canvas
52 | val paint = this.paint
53 | if (isAntiAlias) {
54 | canvas.drawFilter = antiAliasDrawFilter
55 | paint.isAntiAlias = true
56 | } else {
57 | canvas.drawFilter = null
58 | paint.isAntiAlias = false
59 | }
60 | canvas.setBitmap(bitmap)
61 | val saveCount = canvas.save()
62 | action(canvas, paint)
63 | canvas.restoreToCount(saveCount)
64 | canvas.setBitmap(null)
65 | canvas.drawFilter = null
66 | paint.isAntiAlias = false
67 | }
68 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/visualeffect-mosaic/src/main/java/per/goweii/visualeffect/mosaic/MosaicEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.mosaic
2 |
3 | import android.graphics.Bitmap
4 | import android.os.Parcel
5 | import per.goweii.visualeffect.core.BaseVisualEffect
6 | import kotlin.math.ceil
7 | import kotlin.math.max
8 |
9 | class MosaicEffect(var boxSize: Int = 24) : BaseVisualEffect() {
10 | private var pixels: IntArray? = null
11 |
12 | override fun writeToParcel(parcel: Parcel, flags: Int) {
13 | super.writeToParcel(parcel, flags)
14 | parcel.writeInt(boxSize)
15 | }
16 |
17 | override fun readFromParcel(parcel: Parcel) {
18 | super.readFromParcel(parcel)
19 | boxSize = parcel.readInt()
20 | }
21 |
22 | override fun recycle() {
23 | super.recycle()
24 | pixels = null
25 | }
26 |
27 | private fun preparePixels(bitmap: Bitmap) {
28 | val size = bitmap.width * bitmap.height
29 | if (pixels?.size != size) {
30 | pixels = IntArray(size)
31 | }
32 | }
33 |
34 | override fun doEffect(input: Bitmap, output: Bitmap) {
35 | check(input.width == output.width && input.height == output.height)
36 | val boxSize = max(1, boxSize)
37 | if (boxSize == 1 && input === output) return
38 | val w = input.width
39 | val h = input.height
40 | preparePixels(input)
41 | val pix = pixels!!
42 | input.getPixels(pix, 0, w, 0, 0, w, h)
43 | if (boxSize == 1) {
44 | output.setPixels(pix, 0, w, 0, 0, w, h)
45 | return
46 | }
47 | val rowCount = ceil(w.toFloat() / boxSize).toInt()
48 | val columnCount = ceil(h.toFloat() / boxSize).toInt()
49 | for (r in 0 until rowCount) {
50 | val startX = r * boxSize + 1
51 | for (c in 0 until columnCount) {
52 | val startY = c * boxSize + 1
53 | dimBlock(pix, startX, startY, boxSize, w, h)
54 | }
55 | }
56 | output.setPixels(pix, 0, w, 0, 0, w, h)
57 | }
58 |
59 | private fun dimBlock(
60 | pixels: IntArray,
61 | startX: Int,
62 | startY: Int,
63 | blockSize: Int,
64 | maxX: Int,
65 | maxY: Int
66 | ) {
67 | var stopX = startX + blockSize - 1
68 | var stopY = startY + blockSize - 1
69 | if (stopX > maxX) {
70 | stopX = maxX
71 | }
72 | if (stopY > maxY) {
73 | stopY = maxY
74 | }
75 | //
76 | var sampleColorX = startX + blockSize / 2
77 | var sampleColorY = startY + blockSize / 2
78 | //
79 | if (sampleColorX > maxX) {
80 | sampleColorX = maxX
81 | }
82 | if (sampleColorY > maxY) {
83 | sampleColorY = maxY
84 | }
85 | val colorLinePosition = (sampleColorY - 1) * maxX
86 | val sampleColor = pixels[colorLinePosition + sampleColorX - 1]
87 | for (y in startY..stopY) {
88 | val p = (y - 1) * maxX
89 | for (x in startX..stopX) {
90 | pixels[p + x - 1] = sampleColor
91 | }
92 | }
93 | }
94 |
95 | }
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/BackdropVisualEffectView.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.os.Parcelable
6 | import android.util.AttributeSet
7 | import android.view.View
8 | import per.goweii.visualeffect.core.VisualEffect
9 | import kotlin.math.max
10 |
11 | open class BackdropVisualEffectView @JvmOverloads constructor(
12 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
13 | ) : View(context, attrs, defStyleAttr) {
14 | private val effectHelper: BackdropVisualEffectHelper by lazy {
15 | BackdropVisualEffectHelper(this)
16 | }
17 | private val outlineHelper: OutlineHelper by lazy {
18 | OutlineHelper(this)
19 | }
20 |
21 | var overlayColor: Int
22 | get() = effectHelper.overlayColor
23 | set(value) {
24 | effectHelper.overlayColor = value
25 | }
26 | var visualEffect: VisualEffect?
27 | get() = effectHelper.visualEffect
28 | set(value) {
29 | effectHelper.visualEffect = value
30 | }
31 | var simpleSize: Float
32 | get() = effectHelper.simpleSize
33 | set(value) {
34 | effectHelper.simpleSize = value
35 | }
36 | var isShowDebugInfo
37 | get() = effectHelper.isShowDebugInfo
38 | set(value) {
39 | effectHelper.isShowDebugInfo = value
40 | }
41 | var outlineBuilder: OutlineBuilder?
42 | get() = outlineHelper.outlineBuilder
43 | set(value) {
44 | outlineHelper.outlineBuilder = value
45 | }
46 | val isRendering get() = effectHelper.isRendering
47 |
48 | override fun getSuggestedMinimumWidth(): Int {
49 | return max(
50 | super.getSuggestedMinimumWidth(),
51 | outlineHelper.suggestedMinimumWidth
52 | )
53 | }
54 |
55 | override fun getSuggestedMinimumHeight(): Int {
56 | return max(
57 | super.getSuggestedMinimumHeight(),
58 | outlineHelper.suggestedMinimumHeight
59 | )
60 | }
61 |
62 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
63 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
64 | outlineHelper.onMeasure(widthMeasureSpec, heightMeasureSpec)
65 | }
66 |
67 | override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
68 | super.onSizeChanged(w, h, oldw, oldh)
69 | outlineHelper.onSizeChanged(w, h, oldw, oldh)
70 | }
71 |
72 | override fun draw(canvas: Canvas) {
73 | effectHelper.checkRendering()
74 | outlineHelper.draw(canvas) {
75 | super.draw(it)
76 | }
77 | }
78 |
79 | override fun onDraw(canvas: Canvas) {
80 | super.onDraw(canvas)
81 | effectHelper.onDraw(canvas)
82 | }
83 |
84 | override fun onRestoreInstanceState(state: Parcelable?) {
85 | effectHelper.onRestoreInstanceState(state) {
86 | super.onRestoreInstanceState(it)
87 | }
88 | }
89 |
90 | override fun onSaveInstanceState(): Parcelable {
91 | return effectHelper.onSaveInstanceState {
92 | super.onSaveInstanceState()
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/BackdropVisualEffectFrameLayout.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.content.Context
4 | import android.graphics.Canvas
5 | import android.os.Parcelable
6 | import android.util.AttributeSet
7 | import android.widget.FrameLayout
8 | import per.goweii.visualeffect.core.VisualEffect
9 | import kotlin.math.max
10 |
11 | open class BackdropVisualEffectFrameLayout @JvmOverloads constructor(
12 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
13 | ) : FrameLayout(context, attrs, defStyleAttr) {
14 | private val effectHelper: BackdropVisualEffectHelper by lazy {
15 | BackdropVisualEffectHelper(this)
16 | }
17 | private val outlineHelper: OutlineHelper by lazy {
18 | OutlineHelper(this)
19 | }
20 |
21 | var overlayColor: Int
22 | get() = effectHelper.overlayColor
23 | set(value) {
24 | effectHelper.overlayColor = value
25 | }
26 | var visualEffect: VisualEffect?
27 | get() = effectHelper.visualEffect
28 | set(value) {
29 | effectHelper.visualEffect = value
30 | }
31 | var simpleSize: Float
32 | get() = effectHelper.simpleSize
33 | set(value) {
34 | effectHelper.simpleSize = value
35 | }
36 | var isShowDebugInfo: Boolean
37 | get() = effectHelper.isShowDebugInfo
38 | set(value) {
39 | effectHelper.isShowDebugInfo = value
40 | }
41 | var outlineBuilder: OutlineBuilder?
42 | get() = outlineHelper.outlineBuilder
43 | set(value) {
44 | outlineHelper.outlineBuilder = value
45 | }
46 | val isRendering get() = effectHelper.isRendering
47 |
48 |
49 | init {
50 | super.setWillNotDraw(false)
51 | }
52 |
53 | override fun getSuggestedMinimumWidth(): Int {
54 | return max(
55 | super.getSuggestedMinimumWidth(),
56 | outlineHelper.suggestedMinimumWidth
57 | )
58 | }
59 |
60 | override fun getSuggestedMinimumHeight(): Int {
61 | return max(
62 | super.getSuggestedMinimumHeight(),
63 | outlineHelper.suggestedMinimumHeight
64 | )
65 | }
66 |
67 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
68 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
69 | outlineHelper.onMeasure(widthMeasureSpec, heightMeasureSpec)
70 | }
71 |
72 | override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
73 | super.onSizeChanged(w, h, oldw, oldh)
74 | outlineHelper.onSizeChanged(w, h, oldw, oldh)
75 | }
76 |
77 | override fun draw(canvas: Canvas) {
78 | effectHelper.checkRendering()
79 | outlineHelper.draw(canvas) {
80 | super.draw(it)
81 | }
82 | }
83 |
84 | override fun onDraw(canvas: Canvas) {
85 | super.onDraw(canvas)
86 | effectHelper.onDraw(canvas)
87 | }
88 |
89 | override fun onRestoreInstanceState(state: Parcelable?) {
90 | effectHelper.onRestoreInstanceState(state) {
91 | super.onRestoreInstanceState(it)
92 | }
93 | }
94 |
95 | override fun onSaveInstanceState(): Parcelable {
96 | return effectHelper.onSaveInstanceState {
97 | super.onSaveInstanceState()
98 | }
99 | }
100 | }
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/OutlineHelper.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.graphics.*
4 | import android.view.View
5 |
6 | class OutlineHelper(private val view: View) {
7 | private var outlinePath: Path? = null
8 | private var outlineInvalidate = true
9 | private var outlinePaint: Paint? = null
10 | private var outlineXfermode: PorterDuffXfermode? = null
11 |
12 | var outlineBuilder: OutlineBuilder? = null
13 | set(value) {
14 | if (value == null) {
15 | if (field != null) {
16 | field?.detachFromVisualEffectOutlineHelper()
17 | field = null
18 | invalidateOutline()
19 | }
20 | } else {
21 | if (field !== value) {
22 | field = value
23 | field?.attachToVisualEffectOutlineHelper(this)
24 | invalidateOutline()
25 | }
26 | }
27 | }
28 |
29 | val outline: Path?
30 | get() {
31 | if (outlineInvalidate) {
32 | rebuildOutline()
33 | }
34 | return outlinePath
35 | }
36 |
37 | val suggestedMinimumWidth: Int
38 | get() = outlineBuilder?.getSuggestedMinimumWidth() ?: 0
39 |
40 | val suggestedMinimumHeight: Int
41 | get() = outlineBuilder?.getSuggestedMinimumHeight() ?: 0
42 |
43 | fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
44 | invalidateOutline()
45 | }
46 |
47 | fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
48 | invalidateOutline()
49 | }
50 |
51 | fun draw(canvas: Canvas, callSuper: (Canvas) -> Unit) {
52 | val path = outline
53 | if (path == null) {
54 | outlinePaint = null
55 | outlineXfermode = null
56 | callSuper.invoke(canvas)
57 | return
58 | }
59 | val paint = outlinePaint ?: Paint(Paint.ANTI_ALIAS_FLAG).also {
60 | outlinePaint = it
61 | }
62 | val xfermode = outlineXfermode ?: PorterDuffXfermode(PorterDuff.Mode.DST_OUT).also {
63 | outlineXfermode = it
64 | }
65 | val layerId = canvas.saveLayer(
66 | 0f,
67 | 0f,
68 | view.width.toFloat(),
69 | view.height.toFloat(),
70 | null,
71 | Canvas.ALL_SAVE_FLAG
72 | )
73 | callSuper.invoke(canvas)
74 | path.toggleInverseFillType()
75 | paint.style = Paint.Style.FILL
76 | paint.color = Color.BLACK
77 | paint.xfermode = xfermode
78 | canvas.drawPath(path, paint)
79 | paint.xfermode = null
80 | path.toggleInverseFillType()
81 | canvas.restoreToCount(layerId)
82 | }
83 |
84 | fun invalidateOutline() {
85 | outlineInvalidate = true
86 | view.invalidate()
87 | }
88 |
89 | private fun rebuildOutline() {
90 | if (outlineBuilder == null) {
91 | outlinePath = null
92 | } else {
93 | val path = outlinePath?.also {
94 | it.reset()
95 | it.rewind()
96 | } ?: Path().also {
97 | outlinePath = it
98 | }
99 | outlineBuilder!!.buildOutline(view, path)
100 | if (path.isEmpty) {
101 | path.close()
102 | }
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
25 |
26 |
31 |
32 |
39 |
40 |
46 |
47 |
48 |
49 |
54 |
55 |
62 |
63 |
69 |
70 |
71 |
72 |
77 |
78 |
85 |
86 |
92 |
93 |
94 |
95 |
99 |
100 |
107 |
108 |
114 |
115 |
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/VisualEffectImageView.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.content.Context
4 | import android.graphics.*
5 | import android.util.AttributeSet
6 | import android.util.TypedValue
7 | import android.widget.ImageView
8 | import per.goweii.visualeffect.core.VisualEffect
9 | import java.text.NumberFormat
10 | import kotlin.math.max
11 |
12 | open class VisualEffectImageView @JvmOverloads constructor(
13 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
14 | ) : ImageView(context, attrs, defStyleAttr) {
15 | private val bitmapCanvas = Canvas()
16 | private var cacheBitmap: Bitmap? = null
17 |
18 | private val srcRect = Rect()
19 | private val dstRect = Rect()
20 |
21 | private var renderStartTime = 0L
22 | private var renderEndTime = 0L
23 |
24 | var visualEffect: VisualEffect? = null
25 | set(value) {
26 | if (field != value) {
27 | field?.recycle()
28 | field = value
29 | postInvalidate()
30 | }
31 | }
32 | var simpleSize = 1F
33 | set(value) {
34 | if (field != value) {
35 | field = max(1F, value)
36 | postInvalidate()
37 | }
38 | }
39 | var isShowDebugInfo = BuildConfig.DEBUG
40 | set(value) {
41 | if (field != value) {
42 | field = value
43 | postInvalidate()
44 | }
45 | }
46 | val isRendering: Boolean get() = renderEndTime < renderStartTime
47 |
48 | private val paint = Paint().apply {
49 | isAntiAlias = true
50 | typeface = Typeface.MONOSPACE
51 | textSize = TypedValue.applyDimension(
52 | TypedValue.COMPLEX_UNIT_SP,
53 | 9F,
54 | context.resources.displayMetrics
55 | )
56 | }
57 |
58 | override fun onDetachedFromWindow() {
59 | visualEffect?.recycle()
60 | super.onDetachedFromWindow()
61 | }
62 |
63 | override fun onDraw(canvas: Canvas) {
64 | val visualEffect = visualEffect
65 | ?: kotlin.run {
66 | super.onDraw(canvas)
67 | return
68 | }
69 | prepare()
70 | val cacheBitmap = cacheBitmap ?: return
71 | renderStartTime = System.nanoTime()
72 | val restoreCount = bitmapCanvas.save()
73 | bitmapCanvas.drawColor(Color.TRANSPARENT)
74 | bitmapCanvas.scale(
75 | cacheBitmap.width.toFloat() / this.width.toFloat(),
76 | cacheBitmap.height.toFloat() / this.height.toFloat()
77 | )
78 | super.onDraw(bitmapCanvas)
79 | bitmapCanvas.restoreToCount(restoreCount)
80 | visualEffect.process(cacheBitmap, cacheBitmap)
81 | renderEndTime = System.nanoTime()
82 | onDrawEffectedBitmap(canvas, cacheBitmap)
83 | if (isShowDebugInfo) {
84 | onDrawDebugInfo(canvas)
85 | }
86 | }
87 |
88 | private fun prepare() {
89 | val simpledWidth = (width / simpleSize).toInt()
90 | val simpledHeight = (height / simpleSize).toInt()
91 | if (cacheBitmap == null || cacheBitmap!!.width != simpledWidth || cacheBitmap!!.height != simpledHeight) {
92 | cacheBitmap = try {
93 | Bitmap.createBitmap(simpledWidth, simpledHeight, Bitmap.Config.ARGB_8888)
94 | } catch (e: OutOfMemoryError) {
95 | null
96 | }
97 | bitmapCanvas.setBitmap(cacheBitmap)
98 | }
99 | }
100 |
101 | private fun onDrawEffectedBitmap(canvas: Canvas, bitmap: Bitmap) {
102 | paint.color = Color.WHITE
103 | srcRect.right = bitmap.width
104 | srcRect.bottom = bitmap.height
105 | dstRect.right = width
106 | dstRect.bottom = height
107 | canvas.drawBitmap(bitmap, srcRect, dstRect, paint)
108 | }
109 |
110 | private fun onDrawDebugInfo(canvas: Canvas) {
111 | var textBaseLine = 0F
112 | val costTime = (renderEndTime - renderStartTime).toDouble() / 1_000_000
113 | val costText = NumberFormat.getInstance().let {
114 | it.isGroupingUsed = false
115 | it.minimumFractionDigits = 3
116 | it.maximumFractionDigits = 3
117 | it.format(costTime)
118 | }
119 | textBaseLine += -paint.fontMetrics.ascent
120 | canvas.drawText(
121 | costText,
122 | width - paint.measureText(costText),
123 | textBaseLine,
124 | paint.apply {
125 | color = if (costTime > 16.6F) Color.RED else Color.BLACK
126 | }
127 | )
128 | val bmpSizeText = "${cacheBitmap?.width ?: 0}*${cacheBitmap?.height ?: 0}"
129 | textBaseLine += -paint.fontMetrics.ascent
130 | canvas.drawText(
131 | bmpSizeText,
132 | width - paint.measureText(bmpSizeText),
133 | textBaseLine,
134 | paint.apply {
135 | color = Color.BLACK
136 | }
137 | )
138 | }
139 | }
--------------------------------------------------------------------------------
/visualeffect-blur/src/main/java/per/goweii/visualeffect/blur/RSBlurEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.blur
2 |
3 | import android.content.Context
4 | import android.graphics.Bitmap
5 | import android.renderscript.*
6 | import android.util.Log
7 |
8 | class RSBlurEffect @JvmOverloads constructor(
9 | context: Context,
10 | radius: Float = 8F
11 | ) : BlurEffect(radius) {
12 | private val tag = this::class.java.simpleName
13 | private val applicationContext: Context = context.applicationContext
14 |
15 | private var renderScript: RenderScript? = null
16 | private var scriptIntrinsicBlur: ScriptIntrinsicBlur? = null
17 | private var allocationIn: Allocation? = null
18 | private var allocationOut: Allocation? = null
19 | private var bitmapArgb8888: Bitmap? = null
20 |
21 | override fun recycle() {
22 | super.recycle()
23 | destroyAllocations()
24 | destroyScripts()
25 | bitmapArgb8888?.recycle()
26 | bitmapArgb8888 = null
27 | }
28 |
29 | override fun doEffect(input: Bitmap, output: Bitmap) {
30 | check(input.width == output.width && input.height == output.height)
31 | val radius = when {
32 | radius < 0F -> 0F
33 | radius > 25F -> 25F
34 | else -> radius
35 | }
36 | if (radius == 0F && input === output) return
37 | prepareScripts()
38 | val scriptIntrinsicBlur = scriptIntrinsicBlur ?: return
39 | val inputBitmap = getBitmapArgb8888(input)
40 | prepareAllocations(inputBitmap)
41 | val allocInput = allocationIn ?: return
42 | val allocOutput = allocationOut ?: return
43 | if (radius == 0F) {
44 | allocInput.copyTo(output)
45 | return
46 | }
47 | scriptIntrinsicBlur.setRadius(radius)
48 | scriptIntrinsicBlur.setInput(allocInput)
49 | scriptIntrinsicBlur.forEach(allocOutput)
50 | val outputBitmap = getBitmapArgb8888(output)
51 | allocOutput.copyTo(outputBitmap)
52 | if (outputBitmap != output) {
53 | copyBitmap(outputBitmap, output, false)
54 | }
55 | }
56 |
57 | private fun getBitmapArgb8888(bitmap: Bitmap): Bitmap {
58 | if (bitmap.config == Bitmap.Config.ARGB_8888) {
59 | return bitmap
60 | }
61 | Log.w(tag, "Bitmap config should be ARGB_8888")
62 | bitmapArgb8888?.let {
63 | if (it.width != bitmap.width || it.height != bitmap.height) {
64 | it.recycle()
65 | bitmapArgb8888 = null
66 | }
67 | }
68 | val newBitmap = Bitmap.createBitmap(
69 | bitmap.width,
70 | bitmap.height,
71 | Bitmap.Config.ARGB_8888
72 | ).also {
73 | bitmapArgb8888 = it
74 | }
75 | copyBitmap(bitmap, newBitmap, false)
76 | return newBitmap
77 | }
78 |
79 | private fun prepareScripts() {
80 | if (renderScript == null) {
81 | renderScript = RenderScript.create(applicationContext)
82 | }
83 | if (scriptIntrinsicBlur == null) {
84 | scriptIntrinsicBlur = ScriptIntrinsicBlur.create(
85 | renderScript,
86 | Element.U8_4(renderScript)
87 | )
88 | }
89 | }
90 |
91 | private fun prepareAllocations(bitmap: Bitmap) {
92 | if (allocationIn == null || allocationOut == null) {
93 | destroyAllocations()
94 | createAllocations(bitmap)
95 | return
96 | }
97 | if (allocationIn!!.type.x != bitmap.width || allocationIn!!.type.y != bitmap.height) {
98 | destroyAllocations()
99 | createAllocations(bitmap)
100 | return
101 | }
102 | try {
103 | allocationIn!!.copyFrom(bitmap)
104 | } catch (ignore: RSIllegalArgumentException) {
105 | destroyAllocations()
106 | createAllocations(bitmap)
107 | }
108 | }
109 |
110 | private fun createAllocations(bitmap: Bitmap) {
111 | allocationIn = Allocation.createFromBitmap(
112 | renderScript,
113 | bitmap,
114 | Allocation.MipmapControl.MIPMAP_NONE,
115 | Allocation.USAGE_SCRIPT
116 | )
117 | allocationOut = Allocation.createTyped(
118 | renderScript,
119 | allocationIn!!.type
120 | )
121 | }
122 |
123 | private fun destroyAllocations() {
124 | try {
125 | allocationIn?.destroy()
126 | allocationIn = null
127 | } catch (ignore: Exception) {
128 | }
129 | try {
130 | allocationOut?.destroy()
131 | allocationOut = null
132 | } catch (ignore: Exception) {
133 | }
134 | }
135 |
136 | private fun destroyScripts() {
137 | try {
138 | renderScript?.destroy()
139 | renderScript = null
140 | } catch (ignore: Exception) {
141 | }
142 | try {
143 | scriptIntrinsicBlur?.destroy()
144 | scriptIntrinsicBlur = null
145 | } catch (ignore: Exception) {
146 | }
147 | }
148 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/simple/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 |
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/ChildrenVisualEffectHelper.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.graphics.*
4 | import android.os.Parcel
5 | import android.os.Parcelable
6 | import android.util.TypedValue
7 | import android.view.View
8 | import per.goweii.visualeffect.core.ParcelableVisualEffect
9 | import per.goweii.visualeffect.core.VisualEffect
10 | import java.text.NumberFormat
11 | import kotlin.math.max
12 |
13 | class ChildrenVisualEffectHelper(private val view: View) {
14 | private var bitmapCanvas: Canvas? = null
15 | private var cacheBitmap: Bitmap? = null
16 | private val paint = Paint().apply {
17 | isAntiAlias = true
18 | typeface = Typeface.MONOSPACE
19 | textSize = TypedValue.applyDimension(
20 | TypedValue.COMPLEX_UNIT_SP,
21 | 9F,
22 | view.context.resources.displayMetrics
23 | )
24 | }
25 |
26 | private val srcRect = Rect()
27 | private val dstRect = Rect()
28 |
29 | private var renderStartTime = 0L
30 | private var renderEndTime = 0L
31 |
32 | var visualEffect: VisualEffect? = null
33 | set(value) {
34 | if (field != value) {
35 | field?.recycle()
36 | field = value
37 | view.postInvalidate()
38 | }
39 | }
40 | var simpleSize = 1F
41 | set(value) {
42 | if (field != value) {
43 | field = max(1F, value)
44 | view.postInvalidate()
45 | }
46 | }
47 | var isShowDebugInfo = BuildConfig.DEBUG
48 | set(value) {
49 | if (field != value) {
50 | field = value
51 | view.postInvalidate()
52 | }
53 | }
54 | val isRendering: Boolean get() = renderEndTime < renderStartTime
55 |
56 | private val onAttachStateChangeListener = object : View.OnAttachStateChangeListener {
57 | override fun onViewAttachedToWindow(v: View?) {
58 | }
59 |
60 | override fun onViewDetachedFromWindow(v: View?) {
61 | visualEffect?.recycle()
62 | }
63 | }
64 |
65 | init {
66 | view.addOnAttachStateChangeListener(onAttachStateChangeListener)
67 | }
68 |
69 | fun draw(canvas: Canvas, callSuper: (Canvas) -> Unit) {
70 | val visualEffect = visualEffect ?: kotlin.run {
71 | callSuper.invoke(canvas)
72 | return
73 | }
74 | prepare()
75 | val bitmapCanvas = bitmapCanvas ?: return
76 | val cacheBitmap = cacheBitmap ?: return
77 | renderStartTime = System.nanoTime()
78 | val restoreCount = bitmapCanvas.save()
79 | bitmapCanvas.drawColor(Color.TRANSPARENT)
80 | bitmapCanvas.scale(
81 | cacheBitmap.width.toFloat() / view.width.toFloat(),
82 | cacheBitmap.height.toFloat() / view.height.toFloat()
83 | )
84 | callSuper.invoke(bitmapCanvas)
85 | bitmapCanvas.restoreToCount(restoreCount)
86 | visualEffect.process(cacheBitmap, cacheBitmap)
87 | renderEndTime = System.nanoTime()
88 | onDrawEffectedBitmap(canvas, cacheBitmap)
89 | if (isShowDebugInfo) {
90 | onDrawDebugInfo(canvas)
91 | }
92 | }
93 |
94 | fun onRestoreInstanceState(state: Parcelable?, callSuper: (Parcelable?) -> Unit) {
95 | if (state !is SavedState) {
96 | callSuper.invoke(state)
97 | return
98 | }
99 | callSuper.invoke(state.superState)
100 | isShowDebugInfo = state.isShowDebugInfo
101 | simpleSize = state.simpleSize
102 | visualEffect = state.visualEffect
103 | }
104 |
105 | fun onSaveInstanceState(callSuper: () -> Parcelable?): Parcelable {
106 | val superState = callSuper.invoke() ?: View.BaseSavedState.EMPTY_STATE
107 | return SavedState(
108 | superState = superState,
109 | isShowDebugInfo = isShowDebugInfo,
110 | simpleSize = simpleSize,
111 | visualEffect = visualEffect as? ParcelableVisualEffect?
112 | )
113 | }
114 |
115 | private fun prepare() {
116 | val simpledWidth = (view.width / simpleSize).toInt()
117 | val simpledHeight = (view.height / simpleSize).toInt()
118 | if (simpledWidth <= 0 || simpledHeight <= 0) {
119 | bitmapCanvas = null
120 | cacheBitmap = null
121 | } else if (cacheBitmap == null || cacheBitmap!!.width != simpledWidth || cacheBitmap!!.height != simpledHeight) {
122 | cacheBitmap = try {
123 | Bitmap.createBitmap(simpledWidth, simpledHeight, Bitmap.Config.ARGB_8888)
124 | } catch (e: OutOfMemoryError) {
125 | Runtime.getRuntime().gc()
126 | null
127 | }
128 | if (cacheBitmap != null) {
129 | if (bitmapCanvas == null) {
130 | bitmapCanvas = Canvas()
131 | }
132 | bitmapCanvas!!.setBitmap(cacheBitmap)
133 | } else {
134 | bitmapCanvas = null
135 | }
136 | }
137 | }
138 |
139 | private fun onDrawEffectedBitmap(canvas: Canvas, bitmap: Bitmap) {
140 | paint.color = Color.WHITE
141 | srcRect.right = bitmap.width
142 | srcRect.bottom = bitmap.height
143 | dstRect.right = view.width
144 | dstRect.bottom = view.height
145 | canvas.drawBitmap(bitmap, srcRect, dstRect, paint)
146 | }
147 |
148 | private fun onDrawDebugInfo(canvas: Canvas) {
149 | var textBaseLine = 0F
150 | val costTime = (renderEndTime - renderStartTime).toDouble() / 1_000_000
151 | val costText = NumberFormat.getInstance().let {
152 | it.isGroupingUsed = false
153 | it.minimumFractionDigits = 3
154 | it.maximumFractionDigits = 3
155 | it.format(costTime)
156 | }
157 | textBaseLine += -paint.fontMetrics.ascent
158 | canvas.drawText(
159 | costText,
160 | view.width - paint.measureText(costText),
161 | textBaseLine,
162 | paint.apply {
163 | color = if (costTime > 16.6F) Color.RED else Color.BLACK
164 | }
165 | )
166 | val bmpSizeText = "${cacheBitmap?.width ?: 0}*${cacheBitmap?.height ?: 0}"
167 | textBaseLine += -paint.fontMetrics.ascent
168 | canvas.drawText(
169 | bmpSizeText,
170 | view.width - paint.measureText(bmpSizeText),
171 | textBaseLine,
172 | paint.apply {
173 | color = Color.BLACK
174 | }
175 | )
176 | }
177 |
178 | private class SavedState(
179 | superState: Parcelable,
180 | val isShowDebugInfo: Boolean,
181 | val simpleSize: Float,
182 | val visualEffect: ParcelableVisualEffect?
183 | ) : View.BaseSavedState(superState) {
184 | override fun writeToParcel(dest: Parcel, flags: Int) {
185 | super.writeToParcel(dest, flags)
186 | dest.writeInt(if (isShowDebugInfo) 1 else 0)
187 | dest.writeFloat(simpleSize)
188 | dest.writeParcelable(visualEffect, 0)
189 | }
190 | }
191 | }
--------------------------------------------------------------------------------
/visualeffect-blur/src/main/java/per/goweii/visualeffect/blur/FastBlurEffect.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.blur
2 |
3 | import android.graphics.Bitmap
4 | import kotlin.math.abs
5 | import kotlin.math.max
6 | import kotlin.math.min
7 |
8 | class FastBlurEffect @JvmOverloads constructor(
9 | radius: Float = 8F
10 | ) : BlurEffect(radius) {
11 | private var pixels: IntArray? = null
12 | private var reds: IntArray? = null
13 | private var greens: IntArray? = null
14 | private var blues: IntArray? = null
15 | private var vmins: IntArray? = null
16 | private var divs: IntArray? = null
17 |
18 | override fun recycle() {
19 | super.recycle()
20 | pixels = null
21 | reds = null
22 | greens = null
23 | blues = null
24 | vmins = null
25 | divs = null
26 | }
27 |
28 | private fun preparePixels(bitmap: Bitmap) {
29 | val size = bitmap.width * bitmap.height
30 | if (pixels?.size != size) {
31 | pixels = IntArray(size)
32 | }
33 | }
34 |
35 | private fun prepareRGBs(bitmap: Bitmap) {
36 | val size = bitmap.width * bitmap.height
37 | if (reds?.size != size) {
38 | reds = IntArray(size)
39 | }
40 | if (greens?.size != size) {
41 | greens = IntArray(size)
42 | }
43 | if (blues?.size != size) {
44 | blues = IntArray(size)
45 | }
46 | }
47 |
48 | private fun prepareVmins(size: Int) {
49 | if (vmins?.size != size) {
50 | vmins = IntArray(size)
51 | }
52 | }
53 |
54 | private fun prepareDivs(size: Int) {
55 | if (divs?.size != size) {
56 | divs = IntArray(size)
57 | }
58 | }
59 |
60 | @Suppress("JoinDeclarationAndAssignment")
61 | override fun doEffect(input: Bitmap, output: Bitmap) {
62 | check(input.width == output.width && input.height == output.height)
63 | val radius = max(0, radius.toInt())
64 | if (radius == 0 && input === output) return
65 | val w = input.width
66 | val h = input.height
67 | preparePixels(input)
68 | val pix = pixels!!
69 | input.getPixels(pix, 0, w, 0, 0, w, h)
70 | if (radius == 0) {
71 | output.setPixels(pix, 0, w, 0, 0, w, h)
72 | return
73 | }
74 | prepareRGBs(input)
75 | val r = reds!!
76 | val g = greens!!
77 | val b = blues!!
78 | val wm = w - 1
79 | val hm = h - 1
80 | val div = radius + radius + 1
81 | var rsum: Int
82 | var gsum: Int
83 | var bsum: Int
84 | var x: Int
85 | var y: Int
86 | var i: Int
87 | var p: Int
88 | var yp: Int
89 | var yi: Int
90 | var yw: Int
91 | prepareVmins(max(w, h))
92 | val vmin = vmins!!
93 | var divsum = div + 1 shr 1
94 | divsum *= divsum
95 | prepareDivs(256 * divsum)
96 | val dv = divs!!
97 | i = 0
98 | while (i < 256 * divsum) {
99 | dv[i] = i / divsum
100 | i++
101 | }
102 | yi = 0
103 | yw = yi
104 | val stack = Array(div) { IntArray(3) }
105 | var stackpointer: Int
106 | var stackstart: Int
107 | var sir: IntArray
108 | var rbs: Int
109 | val r1 = radius + 1
110 | var routsum: Int
111 | var goutsum: Int
112 | var boutsum: Int
113 | var rinsum: Int
114 | var ginsum: Int
115 | var binsum: Int
116 | y = 0
117 | while (y < h) {
118 | bsum = 0
119 | gsum = bsum
120 | rsum = gsum
121 | boutsum = rsum
122 | goutsum = boutsum
123 | routsum = goutsum
124 | binsum = routsum
125 | ginsum = binsum
126 | rinsum = ginsum
127 | i = -radius
128 | while (i <= radius) {
129 | p = pix[yi + min(wm, max(i, 0))]
130 | sir = stack[i + radius]
131 | sir[0] = p and 0xff0000 shr 16
132 | sir[1] = p and 0x00ff00 shr 8
133 | sir[2] = p and 0x0000ff
134 | rbs = r1 - abs(i)
135 | rsum += sir[0] * rbs
136 | gsum += sir[1] * rbs
137 | bsum += sir[2] * rbs
138 | if (i > 0) {
139 | rinsum += sir[0]
140 | ginsum += sir[1]
141 | binsum += sir[2]
142 | } else {
143 | routsum += sir[0]
144 | goutsum += sir[1]
145 | boutsum += sir[2]
146 | }
147 | i++
148 | }
149 | stackpointer = radius
150 | x = 0
151 | while (x < w) {
152 | r[yi] = dv[rsum]
153 | g[yi] = dv[gsum]
154 | b[yi] = dv[bsum]
155 | rsum -= routsum
156 | gsum -= goutsum
157 | bsum -= boutsum
158 | stackstart = stackpointer - radius + div
159 | sir = stack[stackstart % div]
160 | routsum -= sir[0]
161 | goutsum -= sir[1]
162 | boutsum -= sir[2]
163 | if (y == 0) {
164 | vmin[x] = min(x + radius + 1, wm)
165 | }
166 | p = pix[yw + vmin[x]]
167 | sir[0] = p and 0xff0000 shr 16
168 | sir[1] = p and 0x00ff00 shr 8
169 | sir[2] = p and 0x0000ff
170 | rinsum += sir[0]
171 | ginsum += sir[1]
172 | binsum += sir[2]
173 | rsum += rinsum
174 | gsum += ginsum
175 | bsum += binsum
176 | stackpointer = (stackpointer + 1) % div
177 | sir = stack[stackpointer % div]
178 | routsum += sir[0]
179 | goutsum += sir[1]
180 | boutsum += sir[2]
181 | rinsum -= sir[0]
182 | ginsum -= sir[1]
183 | binsum -= sir[2]
184 | yi++
185 | x++
186 | }
187 | yw += w
188 | y++
189 | }
190 | x = 0
191 | while (x < w) {
192 | bsum = 0
193 | gsum = bsum
194 | rsum = gsum
195 | boutsum = rsum
196 | goutsum = boutsum
197 | routsum = goutsum
198 | binsum = routsum
199 | ginsum = binsum
200 | rinsum = ginsum
201 | yp = -radius * w
202 | i = -radius
203 | while (i <= radius) {
204 | yi = max(0, yp) + x
205 | sir = stack[i + radius]
206 | sir[0] = r[yi]
207 | sir[1] = g[yi]
208 | sir[2] = b[yi]
209 | rbs = r1 - abs(i)
210 | rsum += r[yi] * rbs
211 | gsum += g[yi] * rbs
212 | bsum += b[yi] * rbs
213 | if (i > 0) {
214 | rinsum += sir[0]
215 | ginsum += sir[1]
216 | binsum += sir[2]
217 | } else {
218 | routsum += sir[0]
219 | goutsum += sir[1]
220 | boutsum += sir[2]
221 | }
222 | if (i < hm) {
223 | yp += w
224 | }
225 | i++
226 | }
227 | yi = x
228 | stackpointer = radius
229 | y = 0
230 | while (y < h) {
231 | pix[yi] =
232 | -0x1000000 and pix[yi] or (dv[rsum] shl 16) or (dv[gsum] shl 8) or dv[bsum]
233 | rsum -= routsum
234 | gsum -= goutsum
235 | bsum -= boutsum
236 | stackstart = stackpointer - radius + div
237 | sir = stack[stackstart % div]
238 | routsum -= sir[0]
239 | goutsum -= sir[1]
240 | boutsum -= sir[2]
241 | if (x == 0) {
242 | vmin[y] = min(y + r1, hm) * w
243 | }
244 | p = x + vmin[y]
245 | sir[0] = r[p]
246 | sir[1] = g[p]
247 | sir[2] = b[p]
248 | rinsum += sir[0]
249 | ginsum += sir[1]
250 | binsum += sir[2]
251 | rsum += rinsum
252 | gsum += ginsum
253 | bsum += binsum
254 | stackpointer = (stackpointer + 1) % div
255 | sir = stack[stackpointer]
256 | routsum += sir[0]
257 | goutsum += sir[1]
258 | boutsum += sir[2]
259 | rinsum -= sir[0]
260 | ginsum -= sir[1]
261 | binsum -= sir[2]
262 | yi += w
263 | y++
264 | }
265 | x++
266 | }
267 | output.setPixels(pix, 0, w, 0, 0, w, h)
268 | }
269 | }
--------------------------------------------------------------------------------
/visualeffect-view/src/main/java/per/goweii/visualeffect/view/BackdropVisualEffectHelper.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.view
2 |
3 | import android.graphics.*
4 | import android.os.Parcel
5 | import android.os.Parcelable
6 | import android.util.TypedValue
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import android.view.ViewTreeObserver
10 | import per.goweii.visualeffect.core.ParcelableVisualEffect
11 | import per.goweii.visualeffect.core.VisualEffect
12 | import java.text.NumberFormat
13 | import kotlin.math.max
14 |
15 | class BackdropVisualEffectHelper(private val view: View) {
16 | private var bitmapCanvas: Canvas? = null
17 | private var cacheBitmap: Bitmap? = null
18 | private var activityDecorView: View? = null
19 | private var isDifferentRoot = false
20 |
21 | private val renderingListener = RenderingListener()
22 | private val locations = IntArray(2)
23 | private val srcRect = Rect()
24 | private val dstRect = Rect()
25 |
26 | private val paint = Paint().apply {
27 | isAntiAlias = true
28 | typeface = Typeface.MONOSPACE
29 | textSize = TypedValue.applyDimension(
30 | TypedValue.COMPLEX_UNIT_SP,
31 | 9F,
32 | view.context.resources.displayMetrics
33 | )
34 | }
35 |
36 | private val realScaleXY: FloatArray = floatArrayOf(1F, 1F)
37 | get() {
38 | field[0] = view.scaleX
39 | field[1] = view.scaleY
40 | var viewGroup: ViewGroup? = view.parent as? ViewGroup?
41 | while (viewGroup != null) {
42 | field[0] *= viewGroup.scaleX
43 | field[1] *= viewGroup.scaleY
44 | viewGroup = viewGroup.parent as? ViewGroup?
45 | }
46 | return field
47 | }
48 |
49 | private var renderStartTime = 0L
50 | private var renderEndTime = 0L
51 |
52 | val isRendering: Boolean get() = renderEndTime < renderStartTime
53 |
54 | var overlayColor: Int = Color.TRANSPARENT
55 | set(value) {
56 | if (field != value) {
57 | field = value
58 | view.postInvalidate()
59 | }
60 | }
61 | var visualEffect: VisualEffect? = null
62 | set(value) {
63 | if (field != value) {
64 | field?.recycle()
65 | field = value
66 | view.postInvalidate()
67 | }
68 | }
69 | var simpleSize = 1F
70 | set(value) {
71 | if (field != value) {
72 | field = max(1F, value)
73 | view.postInvalidate()
74 | }
75 | }
76 | var isShowDebugInfo = BuildConfig.DEBUG
77 | set(value) {
78 | if (field != value) {
79 | field = value
80 | view.postInvalidate()
81 | }
82 | }
83 |
84 | init {
85 | view.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener {
86 | override fun onViewAttachedToWindow(v: View) {
87 | onAttachedToWindow()
88 | }
89 |
90 | override fun onViewDetachedFromWindow(v: View) {
91 | onDetachedFromWindow()
92 | }
93 | })
94 | }
95 |
96 | fun checkRendering() {
97 | if (isRendering) {
98 | throw StopException
99 | }
100 | }
101 |
102 | fun onDraw(canvas: Canvas) {
103 | checkRendering()
104 | cacheBitmap?.let {
105 | onDrawEffectedBitmap(canvas, it)
106 | }
107 | canvas.drawColor(overlayColor)
108 | if (isShowDebugInfo) {
109 | onDrawDebugInfo(canvas)
110 | }
111 | }
112 |
113 | fun onRestoreInstanceState(state: Parcelable?, callSuper: (Parcelable?) -> Unit) {
114 | if (state !is SavedState) {
115 | callSuper.invoke(state)
116 | return
117 | }
118 | callSuper.invoke(state.superState)
119 | isShowDebugInfo = state.isShowDebugInfo
120 | simpleSize = state.simpleSize
121 | overlayColor = state.overlayColor
122 | visualEffect = state.visualEffect
123 | }
124 |
125 | fun onSaveInstanceState(callSuper: () -> Parcelable?): Parcelable {
126 | val superState = callSuper.invoke() ?: View.BaseSavedState.EMPTY_STATE
127 | return SavedState(
128 | superState = superState,
129 | isShowDebugInfo = isShowDebugInfo,
130 | simpleSize = simpleSize,
131 | overlayColor = overlayColor,
132 | visualEffect = visualEffect as? ParcelableVisualEffect?
133 | )
134 | }
135 |
136 | private fun onAttachedToWindow() {
137 | view.context.getActivity()?.let {
138 | activityDecorView = it.window?.decorView
139 | }
140 | registerRenderingListener()
141 | activityDecorView?.let {
142 | isDifferentRoot = it.rootView !== view.rootView
143 | if (isDifferentRoot) {
144 | it.postInvalidate()
145 | }
146 | } ?: kotlin.run {
147 | isDifferentRoot = false
148 | }
149 | }
150 |
151 | private fun onDetachedFromWindow() {
152 | unregisterRenderingListener()
153 | visualEffect?.recycle()
154 | }
155 |
156 | private fun registerRenderingListener() {
157 | activityDecorView?.let {
158 | if (it.viewTreeObserver.isAlive) {
159 | it.viewTreeObserver.addOnPreDrawListener(renderingListener)
160 | }
161 | isDifferentRoot = it.rootView !== view.rootView
162 | if (isDifferentRoot) {
163 | it.postInvalidate()
164 | }
165 | }
166 | }
167 |
168 | private fun unregisterRenderingListener() {
169 | activityDecorView?.let {
170 | if (it.viewTreeObserver.isAlive) {
171 | it.viewTreeObserver.removeOnPreDrawListener(renderingListener)
172 | }
173 | }
174 | }
175 |
176 | private fun prepare() {
177 | val simpledWidth = (view.width / simpleSize).toInt()
178 | val simpledHeight = (view.height / simpleSize).toInt()
179 | if (simpledWidth <= 0 || simpledHeight <= 0) {
180 | bitmapCanvas = null
181 | cacheBitmap = null
182 | } else if (cacheBitmap == null || cacheBitmap!!.width != simpledWidth || cacheBitmap!!.height != simpledHeight) {
183 | cacheBitmap = try {
184 | Bitmap.createBitmap(simpledWidth, simpledHeight, Bitmap.Config.ARGB_8888)
185 | } catch (e: OutOfMemoryError) {
186 | Runtime.getRuntime().gc()
187 | null
188 | }
189 | if (cacheBitmap != null) {
190 | if (bitmapCanvas == null) {
191 | bitmapCanvas = Canvas()
192 | }
193 | bitmapCanvas!!.setBitmap(cacheBitmap)
194 | } else {
195 | bitmapCanvas = null
196 | }
197 | }
198 | }
199 |
200 | private fun renderOnce() {
201 | val visualEffect = visualEffect ?: return
202 | if (!view.isShown) return
203 | val decor = activityDecorView ?: return
204 | if (!decor.isDirty) return
205 | prepare()
206 | val canvas = bitmapCanvas ?: return
207 | val bitmap = cacheBitmap ?: return
208 | renderStartTime = System.nanoTime()
209 | bitmap.eraseColor(Color.TRANSPARENT)
210 | captureToBitmap(decor, canvas, bitmap)
211 | visualEffect.process(bitmap, bitmap)
212 | renderEndTime = System.nanoTime()
213 | view.invalidate()
214 | }
215 |
216 | private fun captureToBitmap(decor: View, canvas: Canvas, bitmap: Bitmap) {
217 | val restoreCount = canvas.save()
218 | try {
219 | decor.getLocationOnScreen(locations)
220 | var x = -locations[0]
221 | var y = -locations[1]
222 | view.getLocationOnScreen(locations)
223 | x += locations[0]
224 | y += locations[1]
225 | val realScaleXX = realScaleXY
226 | val vw = view.width.toFloat() * realScaleXX[0]
227 | val vh = view.height.toFloat() * realScaleXX[1]
228 | canvas.scale(
229 | bitmap.width.toFloat() / vw,
230 | bitmap.height.toFloat() / vh
231 | )
232 | canvas.translate(-x.toFloat(), -y.toFloat())
233 | decor.background?.draw(canvas)
234 | decor.draw(canvas)
235 | } catch (e: StopException) {
236 | } finally {
237 | canvas.restoreToCount(restoreCount)
238 | }
239 | }
240 |
241 | private fun onDrawEffectedBitmap(canvas: Canvas, bitmap: Bitmap) {
242 | paint.color = Color.WHITE
243 | srcRect.right = bitmap.width
244 | srcRect.bottom = bitmap.height
245 | dstRect.right = view.width
246 | dstRect.bottom = view.height
247 | canvas.drawBitmap(bitmap, srcRect, dstRect, paint)
248 | }
249 |
250 | private fun onDrawDebugInfo(canvas: Canvas) {
251 | var textBaseLine = 0F
252 | val costTime = (renderEndTime - renderStartTime).toDouble() / 1_000_000
253 | val costText = NumberFormat.getInstance().let {
254 | it.isGroupingUsed = false
255 | it.minimumFractionDigits = 3
256 | it.maximumFractionDigits = 3
257 | it.format(costTime)
258 | }
259 | textBaseLine += -paint.fontMetrics.ascent
260 | canvas.drawText(
261 | costText,
262 | view.width - paint.measureText(costText),
263 | textBaseLine,
264 | paint.apply {
265 | color = if (costTime > 16.6F) Color.RED else Color.BLACK
266 | }
267 | )
268 | val bmpSizeText = "${cacheBitmap?.width ?: 0}*${cacheBitmap?.height ?: 0}"
269 | textBaseLine += -paint.fontMetrics.ascent
270 | canvas.drawText(
271 | bmpSizeText,
272 | view.width - paint.measureText(bmpSizeText),
273 | textBaseLine,
274 | paint.apply {
275 | color = Color.BLACK
276 | }
277 | )
278 | }
279 |
280 | private class SavedState(
281 | superState: Parcelable,
282 | val isShowDebugInfo: Boolean,
283 | val simpleSize: Float,
284 | val overlayColor: Int,
285 | val visualEffect: ParcelableVisualEffect?
286 | ) : View.BaseSavedState(superState) {
287 | override fun writeToParcel(dest: Parcel, flags: Int) {
288 | super.writeToParcel(dest, flags)
289 | dest.writeInt(if (isShowDebugInfo) 1 else 0)
290 | dest.writeFloat(simpleSize)
291 | dest.writeInt(overlayColor)
292 | dest.writeParcelable(visualEffect, 0)
293 | }
294 | }
295 |
296 | private inner class RenderingListener : ViewTreeObserver.OnPreDrawListener {
297 | override fun onPreDraw(): Boolean {
298 | renderOnce()
299 | return true
300 | }
301 | }
302 |
303 | private object StopException : RuntimeException()
304 | }
--------------------------------------------------------------------------------
/simple/src/main/java/per/goweii/visualeffect/simple/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package per.goweii.visualeffect.simple
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Intent
5 | import android.graphics.Color
6 | import android.os.Bundle
7 | import android.util.TypedValue
8 | import android.view.Gravity
9 | import android.view.Menu
10 | import android.view.MenuItem
11 | import android.view.ViewGroup
12 | import android.widget.FrameLayout
13 | import android.widget.SeekBar
14 | import androidx.appcompat.app.AlertDialog
15 | import androidx.appcompat.app.AppCompatActivity
16 | import androidx.cardview.widget.CardView
17 | import androidx.core.view.isVisible
18 | import com.bumptech.glide.Glide
19 | import per.goweii.visualeffect.simple.databinding.ActivityMainBinding
20 | import per.goweii.visualeffect.blur.BlurEffect
21 | import per.goweii.visualeffect.blur.FastBlurEffect
22 | import per.goweii.visualeffect.blur.RSBlurEffect
23 | import per.goweii.visualeffect.core.GroupVisualEffect
24 | import per.goweii.visualeffect.core.VisualEffect
25 | import per.goweii.visualeffect.mosaic.MosaicEffect
26 | import per.goweii.visualeffect.view.BackdropVisualEffectView
27 | import per.goweii.visualeffect.watermask.WatermarkEffect
28 | import kotlin.math.max
29 |
30 | @SuppressLint("SetTextI18n")
31 | class MainActivity : AppCompatActivity() {
32 | private lateinit var binding: ActivityMainBinding
33 |
34 | private val visualEffectArray = arrayOf VisualEffect>>(
35 | RSBlurEffect::class.java.simpleName to {
36 | RSBlurEffect(applicationContext, blurRadius)
37 | },
38 | FastBlurEffect::class.java.simpleName to {
39 | FastBlurEffect(blurRadius)
40 | },
41 | MosaicEffect::class.java.simpleName to {
42 | MosaicEffect(mosaicBoxSize)
43 | },
44 | WatermarkEffect::class.java.simpleName to {
45 | WatermarkEffect("goweii", Color.BLACK, watermarkTextSize)
46 | },
47 | GroupVisualEffect::class.java.simpleName to {
48 | GroupVisualEffect(
49 | RSBlurEffect(applicationContext, blurRadius),
50 | MosaicEffect(mosaicBoxSize),
51 | WatermarkEffect(
52 | "goweii",
53 | Color.BLACK,
54 | watermarkTextSize
55 | ),
56 | )
57 | }
58 | )
59 |
60 | private val blurRadius: Float get() = binding.sbRadius.progress.toFloat()
61 | private val mosaicBoxSize: Int get() = binding.sbBoxSize.progress
62 | private val watermarkTextSize: Float get() = binding.sbWatermarkSize.progress.toFloat()
63 | private val simpleSize: Float get() = max(binding.sbSimpleSize.progress.toFloat(), 1F)
64 |
65 | private lateinit var backdropVisualEffectView: BackdropVisualEffectView
66 |
67 | private var currVisualEffectIndex = 0
68 |
69 | override fun onCreate(savedInstanceState: Bundle?) {
70 | super.onCreate(savedInstanceState)
71 | binding = ActivityMainBinding.inflate(layoutInflater)
72 | setContentView(binding.root)
73 | backdropVisualEffectView = newVisualEffectCard(false)
74 | binding.sbRadius.apply {
75 | max = 100
76 | progress = 10
77 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
78 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
79 | refreshEffectValue()
80 | }
81 |
82 | override fun onStartTrackingTouch(seekBar: SeekBar) {
83 | }
84 |
85 | override fun onStopTrackingTouch(seekBar: SeekBar) {
86 | }
87 | })
88 | }
89 | binding.sbBoxSize.apply {
90 | max = 40
91 | progress = 4
92 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
93 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
94 | refreshEffectValue()
95 | }
96 |
97 | override fun onStartTrackingTouch(seekBar: SeekBar) {
98 | }
99 |
100 | override fun onStopTrackingTouch(seekBar: SeekBar) {
101 | }
102 | })
103 | }
104 | binding.sbWatermarkSize.apply {
105 | max = 40
106 | progress = 10
107 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
108 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
109 | refreshEffectValue()
110 | }
111 |
112 | override fun onStartTrackingTouch(seekBar: SeekBar) {
113 | }
114 |
115 | override fun onStopTrackingTouch(seekBar: SeekBar) {
116 | }
117 | })
118 | }
119 | binding.sbSimpleSize.apply {
120 | max = 20
121 | progress = 8
122 | setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
123 | override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
124 | refreshSimpleSize()
125 | }
126 |
127 | override fun onStartTrackingTouch(seekBar: SeekBar) {
128 | }
129 |
130 | override fun onStopTrackingTouch(seekBar: SeekBar) {
131 | }
132 | })
133 | }
134 | refreshEffectValue()
135 | refreshSimpleSize()
136 | loadImage("https://imgsa.baidu.com/forum/w%3D580/sign=d5b742f157e736d158138c00ab514ffc/b9afb24543a98226a245270a8982b9014b90eb86.gif")
137 | }
138 |
139 | private fun showVisualEffectPopupWindow() {
140 | AlertDialog.Builder(this)
141 | .setView(newVisualEffectView())
142 | .show().apply {
143 | window?.apply {
144 | setLayout(
145 | TypedValue.applyDimension(
146 | TypedValue.COMPLEX_UNIT_DIP,
147 | 300F,
148 | resources.displayMetrics
149 | ).toInt(),
150 | TypedValue.applyDimension(
151 | TypedValue.COMPLEX_UNIT_DIP,
152 | 300F,
153 | resources.displayMetrics
154 | ).toInt()
155 | )
156 | }
157 | }
158 | }
159 |
160 | override fun onCreateOptionsMenu(menu: Menu?): Boolean {
161 | menuInflater.inflate(R.menu.menu_main, menu)
162 | return true
163 | }
164 |
165 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
166 | when (item.itemId) {
167 | R.id.action_blur_add_view -> {
168 | newVisualEffectCard(true)
169 | }
170 | R.id.action_blur_show_dialog -> {
171 | showVisualEffectPopupWindow()
172 | }
173 | R.id.action_blur_select_photo -> {
174 | val intent = Intent(
175 | Intent.ACTION_PICK,
176 | android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
177 | )
178 | startActivityForResult(intent, REQ_CODE_IMAGE)
179 | }
180 | R.id.action_blur_select_effect -> {
181 | AlertDialog.Builder(this)
182 | .setSingleChoiceItems(
183 | visualEffectArray.map { it.first }.toTypedArray(),
184 | currVisualEffectIndex
185 | ) { dialog, which ->
186 | currVisualEffectIndex = which
187 | backdropVisualEffectView.visualEffect =
188 | visualEffectArray[currVisualEffectIndex].second.invoke()
189 | refreshEffectValue()
190 | dialog.dismiss()
191 | }
192 | .create()
193 | .show()
194 | }
195 | }
196 | return true
197 | }
198 |
199 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
200 | super.onActivityResult(requestCode, resultCode, data)
201 | when (requestCode) {
202 | REQ_CODE_IMAGE -> {
203 | if (resultCode == RESULT_OK) {
204 | loadImage(data?.data)
205 | }
206 | }
207 | }
208 | }
209 |
210 | private fun refreshSimpleSize() {
211 | binding.tvSimpleSize.text =
212 | "缩小比例(${binding.sbSimpleSize.progress}/${binding.sbSimpleSize.max})"
213 | backdropVisualEffectView.simpleSize = simpleSize
214 | }
215 |
216 | private fun refreshEffectValue() {
217 | binding.llRadius.isVisible = false
218 | binding.llBoxSize.isVisible = false
219 | binding.llWatermarkSize.isVisible = false
220 | backdropVisualEffectView.visualEffect.run {
221 | when (this) {
222 | is GroupVisualEffect -> {
223 | this.getVisualEffects().forEach {
224 | refreshEffectValue(it)
225 | }
226 | }
227 | is BlurEffect -> {
228 | refreshEffectValue(this)
229 | }
230 | is MosaicEffect -> {
231 | refreshEffectValue(this)
232 | }
233 | is WatermarkEffect -> {
234 | refreshEffectValue(this)
235 | }
236 | }
237 | }
238 | }
239 |
240 | private fun refreshEffectValue(visualEffect: VisualEffect) {
241 | when (visualEffect) {
242 | is BlurEffect -> {
243 | visualEffect.radius = binding.sbRadius.progress.toFloat()
244 | binding.llRadius.isVisible = true
245 | binding.tvRadius.text = "模糊半径(${binding.sbRadius.progress}/${binding.sbRadius.max})"
246 | }
247 | is MosaicEffect -> {
248 | visualEffect.boxSize = binding.sbBoxSize.progress
249 | binding.llBoxSize.isVisible = true
250 | binding.tvBoxSize.text =
251 | "块尺寸(${binding.sbBoxSize.progress}/${binding.sbBoxSize.max})"
252 | }
253 | is WatermarkEffect -> {
254 | visualEffect.textSize = binding.sbWatermarkSize.progress.toFloat()
255 | binding.llWatermarkSize.isVisible = true
256 | binding.tvWatermarkSize.text =
257 | "水印大小(${binding.sbWatermarkSize.progress}/${binding.sbWatermarkSize.max})"
258 | }
259 | }
260 | }
261 |
262 | @SuppressLint("ClickableViewAccessibility")
263 | private fun newVisualEffectView(): BackdropVisualEffectView {
264 | val visualEffectView = BackdropVisualEffectView(this)
265 | visualEffectView.visualEffect = visualEffectArray[currVisualEffectIndex].second.invoke()
266 | visualEffectView.simpleSize = simpleSize
267 | return visualEffectView
268 | }
269 |
270 | @SuppressLint("ClickableViewAccessibility")
271 | private fun newVisualEffectCard(closeable: Boolean): BackdropVisualEffectView {
272 | val cardView = CardView(this).apply {
273 | isSelected = false
274 | setCardBackgroundColor(Color.TRANSPARENT)
275 | cardElevation = TypedValue.applyDimension(
276 | TypedValue.COMPLEX_UNIT_DIP,
277 | 8F,
278 | resources.displayMetrics
279 | )
280 | radius = TypedValue.applyDimension(
281 | TypedValue.COMPLEX_UNIT_DIP,
282 | 6F,
283 | resources.displayMetrics
284 | )
285 | }
286 | val visualEffectView = newVisualEffectView()
287 | cardView.addView(
288 | visualEffectView,
289 | ViewGroup.LayoutParams(
290 | ViewGroup.LayoutParams.MATCH_PARENT,
291 | ViewGroup.LayoutParams.MATCH_PARENT
292 | )
293 | )
294 | val decorView = window.decorView as FrameLayout
295 | decorView.addView(cardView, FrameLayout.LayoutParams(
296 | TypedValue.applyDimension(
297 | TypedValue.COMPLEX_UNIT_DIP,
298 | 120F,
299 | resources.displayMetrics
300 | ).toInt(),
301 | TypedValue.applyDimension(
302 | TypedValue.COMPLEX_UNIT_DIP,
303 | 120F,
304 | resources.displayMetrics
305 | ).toInt()
306 | ).also {
307 | it.gravity = Gravity.CENTER
308 | })
309 | DragGestureHelper.attach(cardView).apply {
310 | onDoubleClick = {
311 | if (closeable) {
312 | decorView.removeView(cardView)
313 | } else {
314 | cardView.isSelected = !cardView.isSelected
315 | val s = if (cardView.isSelected) 2F else 1F
316 | cardView.animate()
317 | .scaleX(s)
318 | .scaleY(s)
319 | .setDuration(2000)
320 | .start()
321 | }
322 | }
323 | }
324 | return visualEffectView
325 | }
326 |
327 | private fun loadImage(data: Any?) {
328 | Glide.with(this)
329 | .load(data)
330 | .into(binding.ivOriginal)
331 | }
332 |
333 | companion object {
334 | private const val REQ_CODE_IMAGE = 1
335 | }
336 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------