package com.cringe_studios.christmastreescanning.scanning.image_scanning;

import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;

public class MultiRGBImageScanner extends RGBImageScanner {
	
	GrayscaleImageScanner redScanner;
	GrayscaleImageScanner greenScanner;
	GrayscaleImageScanner blueScanner;
	
	public MultiRGBImageScanner(BufferedImage rgbImage) {
		super();
		BufferedImage[] grayscaleImages = toGrayscale(rgbImage);
		redScanner   = new GrayscaleImageScanner(grayscaleImages[0]);
		greenScanner = new GrayscaleImageScanner(grayscaleImages[1]);
		blueScanner  = new GrayscaleImageScanner(grayscaleImages[2]);
	}
	
	@Override
	protected BufferedImage[] toGrayscale(BufferedImage rgbImage) {
		BufferedImage redImage = new BufferedImage(rgbImage.getWidth(), rgbImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
		BufferedImage greenImage = new BufferedImage(rgbImage.getWidth(), rgbImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
		BufferedImage blueImage = new BufferedImage(rgbImage.getWidth(), rgbImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);

		for (int i = 0; i < rgbImage.getWidth(); i++) {
			for (int j = 0; j < rgbImage.getHeight(); j++) {
				int currentRGB = rgbImage.getRGB(i, j);
				int currentBlue = currentRGB & 0xFF;
				int currentGreen = (currentRGB >> 8) & 0xFF;
				int currentRed = (currentRGB >> 16) & 0xFF;

				redImage.setRGB(i, j, (currentRed << 16) | (currentRed << 8) | currentRed);
				greenImage.setRGB(i, j, (currentGreen << 16) | (currentGreen << 8) | currentGreen);
				blueImage.setRGB(i, j, (currentBlue << 16) | (currentBlue << 8) | currentBlue);
			}
		}
		return new BufferedImage[] {redImage, greenImage, blueImage};
	}
	
	@Override
	public Point2D getBrightestSpot(byte gammaDelta) {
		redScanner.getBrightestSpot();
		greenScanner.getBrightestSpot();
		blueScanner.getBrightestSpot();
		
		// TODO 
		return null;
	}

}
