package dataBase.subPicture;

import java.awt.Color;
import java.io.IOException;
import java.io.Serializable;

import util.simpleIO.Out;

public class Pixel2 implements Serializable {
	
	private static final long serialVersionUID = 4L;
	public float r,g,b;
	static int count = 0;
	
	/**
	 * Constructor: full
	 * @param rgb - RGB-array. Alpha ignored.
	 */
	public Pixel2(float r, float g, float b){
		this.r = r;
		this.g = g;
		this.b = b;
		
		//if(count++ % 1000 == 0)
		//	Out.pl(" >> Pixel = "+toString());
	}
	
	/**
	 * Constructor: empty
	 */
	public Pixel2(){
		//empty
	}
	
	/**
	 * Testing, assertion
	 * @return true if assertion (pixel values between 0 and 255)
	 */
	public boolean test(){
		return r<256 && g<256 && b<=256 &&
				r>0 && g>0 && b>0;
	}
	
	/**
	 * @return luminance within 255
	 */
	public int getLumi(){
		return (int)(r+g+b+0.5f);
	}
	
//	/**
//	 * @return luminance within 255
//	 */
//	public short getLumi255(){
//		return (short) ((r+g+b+0.5f)/3.0f);
//	}
	
	/**
	 * Also called HSB (Hue, Saturation, Value/Brightness)
	 * @return {Hue,Saturation,Value}
	 */
	public float[] getHSV(){
		float[] hsv = new float[3];
		Color.RGBtoHSB((int)(r+0.5f), (int)(g+0.5f), (int)(b+0.5f), hsv);
		return hsv;
	}
	
	@Override
	public String toString(){
		return ""+r+"/"+g+"/"+b;
	}
	
	protected void writeObjectNew(java.io.ObjectOutputStream out) throws IOException {
		out.writeFloat(r);
		out.writeFloat(g);
		out.writeFloat(b);
	}
	protected Pixel2 readObjectNew(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
		r=in.readFloat();
		g=in.readFloat();
		b=in.readFloat();
		
		//if(count++ % 1000 == 0)
		//	Out.pl(" >> Pixel = "+toString());
		
		return this;
	}
}
