package plugin.basic;

import plugin.IPlugin;

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

public class Binary implements IPlugin{

    @Override
    public BufferedImage perform(BufferedImage img) {

        BufferedImage res = new BufferedImage(img.getWidth(), img.getHeight(), img.getType());
        for (int i = 0; i < img.getWidth(); i++)
            for (int j = 0; j < img.getHeight(); j++) {
                Color c = new Color(img.getRGB(i, j));
                if ((c.getBlue() + c.getRed() + c.getGreen()) / 3 > 127)
                    c = Color.WHITE;
                else
                    c = Color.BLACK;
                res.setRGB(i, j, c.getRGB());
            }

        return res;
    }


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