package dataBase.subPicture;

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

public class Pixel implements Serializable {
	
	private static final long serialVersionUID = 1L;
	public byte r,g,b;
	
	/**
	 * Constructor: full
	 * @param rgb - RGB-array. Alpha ignored.
	 */
	public Pixel(int[] rgb){
		r = (byte) rgb[0];
		g = (byte) rgb[1];
		b = (byte) rgb[2];
		
	}
	
	/**
	 * Constructor: empty
	 */
	public Pixel(){
		//empty
	}
	
	/**
	 * @return luminance
	 */
	public int getLumi(){
		return (int) ((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(r, g, b, hsv);
		return hsv;
	}
	
	@Override
	public String toString(){
		return ""+r+"/"+g+"/"+b;
	}
	
	protected void writeObjectNew(java.io.ObjectOutputStream out) throws IOException {
		out.writeByte(r);
		out.writeByte(g);
		out.writeByte(b);
	}
	protected Pixel readObjectNew(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
		r=in.readByte();
		g=in.readByte();
		b=in.readByte();
		return this;
	}
}
