package pl.vgtworld.imagedraw.filters.mosaic;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;

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

public class MosaicFilter implements ImageDrawFilter {
	
	private int size;
	
	public MosaicFilter(int size) {
		if (size <= 0) {
			throw new IllegalArgumentException("Size must be greater than 0.");
		}
		this.size = size;
	}
	
	@Override
	public void doFilter(ImageDrawEntity image, int x, int y, int width, int height) {
		BufferedImage imageData = image.getImage();
		int scaledWidth = imageData.getWidth() / size;
		scaledWidth = scaledWidth == 0 ? 1 : scaledWidth;
		int scaledHeight = imageData.getHeight() / size;
		scaledHeight = scaledHeight == 0 ? 1 : scaledHeight;
		
		Image scaledImage = imageData.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
		Image finalImage = scaledImage.getScaledInstance(imageData.getWidth(), imageData.getHeight(), Image.SCALE_FAST);
		
		Graphics2D graphics = imageData.createGraphics();
		graphics.drawImage(finalImage, x, y, x + width, y + height, x, y, x + width, y + height, null);
		graphics.dispose();
	}
	
}

@@ -230,16 +230,67 @@
 ilter;%0A%0A
+/**%0A * Filter applying mosaic effect to image.%0A */%0A
 public c
@@ -359,16 +359,104 @@
 size;%0A%09%0A
+%09/**%0A%09 * Creates filter with custom configuration.%0A%09 * %0A%09 * @param size Cell size.%0A%09 */%0A
 %09public 

Add documentation.