本文整理汇总了Java中java.awt.color.ColorSpace类的典型用法代码示例。如果您正苦于以下问题:Java ColorSpace类的具体用法?Java ColorSpace怎么用?Java ColorSpace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColorSpace类属于java.awt.color包,在下文中一共展示了ColorSpace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColorComponents
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* 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;
}
示例2: JFIFExtensionMarkerSegment
import java.awt.color.ColorSpace; //导入依赖的package包/类
JFIFExtensionMarkerSegment(BufferedImage thumbnail)
throws IllegalThumbException {
super(JPEG.APP0);
ColorModel cm = thumbnail.getColorModel();
int csType = cm.getColorSpace().getType();
if (cm.hasAlpha()) {
throw new IllegalThumbException();
}
if (cm instanceof IndexColorModel) {
code = THUMB_PALETTE;
thumb = new JFIFThumbPalette(thumbnail);
} else if (csType == ColorSpace.TYPE_RGB) {
code = THUMB_RGB;
thumb = new JFIFThumbRGB(thumbnail);
} else if (csType == ColorSpace.TYPE_GRAY) {
code = THUMB_JPEG;
thumb = new JFIFThumbJPEG(thumbnail);
} else {
throw new IllegalThumbException();
}
}
示例3: compareImages
import java.awt.color.ColorSpace; //导入依赖的package包/类
protected void compareImages(BufferedImage src, BufferedImage dst) {
ColorSpace srcCS = src.getColorModel().getColorSpace();
ColorSpace dstCS = dst.getColorModel().getColorSpace();
if (!srcCS.equals(dstCS) && srcCS.getType() == ColorSpace.TYPE_GRAY) {
System.out.println("Workaround color difference with GRAY.");
BufferedImage tmp =
new BufferedImage(src.getWidth(), src.getHeight(),
BufferedImage.TYPE_INT_RGB);
Graphics g = tmp.createGraphics();
g.drawImage(src, 0, 0, null);
src = tmp;
}
int y = h / 2;
for (int i = 0; i < colors.length; i++) {
int x = dx * i + dx / 2;
int srcRgb = src.getRGB(x, y);
int dstRgb = dst.getRGB(x, y);
if (srcRgb != dstRgb) {
throw new RuntimeException("Test failed due to color difference: " +
"src_pixel=" + Integer.toHexString(srcRgb) +
"dst_pixel=" + Integer.toHexString(dstRgb));
}
}
}
示例4: getColorComponents
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* 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;
}
示例5: bitsArrayHelper
import java.awt.color.ColorSpace; //导入依赖的package包/类
private static int[] bitsArrayHelper(int[] origBits,
int transferType,
ColorSpace colorSpace,
boolean hasAlpha) {
switch(transferType) {
case DataBuffer.TYPE_BYTE:
case DataBuffer.TYPE_USHORT:
case DataBuffer.TYPE_INT:
if (origBits != null) {
return origBits;
}
break;
default:
break;
}
int numBits = DataBuffer.getDataTypeSize(transferType);
int numComponents = colorSpace.getNumComponents();
if (hasAlpha) {
++numComponents;
}
int[] bits = new int[numComponents];
for (int i = 0; i < numComponents; i++) {
bits[i] = numBits;
}
return bits;
}
示例6: getColorModel
import java.awt.color.ColorSpace; //导入依赖的package包/类
@Override
public ColorModel getColorModel(int transparency) {
switch (transparency) {
case Transparency.OPAQUE:
// REMIND: once the ColorModel spec is changed, this should be
// an opaque premultiplied DCM...
return new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
case Transparency.BITMASK:
return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
case Transparency.TRANSLUCENT:
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
return new DirectColorModel(cs, 32,
0xff0000, 0xff00, 0xff, 0xff000000,
true, DataBuffer.TYPE_INT);
default:
return null;
}
}
示例7: getType
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* Return the type given the number of components.
*
* @param numComponents The number of components in the
* <code>ColorSpace</code>.
* @exception IllegalArgumentException if <code>numComponents</code>
* is less than 1.
*/
private static int getType(int numComponents) {
if(numComponents < 1) {
throw new IllegalArgumentException("numComponents < 1!");
}
int type;
switch(numComponents) {
case 1:
type = ColorSpace.TYPE_GRAY;
break;
default:
// Based on the constant definitions TYPE_2CLR=12 through
// TYPE_FCLR=25. This will return unknown types for
// numComponents > 15.
type = numComponents + 10;
}
return type;
}
示例8: transformForType
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* Given an image type, return the Adobe transform corresponding to
* that type, or ADOBE_IMPOSSIBLE if the image type is incompatible
* with an Adobe marker segment. If <code>input</code> is true, then
* the image type is considered before colorspace conversion.
*/
static int transformForType(ImageTypeSpecifier imageType, boolean input) {
int retval = ADOBE_IMPOSSIBLE;
ColorModel cm = imageType.getColorModel();
switch (cm.getColorSpace().getType()) {
case ColorSpace.TYPE_GRAY:
retval = ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_RGB:
retval = input ? ADOBE_YCC : ADOBE_UNKNOWN;
break;
case ColorSpace.TYPE_YCbCr:
retval = ADOBE_YCC;
break;
case ColorSpace.TYPE_CMYK:
retval = input ? ADOBE_YCCK : ADOBE_IMPOSSIBLE;
}
return retval;
}
示例9: main
import java.awt.color.ColorSpace; //导入依赖的package包/类
public static void main(String[] args) {
int sr = 128;
int sg = 1;
int sb = 128;
System.out.format("Input (sRGB) = %d, %d, %d\n", sr, sg, sb);
System.out.format("XYZref = %10g, %10g, %10g\n", Xref,Yref,Zref);
ColorSpace cs = new LabColorSpace();
//float[] luv = cs.fromCIEXYZ(new float[] {.1f,.5f,.9f});
float[] lab = cs.fromRGB(new float[] {sr/255f, sg/255f, sb/255f});
System.out.format("Lab = %8f, %8f, %8f\n", lab[0],lab[2],lab[2]);
//float[] xyz = cs.toCIEXYZ(luv);
float[] srgb = cs.toRGB(lab);
System.out.format("sRGB = %8f, %8f, %8f\n",
Math.rint(255*srgb[0]), Math.rint(255*srgb[1]), Math.rint(255*srgb[2]));
}
示例10: loadIconCallback
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* This method is used by JNI as a callback from load_stock_icon.
* Image data is passed back to us via this method and loaded into the
* local BufferedImage and then returned via getStockIcon.
*
* Do NOT call this method directly.
*/
public void loadIconCallback(byte[] data, int width, int height,
int rowStride, int bps, int channels, boolean alpha) {
// Reset the stock image to null.
tmpImage = null;
// Create a new BufferedImage based on the data returned from the
// JNI call.
DataBuffer dataBuf = new DataBufferByte(data, (rowStride * height));
// Maybe test # channels to determine band offsets?
WritableRaster raster = Raster.createInterleavedRaster(dataBuf,
width, height, rowStride, channels,
(alpha ? BAND_OFFSETS_ALPHA : BAND_OFFSETS), null);
ColorModel colorModel = new ComponentColorModel(
ColorSpace.getInstance(ColorSpace.CS_sRGB), alpha, false,
ColorModel.TRANSLUCENT, DataBuffer.TYPE_BYTE);
// Set the local image so we can return it later from
// getStockIcon().
tmpImage = new BufferedImage(colorModel, raster, false, null);
}
示例11: blackNWhite
import java.awt.color.ColorSpace; //导入依赖的package包/类
public void blackNWhite(String link, String email) throws Exception{
try{
download(link);
doLogging("Request came for blackNWhite ", "INFO");
String outPath=null;
String fileName=null;
String imageName = null;
int lastSlashIndex = link.lastIndexOf('/');
imageName = link.substring(lastSlashIndex + 1);
String path = Path+imageName;
BufferedImage src = ImageIO.read(new File(path));
ColorConvertOp op =new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
BufferedImage dest = op.filter(src, null);
fileName = path.substring(path.lastIndexOf("/")+1);
path = path.substring(0, path.lastIndexOf("/")+1);
outPath=path+"BNW_"+fileName;
ImageIO.write(dest, "jpg", new File(outPath));
sendMail(outPath, email);
}
catch(Exception e){
doLogging("Failed somewhere "+e.getMessage()+e.getStackTrace(), "Error");
}
}
示例12: Context
import java.awt.color.ColorSpace; //导入依赖的package包/类
public Context(TestEnvironment env, Result result, ColorSpace cs) {
this.cs = cs;
this.env = env;
this.res = result;
numComponents = cs.getNumComponents();
val = new float[numComponents];
for (int i = 0; i < numComponents; i++) {
float min = cs.getMinValue(i);
float max = cs.getMaxValue(i);
val[i] = 0.5f * (max - min);
}
rgb = new float[]{0.5f, 0.5f, 0.5f};
cie = new float[]{0.5f, 0.5f, 0.5f};
}
示例13: createComponentCM
import java.awt.color.ColorSpace; //导入依赖的package包/类
static ColorModel createComponentCM(ColorSpace colorSpace,
int numBands,
int dataType,
boolean hasAlpha,
boolean isAlphaPremultiplied) {
int transparency =
hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
int[] numBits = new int[numBands];
int bits = DataBuffer.getDataTypeSize(dataType);
for (int i = 0; i < numBands; i++) {
numBits[i] = bits;
}
return new ComponentColorModel(colorSpace,
numBits,
hasAlpha,
isAlphaPremultiplied,
transparency,
dataType);
}
示例14: convert
import java.awt.color.ColorSpace; //导入依赖的package包/类
@Override
public ColorModel convert(FieldAccessor fa, Instance instance) throws FieldAccessor.InvalidFieldException {
int bits = fa.getInt(instance, "pixel_bits"); // NOI18N
int rmask = fa.getInt(instance, "red_mask"); // NOI18N
int gmask = fa.getInt(instance, "green_mask"); // NOI18N
int bmask = fa.getInt(instance, "blue_mask"); // NOI18N
int amask = fa.getInt(instance, "alpha_mask"); // NOI18N
boolean ap = fa.getBoolean(instance, "isAlphaPremultiplied"); // NOI18N
int transferType = fa.getInt(instance, "transferType"); // NOI18N
return new DirectColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), bits, rmask, gmask, bmask, amask, ap, transferType);
}
示例15: isNonStandardICC
import java.awt.color.ColorSpace; //导入依赖的package包/类
/**
* Returns {@code true} if the given {@code ColorSpace}
* object is an instance of ICC_ColorSpace but is not one of the
* standard {@code ColorSpaces} returned by
* {@code ColorSpace.getInstance()}.
*/
static boolean isNonStandardICC(ColorSpace cs) {
boolean retval = false;
if ((cs instanceof ICC_ColorSpace)
&& (!cs.isCS_sRGB())
&& (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ)))
&& (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_GRAY)))
&& (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)))
&& (!cs.equals(ColorSpace.getInstance(ColorSpace.CS_PYCC)))
) {
retval = true;
}
return retval;
}