package pl.vgtworld.imagedraw.filters.emboss;

import java.util.HashMap;
import java.util.Map;

import pl.vgtworld.imagedraw.ImageDrawEntity;
import pl.vgtworld.imagedraw.filters.ImageDrawFilter;
import pl.vgtworld.imagedraw.filters.matrix.MatrixFilter;

public class EmbossFilter implements ImageDrawFilter {
	
	private static final Map<EmbossDirection, float[][]> matrices = new HashMap<>();
	
	private EmbossDirection direction;
	
	static {
		matrices.put(EmbossDirection.LOWER_RIGHT, new float[][] {
				{ -2, -1, 0 },
				{ -1, 1, 1 },
				{ 0, 1, 2 }
		});
		matrices.put(EmbossDirection.LOWER_LEFT, new float[][] {
				{ 0, -1, -2 },
				{ 1, 1, -1 },
				{ 2, 1, 0 }
		});
		matrices.put(EmbossDirection.UPPER_LEFT, new float[][] {
				{ 2, 1, 0 },
				{ 1, 1, -1 },
				{ 0, -1, -2 }
		});
		matrices.put(EmbossDirection.UPPER_RIGHT, new float[][] {
				{ 0, 1, 2 },
				{ -1, 1, 1 },
				{ -2, -1, 0 }
		});
	}
	
	public EmbossFilter(EmbossDirection direction) {
		this.direction = direction;
	}
	
	@Override
	public void doFilter(ImageDrawEntity image, int x, int y, int width, int height) {
		if (direction == null) {
			throw new IllegalStateException("Direction is not defined.");
		}
		MatrixFilter filter = new MatrixFilter(matrices.get(direction));
		filter.doFilter(image, x, y, width, height);
	}
	
}

@@ -305,16 +305,63 @@
 ter %7B%0A%09%0A
+%09private static final int MATRICES_SIZE = 3;%0A%09%0A
 %09private
@@ -474,16 +474,43 @@
 tion;%0A%09%0A
+%09private float strength;%0A%09%0A
 %09static 
@@ -1075,16 +1075,145 @@
 n;%0A%09%7D%0A%09%0A
+%09public EmbossFilter(EmbossDirection direction, float strength) %7B%0A%09%09this.direction = direction;%0A%09%09this.strength = strength;%0A%09%7D%0A%09%0A
 %09@Overri
@@ -1395,16 +1395,94 @@
 %22);%0A%09%09%7D%0A
+%09%09float%5B%5D%5B%5D matrix = matrices.get(direction);%0A%09%09matrix = scaleMatrix(matrix);%0A
 %09%09Matrix
@@ -1519,34 +1519,17 @@
 er(matri
-ces.get(direction)
+x
 );%0A%09%09fil
@@ -1575,10 +1575,361 @@
 );%0A%09%7D%0A%09%0A
+%09private float%5B%5D%5B%5D scaleMatrix(float%5B%5D%5B%5D matrix) %7B%0A%09%09float%5B%5D%5B%5D scaledMatrix = new float%5BMATRICES_SIZE%5D%5BMATRICES_SIZE%5D;%0A%09%09for (int i = 0; i %3C MATRICES_SIZE; ++i) %7B%0A%09%09%09for (int j = 0; j %3C MATRICES_SIZE; ++j) %7B%0A%09%09%09%09scaledMatrix%5Bi%5D%5Bj%5D = matrix%5Bi%5D%5Bj%5D * strength;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09scaledMatrix%5BMATRICES_SIZE / 2%5D%5BMATRICES_SIZE / 2%5D = 1;%0A%09%09return scaledMatrix;%0A%09%7D%0A
 %7D%0A

Add option to define emboss strength.