├── example ├── .gitignore ├── libs │ └── nineoldandroids-2.4.0.jar ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ └── photo.jpg │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── dimens.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── list_thumbnail_item.xml │ │ │ │ └── activity_main.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── filters │ │ │ │ ├── ThumbnailCallback.java │ │ │ │ ├── ThumbnailItem.java │ │ │ │ ├── GeneralUtils.java │ │ │ │ ├── ThumbnailsManager.java │ │ │ │ ├── ThumbnailsAdapter.java │ │ │ │ └── MainActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── example │ │ └── filters │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── photofilterssdk ├── .gitignore ├── gradle.properties ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ └── strings.xml │ │ └── drawable │ │ │ └── vignette.png │ │ ├── jni │ │ ├── Application.mk │ │ ├── Android.mk │ │ └── NativeImageProcessor.cpp │ │ ├── java │ │ └── com │ │ │ └── zomato │ │ │ └── photofilters │ │ │ ├── geometry │ │ │ ├── Point.java │ │ │ └── BezierSpline.java │ │ │ ├── imageprocessors │ │ │ ├── SubFilter.java │ │ │ ├── NativeImageProcessor.java │ │ │ ├── subfilters │ │ │ │ ├── SaturationSubFilter.java │ │ │ │ ├── BrightnessSubFilter.java │ │ │ │ ├── ContrastSubFilter.java │ │ │ │ ├── ColorOverlaySubFilter.java │ │ │ │ ├── VignetteSubFilter.java │ │ │ │ └── ToneCurveSubFilter.java │ │ │ ├── ImageProcessor.java │ │ │ └── Filter.java │ │ │ └── SampleFilters.java │ │ └── AndroidManifest.xml ├── proguard-rules.pro ├── build.gradle └── maven-push.gradle ├── settings.gradle ├── art ├── photofilters.gif └── curvedialog_photoshop.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── .travis.yml ├── .gitignore ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /photofilterssdk/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':example', ':photofilterssdk' 2 | -------------------------------------------------------------------------------- /art/photofilters.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/art/photofilters.gif -------------------------------------------------------------------------------- /art/curvedialog_photoshop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/art/curvedialog_photoshop.png -------------------------------------------------------------------------------- /photofilterssdk/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_NAME=AndroidPhotoFilters 2 | POM_ARTIFACT_ID=androidphotofilters 3 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/libs/nineoldandroids-2.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/libs/nineoldandroids-2.4.0.jar -------------------------------------------------------------------------------- /photofilterssdk/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | photofilterssdk 3 | 4 | -------------------------------------------------------------------------------- /example/src/main/res/drawable/photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/src/main/res/drawable/photo.jpg -------------------------------------------------------------------------------- /example/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/example/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /photofilterssdk/src/main/res/drawable/vignette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zomato/AndroidPhotoFilters/HEAD/photofilterssdk/src/main/res/drawable/vignette.png -------------------------------------------------------------------------------- /example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Filters 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := c++_static 2 | APP_ABI := all 3 | APP_CPPFLAGS += -frtti 4 | APP_CPPFLAGS += -fexceptions 5 | APP_CPPFLAGS += -DANDROID 6 | APP_OPTIM := release 7 | APP_PLATFORM=android-8 8 | LOCAL_ARM_MODE := thumb -------------------------------------------------------------------------------- /example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | #a40100 5 | #222322 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 22 16:11:46 IST 2018 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-4.6-all.zip 7 | -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/ThumbnailCallback.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import com.zomato.photofilters.imageprocessors.Filter; 4 | 5 | /** 6 | * @author Varun on 01/07/15. 7 | */ 8 | public interface ThumbnailCallback { 9 | 10 | void onThumbnailClick(Filter filter); 11 | } 12 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/geometry/Point.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.geometry; 2 | 3 | /** 4 | * @author Varun on 29/06/15. 5 | */ 6 | public class Point { 7 | public float x; 8 | public float y; 9 | 10 | public Point(float x, float y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/SubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | /** 6 | * @author varun on 27/07/15. 7 | */ 8 | public interface SubFilter { 9 | Bitmap process(Bitmap inputImage); 10 | 11 | Object getTag(); 12 | 13 | void setTag(Object tag); 14 | } 15 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | include $(CLEAR_VARS) 3 | 4 | LOCAL_MODULE := NativeImageProcessor 5 | LOCAL_LDFLAGS := -Wl,--build-id 6 | LOCAL_SRC_FILES := \ 7 | Android.mk \ 8 | Application.mk \ 9 | NativeImageProcessor.cpp \ 10 | 11 | LOCAL_C_INCLUDES += src/debug/jni 12 | LOCAL_C_INCLUDES += src/main/jni 13 | 14 | include $(BUILD_SHARED_LIBRARY) 15 | -------------------------------------------------------------------------------- /example/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /example/src/androidTest/java/com/example/filters/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/ThumbnailItem.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | import com.zomato.photofilters.imageprocessors.Filter; 6 | 7 | /** 8 | * @author Varun on 01/07/15. 9 | */ 10 | public class ThumbnailItem { 11 | public Bitmap image; 12 | public Filter filter; 13 | 14 | public ThumbnailItem() { 15 | image = null; 16 | filter = new Filter(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 80dp 6 | 100dp 7 | 8dp 8 | 10dp 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/src/main/res/layout/list_thumbnail_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /photofilterssdk/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /adt-bundle-mac/sdk-studio/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | -keep class com.zomato.photofilters.** {*;} 20 | -keepclassmembers class com.zomato.photofilters.** {*;} 21 | -------------------------------------------------------------------------------- /example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "28.0.3" 6 | defaultConfig { 7 | applicationId 'com.example.filters' 8 | minSdkVersion 15 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation project(':photofilterssdk') 24 | implementation 'com.android.support:appcompat-v7:23.4.0' 25 | implementation 'com.android.support:recyclerview-v7:23.4.0' 26 | implementation 'com.github.ksoichiro:android-observablescrollview:1.5.2' 27 | } 28 | -------------------------------------------------------------------------------- /photofilterssdk/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: 'maven-push.gradle' 3 | 4 | android { 5 | compileSdkVersion 23 6 | buildToolsVersion "28.0.3" 7 | 8 | defaultConfig { 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | 15 | ndk { 16 | abiFilters 'armeabi-v7a', 'x86', 'x86_64', 'arm64-v8a' 17 | } 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | externalNativeBuild { 27 | ndkBuild { 28 | path file('src/main/jni/Android.mk') 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) 35 | testImplementation 'junit:junit:4.12' 36 | implementation 'com.android.support:appcompat-v7:23.4.0' 37 | } 38 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/NativeImageProcessor.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors; 2 | 3 | 4 | /** 5 | * @author Varun on 30/06/15. 6 | */ 7 | public final class NativeImageProcessor { 8 | private NativeImageProcessor() { 9 | } 10 | 11 | public static native int[] applyRGBCurve(int[] pixels, int[] rgb, int width, int height); 12 | 13 | public static native int[] applyChannelCurves(int[] pixels, int[] r, int[] g, int[] b, int width, int height); 14 | 15 | public static native int[] doBrightness(int[] pixels, int value, int width, int height); 16 | 17 | public static native int[] doContrast(int[] pixels, float value, int width, int height); 18 | 19 | public static native int[] doColorOverlay(int[] pixels, int depth, 20 | float red, float green, float blue, 21 | int width, int height); 22 | 23 | public static native int[] doSaturation(int[] pixels, float level, int width, int height); 24 | } 25 | -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/GeneralUtils.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.Canvas; 5 | import android.graphics.Path; 6 | 7 | /** 8 | * @author Varun on 30/06/15. 9 | */ 10 | public final class GeneralUtils { 11 | 12 | private GeneralUtils() { 13 | } 14 | 15 | public static Bitmap generateCircularBitmap(Bitmap input) { 16 | 17 | final int width = input.getWidth(); 18 | final int height = input.getHeight(); 19 | final Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 20 | 21 | final Path path = new Path(); 22 | path.addCircle( 23 | (float) (width / 2) 24 | , (float) (height / 2) 25 | , (float) Math.min(width, (height / 2)) 26 | , Path.Direction.CCW 27 | ); 28 | 29 | final Canvas canvas = new Canvas(outputBitmap); 30 | canvas.clipPath(path); 31 | canvas.drawBitmap(input, 0, 0, null); 32 | return outputBitmap; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/SaturationSubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.graphics.Bitmap; 4 | import com.zomato.photofilters.imageprocessors.ImageProcessor; 5 | import com.zomato.photofilters.imageprocessors.SubFilter; 6 | 7 | 8 | /** 9 | * @author varun on 28/07/15. 10 | */ 11 | public class SaturationSubFilter implements SubFilter { 12 | private static String tag = ""; 13 | 14 | // The Level value is float, where level = 1 has no effect on the image 15 | private float level; 16 | 17 | public SaturationSubFilter(float level) { 18 | this.level = level; 19 | } 20 | 21 | @Override 22 | public Bitmap process(Bitmap inputImage) { 23 | return ImageProcessor.doSaturation(inputImage, level); 24 | } 25 | 26 | @Override 27 | public Object getTag() { 28 | return tag; 29 | } 30 | 31 | @Override 32 | public void setTag(Object tag) { 33 | SaturationSubFilter.tag = (String) tag; 34 | } 35 | 36 | public void setLevel(float level) { 37 | this.level = level; 38 | } 39 | 40 | /** 41 | * Get the current saturation level 42 | */ 43 | public float getSaturation() { 44 | return level; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 18 | 19 | 25 | 26 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/ThumbnailsManager.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Varun on 30/06/15. 11 | *

12 | * Singleton Class Used to Manage filters and process them all at once 13 | */ 14 | public final class ThumbnailsManager { 15 | private static List filterThumbs = new ArrayList(10); 16 | private static List processedThumbs = new ArrayList(10); 17 | 18 | private ThumbnailsManager() { 19 | } 20 | 21 | public static void addThumb(ThumbnailItem thumbnailItem) { 22 | filterThumbs.add(thumbnailItem); 23 | } 24 | 25 | public static List processThumbs(Context context) { 26 | for (ThumbnailItem thumb : filterThumbs) { 27 | // scaling down the image 28 | float size = context.getResources().getDimension(R.dimen.thumbnail_size); 29 | thumb.image = Bitmap.createScaledBitmap(thumb.image, (int) size, (int) size, false); 30 | thumb.image = thumb.filter.processFilter(thumb.image); 31 | //cropping circle 32 | thumb.image = GeneralUtils.generateCircularBitmap(thumb.image); 33 | processedThumbs.add(thumb); 34 | } 35 | return processedThumbs; 36 | } 37 | 38 | public static void clearThumbs() { 39 | filterThumbs = new ArrayList<>(); 40 | processedThumbs = new ArrayList<>(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | VERSION_NAME=1.0.2 20 | VERSION_CODE=4 21 | GROUP=com.github.zomato 22 | 23 | POM_DESCRIPTION=Android Library aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media. 24 | POM_URL=https://github.com/zomato/AndroidPhotoFilters 25 | POM_SCM_URL=https://github.com/zomato/AndroidPhotoFilters 26 | POM_SCM_CONNECTION=scm:git@github.com:zomato/AndroidPhotoFilters.git 27 | POM_SCM_DEV_CONNECTION=scm:git@github.com:zomato/AndroidPhotoFilters.git 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | POM_DEVELOPER_ID=zomato 32 | POM_DEVELOPER_NAME=zomato 33 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/BrightnessSubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.graphics.Bitmap; 4 | import com.zomato.photofilters.imageprocessors.ImageProcessor; 5 | import com.zomato.photofilters.imageprocessors.SubFilter; 6 | 7 | 8 | /** 9 | * @author varun 10 | * subfilter used to tweak brightness of the Bitmap 11 | */ 12 | public class BrightnessSubFilter implements SubFilter { 13 | private static String tag = ""; 14 | // Value is in integer 15 | private int brightness = 0; 16 | 17 | /** 18 | * Takes Brightness of the image 19 | * 20 | * @param brightness Integer brightness value {value 0 has no effect} 21 | */ 22 | public BrightnessSubFilter(int brightness) { 23 | this.brightness = brightness; 24 | } 25 | 26 | @Override 27 | public Bitmap process(Bitmap inputImage) { 28 | return ImageProcessor.doBrightness(brightness, inputImage); 29 | } 30 | 31 | @Override 32 | public String getTag() { 33 | return tag; 34 | } 35 | 36 | @Override 37 | public void setTag(Object tag) { 38 | BrightnessSubFilter.tag = (String) tag; 39 | } 40 | 41 | public void setBrightness(int brightness) { 42 | this.brightness = brightness; 43 | } 44 | 45 | /** 46 | * Changes the brightness by the value passed as parameter 47 | */ 48 | public void changeBrightness(int value) { 49 | this.brightness += value; 50 | } 51 | 52 | /** 53 | * Get current Brightness level 54 | */ 55 | public int getBrightness() { 56 | return brightness; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | android: 3 | components: 4 | #- platform-tools 5 | - tools 6 | - build-tools-23.0.3 7 | - android-23 8 | - extra-android-m2repository 9 | 10 | # Additional components 11 | #- add-on 12 | #- extra 13 | 14 | # Specify at least one system image, 15 | # if you need to run emulator(s) during your tests 16 | #- sys-img-armeabi-v7a-android-21 17 | 18 | 19 | jdk: 20 | # Check Travis JDKs http://docs.travis-ci.com/user/languages/java/#Testing-Against-Multiple-JDKs 21 | # Test against one or more JDKs: 'jdk' is combined with 'env' to construct a build matrix. 22 | # - openjdk7 23 | - oraclejdk7 24 | 25 | sudo: false 26 | 27 | env: 28 | - TERM=dumb 29 | 30 | # Emulator Management: Create, Start and Wait 31 | #before_script: 32 | #- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a 33 | #- emulator -avd test -no-skin -no-audio -no-window & 34 | #- curl http://is.gd/android_wait_for_emulator > android-wait-for-emulator 35 | #- chmod u+x android-wait-for-emulator 36 | #- ./android-wait-for-emulator 37 | #- adb shell input keyevent 82 & 38 | 39 | script: ./gradlew clean test 40 | 41 | after_failure: 42 | # Customize this line, 'app' is the specific app module name of this project. Shows log. 43 | - export MY_MOD="app" 44 | #- export MY_LOG_DIR="$(pwd)/${MY_MOD}/build/outputs/reports/androidTests/connected/" 45 | - export MY_LOG_DIR="$(pwd)/${MY_MOD}/build/reports/tests/debug/' 46 | - pwd && cd "${MY_LOG_DIR:-.}" && pwd && ls -al 47 | - apt-get install -qq lynx && lynx --dump index.html > myIndex.log 48 | - for file in *.html; do echo "$file"; echo "====================="; lynx --dump $file; done || true 49 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/ContrastSubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.graphics.Bitmap; 4 | import com.zomato.photofilters.imageprocessors.ImageProcessor; 5 | import com.zomato.photofilters.imageprocessors.SubFilter; 6 | 7 | 8 | /** 9 | * @author varun 10 | * Class to add Contrast Subfilter 11 | */ 12 | public class ContrastSubFilter implements SubFilter { 13 | 14 | private static String tag = ""; 15 | 16 | // The value is in fraction, value 1 has no effect 17 | private float contrast = 0; 18 | 19 | /** 20 | * Initialise contrast subfilter 21 | * 22 | * @param contrast The contrast value ranges in fraction, value 1 has no effect 23 | */ 24 | public ContrastSubFilter(float contrast) { 25 | this.contrast = contrast; 26 | } 27 | 28 | @Override 29 | public Bitmap process(Bitmap inputImage) { 30 | return ImageProcessor.doContrast(contrast, inputImage); 31 | } 32 | 33 | @Override 34 | public String getTag() { 35 | return tag; 36 | } 37 | 38 | @Override 39 | public void setTag(Object tag) { 40 | ContrastSubFilter.tag = (String) tag; 41 | } 42 | 43 | /** 44 | * Sets the contrast value by the value passed in as parameter 45 | */ 46 | public void setContrast(float contrast) { 47 | this.contrast = contrast; 48 | } 49 | 50 | /** 51 | * Changes contrast value by the value passed in as a parameter 52 | */ 53 | public void changeContrast(float value) { 54 | this.contrast += value; 55 | } 56 | 57 | /** 58 | * Get current Contrast level 59 | */ 60 | public float getContrast() { 61 | return contrast; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/ColorOverlaySubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.graphics.Bitmap; 4 | import com.zomato.photofilters.imageprocessors.ImageProcessor; 5 | import com.zomato.photofilters.imageprocessors.SubFilter; 6 | 7 | 8 | /** 9 | * @author varun 10 | * Subfilter used to overlay bitmap with the color defined 11 | */ 12 | public class ColorOverlaySubFilter implements SubFilter { 13 | private static String tag = ""; 14 | 15 | // the color overlay depth is between 0-255 16 | private final int colorOverlayDepth; 17 | 18 | // these values are between 0-1 19 | private final float colorOverlayRed; 20 | private final float colorOverlayGreen; 21 | private final float colorOverlayBlue; 22 | 23 | /** 24 | * Initialize Color Overlay Subfilter 25 | * 26 | * @param depth Value ranging from 0-255 {Defining intensity of color overlay} 27 | * @param red Red value between 0-1 28 | * @param green Green value between 0-1 29 | * @param blue Blue value between 0-1 30 | */ 31 | public ColorOverlaySubFilter(int depth, float red, float green, float blue) { 32 | this.colorOverlayDepth = depth; 33 | this.colorOverlayRed = red; 34 | this.colorOverlayBlue = blue; 35 | this.colorOverlayGreen = green; 36 | } 37 | 38 | @Override 39 | public Bitmap process(Bitmap inputImage) { 40 | return ImageProcessor.doColorOverlay( 41 | colorOverlayDepth, colorOverlayRed, colorOverlayGreen, colorOverlayBlue, inputImage 42 | ); 43 | } 44 | 45 | @Override 46 | public String getTag() { 47 | return tag; 48 | } 49 | 50 | @Override 51 | public void setTag(Object tag) { 52 | ColorOverlaySubFilter.tag = (String) tag; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Local scripts 2 | 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | 10 | # tags 11 | tag 12 | tags 13 | *.taghl 14 | 15 | # Built application files 16 | *.apk 17 | *.ap_ 18 | 19 | # Files for the Dalvik VM 20 | *.dex 21 | 22 | # Java class files 23 | *.class 24 | 25 | # Generated files 26 | bin/ 27 | gen/ 28 | 29 | # Gradle files 30 | .gradle/ 31 | build/ 32 | 33 | # Local configuration file (sdk path, etc) 34 | local.properties 35 | 36 | # Proguard folder generated by Eclipse 37 | proguard/ 38 | 39 | # Windows thumbnail db 40 | Thumbs.db 41 | 42 | # OSX files 43 | .DS_Store 44 | 45 | # Eclipse project files 46 | .classpath 47 | .project 48 | 49 | # Android Studio 50 | .idea 51 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs. 52 | .gradle 53 | build/ 54 | 55 | # Java class files 56 | *.class 57 | 58 | # generated files 59 | bin/ 60 | gen/ 61 | 62 | # Local configuration file (sdk path, etc) 63 | local.properties 64 | 65 | # Proguard folder generated by Eclipse 66 | proguard/ 67 | 68 | # Eclipse Metadata 69 | .metadata/ 70 | 71 | # Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067) 72 | .idea/workspace.xml 73 | .idea/tasks.xml 74 | .idea/datasources.xml 75 | .idea/dataSources.ids 76 | 77 | # User-specific configurations 78 | .idea/libraries/ 79 | .idea/workspace.xml 80 | .idea/tasks.xml 81 | .idea/.name 82 | .idea/compiler.xml 83 | .idea/copyright/profiles_settings.xml 84 | .idea/encodings.xml 85 | .idea/misc.xml 86 | .idea/modules.xml 87 | .idea/scopes/scope_settings.xml 88 | .idea/vcs.xml 89 | *.iml 90 | 91 | # OS-specific files 92 | .DS_Store 93 | .DS_Store? 94 | ._* 95 | .Spotlight-V100 96 | .Trashes 97 | ehthumbs.db 98 | Thumbs.db 99 | 100 | # Tempory files 101 | *~ 102 | #*# 103 | example/src/main/obj 104 | photofilterssdk/src/main/obj 105 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/VignetteSubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.graphics.Canvas; 7 | import android.graphics.Paint; 8 | import com.zomato.photofilters.R; 9 | import com.zomato.photofilters.imageprocessors.SubFilter; 10 | 11 | 12 | /** 13 | * @author varun 14 | * Subfilter to add Vignette effect on an image 15 | */ 16 | public class VignetteSubFilter implements SubFilter { 17 | 18 | private static String tag = ""; 19 | private Context context; 20 | 21 | // value of alpha is between 0-255 22 | private int alpha = 0; 23 | 24 | /** 25 | * Initialise Vignette subfilter 26 | * 27 | * @param alpha value of alpha ranges from 0-255 (Intensity of Vignette effect) 28 | */ 29 | public VignetteSubFilter(Context context, int alpha) { 30 | this.context = context; 31 | this.alpha = alpha; 32 | } 33 | 34 | @Override 35 | public Bitmap process(Bitmap inputImage) { 36 | Bitmap vignette = BitmapFactory.decodeResource(context.getResources(), R.drawable.vignette); 37 | 38 | vignette = Bitmap.createScaledBitmap(vignette, inputImage.getWidth(), inputImage.getHeight(), true); 39 | Paint paint = new Paint(); 40 | paint.setAntiAlias(true); 41 | paint.setAlpha(alpha); 42 | 43 | Canvas comboImage = new Canvas(inputImage); 44 | comboImage.drawBitmap(vignette, 0f, 0f, paint); 45 | 46 | return inputImage; 47 | } 48 | 49 | @Override 50 | public Object getTag() { 51 | return tag; 52 | } 53 | 54 | @Override 55 | public void setTag(Object tag) { 56 | VignetteSubFilter.tag = (String) tag; 57 | } 58 | 59 | /** 60 | * Change alpha value to new value 61 | */ 62 | public void setAlpha(int alpha) { 63 | this.alpha = alpha; 64 | } 65 | 66 | /** 67 | * Changes alpha value by that number 68 | */ 69 | public void changeAlpha(int value) { 70 | this.alpha += value; 71 | if (alpha > 255) { 72 | alpha = 255; 73 | } else if (alpha < 0) { 74 | alpha = 0; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 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 Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/ThumbnailsAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import com.nineoldandroids.view.ViewHelper; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author Varun on 01/07/15. 15 | */ 16 | public class ThumbnailsAdapter extends RecyclerView.Adapter { 17 | private static final String TAG = "THUMBNAILS_ADAPTER"; 18 | private static int lastPosition = -1; 19 | private ThumbnailCallback thumbnailCallback; 20 | private List dataSet; 21 | 22 | public ThumbnailsAdapter(List dataSet, ThumbnailCallback thumbnailCallback) { 23 | Log.v(TAG, "Thumbnails Adapter has " + dataSet.size() + " items"); 24 | this.dataSet = dataSet; 25 | this.thumbnailCallback = thumbnailCallback; 26 | } 27 | 28 | 29 | @Override 30 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 31 | Log.v(TAG, "On Create View Holder Called"); 32 | View itemView = LayoutInflater. 33 | from(viewGroup.getContext()). 34 | inflate(R.layout.list_thumbnail_item, viewGroup, false); 35 | return new ThumbnailsViewHolder(itemView); 36 | } 37 | 38 | @Override 39 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int i) { 40 | final ThumbnailItem thumbnailItem = dataSet.get(i); 41 | Log.v(TAG, "On Bind View Called"); 42 | ThumbnailsViewHolder thumbnailsViewHolder = (ThumbnailsViewHolder) holder; 43 | thumbnailsViewHolder.thumbnail.setImageBitmap(thumbnailItem.image); 44 | thumbnailsViewHolder.thumbnail.setScaleType(ImageView.ScaleType.FIT_START); 45 | setAnimation(thumbnailsViewHolder.thumbnail, i); 46 | thumbnailsViewHolder.thumbnail.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | if (lastPosition != i) { 50 | thumbnailCallback.onThumbnailClick(thumbnailItem.filter); 51 | lastPosition = i; 52 | } 53 | } 54 | 55 | }); 56 | } 57 | 58 | private void setAnimation(View viewToAnimate, int position) { 59 | { 60 | ViewHelper.setAlpha(viewToAnimate, .0f); 61 | com.nineoldandroids.view.ViewPropertyAnimator.animate(viewToAnimate).alpha(1).setDuration(250).start(); 62 | lastPosition = position; 63 | } 64 | } 65 | 66 | @Override 67 | public int getItemCount() { 68 | return dataSet.size(); 69 | } 70 | 71 | public static class ThumbnailsViewHolder extends RecyclerView.ViewHolder { 72 | public ImageView thumbnail; 73 | 74 | public ThumbnailsViewHolder(View v) { 75 | super(v); 76 | this.thumbnail = (ImageView) v.findViewById(R.id.thumbnail); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /photofilterssdk/maven-push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | apply plugin: 'signing' 3 | 4 | def isReleaseBuild() { 5 | return VERSION_NAME.contains("SNAPSHOT") == false 6 | } 7 | 8 | def getReleaseRepositoryUrl() { 9 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 10 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 11 | } 12 | 13 | def getSnapshotRepositoryUrl() { 14 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 15 | : "https://oss.sonatype.org/content/repositories/snapshots/" 16 | } 17 | 18 | def getRepositoryUsername() { 19 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 20 | } 21 | 22 | def getRepositoryPassword() { 23 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 24 | } 25 | 26 | afterEvaluate { project -> 27 | uploadArchives { 28 | repositories { 29 | mavenDeployer { 30 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 31 | 32 | pom.groupId = GROUP 33 | pom.artifactId = POM_ARTIFACT_ID 34 | pom.version = VERSION_NAME 35 | 36 | repository(url: getReleaseRepositoryUrl()) { 37 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 38 | } 39 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 40 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 41 | } 42 | 43 | pom.project { 44 | name POM_NAME 45 | packaging POM_PACKAGING 46 | description POM_DESCRIPTION 47 | url POM_URL 48 | 49 | scm { 50 | url POM_SCM_URL 51 | connection POM_SCM_CONNECTION 52 | developerConnection POM_SCM_DEV_CONNECTION 53 | } 54 | 55 | licenses { 56 | license { 57 | name POM_LICENCE_NAME 58 | url POM_LICENCE_URL 59 | distribution POM_LICENCE_DIST 60 | } 61 | } 62 | 63 | developers { 64 | developer { 65 | id POM_DEVELOPER_ID 66 | name POM_DEVELOPER_NAME 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | signing { 75 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 76 | sign configurations.archives 77 | } 78 | 79 | //task androidJavadocs(type: Javadoc) { 80 | //source = android.sourceSets.main.allJava 81 | //} 82 | 83 | //task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 84 | //classifier = 'javadoc' 85 | //from androidJavadocs.destinationDir 86 | //} 87 | 88 | task androidSourcesJar(type: Jar) { 89 | classifier = 'sources' 90 | from android.sourceSets.main.java.sourceFiles 91 | } 92 | 93 | artifacts { 94 | archives androidSourcesJar 95 | } 96 | } -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/ImageProcessor.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors; 2 | 3 | import android.graphics.Bitmap; 4 | 5 | /** 6 | * @author Varun on 29/06/15. 7 | */ 8 | public final class ImageProcessor { 9 | private ImageProcessor() { 10 | } 11 | 12 | public static Bitmap applyCurves(int[] rgb, int[] red, int[] green, int[] blue, Bitmap inputImage) { 13 | // create output bitmap 14 | Bitmap outputImage = inputImage; 15 | 16 | // get image size 17 | int width = inputImage.getWidth(); 18 | int height = inputImage.getHeight(); 19 | 20 | int[] pixels = new int[width * height]; 21 | outputImage.getPixels(pixels, 0, width, 0, 0, width, height); 22 | 23 | if (rgb != null) { 24 | pixels = NativeImageProcessor.applyRGBCurve(pixels, rgb, width, height); 25 | } 26 | 27 | if (!(red == null && green == null && blue == null)) { 28 | pixels = NativeImageProcessor.applyChannelCurves(pixels, red, green, blue, width, height); 29 | } 30 | 31 | try { 32 | outputImage.setPixels(pixels, 0, width, 0, 0, width, height); 33 | } catch (IllegalStateException ise) { 34 | } 35 | return outputImage; 36 | } 37 | 38 | public static Bitmap doBrightness(int value, Bitmap inputImage) { 39 | int width = inputImage.getWidth(); 40 | int height = inputImage.getHeight(); 41 | int[] pixels = new int[width * height]; 42 | 43 | inputImage.getPixels(pixels, 0, width, 0, 0, width, height); 44 | NativeImageProcessor.doBrightness(pixels, value, width, height); 45 | inputImage.setPixels(pixels, 0, width, 0, 0, width, height); 46 | 47 | return inputImage; 48 | } 49 | 50 | public static Bitmap doContrast(float value, Bitmap inputImage) { 51 | int width = inputImage.getWidth(); 52 | int height = inputImage.getHeight(); 53 | int[] pixels = new int[width * height]; 54 | 55 | inputImage.getPixels(pixels, 0, width, 0, 0, width, height); 56 | NativeImageProcessor.doContrast(pixels, value, width, height); 57 | inputImage.setPixels(pixels, 0, width, 0, 0, width, height); 58 | 59 | return inputImage; 60 | } 61 | 62 | 63 | public static Bitmap doColorOverlay(int depth, float red, float green, float blue, Bitmap inputImage) { 64 | int width = inputImage.getWidth(); 65 | int height = inputImage.getHeight(); 66 | int[] pixels = new int[width * height]; 67 | 68 | inputImage.getPixels(pixels, 0, width, 0, 0, width, height); 69 | NativeImageProcessor.doColorOverlay(pixels, depth, red, green, blue, width, height); 70 | inputImage.setPixels(pixels, 0, width, 0, 0, width, height); 71 | 72 | return inputImage; 73 | } 74 | 75 | public static Bitmap doSaturation(Bitmap inputImage, float level) { 76 | int width = inputImage.getWidth(); 77 | int height = inputImage.getHeight(); 78 | int[] pixels = new int[width * height]; 79 | 80 | inputImage.getPixels(pixels, 0, width, 0, 0, width, height); 81 | NativeImageProcessor.doSaturation(pixels, level, width, height); 82 | inputImage.setPixels(pixels, 0, width, 0, 0, width, height); 83 | return inputImage; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/subfilters/ToneCurveSubFilter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors.subfilters; 2 | 3 | import android.graphics.Bitmap; 4 | import com.zomato.photofilters.geometry.BezierSpline; 5 | import com.zomato.photofilters.geometry.Point; 6 | import com.zomato.photofilters.imageprocessors.ImageProcessor; 7 | import com.zomato.photofilters.imageprocessors.SubFilter; 8 | 9 | 10 | /** 11 | * @author varun 12 | * Subfilter to tweak rgb channels of an image 13 | */ 14 | public class ToneCurveSubFilter implements SubFilter { 15 | private static String tag = ""; 16 | 17 | // These are knots which contains the plot points 18 | private Point[] rgbKnots; 19 | private Point[] greenKnots; 20 | private Point[] redKnots; 21 | private Point[] blueKnots; 22 | private int[] rgb; 23 | private int[] r; 24 | private int[] g; 25 | private int[] b; 26 | 27 | /** 28 | * Initialise ToneCurveSubfilter (NOTE : Don't pass null knots, pass straight line instead) 29 | * Knots are the points in 2D taken by tweaking photoshop channels(plane ranging from 0-255) 30 | * 31 | * @param rgbKnots rgb Knots 32 | * @param redKnots Knots in Red Channel 33 | * @param greenKnots Knots in green Channel 34 | * @param blueKnots Knots in Blue channel 35 | */ 36 | public ToneCurveSubFilter(Point[] rgbKnots, Point[] redKnots, Point[] greenKnots, Point[] blueKnots) { 37 | Point[] straightKnots = new Point[2]; 38 | straightKnots[0] = new Point(0, 0); 39 | straightKnots[1] = new Point(255, 255); 40 | if (rgbKnots == null) { 41 | this.rgbKnots = straightKnots; 42 | } else { 43 | this.rgbKnots = rgbKnots; 44 | } 45 | if (redKnots == null) { 46 | this.redKnots = straightKnots; 47 | } else { 48 | this.redKnots = redKnots; 49 | } 50 | if (greenKnots == null) { 51 | this.greenKnots = straightKnots; 52 | } else { 53 | this.greenKnots = greenKnots; 54 | } 55 | if (blueKnots == null) { 56 | this.blueKnots = straightKnots; 57 | } else { 58 | this.blueKnots = blueKnots; 59 | } 60 | } 61 | 62 | @Override 63 | public Bitmap process(Bitmap inputImage) { 64 | rgbKnots = sortPointsOnXAxis(rgbKnots); 65 | redKnots = sortPointsOnXAxis(redKnots); 66 | greenKnots = sortPointsOnXAxis(greenKnots); 67 | blueKnots = sortPointsOnXAxis(blueKnots); 68 | if (rgb == null) { 69 | rgb = BezierSpline.curveGenerator(rgbKnots); 70 | } 71 | 72 | if (r == null) { 73 | r = BezierSpline.curveGenerator(redKnots); 74 | } 75 | 76 | if (g == null) { 77 | g = BezierSpline.curveGenerator(greenKnots); 78 | } 79 | 80 | if (b == null) { 81 | b = BezierSpline.curveGenerator(blueKnots); 82 | } 83 | 84 | return ImageProcessor.applyCurves(rgb, r, g, b, inputImage); 85 | } 86 | 87 | public Point[] sortPointsOnXAxis(Point[] points) { 88 | if (points == null) { 89 | return null; 90 | } 91 | for (int s = 1; s < points.length - 1; s++) { 92 | for (int k = 0; k <= points.length - 2; k++) { 93 | if (points[k].x > points[k + 1].x) { 94 | float temp = 0; 95 | temp = points[k].x; 96 | points[k].x = points[k + 1].x; //swapping values 97 | points[k + 1].x = temp; 98 | } 99 | } 100 | } 101 | return points; 102 | } 103 | 104 | @Override 105 | public String getTag() { 106 | return tag; 107 | } 108 | 109 | @Override 110 | public void setTag(Object tag) { 111 | ToneCurveSubFilter.tag = (String) tag; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /example/src/main/java/com/example/filters/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.filters; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.os.Bundle; 8 | import android.os.Handler; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.widget.ImageView; 13 | 14 | import com.zomato.photofilters.SampleFilters; 15 | import com.zomato.photofilters.imageprocessors.Filter; 16 | 17 | import java.util.List; 18 | 19 | public class MainActivity extends AppCompatActivity implements ThumbnailCallback { 20 | static { 21 | System.loadLibrary("NativeImageProcessor"); 22 | } 23 | 24 | private Activity activity; 25 | private RecyclerView thumbListView; 26 | private ImageView placeHolderImageView; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | activity = this; 33 | initUIWidgets(); 34 | } 35 | 36 | private void initUIWidgets() { 37 | thumbListView = (RecyclerView) findViewById(R.id.thumbnails); 38 | placeHolderImageView = (ImageView) findViewById(R.id.place_holder_imageview); 39 | placeHolderImageView.setImageBitmap(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(this.getApplicationContext().getResources(), R.drawable.photo), 640, 640, false)); 40 | initHorizontalList(); 41 | } 42 | 43 | private void initHorizontalList() { 44 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 45 | layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); 46 | layoutManager.scrollToPosition(0); 47 | thumbListView.setLayoutManager(layoutManager); 48 | thumbListView.setHasFixedSize(true); 49 | bindDataToAdapter(); 50 | } 51 | 52 | private void bindDataToAdapter() { 53 | final Context context = this.getApplication(); 54 | Handler handler = new Handler(); 55 | Runnable r = new Runnable() { 56 | public void run() { 57 | Bitmap thumbImage = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.photo), 640, 640, false); 58 | ThumbnailItem t1 = new ThumbnailItem(); 59 | ThumbnailItem t2 = new ThumbnailItem(); 60 | ThumbnailItem t3 = new ThumbnailItem(); 61 | ThumbnailItem t4 = new ThumbnailItem(); 62 | ThumbnailItem t5 = new ThumbnailItem(); 63 | ThumbnailItem t6 = new ThumbnailItem(); 64 | 65 | t1.image = thumbImage; 66 | t2.image = thumbImage; 67 | t3.image = thumbImage; 68 | t4.image = thumbImage; 69 | t5.image = thumbImage; 70 | t6.image = thumbImage; 71 | ThumbnailsManager.clearThumbs(); 72 | ThumbnailsManager.addThumb(t1); // Original Image 73 | 74 | t2.filter = SampleFilters.getStarLitFilter(); 75 | ThumbnailsManager.addThumb(t2); 76 | 77 | t3.filter = SampleFilters.getBlueMessFilter(); 78 | ThumbnailsManager.addThumb(t3); 79 | 80 | t4.filter = SampleFilters.getAweStruckVibeFilter(); 81 | ThumbnailsManager.addThumb(t4); 82 | 83 | t5.filter = SampleFilters.getLimeStutterFilter(); 84 | ThumbnailsManager.addThumb(t5); 85 | 86 | t6.filter = SampleFilters.getNightWhisperFilter(); 87 | ThumbnailsManager.addThumb(t6); 88 | 89 | List thumbs = ThumbnailsManager.processThumbs(context); 90 | 91 | ThumbnailsAdapter adapter = new ThumbnailsAdapter(thumbs, (ThumbnailCallback) activity); 92 | thumbListView.setAdapter(adapter); 93 | adapter.notifyDataSetChanged(); 94 | } 95 | }; 96 | handler.post(r); 97 | } 98 | 99 | @Override 100 | public void onThumbnailClick(Filter filter) { 101 | placeHolderImageView.setImageBitmap(filter.processFilter(Bitmap.createScaledBitmap(BitmapFactory.decodeResource(this.getApplicationContext().getResources(), R.drawable.photo), 640, 640, false))); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/imageprocessors/Filter.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.imageprocessors; 2 | 3 | 4 | import android.graphics.Bitmap; 5 | import android.support.annotation.NonNull; 6 | 7 | import com.zomato.photofilters.imageprocessors.subfilters.BrightnessSubFilter; 8 | import com.zomato.photofilters.imageprocessors.subfilters.ColorOverlaySubFilter; 9 | import com.zomato.photofilters.imageprocessors.subfilters.ContrastSubFilter; 10 | import com.zomato.photofilters.imageprocessors.subfilters.SaturationSubFilter; 11 | import com.zomato.photofilters.imageprocessors.subfilters.ToneCurveSubFilter; 12 | import com.zomato.photofilters.imageprocessors.subfilters.VignetteSubFilter; 13 | 14 | import java.util.ArrayList; 15 | import java.util.Iterator; 16 | import java.util.List; 17 | 18 | /** 19 | * This Class represents a ImageFilter and includes many subfilters within, we add different subfilters to this class's 20 | * object and they are then processed in that particular order 21 | */ 22 | public class Filter { 23 | private List subFilters = new ArrayList<>(); 24 | 25 | public Filter(Filter filter) { 26 | this.subFilters = filter.subFilters; 27 | } 28 | 29 | public Filter() { 30 | } 31 | 32 | /** 33 | * Adds a Subfilter to the Main Filter 34 | * 35 | * @param subFilter Subfilter like contrast, brightness, tone Curve etc. subfilter 36 | * @see BrightnessSubFilter 37 | * @see ColorOverlaySubFilter 38 | * @see ContrastSubFilter 39 | * @see ToneCurveSubFilter 40 | * @see VignetteSubFilter 41 | * @see SaturationSubFilter 42 | */ 43 | public void addSubFilter(SubFilter subFilter) { 44 | subFilters.add(subFilter); 45 | } 46 | 47 | /** 48 | * Adds all {@link SubFilter}s from the List to the Main Filter. 49 | * @param subFilterList a list of {@link SubFilter}s; must not be null 50 | */ 51 | public void addSubFilters(@NonNull List subFilterList) { 52 | subFilters.addAll(subFilterList); 53 | } 54 | 55 | /** 56 | * Get a new list of currently applied subfilters. 57 | * 58 | * @return a {@link List} of {@link SubFilter}. 59 | * Empty if no filters are added to {@link #subFilters}; 60 | * never null 61 | * 62 | * @see #addSubFilter(SubFilter) 63 | * @see #addSubFilters(List) 64 | */ 65 | @NonNull 66 | public List getSubFilters() { 67 | if (subFilters == null || subFilters.isEmpty()) 68 | return new ArrayList<>(0); 69 | return new ArrayList<>(subFilters); 70 | } 71 | 72 | /** 73 | * Clears all the subfilters from the Parent Filter 74 | */ 75 | public void clearSubFilters() { 76 | subFilters.clear(); 77 | } 78 | 79 | /** 80 | * Removes the subfilter containing Tag from the Parent Filter 81 | */ 82 | public void removeSubFilterWithTag(String tag) { 83 | Iterator iterator = subFilters.iterator(); 84 | while (iterator.hasNext()) { 85 | SubFilter subFilter = iterator.next(); 86 | if (subFilter.getTag().equals(tag)) { 87 | iterator.remove(); 88 | } 89 | } 90 | } 91 | 92 | /** 93 | * Returns The filter containing Tag 94 | */ 95 | public SubFilter getSubFilterByTag(String tag) { 96 | for (SubFilter subFilter : subFilters) { 97 | if (subFilter.getTag().equals(tag)) { 98 | return subFilter; 99 | } 100 | } 101 | return null; 102 | } 103 | 104 | /** 105 | * Give the output Bitmap by applying the defined filter 106 | * 107 | * @param inputImage Input Bitmap on which filter is to be applied 108 | * @return filtered Bitmap 109 | */ 110 | public Bitmap processFilter(Bitmap inputImage) { 111 | Bitmap outputImage = inputImage; 112 | if (outputImage != null) { 113 | for (SubFilter subFilter : subFilters) { 114 | try { 115 | outputImage = subFilter.process(outputImage); 116 | } catch (OutOfMemoryError oe) { 117 | System.gc(); 118 | try { 119 | outputImage = subFilter.process(outputImage); 120 | } catch (OutOfMemoryError ignored) { 121 | } 122 | } 123 | } 124 | } 125 | 126 | return outputImage; 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/SampleFilters.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters; 2 | 3 | import com.zomato.photofilters.geometry.Point; 4 | import com.zomato.photofilters.imageprocessors.Filter; 5 | import com.zomato.photofilters.imageprocessors.subfilters.BrightnessSubFilter; 6 | import com.zomato.photofilters.imageprocessors.subfilters.ContrastSubFilter; 7 | import com.zomato.photofilters.imageprocessors.subfilters.ToneCurveSubFilter; 8 | 9 | /** 10 | * @author Varun on 01/07/15. 11 | */ 12 | public final class SampleFilters { 13 | 14 | private SampleFilters() { 15 | } 16 | 17 | public static Filter getStarLitFilter() { 18 | Point[] rgbKnots; 19 | rgbKnots = new Point[8]; 20 | rgbKnots[0] = new Point(0, 0); 21 | rgbKnots[1] = new Point(34, 6); 22 | rgbKnots[2] = new Point(69, 23); 23 | rgbKnots[3] = new Point(100, 58); 24 | rgbKnots[4] = new Point(150, 154); 25 | rgbKnots[5] = new Point(176, 196); 26 | rgbKnots[6] = new Point(207, 233); 27 | rgbKnots[7] = new Point(255, 255); 28 | Filter filter = new Filter(); 29 | filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, null, null, null)); 30 | return filter; 31 | } 32 | 33 | public static Filter getBlueMessFilter() { 34 | Point[] redKnots; 35 | redKnots = new Point[8]; 36 | redKnots[0] = new Point(0, 0); 37 | redKnots[1] = new Point(86, 34); 38 | redKnots[2] = new Point(117, 41); 39 | redKnots[3] = new Point(146, 80); 40 | redKnots[4] = new Point(170, 151); 41 | redKnots[5] = new Point(200, 214); 42 | redKnots[6] = new Point(225, 242); 43 | redKnots[7] = new Point(255, 255); 44 | Filter filter = new Filter(); 45 | filter.addSubFilter(new ToneCurveSubFilter(null, redKnots, null, null)); 46 | filter.addSubFilter(new BrightnessSubFilter(30)); 47 | filter.addSubFilter(new ContrastSubFilter(1f)); 48 | return filter; 49 | } 50 | 51 | public static Filter getAweStruckVibeFilter() { 52 | Point[] rgbKnots; 53 | Point[] redKnots; 54 | Point[] greenKnots; 55 | Point[] blueKnots; 56 | 57 | rgbKnots = new Point[5]; 58 | rgbKnots[0] = new Point(0, 0); 59 | rgbKnots[1] = new Point(80, 43); 60 | rgbKnots[2] = new Point(149, 102); 61 | rgbKnots[3] = new Point(201, 173); 62 | rgbKnots[4] = new Point(255, 255); 63 | 64 | redKnots = new Point[5]; 65 | redKnots[0] = new Point(0, 0); 66 | redKnots[1] = new Point(125, 147); 67 | redKnots[2] = new Point(177, 199); 68 | redKnots[3] = new Point(213, 228); 69 | redKnots[4] = new Point(255, 255); 70 | 71 | 72 | greenKnots = new Point[6]; 73 | greenKnots[0] = new Point(0, 0); 74 | greenKnots[1] = new Point(57, 76); 75 | greenKnots[2] = new Point(103, 130); 76 | greenKnots[3] = new Point(167, 192); 77 | greenKnots[4] = new Point(211, 229); 78 | greenKnots[5] = new Point(255, 255); 79 | 80 | 81 | blueKnots = new Point[7]; 82 | blueKnots[0] = new Point(0, 0); 83 | blueKnots[1] = new Point(38, 62); 84 | blueKnots[2] = new Point(75, 112); 85 | blueKnots[3] = new Point(116, 158); 86 | blueKnots[4] = new Point(171, 204); 87 | blueKnots[5] = new Point(212, 233); 88 | blueKnots[6] = new Point(255, 255); 89 | 90 | Filter filter = new Filter(); 91 | filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, redKnots, greenKnots, blueKnots)); 92 | return filter; 93 | } 94 | 95 | public static Filter getLimeStutterFilter() { 96 | Point[] blueKnots; 97 | blueKnots = new Point[3]; 98 | blueKnots[0] = new Point(0, 0); 99 | blueKnots[1] = new Point(165, 114); 100 | blueKnots[2] = new Point(255, 255); 101 | // Check whether output is null or not. 102 | Filter filter = new Filter(); 103 | filter.addSubFilter(new ToneCurveSubFilter(null, null, null, blueKnots)); 104 | return filter; 105 | } 106 | 107 | public static Filter getNightWhisperFilter() { 108 | Point[] rgbKnots; 109 | Point[] redKnots; 110 | Point[] greenKnots; 111 | Point[] blueKnots; 112 | 113 | rgbKnots = new Point[3]; 114 | rgbKnots[0] = new Point(0, 0); 115 | rgbKnots[1] = new Point(174, 109); 116 | rgbKnots[2] = new Point(255, 255); 117 | 118 | redKnots = new Point[4]; 119 | redKnots[0] = new Point(0, 0); 120 | redKnots[1] = new Point(70, 114); 121 | redKnots[2] = new Point(157, 145); 122 | redKnots[3] = new Point(255, 255); 123 | 124 | greenKnots = new Point[3]; 125 | greenKnots[0] = new Point(0, 0); 126 | greenKnots[1] = new Point(109, 138); 127 | greenKnots[2] = new Point(255, 255); 128 | 129 | blueKnots = new Point[3]; 130 | blueKnots[0] = new Point(0, 0); 131 | blueKnots[1] = new Point(113, 152); 132 | blueKnots[2] = new Point(255, 255); 133 | 134 | Filter filter = new Filter(); 135 | filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, redKnots, greenKnots, blueKnots)); 136 | return filter; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 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 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PhotoFiltersSDK 2 | 3 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.html) 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-AndroidPhotoFilters-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3703) 5 | 6 | PhotoFiltersSDK aims to provide fast, powerful and flexible image processing instrument for creating awesome effects on any image media. 7 | 8 | Library supports OS on API 15 and above. 9 | 10 | ![PhotoFilters gif](art/photofilters.gif) 11 | 12 | ## Features 13 | PhotoFiltersSDK processes filter on any Image within fraction of second since processing logic is in NDK. At present following image filters are included: 14 | 15 | * **[ToneCurveSubfilter](#tonecurve) :** With this powerful filter you can change RGB channels of any image to create great results. 16 | * **[SaturationSubfitler](#saturation) :** Used for changing color saturation of an image. 17 | * **[ColorOverlaySubfilter](#coloroverlay) :** As name suggests you can overlay any image with color of your choice. 18 | * **[ContrastSubfilter](#contrast) :** Used for changing contrast value of image. 19 | * **[BrightnessSubfilter](#brightness) :** To change brightness levels. 20 | * **[VignetteSubfilter](#vignette) :** To apply vignette effect on image. 21 | 22 | Library also comes with inbuilt Sample Filters (Refer [SampleFitlers.java](photofilterssdk/src/main/java/com/zomato/photofilters/SampleFilters.java)). Implementation is straightforward: 23 | 24 | ```java 25 | Filter fooFilter = SampleFilters.getBlueMessFilter(); 26 | Bitmap outputImage = fooFilter.processFilter(inputImage); 27 | ``` 28 | 29 | ## Implementation 30 | 31 | ### Adding Dependency 32 | 33 | Simply add Dependency on artifact in your `build.gradle` : 34 | 35 | ```gradle 36 | dependencies { 37 | compile 'com.github.zomato:androidphotofilters:1.0.2' 38 | ... 39 | ``` 40 | 41 | **OR** 42 | 43 | Copy|Paste photofilterssdk from the repo to your project and include photofiltersdk in your `settings.gradle` like this : 44 | 45 | ```gradle 46 | include ':photofilterssdk' 47 | ``` 48 | Add dependency in your `build.gradle` : 49 | 50 | ```gradle 51 | compile project(':photofilterssdk') 52 | ``` 53 | 54 | ### Usage 55 | 56 | Load native library in your activity : 57 | 58 | ```java 59 | public class MainActivity extends AppCompatActivity { 60 | static 61 | { 62 | System.loadLibrary("NativeImageProcessor"); 63 | } 64 | ... 65 | ``` 66 | 67 | then 68 | 69 | ```java 70 | Filter myFilter = new Filter(); 71 | myFilter.addSubFilter(new BrightnessSubFilter(30)); 72 | myFilter.addSubFilter(new ContrastSubFilter(1.1f)); 73 | Bitmap outputImage = myFilter.processFilter(inputImage); 74 | ``` 75 | 76 | Above code snippet will give you outputImage with increased brightness and contrast. You can further refer [example project](example). 77 | 78 | ## Documentation 79 | Although there are few inbuilt filters already present, you may want to create and customize one specific to your need and show your creativity. For that you would require to know how all the Subfilters can be used. Let me take you through all of them. 80 | 81 | ### ToneCurveSubfilter 82 | This is most awesome filter present in this library which differentiates **PhotoFiltersSDK** from other image processing libraries out there. ToneCurveSubFilter applies the changed RGB Channel curve to create effect on image. 83 | 84 | ![CurveDialog](art/curvedialog_photoshop.png) 85 | 86 | Here is the code snippet the apply the above RGB curve on an image : 87 | 88 | ```java 89 | Filter myFilter = new Filter(); 90 | Point[] rgbKnots; 91 | rgbKnots = new Point[3]; 92 | rgbKnots[0] = new Point(0, 0); 93 | rgbKnots[1] = new Point(175, 139); 94 | rgbKnots[2] = new Point(255, 255); 95 | 96 | myFilter.addSubFilter(new ToneCurveSubfilter(rgbKnots, null, null, null)); 97 | Bitmap outputImage = myFilter.processFilter(inputImage); 98 | ``` 99 | 100 | The results are nearly same as we would see in photoshop and other tools. We can also specify knots for Red, Green and Blue channels (in the ToneCurveSubfilter's constructor). 101 | 102 | ### SaturationSubfilter 103 | This fitler can be used to tweak color saturation of an image. Here is the example : 104 | 105 | ```java 106 | Filter myFilter = new Filter(); 107 | myFilter.addSubFilter(new SaturationSubfilter(1.3f)); 108 | Bitmap outputImage = myFilter.processFilter(inputImage); 109 | ``` 110 | 111 | SaturationSubfilter takes float as an argument and has no effect for value 1. 112 | 113 | ### ColorOverlaySubfilter 114 | Increases the specified red, green and blue values for each pixel in an image. 115 | 116 | ```java 117 | Filter myFilter = new Filter(); 118 | myFilter.addSubFilter(new ColorOverlaySubfilter(100, .2f, .2f, .0f)); 119 | Bitmap outputImage = myFilter.processFilter(inputImage); 120 | ``` 121 | 122 | ### ContrastSubfilter 123 | To change the contrast levels of an image use this filter : 124 | 125 | ```java 126 | Filter myFilter = new Filter(); 127 | myFilter.addSubFilter(new ContrastSubfilter(1.2f)); 128 | Bitmap outputImage = myFilter.processFilter(inputImage); 129 | ``` 130 | 131 | ContrastSubfilter takes float as an argument where value 1 has no effect on the image. 132 | 133 | ### BrightnessSubfilter 134 | As the name suggest, this filter is used for changing brightness levels : 135 | 136 | ```java 137 | Filter myFilter = new Filter(); 138 | myFilter.addSubFilter(new BrightnessSubfilter(30)); 139 | Bitmap ouputImage = myFilter.processFilter(inputImage); 140 | ``` 141 | BrightnessSubfilter takes int as an argument where value 0 has no effect. Negative values can be used to decrease brightness of the image. 142 | 143 | ### VignetteSubfilter 144 | This filter can be used to put vignette effect on the image. 145 | 146 | ```java 147 | Filter myFilter = new Filter(); 148 | myFilter.addSubFilter(new VignetteSubfilter(context, 100)); 149 | Bitmap outputImage = myFilter.processFilter(inputImage); 150 | ``` 151 | 152 | VignetteSubfilter takes int as an argument whoes value ranges from 0-255, which defines intesity of the vignette effect. 153 | 154 | ## Proguard 155 | If you are using proguard, consider adding the following to your proguard rules: 156 | 157 | ```proguard 158 | -keep class com.zomato.photofilters.** {*;} 159 | -keepclassmembers class com.zomato.photofilters.** {*;} 160 | ``` 161 | 162 | ## License 163 | This library falls under [Apache v2](LICENSE) 164 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/java/com/zomato/photofilters/geometry/BezierSpline.java: -------------------------------------------------------------------------------- 1 | package com.zomato.photofilters.geometry; 2 | 3 | 4 | import android.graphics.Path; 5 | import android.graphics.PathMeasure; 6 | import android.os.Build; 7 | import android.view.animation.PathInterpolator; 8 | 9 | /** 10 | * @author Varun on 29/06/15. 11 | */ 12 | public final class BezierSpline { 13 | private BezierSpline() { 14 | } 15 | 16 | /** 17 | * Generates Curve {in a plane ranging from 0-255} using the knots provided 18 | */ 19 | public static int[] curveGenerator(Point[] knots) { 20 | if (knots == null) { 21 | throw new NullPointerException("Knots cannot be null"); 22 | } 23 | 24 | int n = knots.length - 1; 25 | if (n < 1) { 26 | throw new IllegalArgumentException("Atleast two points are required"); 27 | } 28 | 29 | if (Build.VERSION.SDK_INT >= 21) { 30 | return getOutputPointsForNewerDevices(knots); 31 | } else { 32 | return getOutputPointsForOlderDevices(knots); 33 | } 34 | } 35 | 36 | // This is for lollipop and newer devices 37 | private static int[] getOutputPointsForNewerDevices(Point[] knots) { 38 | 39 | Point[] controlPoints = calculateControlPoints(knots); 40 | Path path = new Path(); 41 | path.moveTo(0, 0); 42 | path.lineTo(knots[0].x / 255.0f, knots[0].y / 255.0f); 43 | path.moveTo(knots[0].x / 255.0f, knots[0].y / 255.0f); 44 | 45 | for (int index = 1; index < knots.length; index++) { 46 | path.quadTo( 47 | controlPoints[index - 1].x / 255.0f, 48 | controlPoints[index - 1].y / 255.0f, 49 | knots[index].x / 255.0f, 50 | knots[index].y / 255.0f 51 | ); 52 | path.moveTo(knots[index].x / 255.0f, knots[index].y / 255.0f); 53 | } 54 | 55 | path.lineTo(1, 1); 56 | path.moveTo(1, 1); 57 | 58 | float[] allPoints = new float[256]; 59 | 60 | for (int x = 0; x < 256; x++) { 61 | PathInterpolator pathInterpolator = new PathInterpolator(path); 62 | allPoints[x] = 255.0f * pathInterpolator.getInterpolation((float) x / 255.0f); 63 | } 64 | 65 | allPoints[0] = knots[0].y; 66 | allPoints[255] = knots[knots.length - 1].y; 67 | return validateCurve(allPoints); 68 | } 69 | 70 | 71 | //This is for devices older than lollipop 72 | private static int[] getOutputPointsForOlderDevices(Point[] knots) { 73 | Point[] controlPoints = calculateControlPoints(knots); 74 | Path path = new Path(); 75 | path.moveTo(0, 0); 76 | path.lineTo(knots[0].x, knots[0].y); 77 | path.moveTo(knots[0].x, knots[0].y); 78 | 79 | for (int index = 1; index < knots.length; index++) { 80 | path.quadTo(controlPoints[index - 1].x, controlPoints[index - 1].y, knots[index].x, knots[index].y); 81 | path.moveTo(knots[index].x, knots[index].y); 82 | } 83 | 84 | path.lineTo(255, 255); 85 | path.moveTo(255, 255); 86 | 87 | float[] allPoints = new float[256]; 88 | 89 | PathMeasure pm = new PathMeasure(path, false); 90 | for (int i = 0; i < 256; i++) { 91 | allPoints[i] = -1; 92 | } 93 | 94 | int x = 0; 95 | float[] acoordinates = {0, 0}; 96 | 97 | do { 98 | float pathLength = pm.getLength(); 99 | for (float i = 0; i <= pathLength; i += 0.08f) { 100 | pm.getPosTan(i, acoordinates, null); 101 | if ((int) (acoordinates[0]) > x && x < 256) { 102 | allPoints[x] = acoordinates[1]; 103 | x++; 104 | } 105 | if (x > 255) { 106 | break; 107 | } 108 | } 109 | } while (pm.nextContour()); 110 | 111 | 112 | allPoints[0] = knots[0].y; 113 | for (int i = 0; i < 256; i++) { 114 | if (allPoints[i] == -1) { 115 | allPoints[i] = allPoints[i - 1]; 116 | } 117 | } 118 | allPoints[255] = knots[knots.length - 1].y; 119 | return validateCurve(allPoints); 120 | } 121 | 122 | private static int[] validateCurve(float[] allPoints) { 123 | int[] curvedPath = new int[256]; 124 | for (int x = 0; x < 256; x++) { 125 | if (allPoints[x] > 255.0f) { 126 | curvedPath[x] = 255; 127 | } else if (allPoints[x] < 0.0f) { 128 | curvedPath[x] = 0; 129 | } else { 130 | curvedPath[x] = Math.round(allPoints[x]); 131 | } 132 | } 133 | return curvedPath; 134 | } 135 | 136 | // Calculates the control points for the specified knots 137 | private static Point[] calculateControlPoints(Point[] knots) { 138 | int n = knots.length - 1; 139 | Point[] controlPoints = new Point[n]; 140 | 141 | if (n == 1) { // Special case: Bezier curve should be a straight line. 142 | // 3P1 = 2P0 + P3 143 | controlPoints[0] = new Point((2 * knots[0].x + knots[1].x) / 3, (2 * knots[0].y + knots[1].y) / 3); 144 | // P2 = 2P1 – P0 145 | //controlPoints[1][0] = new Point(2*controlPoints[0][0].x - knots[0].x, 2*controlPoints[0][0].y-knots[0].y); 146 | } else { 147 | // Calculate first Bezier control points 148 | // Right hand side vector 149 | float[] rhs = new float[n]; 150 | 151 | // Set right hand side x values 152 | for (int i = 1; i < n - 1; ++i) { 153 | rhs[i] = 4 * knots[i].x + 2 * knots[i + 1].x; 154 | } 155 | rhs[0] = knots[0].x + 2 * knots[1].x; 156 | rhs[n - 1] = (8 * knots[n - 1].x + knots[n].x) / 2.0f; 157 | // Get first control points x-values 158 | float[] x = getFirstControlPoints(rhs); 159 | 160 | // Set right hand side y values 161 | for (int i = 1; i < n - 1; ++i) { 162 | rhs[i] = 4 * knots[i].y + 2 * knots[i + 1].y; 163 | } 164 | rhs[0] = knots[0].y + 2 * knots[1].y; 165 | rhs[n - 1] = (8 * knots[n - 1].y + knots[n].y) / 2.0f; 166 | // Get first control points y-values 167 | float[] y = getFirstControlPoints(rhs); 168 | for (int i = 0; i < n; ++i) { 169 | controlPoints[i] = new Point(x[i], y[i]); 170 | } 171 | } 172 | 173 | return controlPoints; 174 | } 175 | 176 | private static float[] getFirstControlPoints(float[] rhs) { 177 | int n = rhs.length; 178 | float[] x = new float[n]; // Solution vector. 179 | float[] tmp = new float[n]; // Temp workspace. 180 | 181 | float b = 1.0f; // Control Point Factor 182 | x[0] = rhs[0] / b; 183 | for (int i = 1; i < n; i++) // Decomposition and forward substitution. 184 | { 185 | tmp[i] = 1 / b; 186 | b = (i < n - 1 ? 4.0f : 3.5f) - tmp[i]; 187 | x[i] = (rhs[i] - x[i - 1]) / b; 188 | } 189 | for (int i = 1; i < n; i++) { 190 | x[n - i - 1] -= tmp[n - i] * x[n - i]; // Backsubstitution. 191 | } 192 | return x; 193 | } 194 | } 195 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /photofilterssdk/src/main/jni/NativeImageProcessor.cpp: -------------------------------------------------------------------------------- 1 | /* C++ Version */ 2 | 3 | #include 4 | #include 5 | 6 | extern "C" { 7 | 8 | static void HSLtoRGB_Subfunction(unsigned int &c, const float &temp1, const float &temp2, const float &temp3) { 9 | if ((temp3 * 6) < 1) 10 | c = (unsigned int) ((temp2 + (temp1 - temp2) * 6 * temp3) * 100); 11 | else if ((temp3 * 2) < 1) 12 | c = (unsigned int) (temp1 * 100); 13 | else if ((temp3 * 3) < 2) 14 | c = (unsigned int) ((temp2 + (temp1 - temp2) * (.66666 - temp3) * 6) * 100); 15 | else 16 | c = (unsigned int) (temp2 * 100); 17 | return; 18 | } 19 | 20 | // This function extracts the hue, saturation, and luminance from "color" 21 | // and places these values in h, s, and l respectively. 22 | void saturation(int *pixels, float level, int width, int height) { 23 | unsigned int r; 24 | unsigned int g; 25 | unsigned int b; 26 | 27 | float temp1, temp2, temp3; 28 | 29 | float r_percent; 30 | float g_percent; 31 | float b_percent; 32 | 33 | float max_color, min_color; 34 | float L, S, H; 35 | 36 | for (int i = 0; i < width * height; i++) { 37 | r = (unsigned int) (pixels[i] >> 16) & 0xFF; 38 | g = (unsigned int) (pixels[i] >> 8) & 0xFF; 39 | b = (unsigned int) (pixels[i]) & 0xFF; 40 | 41 | r_percent = ((float) r) / 255; 42 | g_percent = ((float) g) / 255; 43 | b_percent = ((float) b) / 255; 44 | 45 | max_color = 0; 46 | if ((r_percent >= g_percent) && (r_percent >= b_percent)) { 47 | max_color = r_percent; 48 | } 49 | if ((g_percent >= r_percent) && (g_percent >= b_percent)) 50 | max_color = g_percent; 51 | if ((b_percent >= r_percent) && (b_percent >= g_percent)) 52 | max_color = b_percent; 53 | 54 | min_color = 0; 55 | if ((r_percent <= g_percent) && (r_percent <= b_percent)) 56 | min_color = r_percent; 57 | if ((g_percent <= r_percent) && (g_percent <= b_percent)) 58 | min_color = g_percent; 59 | if ((b_percent <= r_percent) && (b_percent <= g_percent)) 60 | min_color = b_percent; 61 | 62 | L = 0; 63 | S = 0; 64 | H = 0; 65 | 66 | L = (max_color + min_color) / 2; 67 | 68 | if (max_color == min_color) { 69 | S = 0; 70 | H = 0; 71 | } 72 | else { 73 | if (L < .50) { 74 | S = (max_color - min_color) / (max_color + min_color); 75 | } 76 | else { 77 | S = (max_color - min_color) / (2 - max_color - min_color); 78 | } 79 | if (max_color == r_percent) { 80 | H = (g_percent - b_percent) / (max_color - min_color); 81 | } 82 | if (max_color == g_percent) { 83 | H = 2 + (b_percent - r_percent) / (max_color - min_color); 84 | } 85 | if (max_color == b_percent) { 86 | H = 4 + (r_percent - g_percent) / (max_color - min_color); 87 | } 88 | } 89 | S = (unsigned int) (S * 100); 90 | L = (unsigned int) (L * 100); 91 | H = H * 60; 92 | if (H < 0) 93 | H += 360; 94 | 95 | S *= level; 96 | if (S > 100) { 97 | S = 100; 98 | } 99 | else if (S < 0) { 100 | S = 0; 101 | } 102 | 103 | L = ((float) L) / 100; 104 | S = ((float) S) / 100; 105 | H = ((float) H) / 360; 106 | 107 | if (S == 0) { 108 | r = L * 100; 109 | g = L * 100; 110 | b = L * 100; 111 | } 112 | else { 113 | temp1 = 0; 114 | if (L < .50) { 115 | temp1 = L * (1 + S); 116 | } 117 | else { 118 | temp1 = L + S - (L * S); 119 | } 120 | 121 | temp2 = 2 * L - temp1; 122 | 123 | temp3 = 0; 124 | for (int i = 0; i < 3; i++) { 125 | switch (i) { 126 | case 0: // red 127 | { 128 | temp3 = H + .33333f; 129 | if (temp3 > 1) 130 | temp3 -= 1; 131 | HSLtoRGB_Subfunction(r, temp1, temp2, temp3); 132 | break; 133 | } 134 | case 1: // green 135 | { 136 | temp3 = H; 137 | HSLtoRGB_Subfunction(g, temp1, temp2, temp3); 138 | break; 139 | } 140 | case 2: // blue 141 | { 142 | temp3 = H - .33333f; 143 | if (temp3 < 0) 144 | temp3 += 1; 145 | HSLtoRGB_Subfunction(b, temp1, temp2, temp3); 146 | break; 147 | } 148 | default: { 149 | } 150 | } 151 | } 152 | } 153 | r = (unsigned int) ((((float) r) / 100) * 255); 154 | g = (unsigned int) ((((float) g) / 100) * 255); 155 | b = (unsigned int) ((((float) b) / 100) * 255); 156 | 157 | pixels[i] = (pixels[i] & 0xFF000000) | (((int) r << 16) & 0x00FF0000) | (((int) g << 8) & 0x0000FF00) | 158 | ((int) b & 0x000000FF); 159 | 160 | } 161 | } 162 | 163 | static void colorOverlay(int *pixels, int depth, float red, float green, float blue, int width, int height) { 164 | 165 | float R, G, B; 166 | 167 | for (int i = 0; i < width * height; i++) { 168 | R = (pixels[i] >> 16) & 0xFF; 169 | G = (pixels[i] >> 8) & 0xFF; 170 | B = (pixels[i]) & 0xFF; 171 | 172 | // apply intensity level for sepid-toning on each channel 173 | R += (depth * red); 174 | if (R > 255) { R = 255; } 175 | 176 | G += (depth * green); 177 | if (G > 255) { G = 255; } 178 | 179 | B += (depth * blue); 180 | if (B > 255) { B = 255; } 181 | 182 | pixels[i] = (pixels[i] & 0xFF000000) | (((int) R << 16) & 0x00FF0000) | (((int) G << 8) & 0x0000FF00) | 183 | ((int) B & 0x000000FF); 184 | } 185 | } 186 | 187 | static void contrast(int width, int height, int *pixels, float value) { 188 | 189 | float red, green, blue; 190 | int R, G, B; 191 | 192 | for (int i = 0; i < width * height; i++) { 193 | red = (pixels[i] >> 16) & 0xFF; 194 | green = (pixels[i] >> 8) & 0xFF; 195 | blue = (pixels[i]) & 0xFF; 196 | 197 | red = (((((red / 255.0) - 0.5) * value) + 0.5) * 255.0); 198 | green = (((((green / 255.0) - 0.5) * value) + 0.5) * 255.0); 199 | blue = (((((blue / 255.0) - 0.5) * value) + 0.5) * 255.0); 200 | 201 | // validation check 202 | if (red > 255) 203 | red = 255; 204 | else if (red < 0) 205 | red = 0; 206 | 207 | if (green > 255) 208 | green = 255; 209 | else if (green < 0) 210 | green = 0; 211 | 212 | if (blue > 255) 213 | blue = 255; 214 | else if (blue < 0) 215 | blue = 0; 216 | 217 | R = (int) red; 218 | G = (int) green; 219 | B = (int) blue; 220 | pixels[i] = (pixels[i] & 0xFF000000) | ((R << 16) & 0x00FF0000) | ((G << 8) & 0x0000FF00) | (B & 0x000000FF); 221 | } 222 | } 223 | 224 | static void brightness(int width, int height, int *pixels, int value) { 225 | 226 | int red, green, blue; 227 | 228 | for (int i = 0; i < width * height; i++) { 229 | red = (pixels[i] >> 16) & 0xFF; 230 | green = (pixels[i] >> 8) & 0xFF; 231 | blue = (pixels[i]) & 0xFF; 232 | 233 | red += value; 234 | green += value; 235 | blue += value; 236 | 237 | // validation check 238 | if (red > 255) 239 | red = 255; 240 | else if (red < 0) 241 | red = 0; 242 | 243 | if (green > 255) 244 | green = 255; 245 | else if (green < 0) 246 | green = 0; 247 | 248 | if (blue > 255) 249 | blue = 255; 250 | else if (blue < 0) 251 | blue = 0; 252 | 253 | pixels[i] = (pixels[i] & 0xFF000000) | ((red << 16) & 0x00FF0000) | ((green << 8) & 0x0000FF00) | (blue & 0x000000FF); 254 | } 255 | } 256 | 257 | 258 | static void applyChannelCurves(int width, int height, int *pixels, int *r, int *g, int *b) { 259 | int red; 260 | int green; 261 | int blue; 262 | int alpha; 263 | 264 | for (int i = 0; i < width * height; i++) { 265 | if (r != NULL) 266 | red = (r[(pixels[i] >> 16) & 0xFF] << 16) & 0x00FF0000; 267 | else 268 | red = (pixels[i] << 16) & 0x00FF0000; 269 | 270 | if (g != NULL) 271 | green = (g[(pixels[i] >> 8) & 0xFF] << 8) & 0x0000FF00; 272 | else 273 | green = (pixels[i] << 8) & 0x0000FF00; 274 | 275 | if (b != NULL) 276 | blue = b[pixels[i] & 0xFF] & 0x000000FF; 277 | else 278 | blue = pixels[i] & 0x000000FF; 279 | 280 | alpha = pixels[i] & 0xFF000000; 281 | 282 | pixels[i] = alpha | red | green | blue; 283 | } 284 | } 285 | 286 | static void applyRGBCurve(int width, int height, int *pixels, int *rgb) { 287 | int R[256]; 288 | int G[256]; 289 | int B[256]; 290 | for (int i = 0; i < 256; i++) { 291 | R[i] = (rgb[i] << 16) & 0x00FF0000; 292 | G[i] = (rgb[i] << 8) & 0x0000FF00; 293 | B[i] = rgb[i] & 0x000000FF; 294 | } 295 | 296 | for (int i = 0; i < width * height; i++) { 297 | pixels[i] = 298 | (0xFF000000 & pixels[i]) | (R[(pixels[i] >> 16) & 0xFF]) | (G[(pixels[i] >> 8) & 0xFF]) | (B[pixels[i] & 0xFF]); 299 | } 300 | 301 | } 302 | 303 | static inline jint *getPointerArray(JNIEnv *env, jintArray buff) { 304 | jint *ptrBuff = NULL; 305 | if (buff != NULL) 306 | ptrBuff = env->GetIntArrayElements(buff, JNI_FALSE); 307 | return ptrBuff; 308 | } 309 | 310 | static inline jintArray jintToJintArray(JNIEnv *env, jint size, jint *arr) { 311 | jintArray result = env->NewIntArray(size); 312 | env->SetIntArrayRegion(result, 0, size, arr); 313 | return result; 314 | } 315 | 316 | static inline void releaseArray(JNIEnv *env, jintArray array1, jint *array2) { 317 | if (array1 != NULL) 318 | env->ReleaseIntArrayElements(array1, array2, 0); 319 | } 320 | 321 | 322 | JNIEXPORT jintArray 323 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_applyRGBCurve(JNIEnv *env, jobject thiz, 324 | jintArray pixels, jintArray rgb, 325 | jint width, jint height) { 326 | jint *pixelsBuff = getPointerArray(env, pixels); 327 | jint *RGBBuff = getPointerArray(env, rgb); 328 | applyRGBCurve(width, height, pixelsBuff, RGBBuff); 329 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 330 | releaseArray(env, pixels, pixelsBuff); 331 | releaseArray(env, rgb, RGBBuff); 332 | return result; 333 | } 334 | 335 | JNIEXPORT jintArray 336 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_applyChannelCurves(JNIEnv *env, jobject thiz, 337 | jintArray pixels, jintArray r, 338 | jintArray g, jintArray b, 339 | jint width, jint height) { 340 | jint *pixelsBuff = getPointerArray(env, pixels); 341 | jint *RBuff = getPointerArray(env, r); 342 | jint *GBuff = getPointerArray(env, g); 343 | jint *BBuff = getPointerArray(env, b); 344 | applyChannelCurves(width, height, pixelsBuff, RBuff, GBuff, BBuff); 345 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 346 | releaseArray(env, pixels, pixelsBuff); 347 | releaseArray(env, r, RBuff); 348 | releaseArray(env, g, GBuff); 349 | releaseArray(env, b, BBuff); 350 | return result; 351 | } 352 | 353 | JNIEXPORT jintArray 354 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_doBrightness(JNIEnv *env, jobject thiz, 355 | jintArray pixels, jint value, jint width, 356 | jint height) { 357 | jint *pixelsBuff = getPointerArray(env, pixels); 358 | brightness(width, height, pixelsBuff, value); 359 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 360 | releaseArray(env, pixels, pixelsBuff); 361 | return result; 362 | } 363 | 364 | JNIEXPORT jintArray 365 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_doContrast(JNIEnv *env, jobject thiz, 366 | jintArray pixels, jfloat value, jint width, 367 | jint height) { 368 | jint *pixelsBuff = getPointerArray(env, pixels); 369 | contrast(width, height, pixelsBuff, value); 370 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 371 | releaseArray(env, pixels, pixelsBuff); 372 | return result; 373 | } 374 | 375 | JNIEXPORT jintArray 376 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_doColorOverlay(JNIEnv *env, jobject thiz, 377 | jintArray pixels, jint depth, 378 | jfloat red, jfloat green, jfloat blue, 379 | jint width, jint height) { 380 | jint *pixelsBuff = getPointerArray(env, pixels); 381 | colorOverlay(pixelsBuff, depth, red, green, blue, width, height); 382 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 383 | releaseArray(env, pixels, pixelsBuff); 384 | return result; 385 | } 386 | 387 | JNIEXPORT jintArray 388 | Java_com_zomato_photofilters_imageprocessors_NativeImageProcessor_doSaturation(JNIEnv *env, jobject thiz, 389 | jintArray pixels, float level, 390 | jint width, jint height) { 391 | jint *pixelsBuff = getPointerArray(env, pixels); 392 | saturation(pixelsBuff, level, width, height); 393 | jintArray result = jintToJintArray(env, width * height, pixelsBuff); 394 | releaseArray(env, pixels, pixelsBuff); 395 | return result; 396 | } 397 | } 398 | --------------------------------------------------------------------------------