package net.akhyar.android.imgpro.actions;

import net.akhyar.android.imgpro.Action;
import android.graphics.Color;

public class Colorize extends Action {

	private int color;
	private float factor;

	public Colorize(float factor, int color) {
		this.color = color;
		this.factor = factor;
	}

	@Override
	protected void adjustPixels(int[] colors) {

		int r, g, b;
		int tR, tG, tB;
		r = Color.red(this.color);
		g = Color.green(this.color);
		b = Color.blue(this.color);

		Blend.Mode mode = Blend.Mode.LIGHTEN;
		int[][] cache = new int[256][256];
		for (int i = 0; i < cache.length; i++) {
			for (int j = 0; j < cache[i].length; j++) {
				cache[i][j] = clamp(mode.apply(i, j) * factor);
			}
		}

		for (int i = 0; i < colors.length; i++) {
			tR = Color.red(colors[i]);
			tG = Color.green(colors[i]);
			tB = Color.blue(colors[i]);
			tR = tG = tB = (tR + tG + tB) / 3;

			tR = cache[tR][r];
			tG = cache[tG][g];
			tB = cache[tB][b];

			colors[i] = Color.rgb(tR, tG, tB);
		}
	}

}

@@ -168,18 +168,22 @@
 nt color
+Mask
 ;%0A
-
 %09private
@@ -238,16 +238,20 @@
 nt color
+Mask
 ) %7B%0A%09%09th
@@ -262,16 +262,20 @@
 olor
+Mask
  = color
 ;%0A%09%09
@@ -270,16 +270,20 @@
  = color
+Mask
 ;%0A%09%09this
@@ -416,24 +416,28 @@
 d(this.color
+Mask
 );%0A%09%09g = Col
@@ -455,16 +455,20 @@
 is.color
+Mask
 );%0A%09%09b =
@@ -489,16 +489,20 @@
 is.color
+Mask
 );%0A%0A%09%09Bl

rename variable in Colorize action (minor)