Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Instagram-like filters. #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 99 additions & 29 deletions example/src/main/java/com/example/filters/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,106 @@ private void bindDataToAdapter() {
Runnable r = new Runnable() {
public void run() {
Bitmap thumbImage = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.photo), 640, 640, false);
ThumbnailItem t1 = new ThumbnailItem();
ThumbnailItem t2 = new ThumbnailItem();
ThumbnailItem t3 = new ThumbnailItem();
ThumbnailItem t4 = new ThumbnailItem();
ThumbnailItem t5 = new ThumbnailItem();
ThumbnailItem t6 = new ThumbnailItem();

t1.image = thumbImage;
t2.image = thumbImage;
t3.image = thumbImage;
t4.image = thumbImage;
t5.image = thumbImage;
t6.image = thumbImage;
ThumbnailsManager.clearThumbs();
ThumbnailsManager.addThumb(t1); // Original Image

t2.filter = SampleFilters.getStarLitFilter();
ThumbnailsManager.addThumb(t2);

t3.filter = SampleFilters.getBlueMessFilter();
ThumbnailsManager.addThumb(t3);

t4.filter = SampleFilters.getAweStruckVibeFilter();
ThumbnailsManager.addThumb(t4);

t5.filter = SampleFilters.getLimeStutterFilter();
ThumbnailsManager.addThumb(t5);

t6.filter = SampleFilters.getNightWhisperFilter();
ThumbnailsManager.addThumb(t6);
ThumbnailItem originalImage = new ThumbnailItem();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to redo the object instantiations in order to make the code better understanding. I have used the respective filter names for variables.

originalImage.image = thumbImage;
ThumbnailsManager.clearThumbs();
ThumbnailsManager.addThumb(originalImage); // Original Image

ThumbnailItem defaultImage = new ThumbnailItem();
defaultImage.image = thumbImage;
defaultImage.filter = SampleFilters.getDefaultFilter();
ThumbnailsManager.addThumb(defaultImage);

ThumbnailItem starLitImage = new ThumbnailItem();
starLitImage.image = thumbImage;
starLitImage.filter = SampleFilters.getStarLitFilter();
ThumbnailsManager.addThumb(starLitImage);

ThumbnailItem clarendonImage = new ThumbnailItem();
clarendonImage.image = thumbImage;
clarendonImage.filter = SampleFilters.getClarendonFilter();
ThumbnailsManager.addThumb(clarendonImage);

ThumbnailItem seirraImage = new ThumbnailItem();
seirraImage.image = thumbImage;
seirraImage.filter = SampleFilters.getSierraFilter();
ThumbnailsManager.addThumb(seirraImage);

ThumbnailItem mayfairImage = new ThumbnailItem();
mayfairImage.image = thumbImage;
mayfairImage.filter = SampleFilters.getMayFairFilter();
ThumbnailsManager.addThumb(mayfairImage);

ThumbnailItem aweStruckVibeImage = new ThumbnailItem();
aweStruckVibeImage.image = thumbImage;
aweStruckVibeImage.filter = SampleFilters.getAweStruckVibeFilter();
ThumbnailsManager.addThumb(aweStruckVibeImage);

ThumbnailItem blueMessImage = new ThumbnailItem();
blueMessImage.image = thumbImage;
blueMessImage.filter = SampleFilters.getBlueMessFilter();
ThumbnailsManager.addThumb(blueMessImage);

ThumbnailItem limeStutterImage = new ThumbnailItem();
limeStutterImage.image = thumbImage;
limeStutterImage.filter = SampleFilters.getLimeStutterFilter();
ThumbnailsManager.addThumb(limeStutterImage);

ThumbnailItem nightWhisperImage = new ThumbnailItem();
nightWhisperImage.image = thumbImage;
nightWhisperImage.filter = SampleFilters.getNightWhisperFilter();
ThumbnailsManager.addThumb(nightWhisperImage);

ThumbnailItem amazonImage = new ThumbnailItem();
amazonImage.image = thumbImage;
amazonImage.filter = SampleFilters.getAmazonFilter();
ThumbnailsManager.addThumb(amazonImage);

ThumbnailItem audreyImage = new ThumbnailItem();
audreyImage.image = thumbImage;
audreyImage.filter = SampleFilters.getAudreyFilter();
ThumbnailsManager.addThumb(audreyImage);

ThumbnailItem riseImage = new ThumbnailItem();
riseImage.image = thumbImage;
riseImage.filter = SampleFilters.getRiseFilter();
ThumbnailsManager.addThumb(riseImage);

ThumbnailItem marsImage = new ThumbnailItem();
marsImage.image = thumbImage;
marsImage.filter = SampleFilters.getMarsFilter();
ThumbnailsManager.addThumb(marsImage);

ThumbnailItem aprilImage = new ThumbnailItem();
aprilImage.image = thumbImage;
aprilImage.filter = SampleFilters.getAprilFilter();
ThumbnailsManager.addThumb(aprilImage);

ThumbnailItem haanImage = new ThumbnailItem();
haanImage.image = thumbImage;
haanImage.filter = SampleFilters.getHaanFilter();
ThumbnailsManager.addThumb(haanImage);

ThumbnailItem oldManImage = new ThumbnailItem();
oldManImage.image = thumbImage;
oldManImage.filter = SampleFilters.getOldManFilter();
ThumbnailsManager.addThumb(oldManImage);

ThumbnailItem adeleImage = new ThumbnailItem();
adeleImage.image = thumbImage;
adeleImage.filter = SampleFilters.getAdeleFilter();
ThumbnailsManager.addThumb(adeleImage);

ThumbnailItem cruzImage = new ThumbnailItem();
cruzImage.image = thumbImage;
cruzImage.filter = SampleFilters.getCruzFilter();
ThumbnailsManager.addThumb(cruzImage);

ThumbnailItem metropolisImage = new ThumbnailItem();
metropolisImage.image = thumbImage;
metropolisImage.filter = SampleFilters.getMetropolisFilter();
ThumbnailsManager.addThumb(metropolisImage);

List<ThumbnailItem> thumbs = ThumbnailsManager.processThumbs(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nineoldandroids.view.ViewHelper;

import java.util.List;
Expand Down
9 changes: 5 additions & 4 deletions example/src/main/res/layout/list_thumbnail_item.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/thumb_background_color">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/thumb_background_color"
android:orientation="vertical">

<ImageView
android:id="@+id/thumbnail"
android:layout_width="@dimen/thumbnail_size"
android:layout_height="@dimen/thumbnail_size"
android:paddingLeft="@dimen/thumbnail_horizontal_padding"
android:paddingRight="@dimen/thumbnail_horizontal_padding"/>
android:paddingRight="@dimen/thumbnail_horizontal_padding" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import com.zomato.photofilters.geometry.Point;
import com.zomato.photofilters.imageprocessors.Filter;
import com.zomato.photofilters.imageprocessors.subfilters.BrightnessSubFilter;
import com.zomato.photofilters.imageprocessors.subfilters.ColorOverlaySubFilter;
import com.zomato.photofilters.imageprocessors.subfilters.ContrastSubFilter;
import com.zomato.photofilters.imageprocessors.subfilters.SaturationSubFilter;
import com.zomato.photofilters.imageprocessors.subfilters.ToneCurveSubFilter;

import java.lang.reflect.Array;

/**
* @author Varun on 01/07/15.
*/
Expand Down Expand Up @@ -135,4 +139,200 @@ public static Filter getNightWhisperFilter() {
filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, redKnots, greenKnots, blueKnots));
return filter;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the recreated Instagram filters.

public static Filter getDefaultFilter() {
Filter filter = new Filter();
filter.addSubFilter(new BrightnessSubFilter(20));
filter.addSubFilter(new ContrastSubFilter(1.4f));
filter.addSubFilter(new SaturationSubFilter(1.4f));
return filter;
}

public static Filter getMayFairFilter() {
Point[] rgbKnots = new Point[8];
rgbKnots[0] = new Point(0f, 0f);
rgbKnots[1] = new Point(34f, 6f);
rgbKnots[2] = new Point(69f, 23f);
rgbKnots[3] = new Point(100f, 58f);
rgbKnots[4] = new Point(150f, 154f);
rgbKnots[5] = new Point(176f, 196f);
rgbKnots[6] = new Point(207f, 233f);
rgbKnots[7] = new Point(255f, 255f);
Filter filter = new Filter();
filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, null, null, null));
return filter;
}

public static Filter getSierraFilter() {
Point[] rgbKnots = new Point[2];
Point[] redKnots = new Point[2];

rgbKnots[0] = new Point(0f, 54f);
rgbKnots[1] = new Point(255f, 255f);

redKnots[0] = new Point(0f, 21f);
redKnots[1] = new Point(255f, 255f);


Filter filter = new Filter();
filter.addSubFilter(new ToneCurveSubFilter(rgbKnots, redKnots, null, null));
filter.addSubFilter(new ContrastSubFilter(1.33f));
filter.addSubFilter(new BrightnessSubFilter(-30));
return filter;
}

public static Filter getAmazonFilter() {
Point[] blueKnots = new Point[6];
blueKnots[0] = new Point(0f, 0f);
blueKnots[1] = new Point(11f, 40f);
blueKnots[2] = new Point(36f, 99f);
blueKnots[3] = new Point(86f, 151f);
blueKnots[4] = new Point(167f, 209f);
blueKnots[5] = new Point(255f, 255f);
Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.2f));
filter.addSubFilter(new ToneCurveSubFilter(null, null, null, blueKnots));
return filter;
}

public static Filter getAdeleFilter() {
Filter filter = new Filter();
filter.addSubFilter(new SaturationSubFilter(-100f));
return filter;
}

public static Filter getCruzFilter() {
Filter filter = new Filter();
filter.addSubFilter(new SaturationSubFilter(-100f));
filter.addSubFilter(new ContrastSubFilter(1.3f));
filter.addSubFilter(new BrightnessSubFilter(20));
return filter;
}

public static Filter getMetropolisFilter() {
Filter filter = new Filter();
filter.addSubFilter(new SaturationSubFilter(-1f));
filter.addSubFilter(new ContrastSubFilter(1.7f));
filter.addSubFilter(new BrightnessSubFilter(70));
return filter;
}

public static Filter getAudreyFilter() {
Filter filter = new Filter();

Point[] redKnots = new Point[3];
redKnots[0] = new Point(0f, 0f);
redKnots[1] = new Point(124f, 138f);
redKnots[2] = new Point(255f, 255f);

filter.addSubFilter(new SaturationSubFilter(-100f));
filter.addSubFilter(new ContrastSubFilter(1.3f));
filter.addSubFilter(new BrightnessSubFilter(20));
filter.addSubFilter(new ToneCurveSubFilter(null, redKnots, null, null));
return filter;
}

public static Filter getRiseFilter() {
Point[] blueKnots = new Point[4];
Point[] redKnots = new Point[4];

blueKnots[0] = new Point(0f, 0f);
blueKnots[1] = new Point(39f, 70f);
blueKnots[2] = new Point(150f, 200f);
blueKnots[3] = new Point(255f, 255f);

redKnots[0] = new Point(0f, 0f);
redKnots[1] = new Point(45f, 64f);
redKnots[2] = new Point(170f, 190f);
redKnots[3] = new Point(255f, 255f);

Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.9f));
filter.addSubFilter(new BrightnessSubFilter(60));
// filter.addSubFilter(VignetteSubfilter(ctx, 200))
filter.addSubFilter(new ToneCurveSubFilter(null, redKnots, null, blueKnots));
return filter;
}

public static Filter getMarsFilter() {
Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.5f));
filter.addSubFilter(new BrightnessSubFilter(10));
return filter;
}

public static Filter getAprilFilter() {
Point[] blueKnots = new Point[4];
Point[] redKnots = new Point[4];

blueKnots[0] = new Point(0f, 0f);
blueKnots[1] = new Point(39f, 70f);
blueKnots[2] = new Point(150f, 200f);
blueKnots[3] = new Point(255f, 255f);

redKnots[0] = new Point(0f, 0f);
redKnots[1] = new Point(45f, 64f);
redKnots[2] = new Point(170f, 190f);
redKnots[3] = new Point(255f, 255f);

Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.5f));
filter.addSubFilter(new BrightnessSubFilter(5));
// filter.addSubFilter(VignetteSubfilter(context, 150))
filter.addSubFilter(new ToneCurveSubFilter(null, redKnots, null, blueKnots));
return filter;
}

public static Filter getHaanFilter() {
Point[] greenKnots = new Point[3];
greenKnots[0] = new Point(0f, 0f);
greenKnots[1] = new Point(113f, 142f);
greenKnots[2] = new Point(255f, 255f);

Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.3f));
filter.addSubFilter(new BrightnessSubFilter(60));
// filter.addSubFilter(VignetteSubfilter(context, 200))
filter.addSubFilter(new ToneCurveSubFilter(null, null, greenKnots, null));
return filter;
}

public static Filter getOldManFilter() {
Filter filter = new Filter();
filter.addSubFilter(new BrightnessSubFilter(30));
filter.addSubFilter(new SaturationSubFilter(0.8f));
filter.addSubFilter(new ContrastSubFilter(1.3f));
// filter.addSubFilter(VignetteSubfilter(context, 100))
filter.addSubFilter(new ColorOverlaySubFilter(100, .2f, .2f, .1f));
return filter;
}

public static Filter getClarendonFilter() {
Point[] redKnots = new Point[4];
Point[] greenKnots = new Point[4];
Point[] blueKnots = new Point[4];

redKnots[0] = new Point(0f, 0f);
redKnots[1] = new Point(56f, 68f);
redKnots[2] = new Point(196f, 206f);
redKnots[3] = new Point(255f, 255f);


greenKnots[0] = new Point(0f, 0f);
greenKnots[1] = new Point(46f, 77f);
greenKnots[2] = new Point(160f, 200f);
greenKnots[3] = new Point(255f, 255f);


blueKnots[0] = new Point(0f, 0f);
blueKnots[1] = new Point(33f, 86f);
blueKnots[2] = new Point(126f, 220f);
blueKnots[3] = new Point(255f, 255f);

Filter filter = new Filter();
filter.addSubFilter(new ContrastSubFilter(1.5f));
filter.addSubFilter(new BrightnessSubFilter(-10));
filter.addSubFilter(new ToneCurveSubFilter(null, redKnots, greenKnots, blueKnots));
return filter;
}
}