├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── test.jpg │ │ │ │ ├── test2.jpg │ │ │ │ ├── built1.png │ │ │ │ ├── test_watermark.png │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── font │ │ │ │ └── champagne.ttf │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── layout │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── watermark │ │ │ └── androidwm │ │ │ └── sample │ │ │ ├── Leaks.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── watermark │ │ │ └── androidwm │ │ │ └── sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── watermark │ │ └── androidwm │ │ └── sample │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── androidwm ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── watermark │ │ │ │ └── androidwm │ │ │ │ ├── listener │ │ │ │ ├── BuildFinishListener.java │ │ │ │ └── DetectFinishListener.java │ │ │ │ ├── bean │ │ │ │ ├── WatermarkObject.java │ │ │ │ ├── WatermarkPosition.java │ │ │ │ ├── AsyncTaskParams.java │ │ │ │ ├── WatermarkImage.java │ │ │ │ └── WatermarkText.java │ │ │ │ ├── task │ │ │ │ ├── DetectionReturnValue.java │ │ │ │ ├── LSBDetectionTask.java │ │ │ │ ├── FDDetectionTask.java │ │ │ │ ├── LSBWatermarkTask.java │ │ │ │ └── FDWatermarkTask.java │ │ │ │ ├── utils │ │ │ │ ├── Constant.java │ │ │ │ ├── FastDctFft.java │ │ │ │ ├── StringUtils.java │ │ │ │ ├── Fft.java │ │ │ │ └── BitmapUtils.java │ │ │ │ ├── WatermarkDetector.java │ │ │ │ └── Watermark.java │ │ └── cpp │ │ │ └── Watermark.cpp │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── watermark │ │ │ └── androidwm │ │ │ ├── ExampleUnitTest.java │ │ │ ├── LSBDetectionTest.java │ │ │ └── DCTTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── watermark │ │ └── androidwm │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro ├── build.gradle ├── android-release-aar.gradle └── CMakeLists.txt ├── _config.yml ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── caches │ └── build_file_checksums.ser ├── compiler.xml ├── vcs.xml ├── modules.xml ├── checkstyle-idea.xml ├── gradle.xml ├── jarRepositories.xml ├── codeStyles │ └── Project.xml └── misc.xml ├── gradle.properties ├── .travis.yml ├── .gitignore ├── gradlew.bat ├── wikis ├── WIKI-CN.md └── WIKI.md ├── gradlew ├── README-CN.md ├── config └── pmd-ruleset.xml ├── README.md └── images └── logo.svg /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /androidwm/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':androidwm' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /androidwm/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | androidwm 3 | 4 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /sample/src/main/res/drawable/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/drawable/test.jpg -------------------------------------------------------------------------------- /sample/src/main/res/drawable/test2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/drawable/test2.jpg -------------------------------------------------------------------------------- /sample/src/main/res/font/champagne.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/font/champagne.ttf -------------------------------------------------------------------------------- /sample/src/main/res/drawable/built1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/drawable/built1.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable/test_watermark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/drawable/test_watermark.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /androidwm/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangyz0918/AndroidWM/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 09 11:07:57 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /androidwm/src/test/java/com/watermark/androidwm/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/src/test/java/com/watermark/androidwm/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | androidWM 3 | create text 4 | create image 5 | invisible image 6 | invisible text 7 | detect image 8 | detect text 9 | Clear watermarks 10 | Load picture 11 | input mark text here 12 | 13 | -------------------------------------------------------------------------------- /.idea/checkstyle-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 15 | 16 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /androidwm/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m -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 | android.useAndroidX=true 15 | android.enableJetifier=true 16 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 20 | 21 | -------------------------------------------------------------------------------- /androidwm/src/androidTest/java/com/watermark/androidwm/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.androidwm.watermark.androidwm.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/watermark/androidwm/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm.sample; 2 | 3 | import android.content.Context; 4 | import androidx.test.platform.app.InstrumentationRegistry; 5 | import androidx.test.ext.junit.runners.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 23 | 24 | assertEquals("com.androidwm.watermark.androidwm", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | sudo: false 4 | 5 | notifications: 6 | email: false 7 | 8 | before_cache: 9 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 10 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 11 | 12 | cache: 13 | directories: 14 | - $HOME/.gradle/caches/ 15 | - $HOME/.gradle/wrapper/ 16 | - $HOME/.android/build-cache 17 | 18 | before_install: 19 | - echo y | android update sdk --no-ui --all --filter sys-img-armeabi-v7a-android-27,sys-img-x86_64-android-27,build-tools-27.0.3 20 | - sudo apt-get install ant 21 | 22 | install: 23 | - echo y | sdkmanager "ndk-bundle" 24 | - echo y | sdkmanager "cmake;3.6.4111459" 25 | - echo y | sdkmanager "lldb;3.1" 26 | 27 | before_script: 28 | - export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle 29 | 30 | android: 31 | components: 32 | - platform-tools 33 | - tools 34 | - build-tools-28 35 | - android-28 36 | - extra-android-m2repository 37 | 38 | script: ./gradlew check 39 | -------------------------------------------------------------------------------- /sample/src/main/java/com/watermark/androidwm/sample/Leaks.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.sample; 18 | 19 | import android.app.Application; 20 | 21 | import com.squareup.leakcanary.LeakCanary; 22 | 23 | /** 24 | * To detect the memory leaks. 25 | */ 26 | public class Leaks extends Application { 27 | 28 | @Override 29 | public void onCreate() { 30 | super.onCreate(); 31 | LeakCanary.install(this); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/listener/BuildFinishListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.listener; 18 | 19 | 20 | /** 21 | * This interface is for listening if the task of 22 | * creating invisible watermark is finished. 23 | * 24 | * @param can be the image and the string watermarks. 25 | * @author huangyz0918 (huangyz0918@gmail.com) 26 | */ 27 | public interface BuildFinishListener { 28 | 29 | void onSuccess(T object); 30 | 31 | void onFailure(String message); 32 | } 33 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/listener/DetectFinishListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.listener; 18 | 19 | import com.watermark.androidwm.task.DetectionReturnValue; 20 | 21 | /** 22 | * This interface is for listening if the task of 23 | * detecting invisible watermark is finished. 24 | * 25 | * @author huangyz0918 (huangyz0918@gmail.com) 26 | */ 27 | public interface DetectFinishListener { 28 | 29 | void onSuccess(DetectionReturnValue returnValue); 30 | 31 | void onFailure(String message); 32 | } 33 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | 29 | 30 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/bean/WatermarkObject.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm.bean; 2 | 3 | public abstract class WatermarkObject { 4 | protected int alpha = 50; 5 | // set the default values for the position. 6 | protected WatermarkPosition position = new WatermarkPosition(0, 0, 0); 7 | protected WatermarkPosition origin = new WatermarkPosition(0, 0, 0); 8 | 9 | public WatermarkPosition getPosition() { 10 | return position; 11 | } 12 | 13 | public T setPosition(WatermarkPosition position) { 14 | this.position = position; 15 | return (T)this; 16 | } 17 | 18 | public WatermarkPosition getOrigin() { 19 | return origin; 20 | } 21 | 22 | public T setOrigin(WatermarkPosition origin) { 23 | this.origin = origin; 24 | return (T)this; 25 | } 26 | 27 | 28 | public T setPositionX(double x) { 29 | this.position.setPositionX(x); 30 | return (T)this; 31 | } 32 | 33 | public T setPositionY(double y) { 34 | this.position.setPositionY(y); 35 | return (T)this; 36 | } 37 | 38 | public T setRotation(double rotation) { 39 | this.position.setRotation(rotation); 40 | return (T)this; 41 | } 42 | 43 | public T setOriginX(double x) { 44 | this.origin.setPositionX(x); 45 | return (T)this; 46 | } 47 | 48 | public T setOriginY(double y) { 49 | this.origin.setPositionY(y); 50 | return (T)this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /androidwm/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | apply plugin: 'com.jfrog.bintray' 4 | 5 | android { 6 | compileSdkVersion 31 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 31 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 15 | 16 | externalNativeBuild { 17 | cmake { 18 | cppFlags "" 19 | } 20 | } 21 | 22 | ndk { 23 | // Add libs for ndk, here is log. 24 | ldLibs("log") 25 | } 26 | } 27 | 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | 35 | externalNativeBuild { 36 | cmake { 37 | path "CMakeLists.txt" 38 | } 39 | } 40 | 41 | compileOptions { 42 | sourceCompatibility JavaVersion.VERSION_1_8 43 | targetCompatibility JavaVersion.VERSION_1_8 44 | } 45 | 46 | } 47 | 48 | dependencies { 49 | implementation fileTree(dir: 'libs', include: ['*.jar']) 50 | 51 | implementation 'androidx.appcompat:appcompat:1.0.0' 52 | testImplementation 'junit:junit:4.12' 53 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 54 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 55 | implementation 'com.jakewharton.timber:timber:4.7.1' 56 | } 57 | 58 | if (project.rootProject.file('local.properties').exists()) { 59 | apply from: 'android-release-aar.gradle' 60 | } -------------------------------------------------------------------------------- /androidwm/android-release-aar.gradle: -------------------------------------------------------------------------------- 1 | // Run with: ./gradlew clean bintrayUpload 2 | 3 | Properties properties = new Properties() 4 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 5 | 6 | group = properties.getProperty('group') 7 | version = properties.getProperty('version') 8 | 9 | static def getDate() { 10 | def date = new Date() 11 | def formattedDate = date.format('yyyyMMddHHmmss') 12 | return formattedDate 13 | } 14 | 15 | bintray { 16 | user = properties.getProperty("bintray.user") 17 | key = properties.getProperty("bintray.apikey") 18 | 19 | pkg { 20 | repo = 'androidwm' 21 | name = 'androidwm' 22 | 23 | version { 24 | name = '0.2.3' 25 | desc = "A lightweight android image watermark library that supports encrypted watermarks." 26 | vcsTag = version 27 | } 28 | 29 | licenses = ['Apache-2.0'] 30 | vcsUrl = 'https://github.com/huangyz0918/AndroidWM' 31 | websiteUrl = 'http://huangyz.name/AndroidWM/' 32 | } 33 | 34 | configurations = ['archives'] 35 | 36 | } 37 | 38 | task sourcesJar(type: Jar) { 39 | from android.sourceSets.main.java.srcDirs 40 | classifier = 'sources' 41 | } 42 | 43 | task javadoc(type: Javadoc) { 44 | source = android.sourceSets.main.java.srcDirs 45 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 46 | } 47 | 48 | task javadocJar(type: Jar, dependsOn: javadoc) { 49 | classifier = 'javadoc' 50 | from javadoc.destinationDir 51 | } 52 | 53 | artifacts { 54 | archives javadocJar 55 | archives sourcesJar 56 | } 57 | 58 | task findConventions { 59 | println project.getConvention() 60 | } -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 31 5 | defaultConfig { 6 | applicationId "com.watermark.androidwm.sample" 7 | minSdkVersion 16 8 | targetSdkVersion 31 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | 20 | compileOptions { 21 | sourceCompatibility JavaVersion.VERSION_1_8 22 | targetCompatibility JavaVersion.VERSION_1_8 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation 'androidx.appcompat:appcompat:1.0.0' 29 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 30 | testImplementation 'junit:junit:4.12' 31 | androidTestImplementation 'androidx.test.ext:junit:1.1.1' 32 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 33 | // test for local library. 34 | implementation project(":androidwm") 35 | // glide 36 | implementation 'com.github.bumptech.glide:glide:4.8.0' 37 | annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' 38 | // leakcanary 39 | debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.1' 40 | releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1' 41 | // Optional, if you use support library fragments: 42 | debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.1' 43 | // timber 44 | implementation 'com.jakewharton.timber:timber:4.7.1' 45 | 46 | } 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.cxx 2 | 3 | # Built application files 4 | *.apk 5 | *.ap_ 6 | 7 | # Files for the ART/Dalvik VM 8 | *.dex 9 | 10 | # Java class files 11 | *.class 12 | 13 | # Generated files 14 | bin/ 15 | gen/ 16 | out/ 17 | 18 | # Gradle files 19 | .gradle/ 20 | build/ 21 | 22 | # Local configuration file (sdk path, etc) 23 | local.properties 24 | 25 | # Proguard folder generated by Eclipse 26 | proguard/ 27 | 28 | # Log Files 29 | *.log 30 | 31 | # Android Studio Navigation editor temp files 32 | .navigation/ 33 | 34 | # Android Studio captures folder 35 | captures/ 36 | 37 | # IntelliJ 38 | *.iml 39 | .idea/workspace.xml 40 | .idea/tasks.xml 41 | .idea/gradle.xml 42 | .idea/assetWizardSettings.xml 43 | .idea/dictionaries 44 | .idea/libraries 45 | .idea/caches 46 | .idea/misc.xml 47 | 48 | # Keystore files 49 | # Uncomment the following line if you do not want to check your keystore files in. 50 | #*.jks 51 | 52 | # External native build folder generated in Android Studio 2.2 and later 53 | .externalNativeBuild 54 | 55 | # Google Services (e.g. APIs or Firebase) 56 | google-services.json 57 | 58 | # Freeline 59 | freeline.py 60 | freeline/ 61 | freeline_project_description.json 62 | 63 | # fastlane 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | fastlane/readme.md 69 | 70 | ### macOS ### 71 | *.DS_Store 72 | .AppleDouble 73 | .LSOverride 74 | 75 | # Icon must end with two \r 76 | Icon 77 | 78 | # Thumbnails 79 | ._* 80 | 81 | # Files that might appear in the root of a volume 82 | .DocumentRevisions-V100 83 | .fseventsd 84 | .Spotlight-V100 85 | .TemporaryItems 86 | .Trashes 87 | .VolumeIcon.icns 88 | .com.apple.timemachine.donotpresent 89 | 90 | # Directories potentially created on remote AFP share 91 | .AppleDB 92 | .AppleDesktop 93 | Network Trash Folder 94 | Temporary Items 95 | .apdisk 96 | 97 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/task/DetectionReturnValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.task; 18 | 19 | import android.graphics.Bitmap; 20 | 21 | /** 22 | * This is a simple class that can help we get more than two kinds of 23 | * return values in the task. 24 | * 25 | * @author huangyz0918 (huangyz0918@gmail.com) 26 | */ 27 | public class DetectionReturnValue { 28 | 29 | private Bitmap watermarkBitmap; 30 | private String watermarkString; 31 | 32 | public DetectionReturnValue() { 33 | 34 | } 35 | 36 | public DetectionReturnValue(Bitmap watermarkBitmap, String watermarkString) { 37 | this.watermarkBitmap = watermarkBitmap; 38 | this.watermarkString = watermarkString; 39 | } 40 | 41 | public Bitmap getWatermarkBitmap() { 42 | return watermarkBitmap; 43 | } 44 | 45 | protected void setWatermarkBitmap(Bitmap watermarkBitmap) { 46 | this.watermarkBitmap = watermarkBitmap; 47 | } 48 | 49 | public String getWatermarkString() { 50 | return watermarkString; 51 | } 52 | 53 | protected void setWatermarkString(String watermarkString) { 54 | this.watermarkString = watermarkString; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /androidwm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.4.1) 7 | 8 | # Creates and names a library, sets it as either STATIC 9 | # or SHARED, and provides the relative paths to its source code. 10 | # You can define multiple libraries, and CMake builds them for you. 11 | # Gradle automatically packages shared libraries with your APK. 12 | 13 | add_library( # Sets the name of the library. 14 | Watermark 15 | 16 | # Sets the library as a shared library. 17 | SHARED 18 | 19 | # Provides a relative path to your source file(s). 20 | src/main/cpp/Watermark.cpp) 21 | # Searches for a specified prebuilt library and stores the path as a 22 | # variable. Because CMake includes system libraries in the search path by 23 | # default, you only need to specify the name of the public NDK library 24 | # you want to add. CMake verifies that the library exists before 25 | # completing its build. 26 | 27 | find_library( # Sets the name of the path variable. 28 | log-lib 29 | 30 | # Specifies the name of the NDK library that 31 | # you want CMake to locate. 32 | log ) 33 | 34 | # Specifies libraries CMake should link to your target library. You 35 | # can link multiple libraries, such as libraries you define in this 36 | # build script, prebuilt third-party libraries, or system libraries. 37 | 38 | target_link_libraries( # Specifies the target library. 39 | Watermark 40 | 41 | # Links the target library to the log library 42 | # included in the NDK. 43 | ${log-lib} ) 44 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/utils/Constant.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.utils; 18 | 19 | /** 20 | * the constant pool. 21 | * 22 | * @author huangyz0918 (huangyz0918@gmail.com) 23 | */ 24 | public class Constant { 25 | public static final String LSB_IMG_PREFIX_FLAG = "1212"; 26 | public static final String LSB_TEXT_PREFIX_FLAG = "2323"; 27 | public static final String LSB_IMG_SUFFIX_FLAG = "3434"; 28 | public static final String LSB_TEXT_SUFFIX_FLAG = "4545"; 29 | 30 | public static final int MAX_IMAGE_SIZE = 1024; 31 | // use the watermark image's size 32 | public static final int CHUNK_SIZE = 5000; 33 | 34 | public static final String ERROR_NO_WATERMARKS = "No input text or image! please load an image or a text in your WatermarkBuilder!"; 35 | public static final String ERROR_CREATE_FAILED = "created watermark failed!"; 36 | public static final String ERROR_NO_BACKGROUND = "No background image! please load an image in your WatermarkBuilder!"; 37 | public static final String ERROR_PIXELS_NOT_ENOUGH = "The Pixels in background are too small to put the watermark in, " + 38 | "the data has been lost! Please make sure the maxImageSize is bigger enough!"; 39 | 40 | public static final String ERROR_DETECT_FAILED = "Failed to detect the watermark!"; 41 | public static final String ERROR_NO_WATERMARK_FOUND = "No watermarks found in this image!"; 42 | public static final String ERROR_BITMAP_NULL = "Cannot detect the watermark! markedBitmap is null object!"; 43 | 44 | public static final String WARNING_BIG_IMAGE = "The input image may be too large to put into the memory, please be careful of the OOM!"; 45 | } 46 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/bean/WatermarkPosition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.bean; 18 | 19 | import androidx.annotation.FloatRange; 20 | 21 | /** 22 | * It's a class for saving the position of watermark. 23 | * Can be used for a single image/text or a set of 24 | * images/texts. 25 | * 26 | * @author huangyz0918 (huangyz0918@gmail.com) 27 | * @since 29/08/2018 28 | */ 29 | public class WatermarkPosition { 30 | 31 | private double positionX; 32 | private double positionY; 33 | private double rotation; 34 | 35 | /** 36 | * Constructors for WatermarkImage 37 | */ 38 | public WatermarkPosition(@FloatRange(from = 0, to = 1) double positionX, 39 | @FloatRange(from = 0, to = 1) double positionY) { 40 | this.positionX = positionX; 41 | this.positionY = positionY; 42 | } 43 | 44 | public WatermarkPosition(@FloatRange(from = 0, to = 1) double positionX, 45 | @FloatRange(from = 0, to = 1) double positionY, 46 | double rotation) { 47 | this.positionX = positionX; 48 | this.positionY = positionY; 49 | this.rotation = rotation; 50 | } 51 | 52 | /** 53 | * Getters and Setters for those attrs. 54 | */ 55 | public double getPositionX() { 56 | return positionX; 57 | } 58 | 59 | public WatermarkPosition setPositionX(double positionX) { 60 | this.positionX = positionX; 61 | return this; 62 | } 63 | 64 | public double getPositionY() { 65 | return positionY; 66 | } 67 | 68 | public WatermarkPosition setPositionY(double positionY) { 69 | this.positionY = positionY; 70 | return this; 71 | } 72 | 73 | public double getRotation() { 74 | return rotation; 75 | } 76 | 77 | public WatermarkPosition setRotation(double rotation) { 78 | this.rotation = rotation; 79 | return this; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/WatermarkDetector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm; 18 | 19 | import android.graphics.Bitmap; 20 | import android.graphics.drawable.BitmapDrawable; 21 | import androidx.annotation.NonNull; 22 | import android.widget.ImageView; 23 | 24 | import com.watermark.androidwm.listener.DetectFinishListener; 25 | import com.watermark.androidwm.task.FDDetectionTask; 26 | import com.watermark.androidwm.task.LSBDetectionTask; 27 | 28 | /** 29 | * This is for detecting the invisible watermark in one picture. 30 | * 31 | * @author huangyz0918 (huangyz0918@gmail.com) 32 | */ 33 | public final class WatermarkDetector { 34 | private Bitmap imageWithWatermark; 35 | private boolean isLSB; 36 | 37 | private WatermarkDetector( 38 | @NonNull Bitmap imageWithWatermark, 39 | boolean isLSB) { 40 | this.imageWithWatermark = imageWithWatermark; 41 | this.isLSB = isLSB; 42 | } 43 | 44 | /** 45 | * to get an instance form class. 46 | * 47 | * @return instance of {@link WatermarkDetector} 48 | */ 49 | public static WatermarkDetector create(@NonNull Bitmap imageWithWatermark, boolean isLSB) { 50 | return new WatermarkDetector(imageWithWatermark, isLSB); 51 | } 52 | 53 | /** 54 | * to get an instance form class. 55 | * If the imageView has no src or bitmap image, it will throws a {@link NullPointerException}. 56 | * 57 | * @return instance of {@link WatermarkDetector} 58 | */ 59 | public static WatermarkDetector create(ImageView imageView, boolean isLSB) { 60 | BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 61 | return new WatermarkDetector(drawable.getBitmap(), isLSB); 62 | } 63 | 64 | /** 65 | * The method for watermark detecting. 66 | */ 67 | public void detect(DetectFinishListener listener) { 68 | if (isLSB) { 69 | new LSBDetectionTask(listener).execute(imageWithWatermark); 70 | } else { 71 | new FDDetectionTask(listener).execute(imageWithWatermark); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/bean/AsyncTaskParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.bean; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | 22 | /** 23 | * This is a simple class that can help we put multiple primitive 24 | * parameters into the task. 25 | * 26 | * @author huangyz0918 (huangyz0918@gmail.com) 27 | */ 28 | public class AsyncTaskParams { 29 | private Bitmap backgroundImg; 30 | private WatermarkText watermarkText; 31 | private Bitmap watermarkImg; 32 | private Context context; 33 | 34 | public AsyncTaskParams(Context context, Bitmap backgroundImg, WatermarkText watermarkText, Bitmap watermarkImg) { 35 | this.backgroundImg = backgroundImg; 36 | this.watermarkText = watermarkText; 37 | this.watermarkImg = watermarkImg; 38 | } 39 | 40 | public AsyncTaskParams(Context context, Bitmap backgroundImg, Bitmap watermarkImg) { 41 | this.backgroundImg = backgroundImg; 42 | this.watermarkImg = watermarkImg; 43 | } 44 | 45 | public AsyncTaskParams(Context context, Bitmap backgroundImg, WatermarkText watermarkText) { 46 | this.backgroundImg = backgroundImg; 47 | this.watermarkText = watermarkText; 48 | } 49 | 50 | /** 51 | * Getters and Setters for {@link AsyncTaskParams}. 52 | */ 53 | public Bitmap getBackgroundImg() { 54 | return backgroundImg; 55 | } 56 | 57 | public void setBackgroundImg(Bitmap backgroundImg) { 58 | this.backgroundImg = backgroundImg; 59 | } 60 | 61 | public WatermarkText getWatermarkText() { 62 | return watermarkText; 63 | } 64 | 65 | public void setWatermarkText(WatermarkText watermarkText) { 66 | this.watermarkText = watermarkText; 67 | } 68 | 69 | public Bitmap getWatermarkImg() { 70 | return watermarkImg; 71 | } 72 | 73 | public void setWatermarkImg(Bitmap watermarkImg) { 74 | this.watermarkImg = watermarkImg; 75 | } 76 | 77 | public Context getContext() { 78 | return context; 79 | } 80 | 81 | public void setContext(Context context) { 82 | this.context = context; 83 | } 84 | } -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/utils/FastDctFft.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package com.watermark.androidwm.utils; 19 | 20 | 21 | import java.util.Arrays; 22 | import java.util.Objects; 23 | 24 | public final class FastDctFft { 25 | 26 | /** 27 | * Computes the unscaled DCT type II on the specified array in place. 28 | * The array length must be a power of 2 or zero. 29 | * 30 | * @param vector the vector of numbers to transform 31 | * @throws NullPointerException if the array is {@code null} 32 | */ 33 | public static void transform(double[] vector) { 34 | Objects.requireNonNull(vector); 35 | int len = vector.length; 36 | int halfLen = len / 2; 37 | double[] real = new double[len]; 38 | 39 | for (int i = 0; i < halfLen; i++) { 40 | real[i] = vector[i * 2]; 41 | real[len - 1 - i] = vector[i * 2 + 1]; 42 | } 43 | 44 | if (len % 2 == 1) { 45 | real[halfLen] = vector[len - 1]; 46 | } 47 | 48 | Arrays.fill(vector, 0.0); 49 | Fft.transform(real, vector); 50 | for (int i = 0; i < len; i++) { 51 | double temp = i * Math.PI / (len * 2); 52 | vector[i] = real[i] * Math.cos(temp) + vector[i] * Math.sin(temp); 53 | } 54 | } 55 | 56 | 57 | /** 58 | * Computes the unscaled DCT type III on the specified array in place. 59 | * The array length must be a power of 2 or zero. 60 | * 61 | * @param vector the vector of numbers to transform 62 | * @throws NullPointerException if the array is {@code null} 63 | */ 64 | public static void inverseTransform(double[] vector) { 65 | Objects.requireNonNull(vector); 66 | int len = vector.length; 67 | if (len > 0) { 68 | vector[0] = vector[0] / 2; 69 | } 70 | 71 | double[] real = new double[len]; 72 | 73 | for (int i = 0; i < len; i++) { 74 | double temp = i * Math.PI / (len * 2); 75 | real[i] = vector[i] * Math.cos(temp); 76 | vector[i] *= -Math.sin(temp); 77 | } 78 | 79 | Fft.transform(real, vector); 80 | 81 | int halfLen = len / 2; 82 | for (int i = 0; i < halfLen; i++) { 83 | vector[i * 2] = real[i]; 84 | vector[i * 2 + 1] = real[len - 1 - i]; 85 | } 86 | 87 | if (len % 2 == 1) { 88 | vector[len - 1] = real[halfLen]; 89 | } 90 | 91 | double scale = (double) len / 2; 92 | for (int i = 0; i < len; i++) { 93 | vector[i] = (int) Math.round(vector[i] / scale); 94 | } 95 | 96 | } 97 | 98 | } -------------------------------------------------------------------------------- /androidwm/src/test/java/com/watermark/androidwm/LSBDetectionTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm; 2 | 3 | 4 | import org.junit.Test; 5 | 6 | import java.util.Arrays; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * The unit tests for the LSB invisible watermark detection methods. 12 | * 13 | * @author huangyz0918 (huangyz0918@gmail.com) 14 | */ 15 | public class LSBDetectionTest { 16 | 17 | private static int[][] chunkArray(int[] array, int chunkSize) { 18 | int numOfChunks = (int) Math.ceil((double) array.length / chunkSize); 19 | int[][] output = new int[numOfChunks][]; 20 | 21 | for (int i = 0; i < numOfChunks; ++i) { 22 | int start = i * chunkSize; 23 | int length = Math.min(array.length - start, chunkSize); 24 | 25 | int[] temp = new int[length]; 26 | System.arraycopy(array, start, temp, 0, length); 27 | output[i] = temp; 28 | } 29 | 30 | return output; 31 | } 32 | 33 | @Test 34 | public void arrayToStringTest() { 35 | int[] inputArray = { 36 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 37 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 38 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 39 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 40 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 41 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 42 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 43 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 44 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 45 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 46 | }; 47 | int minSize = 8; 48 | 49 | int multiple = inputArray.length / minSize; 50 | int mod = inputArray.length % minSize; 51 | 52 | StringBuilder[] builders = new StringBuilder[multiple + 1]; 53 | builders[builders.length - 1] = new StringBuilder(); 54 | 55 | int[] arrayWithout = Arrays.copyOfRange(inputArray, multiple * minSize, inputArray.length); 56 | int[] expectArray = {7, 8, 9, 0}; 57 | 58 | assertEquals(Arrays.toString(expectArray), Arrays.toString(arrayWithout)); 59 | assertEquals(mod, arrayWithout.length); 60 | } 61 | 62 | @Test 63 | public void chunkArrayTest() { 64 | int[] inputArray = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 65 | int chunkSize = 3; 66 | int[][] result = chunkArray(inputArray, chunkSize); 67 | StringBuilder[] builders = new StringBuilder[result.length]; 68 | StringBuilder resultBuilder = new StringBuilder(); 69 | 70 | for (int i = 0; i < result.length - 1; i++) { 71 | builders[i] = new StringBuilder(); 72 | for (int j = 0; j < chunkSize; j++) { 73 | builders[i].append(result[i][j]); 74 | } 75 | } 76 | 77 | builders[builders.length - 1] = new StringBuilder(); 78 | for (int i : result[result.length - 1]) { 79 | builders[builders.length - 1].append(i); 80 | } 81 | 82 | for (StringBuilder builder : builders) { 83 | resultBuilder.append(builder.toString()); 84 | } 85 | 86 | assertEquals(resultBuilder.toString(), "1234567891011121314"); 87 | assertEquals(Arrays.toString(result[0]), "[1, 2, 3]"); 88 | assertEquals(Arrays.toString(result[3]), "[10, 11, 12]"); 89 | assertEquals(Arrays.toString(result[result.length - 1]), "[13, 14]"); 90 | assertEquals(result.length, 5); 91 | 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 33 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | -------------------------------------------------------------------------------- /wikis/WIKI-CN.md: -------------------------------------------------------------------------------- 1 | # 使用说明 2 | 3 | ## 水印位置 4 | 我们使用 `WatermarkPosition` 这个类的对象来控制具体水印出现的位置。 5 | 6 | ```java 7 | WatermarkPosition watermarkPosition = new WatermarkPosition(double position_x, double position_y, double rotation); 8 | WatermarkPosition watermarkPosition = new WatermarkPosition(double position_x, double position_y); 9 | ``` 10 | 11 | 在函数构造器中,我们可以设定水印图片的横纵坐标,如果你想在构造器中初始化一个水印旋转角度也是可以的, 水印的坐标系以背景图片的左上角为原点,横轴向右,纵轴向下。 12 | 如果需要将定位原点从左上角修改为其他位置,可以稍后给`WatermarkText`或`WatermarkImage`调用`setOrigin(new WatermarkPosition(0.5, 0.5))`方法, 13 | 这里x,y都是0到1的浮点数,默认都是0,表示左上角对齐;0.5,0.5则表示中心对齐。 14 | 15 | `WatermarkPosition` 同时也支持动态调整水印的位置,这样你就不需要一次又一次地初始化新的位置对象了, androidwm 提供了一些方法: 16 | 17 | ```java 18 | watermarkPosition 19 | .setPositionX(x) 20 | .setPositionY(y) 21 | .setRotation(rotation); 22 | ``` 23 | 在全覆盖水印模式(Tile mode)下,关于水印位置的参数将会失效。 24 | 25 | | ![](https://i.loli.net/2018/09/05/5b8f4a970a83e.png) | ![](https://i.loli.net/2018/09/05/5b8f4a9706788.png) | 26 | | :-------------: | :-------------: | 27 | | x = y = 0, rotation = 15 | x = y = 0.5, rotation = -15 | 28 | 29 | 横纵坐标都是一个从 0 到 1 的浮点数,代表着和背景图片的相对比例。 30 | 31 | 32 | ## 字体水印的颜色 33 | 34 | 你可以在 `WatermarkText` 中设置字体水印的颜色或者是其背景颜色: 35 | 36 | ```java 37 | WatermarkText watermarkText = new WatermarkText(editText) 38 | .setPositionX(0.5) 39 | .setPositionY(0.5) 40 | .setTextSize(30) 41 | .setTextAlpha(200) 42 | .setTextColor(Color.GREEN) 43 | .setBackgroundColor(Color.WHITE); // 默认背景颜色是透明的 44 | ``` 45 | 46 | | ![](https://i.loli.net/2018/09/05/5b8f4ce0cf6ce.png) | ![](https://i.loli.net/2018/09/05/5b8f4ce11a28c.png) | 47 | | :-------------: | :-------------: | 48 | | color = green, background color = white | color = green, background color = default | 49 | 50 | ## 字体颜色的阴影和字体 51 | 你可以从软件资源中加载一种字体,也可以通过方法 `setTextShadow` 设置字体的阴影。 52 | 53 | ```java 54 | WatermarkText watermarkText = new WatermarkText(editText) 55 | .setPositionX(0.5) 56 | .setPositionY(0.5) 57 | .setOrigin(new WatermarkPosition(0.5, 0.5)) 58 | .setTextSize(40) 59 | .setTextAlpha(200) 60 | .setTextColor(Color.GREEN) 61 | .setTextFont(R.font.champagne) 62 | .setTextShadow(0.1f, 5, 5, Color.BLUE); 63 | ``` 64 | 65 | | ![](https://i.loli.net/2018/09/05/5b8f5c48e2631.png) | ![](https://i.loli.net/2018/09/05/5b8f5c48e081c.png) | 66 | | :-------------: | :-------------: | 67 | | font = champagne | shadow = (0.1f, 5, 5, BLUE) | 68 | 69 | 阴影的四个参数分别为: `(blur radius, x offset, y offset, color)`. 70 | 71 | ## 字体大小和图片大小 72 | 73 | 水印字体和水印图片大小的单位是不同的: 74 | - 字体大小和系统布局中字体大小是类似的,取决于屏幕的分辨率和背景图片的像素,您可能需要动态调整。 75 | - 图片大小是一个从 0 到 1 的浮点数,是水印图片的宽度占背景图片宽度的比例。 76 | 77 | | ![](https://i.loli.net/2018/09/05/5b8f5eb1a7fb0.png) | ![](https://i.loli.net/2018/09/05/5b8f5eb24d0fd.png) | 78 | | :-------------: | :-------------: | 79 | | image size = 0.3 | text size = 40 | 80 | 81 | 82 | ## 方法列表 83 | 对于 `WatermarkText` 和 `WatermarkImage` 的定制化,我们提供了一些常用的方法: 84 | 85 | 86 | | __方法名称__ | __备注__ | __默认值__ | 87 | | ------------- | ------------- | ------------- | 88 | | setPosition | 水印的位置类 `WatermarkPosition` | _null_ | 89 | | setPositionX | 水印的横轴坐标,从背景图片左上角为(0,0) | _0_ | 90 | | setPositionY | 水印的纵轴坐标,从背景图片左上角为(0,0) | _0_ | 91 | | setRotation | 水印的旋转角度| _0_ | 92 | | setOrigin | 水印的对齐原点| _null_ | 93 | | setOriginX | 水印的横坐标对齐位置,0~1之间| _0_ | 94 | | setOriginY | 水印的纵坐标对齐位置,0~1之间| _0_ | 95 | | setTextColor (`WatermarkText`) | `WatermarkText` 的文字颜色 | _`Color.BLACK`_ | 96 | | setTextStyle (`WatermarkText`) | `WatermarkText` 的文字样式| _`Paint.Style.FILL`_ | 97 | | setBackgroundColor (`WatermarkText`) | `WatermarkText` 的背景颜色 | _null_ | 98 | | setTextAlpha (`WatermarkText`) | `WatermarkText` 文字的透明度, 从 0 到 255 | _50_ | 99 | | setImageAlpha (`WatermarkImage`) | `WatermarkImage` 图片的透明度, 从 0 到 255 | _50_ | 100 | | setTextSize (`WatermarkText`) | `WatermarkText` 字体的大小,单位与系统 layout 相同 | _20_ | 101 | | setSize (`WatermarkImage`)| `WatermarkImage` 水印图片的大小,从 0 到 1 (背景图片大小的比例) | _0.2_ | 102 | | setTextFont (`WatermarkText`) | `WatermarkText` 的字体| _default_ | 103 | | setTextShadow (`WatermarkText`)| `WatermarkText` 字体的阴影与圆角 | _(0, 0, 0)_ | 104 | | setImageDrawable (`WatermarkImage`)| `WatermarkImage`的图片资源 | _null_ | 105 | 106 | `WatermarkImage` 的一些基本属性和`WatermarkText` 的相同。 107 | -------------------------------------------------------------------------------- /androidwm/src/test/java/com/watermark/androidwm/DCTTest.java: -------------------------------------------------------------------------------- 1 | package com.watermark.androidwm; 2 | 3 | import com.watermark.androidwm.utils.FastDctFft; 4 | 5 | import org.junit.Test; 6 | 7 | import java.util.Arrays; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertNotEquals; 11 | 12 | /** 13 | * The unit tests for the FD invisible watermark detection methods. 14 | * 15 | * @author huangyz0918 (huangyz0918@gmail.com) 16 | */ 17 | public class DCTTest { 18 | 19 | @Test 20 | public void testFftDct() { 21 | double[] test = {255.0, 254.0, 243.0, 253.0, 255.0, 255.0, 246.0, 255.0, 255.0, 255.0}; 22 | double[] temp = {255.0, 254.0, 243.0, 253.0, 255.0, 255.0, 246.0, 255.0, 255.0, 255.0}; 23 | FastDctFft.transform(test); 24 | FastDctFft.inverseTransform(test); 25 | 26 | assertEquals(temp[0] - test[0], 0, 0); 27 | assertEquals(temp[1] - test[1], 0, 0); 28 | assertEquals(temp[2] - test[2], 0, 0); 29 | assertEquals(temp[3] - test[3], 0, 0); 30 | } 31 | 32 | @Test 33 | public void testCombine() { 34 | double[] a = {1, 2, 3, 4, 5}; 35 | double[] b = {6, 7, 8, 9, 0}; 36 | double[] c = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; 37 | 38 | FastDctFft.transform(a); 39 | FastDctFft.transform(b); 40 | FastDctFft.transform(c); 41 | 42 | double[] combine = new double[10]; 43 | System.arraycopy(a, 0, combine, 0, 5); 44 | System.arraycopy(b, 0, combine, 5, 5); 45 | 46 | assertNotEquals(Arrays.toString(combine), Arrays.toString(c)); 47 | } 48 | 49 | @Test 50 | public void testDivide() { 51 | boolean result = false; 52 | int count = 0; 53 | int[] test = new int[200]; 54 | for (int i = 0; i < test.length; i++) { 55 | test[i] = 0; 56 | } 57 | 58 | int numOfChunks = (int) Math.ceil((double) test.length / 20); 59 | for (int i = 0; i < numOfChunks; i++) { 60 | int start = i * 20; 61 | int length = Math.min(test.length - start, 20); 62 | int[] temp = new int[length]; 63 | System.arraycopy(test, start, temp, 0, length); 64 | 65 | for (int j = 0; j < temp.length; j++) { 66 | temp[j] = 1; 67 | count++; 68 | test[start + j] = 1; 69 | } 70 | } 71 | 72 | for (int i : test 73 | ) { 74 | if (i == 0) { 75 | result = true; 76 | } 77 | } 78 | 79 | assertEquals(result, false); 80 | assertEquals(count, 200); 81 | 82 | } 83 | 84 | @Test 85 | public void testDct() { 86 | double[] test64 = { 87 | 231.0, 224.0, 224.0, 217.0, 217.0, 203.0, 189.0, 196.0, 88 | 210.0, 217.0, 203.0, 189.0, 203.0, 224.0, 217.0, 224.0, 89 | 196.0, 217.0, 210.0, 224.0, 203.0, 203.0, 196.0, 189.0, 90 | 210.0, 203.0, 196.0, 203.0, 182.0, 203.0, 182.0, 189.0, 91 | 203.0, 224.0, 203.0, 217.0, 196.0, 175.0, 154.0, 140.0, 92 | 182.0, 189.0, 168.0, 161.0, 154.0, 126.0, 119.0, 112.0, 93 | 175.0, 154.0, 126.0, 105.0, 140.0, 105.0, 119.0, 84.0, 94 | 154.0, 98.0, 105.0, 98.0, 105.0, 63.0, 112.0, 84.0}; 95 | // 96 | // double[] temp = { 97 | // 231.0, 224.0, 224.0, 217.0, 217.0, 203.0, 189.0, 196.0, 98 | // 210.0, 217.0, 203.0, 189.0, 203.0, 224.0, 217.0, 224.0, 99 | // 196.0, 217.0, 210.0, 224.0, 203.0, 203.0, 196.0, 189.0, 100 | // 210.0, 203.0, 196.0, 203.0, 182.0, 203.0, 182.0, 189.0, 101 | // 203.0, 224.0, 203.0, 217.0, 196.0, 175.0, 154.0, 140.0, 102 | // 182.0, 189.0, 168.0, 161.0, 154.0, 126.0, 119.0, 112.0, 103 | // 175.0, 154.0, 126.0, 105.0, 140.0, 105.0, 119.0, 84.0, 104 | // 154.0, 98.0, 105.0, 98.0, 105.0, 63.0, 112.0, 84.0}; 105 | 106 | FastDctFft.transform(test64); 107 | 108 | // the operations need to be done. 109 | 110 | for (int j = 0; j < test64.length; j++) { 111 | test64[j] = test64[j] * 2; 112 | } 113 | 114 | FastDctFft.inverseTransform(test64); 115 | // 116 | // for (int i = 0; i < test64.length; i++) { 117 | // temp[i] = test64[i] - temp[i]; 118 | // } 119 | 120 | // for (double i : test64) { 121 | // System.out.println(i / 2); 122 | // } 123 | 124 | } 125 | 126 | 127 | } 128 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/task/LSBDetectionTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.task; 18 | 19 | import android.graphics.Bitmap; 20 | import android.os.AsyncTask; 21 | 22 | import com.watermark.androidwm.listener.DetectFinishListener; 23 | import com.watermark.androidwm.utils.BitmapUtils; 24 | 25 | import static com.watermark.androidwm.utils.BitmapUtils.pixel2ARGBArray; 26 | import static com.watermark.androidwm.utils.BitmapUtils.getBitmapPixels; 27 | import static com.watermark.androidwm.utils.Constant.ERROR_BITMAP_NULL; 28 | import static com.watermark.androidwm.utils.Constant.ERROR_DETECT_FAILED; 29 | import static com.watermark.androidwm.utils.Constant.LSB_IMG_PREFIX_FLAG; 30 | import static com.watermark.androidwm.utils.Constant.LSB_IMG_SUFFIX_FLAG; 31 | import static com.watermark.androidwm.utils.Constant.LSB_TEXT_PREFIX_FLAG; 32 | import static com.watermark.androidwm.utils.Constant.LSB_TEXT_SUFFIX_FLAG; 33 | import static com.watermark.androidwm.utils.Constant.MAX_IMAGE_SIZE; 34 | import static com.watermark.androidwm.utils.Constant.WARNING_BIG_IMAGE; 35 | import static com.watermark.androidwm.utils.StringUtils.binaryToString; 36 | import static com.watermark.androidwm.utils.StringUtils.getBetweenStrings; 37 | import static com.watermark.androidwm.utils.StringUtils.intArrayToStringJ; 38 | import static com.watermark.androidwm.utils.StringUtils.replaceNinesJ; 39 | 40 | /** 41 | * This is a task for watermark image detection. 42 | * In LSB mode, all the task will return a bitmap; 43 | * 44 | * @author huangyz0918 (huangyz0918@gmail.com) 45 | */ 46 | public class LSBDetectionTask extends AsyncTask { 47 | 48 | private DetectFinishListener listener; 49 | 50 | public LSBDetectionTask(DetectFinishListener listener) { 51 | this.listener = listener; 52 | } 53 | 54 | @Override 55 | protected DetectionReturnValue doInBackground(Bitmap... bitmaps) { 56 | Bitmap markedBitmap = bitmaps[0]; 57 | DetectionReturnValue resultValue = new DetectionReturnValue(); 58 | 59 | if (markedBitmap == null) { 60 | listener.onFailure(ERROR_BITMAP_NULL); 61 | return null; 62 | } 63 | 64 | if (markedBitmap.getWidth() > MAX_IMAGE_SIZE || markedBitmap.getHeight() > MAX_IMAGE_SIZE) { 65 | listener.onFailure(WARNING_BIG_IMAGE); 66 | return null; 67 | } 68 | 69 | int[] pixels = getBitmapPixels(markedBitmap); 70 | int[] colorArray = pixel2ARGBArray(pixels); 71 | 72 | for (int i = 0; i < colorArray.length; i++) { 73 | colorArray[i] = colorArray[i] % 10; 74 | } 75 | 76 | replaceNinesJ(colorArray); 77 | String binaryString = intArrayToStringJ(colorArray); 78 | String resultString; 79 | 80 | if (binaryString.contains(LSB_TEXT_PREFIX_FLAG) && binaryString.contains(LSB_TEXT_SUFFIX_FLAG)) { 81 | resultString = getBetweenStrings(binaryString, true, listener); 82 | resultString = binaryToString(resultString); 83 | resultValue.setWatermarkString(resultString); 84 | } else if (binaryString.contains(LSB_IMG_PREFIX_FLAG) && binaryString.contains(LSB_IMG_SUFFIX_FLAG)) { 85 | binaryString = getBetweenStrings(binaryString, false, listener); 86 | resultString = binaryToString(binaryString); 87 | resultValue.setWatermarkBitmap(BitmapUtils.stringToBitmap(resultString)); 88 | } 89 | 90 | return resultValue; 91 | } 92 | 93 | @Override 94 | protected void onPostExecute(DetectionReturnValue detectionReturnValue) { 95 | if (detectionReturnValue == null) { 96 | listener.onFailure(ERROR_DETECT_FAILED); 97 | return; 98 | } 99 | 100 | if (detectionReturnValue.getWatermarkString() != null && 101 | !"".equals(detectionReturnValue.getWatermarkString()) || 102 | detectionReturnValue.getWatermarkBitmap() != null) { 103 | listener.onSuccess(detectionReturnValue); 104 | } else { 105 | listener.onFailure(ERROR_DETECT_FAILED); 106 | } 107 | super.onPostExecute(detectionReturnValue); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/bean/WatermarkImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.bean; 18 | 19 | import android.content.Context; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.graphics.drawable.BitmapDrawable; 23 | import androidx.annotation.DrawableRes; 24 | import androidx.annotation.FloatRange; 25 | import android.widget.ImageView; 26 | 27 | import static com.watermark.androidwm.utils.BitmapUtils.resizeBitmap; 28 | import static com.watermark.androidwm.utils.Constant.MAX_IMAGE_SIZE; 29 | 30 | /** 31 | * It's a wrapper of the watermark image. 32 | * 33 | * @author huangyz0918 (huangyz0918@gmail.com) 34 | * @since 29/08/2018 35 | */ 36 | public class WatermarkImage extends WatermarkObject { 37 | private Bitmap image; 38 | @DrawableRes 39 | private int imageDrawable; 40 | private Context context; 41 | private double size = 0.2; 42 | 43 | /** 44 | * Constructors for WatermarkImage. 45 | * since we use the mobile to calculate the image, the image cannot be to large, 46 | * we set the maxsize of an image to 1024x1024. 47 | */ 48 | public WatermarkImage(Bitmap image) { 49 | this.image = resizeBitmap(image, MAX_IMAGE_SIZE); 50 | } 51 | 52 | public WatermarkImage(Context context, @DrawableRes int imageDrawable, WatermarkPosition position) { 53 | this.imageDrawable = imageDrawable; 54 | this.position = position; 55 | this.context = context; 56 | this.image = getBitmapFromDrawable(imageDrawable); 57 | } 58 | 59 | public WatermarkImage(Context context, @DrawableRes int imageDrawable, WatermarkPosition position, WatermarkPosition origin) { 60 | this.imageDrawable = imageDrawable; 61 | this.position = position; 62 | this.origin = origin; 63 | this.context = context; 64 | this.image = getBitmapFromDrawable(imageDrawable); 65 | } 66 | 67 | public WatermarkImage(Context context, @DrawableRes int imageDrawable) { 68 | this.imageDrawable = imageDrawable; 69 | this.context = context; 70 | this.image = getBitmapFromDrawable(imageDrawable); 71 | } 72 | 73 | public WatermarkImage(Bitmap image, WatermarkPosition position) { 74 | this.image = resizeBitmap(image, MAX_IMAGE_SIZE); 75 | this.position = position; 76 | } 77 | 78 | public WatermarkImage(ImageView imageView) { 79 | watermarkFromImageView(imageView); 80 | } 81 | 82 | /** 83 | * Getters and Setters for those attrs. 84 | */ 85 | public Bitmap getImage() { 86 | return image; 87 | } 88 | 89 | public int getAlpha() { 90 | return alpha; 91 | } 92 | 93 | public double getSize() { 94 | return size; 95 | } 96 | 97 | /** 98 | * @param size can be set to 0-1 as the proportion of 99 | * background image. 100 | */ 101 | public WatermarkImage setSize(@FloatRange(from = 0, to = 1) double size) { 102 | this.size = size; 103 | return this; 104 | } 105 | 106 | public int getImageDrawable() { 107 | return imageDrawable; 108 | } 109 | 110 | public WatermarkImage setImageDrawable(@DrawableRes int imageDrawable) { 111 | this.imageDrawable = imageDrawable; 112 | return this; 113 | } 114 | 115 | /** 116 | * @param imageAlpha can be set to 0-255. 117 | */ 118 | public WatermarkImage setImageAlpha(int imageAlpha) { 119 | this.alpha = imageAlpha; 120 | return this; 121 | } 122 | 123 | /** 124 | * load a bitmap as watermark image from a ImageView. 125 | * 126 | * @param imageView the ImageView we need to use. 127 | */ 128 | private void watermarkFromImageView(ImageView imageView) { 129 | imageView.invalidate(); 130 | BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 131 | // set the limitation of input bitmap. 132 | this.image = resizeBitmap(drawable.getBitmap(), MAX_IMAGE_SIZE); 133 | } 134 | 135 | private Bitmap getBitmapFromDrawable(@DrawableRes int imageDrawable) { 136 | return resizeBitmap(BitmapFactory.decodeResource(context.getResources(), 137 | imageDrawable), MAX_IMAGE_SIZE); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /androidwm/src/main/java/com/watermark/androidwm/task/FDDetectionTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Yizheng Huang 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | package com.watermark.androidwm.task; 18 | 19 | import android.graphics.Bitmap; 20 | import android.os.AsyncTask; 21 | 22 | import com.watermark.androidwm.listener.DetectFinishListener; 23 | import com.watermark.androidwm.utils.FastDctFft; 24 | 25 | import static com.watermark.androidwm.utils.BitmapUtils.pixel2ARGBArray; 26 | import static com.watermark.androidwm.utils.BitmapUtils.getBitmapPixels; 27 | import static com.watermark.androidwm.utils.Constant.CHUNK_SIZE; 28 | import static com.watermark.androidwm.utils.Constant.ERROR_BITMAP_NULL; 29 | import static com.watermark.androidwm.utils.Constant.ERROR_DETECT_FAILED; 30 | import static com.watermark.androidwm.utils.Constant.MAX_IMAGE_SIZE; 31 | import static com.watermark.androidwm.utils.Constant.WARNING_BIG_IMAGE; 32 | import static com.watermark.androidwm.utils.StringUtils.copyFromIntArray; 33 | 34 | /** 35 | * This is a task for watermark image detection. 36 | * In FD mode, all the task will return a bitmap; 37 | * 38 | * @author huangyz0918 (huangyz0918@gmail.com) 39 | */ 40 | @SuppressWarnings("PMD") 41 | public class FDDetectionTask extends AsyncTask { 42 | 43 | private DetectFinishListener listener; 44 | 45 | public FDDetectionTask(DetectFinishListener listener) { 46 | this.listener = listener; 47 | } 48 | 49 | @Override 50 | protected DetectionReturnValue doInBackground(Bitmap... bitmaps) { 51 | Bitmap markedBitmap = bitmaps[0]; 52 | DetectionReturnValue resultValue = new DetectionReturnValue(); 53 | 54 | if (markedBitmap == null) { 55 | listener.onFailure(ERROR_BITMAP_NULL); 56 | return null; 57 | } 58 | 59 | if (markedBitmap.getWidth() > MAX_IMAGE_SIZE || markedBitmap.getHeight() > MAX_IMAGE_SIZE) { 60 | listener.onFailure(WARNING_BIG_IMAGE); 61 | return null; 62 | } 63 | 64 | int[] pixels = getBitmapPixels(markedBitmap); 65 | 66 | // divide and conquer 67 | if (pixels.length < CHUNK_SIZE) { 68 | int[] watermarkRGB = pixel2ARGBArray(pixels); 69 | double[] watermarkArray = copyFromIntArray(watermarkRGB); 70 | FastDctFft.transform(watermarkArray); 71 | 72 | //TODO: do some operations with colorTempArray. 73 | 74 | 75 | } else { 76 | int numOfChunks = (int) Math.ceil((double) pixels.length / CHUNK_SIZE); 77 | for (int i = 0; i < numOfChunks; i++) { 78 | int start = i * CHUNK_SIZE; 79 | int length = Math.min(pixels.length - start, CHUNK_SIZE); 80 | int[] temp = new int[length]; 81 | System.arraycopy(pixels, start, temp, 0, length); 82 | double[] colorTempArray = copyFromIntArray(pixel2ARGBArray(temp)); 83 | FastDctFft.transform(colorTempArray); 84 | 85 | //TODO: do some operations with colorTempArray. 86 | 87 | } 88 | } 89 | 90 | /* TODO: new detection operations will replace this block. 91 | String resultString; 92 | 93 | if (binaryString.contains(LSB_TEXT_PREFIX_FLAG) && binaryString.contains(LSB_TEXT_SUFFIX_FLAG)) { 94 | resultString = getBetweenStrings(binaryString, true, listener); 95 | resultString = binaryToString(resultString); 96 | resultValue.setWatermarkString(resultString); 97 | } else if (binaryString.contains(LSB_IMG_PREFIX_FLAG) && binaryString.contains(LSB_IMG_SUFFIX_FLAG)) { 98 | binaryString = getBetweenStrings(binaryString, false, listener); 99 | resultString = binaryToString(binaryString); 100 | resultValue.setWatermarkBitmap(BitmapUtils.stringToBitmap(resultString)); 101 | }*/ 102 | 103 | return resultValue; 104 | } 105 | 106 | @Override 107 | protected void onPostExecute(DetectionReturnValue detectionReturnValue) { 108 | if (detectionReturnValue == null) { 109 | listener.onFailure(ERROR_DETECT_FAILED); 110 | return; 111 | } 112 | 113 | if (detectionReturnValue.getWatermarkString() != null && 114 | !"".equals(detectionReturnValue.getWatermarkString()) || 115 | detectionReturnValue.getWatermarkBitmap() != null) { 116 | listener.onSuccess(detectionReturnValue); 117 | } else { 118 | listener.onFailure(ERROR_DETECT_FAILED); 119 | } 120 | super.onPostExecute(detectionReturnValue); 121 | } 122 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 | 22 | 23 | 29 | 30 | 36 | 37 | 42 | 43 | 47 | 51 | 52 | 57 | 61 | 62 | 68 | 72 | 73 | 78 | 82 | 83 | 84 | 85 | 90 | 91 |