Created
April 22, 2019 12:55
-
-
Save tizisdeepan/f024a555d0c7b60cdf03cdec1cac3729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap | |
import com.zomato.photofilters.imageprocessors.ImageProcessor | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class BrightnessSubFilter(brightness: Int) : SubFilter { | |
// Value is in integer | |
private var brightness = 0 | |
init { | |
this.brightness = brightness | |
} | |
override fun process(inputImage: Bitmap): Bitmap { | |
return ImageProcessor.doBrightness(brightness, inputImage) | |
} | |
override fun getTag(): String { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
fun setBrightness(brightness: Int) { | |
this.brightness = brightness | |
} | |
fun changeBrightness(value: Int) { | |
this.brightness += value | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap | |
import com.zomato.photofilters.imageprocessors.ImageProcessor | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class ColorOverlaySubFilter(// the color overlay depth is between 0-255 | |
private val colorOverlayDepth: Int, // these values are between 0-1 | |
private val colorOverlayRed: Float, private val colorOverlayGreen: Float, private val colorOverlayBlue: Float) : SubFilter { | |
override fun process(inputImage: Bitmap): Bitmap { | |
return ImageProcessor.doColorOverlay( | |
colorOverlayDepth, colorOverlayRed, colorOverlayGreen, colorOverlayBlue, inputImage | |
) | |
} | |
override fun getTag(): String { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap | |
import com.zomato.photofilters.imageprocessors.ImageProcessor | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class ContrastSubFilter(contrast: Float) : SubFilter { | |
// The value is in fraction, value 1 has no effect | |
private var contrast = 0f | |
init { | |
this.contrast = contrast | |
} | |
override fun process(inputImage: Bitmap): Bitmap { | |
return ImageProcessor.doContrast(contrast, inputImage) | |
} | |
override fun getTag(): String { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
fun setContrast(contrast: Float) { | |
this.contrast = contrast | |
} | |
fun changeContrast(value: Float) { | |
this.contrast += value | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.ContrastSubfilter | |
import com.zomato.photofilters.imageprocessors.subfilters.ToneCurveSubfilter | |
import com.zomato.photofilters.imageprocessors.subfilters.SaturationSubfilter | |
object SampleFilters { | |
val defaultFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(BrightnessSubFilter(20)) | |
filter.addSubFilter(ContrastSubFilter(1.4f)) | |
filter.addSubFilter(SaturationSubFilter(1.4f)) | |
return filter | |
} | |
val mayfairFilter: Filter | |
get() { | |
val rgbKnots: Array<Point?> = arrayOfNulls(8) | |
rgbKnots[0] = Point(0f, 0f) | |
rgbKnots[1] = Point(34f, 6f) | |
rgbKnots[2] = Point(69f, 23f) | |
rgbKnots[3] = Point(100f, 58f) | |
rgbKnots[4] = Point(150f, 154f) | |
rgbKnots[5] = Point(176f, 196f) | |
rgbKnots[6] = Point(207f, 233f) | |
rgbKnots[7] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(rgbKnots, null, null, null)) | |
return filter | |
} | |
val blueMessFilter: Filter | |
get() { | |
val redKnots: Array<Point?> = arrayOfNulls(8) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(86f, 34f) | |
redKnots[2] = Point(117f, 41f) | |
redKnots[3] = Point(146f, 80f) | |
redKnots[4] = Point(170f, 151f) | |
redKnots[5] = Point(200f, 214f) | |
redKnots[6] = Point(225f, 242f) | |
redKnots[7] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(null, redKnots, null, null)) | |
filter.addSubFilter(BrightnessSubfilter(30)) | |
filter.addSubFilter(ContrastSubfilter(1f)) | |
return filter | |
} | |
val aweStruckVibeFilter: Filter | |
get() { | |
val rgbKnots: Array<Point?> = arrayOfNulls(5) | |
val redKnots: Array<Point?> = arrayOfNulls(5) | |
val greenKnots: Array<Point?> = arrayOfNulls(6) | |
val blueKnots: Array<Point?> = arrayOfNulls(7) | |
rgbKnots[0] = Point(0f, 0f) | |
rgbKnots[1] = Point(80f, 43f) | |
rgbKnots[2] = Point(149f, 102f) | |
rgbKnots[3] = Point(201f, 173f) | |
rgbKnots[4] = Point(255f, 255f) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(125f, 147f) | |
redKnots[2] = Point(177f, 199f) | |
redKnots[3] = Point(213f, 228f) | |
redKnots[4] = Point(255f, 255f) | |
greenKnots[0] = Point(0f, 0f) | |
greenKnots[1] = Point(57f, 76f) | |
greenKnots[2] = Point(103f, 130f) | |
greenKnots[3] = Point(167f, 192f) | |
greenKnots[4] = Point(211f, 229f) | |
greenKnots[5] = Point(255f, 255f) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(38f, 62f) | |
blueKnots[2] = Point(75f, 112f) | |
blueKnots[3] = Point(116f, 158f) | |
blueKnots[4] = Point(171f, 204f) | |
blueKnots[5] = Point(212f, 233f) | |
blueKnots[6] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(rgbKnots, redKnots, greenKnots, blueKnots)) | |
return filter | |
} | |
// Check whether output is null or not. | |
val limeStutterFilter: Filter | |
get() { | |
val blueKnots: Array<Point?> = arrayOfNulls(3) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(165f, 114f) | |
blueKnots[2] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(null, null, null, blueKnots)) | |
return filter | |
} | |
val nightWhisperFilter: Filter | |
get() { | |
val rgbKnots: Array<Point?> = arrayOfNulls(3) | |
val redKnots: Array<Point?> = arrayOfNulls(4) | |
val greenKnots: Array<Point?> = arrayOfNulls(3) | |
val blueKnots: Array<Point?> = arrayOfNulls(3) | |
rgbKnots[0] = Point(0f, 0f) | |
rgbKnots[1] = Point(174f, 109f) | |
rgbKnots[2] = Point(255f, 255f) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(70f, 114f) | |
redKnots[2] = Point(157f, 145f) | |
redKnots[3] = Point(255f, 255f) | |
greenKnots[0] = Point(0f, 0f) | |
greenKnots[1] = Point(109f, 138f) | |
greenKnots[2] = Point(255f, 255f) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(113f, 152f) | |
blueKnots[2] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(rgbKnots, redKnots, greenKnots, blueKnots)) | |
return filter | |
} | |
val sierraFilter: Filter | |
get() { | |
val rgbKnots: Array<Point?> = arrayOfNulls(2) | |
val redKnots: Array<Point?> = arrayOfNulls(2) | |
rgbKnots[0] = Point(0f, 54f) | |
rgbKnots[1] = Point(255f, 255f) | |
redKnots[0] = Point(0f, 21f) | |
redKnots[1] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ToneCurveSubfilter(rgbKnots, redKnots, null, null)) | |
filter.addSubFilter(ContrastSubFilter(1.33f)) | |
filter.addSubFilter(BrightnessSubFilter(-30)) | |
return filter | |
} | |
val amazonFilter: Filter | |
get() { | |
val blueKnots: Array<Point?> = arrayOfNulls(6) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(11f, 40f) | |
blueKnots[2] = Point(36f, 99f) | |
blueKnots[3] = Point(86f, 151f) | |
blueKnots[4] = Point(167f, 209f) | |
blueKnots[5] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.2f)) | |
filter.addSubFilter(ToneCurveSubFilter(null, null, null, blueKnots)) | |
return filter | |
} | |
val adeleFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(SaturationSubfilter(-100f)) | |
return filter | |
} | |
val cruzFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(SaturationSubfilter(-100f)) | |
filter.addSubFilter(ContrastSubFilter(1.3f)) | |
filter.addSubFilter(BrightnessSubFilter(20)) | |
return filter | |
} | |
val metropolisFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(SaturationSubfilter(-1f)) | |
filter.addSubFilter(ContrastSubFilter(1.7f)) | |
filter.addSubFilter(BrightnessSubFilter(70)) | |
return filter | |
} | |
val audreyFilter: Filter | |
get() { | |
val filter = Filter() | |
val redKnots: Array<Point?> = arrayOfNulls(3) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(124f, 138f) | |
redKnots[2] = Point(255f, 255f) | |
filter.addSubFilter(SaturationSubfilter(-100f)) | |
filter.addSubFilter(ContrastSubFilter(1.3f)) | |
filter.addSubFilter(BrightnessSubFilter(20)) | |
filter.addSubFilter(ToneCurveSubFilter(null, redKnots, null, null)) | |
return filter | |
} | |
val riseFilter: Filter | |
get() { | |
val blueKnots: Array<Point?> = arrayOfNulls(4) | |
val redKnots: Array<Point?> = arrayOfNulls(4) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(39f, 70f) | |
blueKnots[2] = Point(150f, 200f) | |
blueKnots[3] = Point(255f, 255f) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(45f, 64f) | |
redKnots[2] = Point(170f, 190f) | |
redKnots[3] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.9f)) | |
filter.addSubFilter(BrightnessSubFilter(60)) | |
// filter.addSubFilter(VignetteSubfilter(ctx, 200)) | |
filter.addSubFilter(ToneCurveSubFilter(null, redKnots, null, blueKnots)) | |
return filter | |
} | |
val marsFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.5f)) | |
filter.addSubFilter(BrightnessSubFilter(10)) | |
return filter | |
} | |
val aprilFilter: Filter | |
get() { | |
val blueKnots: Array<Point?> = arrayOfNulls(4) | |
val redKnots: Array<Point?> = arrayOfNulls(4) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(39f, 70f) | |
blueKnots[2] = Point(150f, 200f) | |
blueKnots[3] = Point(255f, 255f) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(45f, 64f) | |
redKnots[2] = Point(170f, 190f) | |
redKnots[3] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.5f)) | |
filter.addSubFilter(BrightnessSubFilter(5)) | |
// filter.addSubFilter(VignetteSubfilter(context, 150)) | |
filter.addSubFilter(ToneCurveSubFilter(null, redKnots, null, blueKnots)) | |
return filter | |
} | |
val haanFilter: Filter | |
get() { | |
val greenKnots: Array<Point?> = arrayOfNulls(3) | |
greenKnots[0] = Point(0f, 0f) | |
greenKnots[1] = Point(113f, 142f) | |
greenKnots[2] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.3f)) | |
filter.addSubFilter(BrightnessSubFilter(60)) | |
// filter.addSubFilter(VignetteSubfilter(context, 200)) | |
filter.addSubFilter(ToneCurveSubFilter(null, null, greenKnots, null)) | |
return filter | |
} | |
val oldManFilter: Filter | |
get() { | |
val filter = Filter() | |
filter.addSubFilter(BrightnessSubFilter(30)) | |
filter.addSubFilter(SaturationSubfilter(0.8f)) | |
filter.addSubFilter(ContrastSubFilter(1.3f)) | |
// filter.addSubFilter(VignetteSubfilter(context, 100)) | |
filter.addSubFilter(ColorOverlaySubFilter(100, .2f, .2f, .1f)) | |
return filter | |
} | |
val clarendonFilter: Filter | |
get() { | |
val redKnots: Array<Point?> = arrayOfNulls(4) | |
val greenKnots: Array<Point?> = arrayOfNulls(4) | |
val blueKnots: Array<Point?> = arrayOfNulls(4) | |
redKnots[0] = Point(0f, 0f) | |
redKnots[1] = Point(56f, 68f) | |
redKnots[2] = Point(196f, 206f) | |
redKnots[3] = Point(255f, 255f) | |
greenKnots[0] = Point(0f, 0f) | |
greenKnots[1] = Point(46f, 77f) | |
greenKnots[2] = Point(160f, 200f) | |
greenKnots[3] = Point(255f, 255f) | |
blueKnots[0] = Point(0f, 0f) | |
blueKnots[1] = Point(33f, 86f) | |
blueKnots[2] = Point(126f, 220f) | |
blueKnots[3] = Point(255f, 255f) | |
val filter = Filter() | |
filter.addSubFilter(ContrastSubFilter(1.5f)) | |
filter.addSubFilter(BrightnessSubFilter(-10)) | |
filter.addSubFilter(ToneCurveSubFilter(null, redKnots, greenKnots, blueKnots)) | |
return filter | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap | |
import com.zomato.photofilters.imageprocessors.ImageProcessor | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class SaturationSubFilter(// The Level value is float, where level = 1 has no effect on the image | |
private var level: Float) : SubFilter { | |
override fun process(inputImage: Bitmap): Bitmap { | |
return ImageProcessor.doSaturation(inputImage, level) | |
} | |
override fun getTag(): Any { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
fun setLevel(level: Float) { | |
this.level = level | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.graphics.Bitmap | |
import com.zomato.photofilters.geometry.BezierSpline | |
import com.zomato.photofilters.geometry.Point | |
import com.zomato.photofilters.imageprocessors.ImageProcessor | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class ToneCurveSubFilter(rgbKnots: Array<Point?>?, redKnots: Array<Point?>?, greenKnots: Array<Point?>?, blueKnots: Array<Point?>?) : SubFilter { | |
// These are knots which contains the plot points | |
private var rgbKnots: Array<Point?>? = null | |
private var greenKnots: Array<Point?>? = null | |
private var redKnots: Array<Point?>? = null | |
private var blueKnots: Array<Point?>? = null | |
private var rgb: IntArray? = null | |
private var r: IntArray? = null | |
private var g: IntArray? = null | |
private var b: IntArray? = null | |
init { | |
val straightKnots = arrayOfNulls<Point>(2) | |
straightKnots[0] = Point(0f, 0f) | |
straightKnots[1] = Point(255f, 255f) | |
if (rgbKnots == null) { | |
this.rgbKnots = straightKnots | |
} else { | |
this.rgbKnots = rgbKnots | |
} | |
if (redKnots == null) { | |
this.redKnots = straightKnots | |
} else { | |
this.redKnots = redKnots | |
} | |
if (greenKnots == null) { | |
this.greenKnots = straightKnots | |
} else { | |
this.greenKnots = greenKnots | |
} | |
if (blueKnots == null) { | |
this.blueKnots = straightKnots | |
} else { | |
this.blueKnots = blueKnots | |
} | |
} | |
override fun process(inputImage: Bitmap): Bitmap { | |
rgbKnots = sortPointsOnXAxis(rgbKnots) | |
redKnots = sortPointsOnXAxis(redKnots) | |
greenKnots = sortPointsOnXAxis(greenKnots) | |
blueKnots = sortPointsOnXAxis(blueKnots) | |
if (rgb == null) { | |
rgb = BezierSpline.curveGenerator(rgbKnots!!) | |
} | |
if (r == null) { | |
r = BezierSpline.curveGenerator(redKnots!!) | |
} | |
if (g == null) { | |
g = BezierSpline.curveGenerator(greenKnots!!) | |
} | |
if (b == null) { | |
b = BezierSpline.curveGenerator(blueKnots!!) | |
} | |
return ImageProcessor.applyCurves(rgb, r, g, b, inputImage) | |
} | |
fun sortPointsOnXAxis(points: Array<Point?>?): Array<Point?>? { | |
if (points == null) { | |
return null | |
} | |
for (s in 1 until points.size - 1) { | |
for (k in 0..points.size - 2) { | |
if (points[k]?.x!! > points[k + 1]?.x!!) { | |
var temp = 0f | |
temp = points[k]?.x!! | |
points[k]?.x = points[k + 1]?.x //swapping values | |
points[k + 1]?.x = temp | |
} | |
} | |
} | |
return points | |
} | |
override fun getTag(): String { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.Bitmap | |
import android.graphics.BitmapFactory | |
import android.graphics.Canvas | |
import android.graphics.Paint | |
import com.zoho.zohosocial.R | |
import com.zomato.photofilters.imageprocessors.SubFilter | |
class VignetteSubFilter(private val context: Context, alpha: Int) : SubFilter { | |
// value of alpha is between 0-255 | |
private var alpha = 0 | |
init { | |
this.alpha = alpha | |
} | |
override fun process(inputImage: Bitmap): Bitmap { | |
var vignette = BitmapFactory.decodeResource(context.resources, R.drawable.vignette) | |
vignette = Bitmap.createScaledBitmap(vignette, inputImage.width, inputImage.height, true) | |
val paint = Paint() | |
paint.isAntiAlias = true | |
paint.alpha = alpha | |
val comboImage = Canvas(inputImage) | |
comboImage.drawBitmap(vignette, 0f, 0f, paint) | |
return inputImage | |
} | |
override fun getTag(): Any { | |
return tag | |
} | |
override fun setTag(tag: Any) { | |
this.tag = tag as String | |
} | |
fun setAlpha(alpha: Int) { | |
this.alpha = alpha | |
} | |
fun changeAlpha(value: Int) { | |
this.alpha += value | |
if (alpha > 255) { | |
alpha = 255 | |
} else if (alpha < 0) { | |
alpha = 0 | |
} | |
} | |
companion object { | |
private var tag = "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment