import imp.*;
import java.awt.Color;

public class HSBFarbmodell
{
    public  Picture graustufenHSB(Picture originalbild) {
        int breite = originalbild.getWidth();
        int hoehe  = originalbild.getHeight();

        Color[][] pixel = originalbild.getPixelArray();
        Color[][] pixelNeu = new Color[breite][hoehe];

        for(int x=0; x < breite; x++) {
            for(int y=0;y < hoehe; y++) {
                double h = HSB.getHue(pixel[x][y]);
                double s = 0.0;
                double b = HSB.getBrightness(pixel[x][y]);
                pixelNeu[x][y] = HSB.getColor(h, s, b);
            }
        }
        Picture neuesBild = new Picture();
        neuesBild.setPixelArray(pixelNeu); 
        return neuesBild;
    }

    public  Picture farbaenderungHSB(Picture originalbild, double dHue, double fSaturation, double fBrightness) {
        int breite = originalbild.getWidth();
        int hoehe  = originalbild.getHeight();

        Color[][] pixel = originalbild.getPixelArray();
        Color[][] pixelNeu = new Color[breite][hoehe];

        for(int x=0; x < breite; x++) {
            for(int y=0;y < hoehe; y++) {

                double h =  HSB.getHue(pixel[x][y]) + dHue;
                double s =  HSB.getSaturation(pixel[x][y]) * fSaturation;
                double b =  HSB.getBrightness(pixel[x][y]) * fBrightness;
                if (s > 1.0) s = 1.0;
                if (s < 0.0) s = 0.0;
                if (b > 1.0) b = 1.0;
                if (b < 0.0) b = 0.0;
                pixelNeu[x][y] = HSB.getColor(h,s,b);
            } 
        }

        Picture neuesBild = new Picture(); 
        neuesBild.setPixelArray(pixelNeu); 
        return neuesBild;
    }   

}

