package de.mpi.rgblab.gui.palette;
import java.awt.image.ImageConsumer;
import de.mpi.rgblab.color.ColorModel;
import de.mpi.rgblab.color.ColorTransformer;
import de.mpi.rgblab.color.ColorType;
import de.mpi.rgblab.color.HighlightColor;
/***
*
* HCL Image Class
*/
class HCLImage extends SyntheticImage {
protected float h = .0f;
protected float c = .0f;
protected float l = .0f;
protected float[] hcl = new float[3];
protected boolean isDirty = true;
protected int cachedX;
protected int cachedColor;
protected int type;
public static final int HSLIDER = 3;
public static final int CSLIDER = 4;
public static final int LSLIDER = 5;
public static final int HHSLIDER = 6;
private static final int MAX_HUE_VALUE = 360;
private static final int MAX_CHROMA_VALUE = 100;
private static final int MAX_LIGHTNESS_VALUE = 100;
protected HCLImage(int type, int width, int height, float h, float c, float l) {
super(width, height);
setValues(type, h, c, l);
}
public void setValues(int type, float h, float c, float l) {
this.type = type;
cachedX = -1;
cachedColor = 0;
setHue( h );
setChroma( c );
setLightness( l );
}
public final void setHue( float hue ) {
h = hue;
}
public final void setChroma( float chroma ) {
c = chroma;
}
public final void setLightness( float lightness ) {
l = lightness;
}
public final float getHue() {
return h;
}
public final float getChroma() {
return c;
}
public final float getLightness() {
return l;
}
protected boolean isStatic() {
return false;
}
public synchronized void nextFrame() {
isDirty = true;
notifyAll();
}
public synchronized void addConsumer(ImageConsumer ic) {
isDirty = true;
super.addConsumer(ic);
}
/**
* Overriden method from SyntheticImage
*/
protected void computeRow( int y, int[] row ) {
if ( y == 0 ) {
synchronized ( this ) {
try {
while ( !isDirty ) {
wait();
}
} catch (InterruptedException ie) {
}
isDirty = false;
}
}
if (aborted) {
return;
}
if (type == HSLIDER){
int quot = Math.round((float)row.length/MAX_HUE_VALUE);
int j=0;
int x = 0;
int color = 0;
// System.out.println("quot: "+quot);
for (int i=0;i<row.length;++i,++j){
color = ColorModel.getRGBColor(HighlightColor.msc(i));
row[i] = color;
}
}
else if (type == CSLIDER){
int quot = Math.round((float)row.length/MAX_CHROMA_VALUE);
int j=0;
int x = 0;
int color = 0;
for (int i=0;i<row.length;++i,++j){
if (i==0 || j>=quot){
ColorModel myLCH = new ColorModel(l,x,h,ColorType.LCH_uv);
color = ColorModel.getRGBColor( ColorTransformer.lch_uv2rgb(myLCH));
x++;
j = 0;
}
//System.out.println("CSlider Color ["+i+"]="+new Color(color));
row[i] = color;
}
}
else if (type == LSLIDER){
int quot = Math.round((float)row.length/MAX_LIGHTNESS_VALUE);
int j=0;
int x = 0;
int color = 0;
for (int i=0;i<row.length;++i,++j){
if (i==0 || j>=quot){
ColorModel myLCH = new ColorModel(x,c,h,ColorType.LCH_uv);
color = ColorModel.getRGBColor( ColorTransformer.lch_uv2rgb(myLCH));
x++;
j = 0;
}
row[i] = color;
}
}
}
}