package com.cringe_studios.christmastreescanning.scanning.image_scanning;

import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.cringe_studios.christmastreescanning.scanning.PointInterpolator;

public abstract class ImageScanner {
	public static final byte GAMMA_DELTA_DEFAULT = 0;
	
	public abstract Point2D getBrightestSpot(byte gammaDelta);
	
	public Point2D getBrightestSpot() {
		return getBrightestSpot(GAMMA_DELTA_DEFAULT);
	}

//	// gammaDelta is the difference between the brightest pixel and the darkest
//	// pixel included in the search set for the brightest spot
//	// The brightest point Operation is done per color dimension, so you could
//	// provide different images for red, green and blue brightest points
//	static public Point2D getBrightestSpot(BufferedImage redImage, BufferedImage greenImage, BufferedImage blueImage,
//			byte gammaDelta) {
//		Point2D brightestRedSpot = getBrightestSpotGrayscale(redImage, gammaDelta);
//		Point2D brightestGreenSpot = getBrightestSpotGrayscale(greenImage, gammaDelta);
//		Point2D brightestBlueSpot = getBrightestSpotGrayscale(blueImage, gammaDelta);
//
//		double RGdistance = brightestRedSpot.distanceSq(brightestGreenSpot);
//		double GBdistance = brightestGreenSpot.distanceSq(brightestBlueSpot);
//		double BRdistance = brightestBlueSpot.distanceSq(brightestRedSpot);
//
//		PointInterpolator brightestSpot;
//		
//		brightestSpot = new PointInterpolator(brightestRedSpot);
//
////		// Get the center between the two closest points; a better implementation would
////		// work on a confidentnes-value
////		if (RGdistance < GBdistance && RGdistance < BRdistance) {
////			brightestSpot = new PointInterpolator(brightestRedSpot, brightestGreenSpot);
////		} else if (GBdistance < RGdistance && GBdistance < BRdistance) {
////			brightestSpot = new PointInterpolator(brightestGreenSpot, brightestBlueSpot);
////		} else {
////			brightestSpot = new PointInterpolator(brightestBlueSpot, brightestRedSpot);
////		}
//
//		return brightestSpot.getCenter();
//	}
//
//	static public Point2D getBrightestSpot(BufferedImage image, byte gammaDelta) {
//		BufferedImage redImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
//		BufferedImage greenImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
//		BufferedImage blueImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
//
//		for (int i = 0; i < image.getWidth(); i++) {
//			for (int j = 0; j < image.getHeight(); j++) {
//				int currentRGB = image.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 getBrightestSpot(redImage, greenImage, blueImage, gammaDelta);
//	}
//
//	static public Point2D getBrightestSpot(BufferedImage image) {
//		return getBrightestSpot(image, GAMMA_DELTA_DEFAULT);
//	}
}
