package filter.basic;

import filter.Filter;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * Created by Alexandre on 24/04/2016.
 */
public class Binary implements Filter
{
    @Override
    public BufferedImage perform(BufferedImage img)
    {
        GrayScale filter = new GrayScale();
        BufferedImage res = filter.perform(img);
        int white = Color.WHITE.getRGB();
        int black = Color.BLACK.getRGB();
        int w = img.getWidth();
        int h = img.getHeight();
        for (int i = 0; i < w; i++)
            for (int j = 0; j < h; j++)
                res.setRGB(i, j, new Color(img.getRGB(i, j)).getRed() > 127 ? white : black);
        return res;
    }

    @Override
    public String getName()
    {
        return "Binary";
    }
}
