package illume.analysis;

import java.awt.image.BufferedImage;

/* This simple analyser example averages pixel values. */
public class SimpleImageAnalyser<T extends BufferedImage> extends AbstractImageAnalyser<T> {

    @Override
    public double analyse(T input) {
        int sum_r = 0;
        int sum_g = 0;
        int sum_b = 0;
        for (int y = 0; y < input.getHeight(); y++) {
            for (int x = 0; x < input.getWidth(); x++) {
                final int clr = input.getRGB(x, y);
                sum_r += (clr & 0x00ff0000) >> 16;
                sum_g += (clr & 0x0000ff00) >> 8;
                sum_b += clr & 0x000000ff;
            }
        }
        double sum_rgb = ((sum_r + sum_b + sum_g) / 3.0d);
        double avg = sum_rgb / (input.getHeight() * input.getWidth());
        // 8-bit RGB
        return avg / 255;
    }
}
