package de.mpi.rgblab.utils;
import de.mpi.rgblab.color.ColorModel;
import de.mpi.rgblab.color.ColorTransformer;
import de.mpi.rgblab.color.ColorType;
public class LAB {
public static int L_MAX = 100;
public static int L_MIN = 20;
public static int A_MAX = 127;
public static int A_MIN = -127;
public static int B_MAX = 127;
public static int B_MIN = -127;
public static double getCorrectL(double l) {
if (L_MAX < l)
return L_MAX;
else if (L_MIN > l)
return L_MIN;
return l;
}
public static double getCorrectA(double a) {
if (A_MAX < a)
return A_MAX;
else if (A_MIN > a)
return A_MIN;
return a;
}
public static double getCorrectB(double b) {
if (B_MAX < b)
return B_MAX;
else if (B_MIN > b)
return B_MIN;
return b;
}
public static boolean isInRGBSpace(ColorModel lab) {
if (lab.getDimension_1() > L_MAX)
return false;
if (lab.getDimension_1() < L_MIN)
return false;
if (lab.getDimension_2() > A_MAX)
return false;
if (lab.getDimension_2() < A_MIN)
return false;
if (lab.getDimension_3() > B_MAX)
return false;
if (lab.getDimension_3() < B_MIN)
return false;
ColorModel rgb = ColorTransformer.lab2rgb(lab);
double c;
for (int i = 0; i < 3; i++) {
c = rgb.getDimension(i);
if (c > 255 || c < 0)
return false;
}
return true;
}
// test
public static void main(String[] args) {
// TODO Auto-generated method stub
double l = -127.87431826763529;
double a = -617.8203664542718;
double b = 339.6924724930096;
//for (int i = 0; i < 105; i++)
System.out.println(isInRGBSpace(new ColorModel(l, a, b,
ColorType.LAB)));
}
}