package yi.iu.processor.channel;

import java.awt.*;
import yi.iu.processor.channel.ChannelMaker;
import yi.iu.ui.*;

public class HSB extends ChannelMaker
{
    public int[] getProcessedPseudoColor(int[] source, Dimension d)
    {
        int[][] hsb= getProcessed_ex(source,d);
        (new InfoFrame("HSB", source, d.width, d.height, hsb)).show();
        return null;
    }
    
    public int[] getProcessed(int rgb[], Dimension d)
    {
	    int width=d.width, height=d.height;
	    int size=width*height;
	    
	    int[] intensity= new int[size];
	    float[] hsb= new float[3];
	    for (int i=0;i<size;i++) {
	        int r=rgb[i]>>16&255;
	        int g=rgb[i]>>8&255;
	        int b=rgb[i]&255;
            Color.RGBtoHSB(r, g, b, hsb);
            intensity[i]= (int)Math.round(hsb[2]*255);
	    }
	    return intensity;
    }
    
    public static int[][] getProcessed_ex(int rgb[], Dimension d)
    {
        int width=d.width, height=d.height;
	    int size=width*height;
	    int[][] hsb= new int[size][3];
	    float[] tmp= new float[3];
	    
	    for (int i=0;i<size;i++) {
	        int r=rgb[i]>>16&255;
	        int g=rgb[i]>>8&255;
	        int b=rgb[i]&255;
            Color.RGBtoHSB(r, g, b, tmp);
	        hsb[i][0]= (int)Math.round(tmp[0]*255);
	        hsb[i][1]= (int)Math.round(tmp[1]*255);
	        hsb[i][2]= (int)Math.round(tmp[2]*255);
	    }
	    return hsb;
    }
    

    public static int[][] getHSB(int rgb[], Dimension d)
    {
	    return getProcessed_ex(rgb, d);
    }
    
    public static int[] getHue(int rgb[], Dimension d)
    {
        int width=d.width, height=d.height;
	    int size=width*height;
	    int[] h= new int[size];
	    
	    float[] tmp= new float[3];
	    for (int i=0;i<size;i++) {
	        int r=rgb[i]>>16&255;
	        int g=rgb[i]>>8&255;
	        int b=rgb[i]&255;
            Color.RGBtoHSB(r, g, b, tmp);
	        h[i]= (int)Math.round(tmp[0]*255);
	    }
	    return h;
    }
    
    public static int[] makeNewImageFromHSB(int[][] hsb, Dimension d)
    {
        int width=d.width, height=d.height;
	    int size=width*height;
	    
	    int[] rgb= new int[size];
	    for (int i=0;i<size;i++) {
	        rgb[i]=Color.HSBtoRGB(hsb[i][0]/(float)255.0,hsb[i][1]/(float)255.0,hsb[i][2]/(float)255.0);
	    }
	    return rgb;
    }
    
    public static void makeImageFromHue(int[] hue, Dimension d)
    {
        int width=d.width, height=d.height;
	    int size=width*height;
	    
	    int[] hsb= new int[3];
	    for (int i=0;i<size;i++) {
	        hue[i]=Color.HSBtoRGB(hue[i]/(float)255.0,1,1);
	    }
    }
    
}