下面列出了java.awt.color.ColorSpace#fromCIEXYZ ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a {@code float} array containing only the color
* components of the {@code Color} in the
* {@code ColorSpace} specified by the {@code cspace}
* parameter. If {@code compArray} is {@code null}, an array
* with length equal to the number of components in
* {@code cspace} is created for the return value. Otherwise,
* {@code compArray} must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified {@code ColorSpace}
* @param compArray an array that this method fills with the color
* components of this {@code Color} in the specified
* {@code ColorSpace}
* @return the color components in a {@code float} array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
/**
* Returns a <code>float</code> array containing only the color
* components of the <code>Color</code> in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an array
* with length equal to the number of components in
* <code>cspace</code> is created for the return value. Otherwise,
* <code>compArray</code> must have at least this length, and it is
* filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the color
* components of this <code>Color</code> in the specified
* <code>ColorSpace</code>
* @return the color components in a <code>float</code> array.
*/
public float[] getColorComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
return tmpout;
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
return compArray;
}
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context) ctx;
final ColorSpace cs = ictx.cs;
final float[] val = ictx.cie;
do {
try {
cs.fromCIEXYZ(val);
} catch (Exception e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
/**
* Returns a {@code float} array containing the color and alpha
* components of the {@code Color}, in the
* {@code ColorSpace} specified by the {@code cspace}
* parameter. If {@code compArray} is {@code null}, an
* array with length equal to the number of components in
* {@code cspace} plus one is created for the return value.
* Otherwise, {@code compArray} must have at least this
* length, and it is filled in with the components and returned.
* @param cspace a specified {@code ColorSpace}
* @param compArray an array that this method fills with the
* color and alpha components of this {@code Color} in
* the specified {@code ColorSpace} and returns
* @return the color and alpha components in a {@code float}
* array.
*/
public float[] getComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
compArray = new float[tmpout.length + 1];
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
if (fvalue == null) {
compArray[tmpout.length] = ((float)getAlpha())/255f;
} else {
compArray[tmpout.length] = falpha;
}
return compArray;
}
/**
* Returns a <code>float</code> array containing the color and alpha
* components of the <code>Color</code>, in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an
* array with length equal to the number of components in
* <code>cspace</code> plus one is created for the return value.
* Otherwise, <code>compArray</code> must have at least this
* length, and it is filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the
* color and alpha components of this <code>Color</code> in
* the specified <code>ColorSpace</code> and returns
* @return the color and alpha components in a <code>float</code>
* array.
*/
public float[] getComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
compArray = new float[tmpout.length + 1];
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
if (fvalue == null) {
compArray[tmpout.length] = ((float)getAlpha())/255f;
} else {
compArray[tmpout.length] = falpha;
}
return compArray;
}
/**
* Returns a <code>float</code> array containing the color and alpha
* components of the <code>Color</code>, in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an
* array with length equal to the number of components in
* <code>cspace</code> plus one is created for the return value.
* Otherwise, <code>compArray</code> must have at least this
* length, and it is filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the
* color and alpha components of this <code>Color</code> in
* the specified <code>ColorSpace</code> and returns
* @return the color and alpha components in a <code>float</code>
* array.
*/
public float[] getComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
compArray = new float[tmpout.length + 1];
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
if (fvalue == null) {
compArray[tmpout.length] = ((float)getAlpha())/255f;
} else {
compArray[tmpout.length] = falpha;
}
return compArray;
}
/**
* Returns a <code>float</code> array containing the color and alpha
* components of the <code>Color</code>, in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an
* array with length equal to the number of components in
* <code>cspace</code> plus one is created for the return value.
* Otherwise, <code>compArray</code> must have at least this
* length, and it is filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the
* color and alpha components of this <code>Color</code> in
* the specified <code>ColorSpace</code> and returns
* @return the color and alpha components in a <code>float</code>
* array.
*/
public float[] getComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
compArray = new float[tmpout.length + 1];
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
if (fvalue == null) {
compArray[tmpout.length] = ((float)getAlpha())/255f;
} else {
compArray[tmpout.length] = falpha;
}
return compArray;
}
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context) ctx;
final ColorSpace cs = ictx.cs;
final float[] val = ictx.cie;
do {
try {
cs.fromCIEXYZ(val);
} catch (Exception e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context) ctx;
final ColorSpace cs = ictx.cs;
final float[] val = ictx.cie;
do {
try {
cs.fromCIEXYZ(val);
} catch (Exception e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
/**
* Returns a <code>float</code> array containing the color and alpha
* components of the <code>Color</code>, in the
* <code>ColorSpace</code> specified by the <code>cspace</code>
* parameter. If <code>compArray</code> is <code>null</code>, an
* array with length equal to the number of components in
* <code>cspace</code> plus one is created for the return value.
* Otherwise, <code>compArray</code> must have at least this
* length, and it is filled in with the components and returned.
* @param cspace a specified <code>ColorSpace</code>
* @param compArray an array that this method fills with the
* color and alpha components of this <code>Color</code> in
* the specified <code>ColorSpace</code> and returns
* @return the color and alpha components in a <code>float</code>
* array.
*/
public float[] getComponents(ColorSpace cspace, float[] compArray) {
if (cs == null) {
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
}
float f[];
if (fvalue == null) {
f = new float[3];
f[0] = ((float)getRed())/255f;
f[1] = ((float)getGreen())/255f;
f[2] = ((float)getBlue())/255f;
} else {
f = fvalue;
}
float tmp[] = cs.toCIEXYZ(f);
float tmpout[] = cspace.fromCIEXYZ(tmp);
if (compArray == null) {
compArray = new float[tmpout.length + 1];
}
for (int i = 0 ; i < tmpout.length ; i++) {
compArray[i] = tmpout[i];
}
if (fvalue == null) {
compArray[tmpout.length] = ((float)getAlpha())/255f;
} else {
compArray[tmpout.length] = falpha;
}
return compArray;
}
public static float[] toSRGB(int colorSpace, float[] rgb) {
ColorSpace cs = ColorSpace.getInstance(colorSpace);
float[] xyz = cs.toCIEXYZ(rgb);
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
float[] srgb = cs.fromCIEXYZ(xyz);
return srgb;
}
public void runTest(Object ctx, int numReps) {
final Context ictx = (Context) ctx;
final ColorSpace cs = ictx.cs;
final float[] val = ictx.cie;
do {
try {
cs.fromCIEXYZ(val);
} catch (Exception e) {
e.printStackTrace();
}
} while (--numReps >= 0);
}
@Override
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
if (usePureJavaCMYKConversion)
{
BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
BufferedImage.TYPE_INT_RGB);
ColorSpace destCS = dest.getColorModel().getColorSpace();
WritableRaster destRaster = dest.getRaster();
float[] srcValues = new float[4];
float[] lastValues = new float[] { -1.0f, -1.0f, -1.0f, -1.0f };
float[] destValues = new float[3];
int width = raster.getWidth();
int startX = raster.getMinX();
int height = raster.getHeight();
int startY = raster.getMinY();
for (int x = startX; x < width + startX; x++)
{
for (int y = startY; y < height + startY; y++)
{
raster.getPixel(x, y, srcValues);
// check if the last value can be reused
if (!Arrays.equals(lastValues, srcValues))
{
for (int k = 0; k < 4; k++)
{
lastValues[k] = srcValues[k];
srcValues[k] = srcValues[k] / 255f;
}
// use CIEXYZ as intermediate format to optimize the color conversion
destValues = destCS.fromCIEXYZ(colorSpace.toCIEXYZ(srcValues));
for (int k = 0; k < destValues.length; k++)
{
destValues[k] = destValues[k] * 255f;
}
}
destRaster.setPixel(x, y, destValues);
}
}
return dest;
}
else
{
return super.toRGBImageAWT(raster, colorSpace);
}
}
public static double[] convert(ColorSpace cs, CIEData d) {
double[] xyz = ColorBase.array(d.getRelativeX(), d.getRelativeY(), d.getRelativeZ());
float[] fxyz = cs.fromCIEXYZ(ColorBase.arrayFloat(xyz));
double[] outputs = clipRGB(arrayDouble(fxyz));
return outputs;
}