类java.awt.color.ColorSpace源码实例Demo

下面列出了怎么用java.awt.color.ColorSpace的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: gcs   文件: PDColorSpace.java
/**
 * Returns the (A)RGB equivalent of the given raster, using the given AWT color space
 * to perform the conversion.
 * @param raster the source raster
 * @param colorSpace the AWT
 * @return an (A)RGB buffered image
 */
protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
{
    //
    // WARNING: this method is performance sensitive, modify with care!
    //

    // ICC Profile color transforms are only fast when performed using ColorConvertOp
    ColorModel colorModel = new ComponentColorModel(colorSpace,
        false, false, Transparency.OPAQUE, raster.getDataBuffer().getDataType());

    BufferedImage src = new BufferedImage(colorModel, raster, false, null);
    BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
                                           BufferedImage.TYPE_INT_RGB);
    ColorConvertOp op = new ColorConvertOp(null);
    op.filter(src, dest);
    return dest;
}
 
源代码2 项目: openjdk-8-source   文件: Color.java
/**
 * 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;
}
 
源代码3 项目: Bytecoder   文件: ComponentColorModel.java
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;
}
 
源代码4 项目: openjdk-jdk9   文件: JFIFMarkerSegment.java
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();
    }
}
 
源代码5 项目: orbit-image-analysis   文件: JSliderOrbit.java
@Override
protected Icon getIcon ()
{
    // TODO Use that to get the state (-> highlight or not)
    TransitionAwareUI transitionAwareUI = (TransitionAwareUI) slider.getUI();
    StateTransitionTracker stateTransitionTracker = transitionAwareUI.getTransitionTracker();
    // stateTransitionTracker.getModelStateInfo().getCurrModelState();

    final Icon icon = super.getIcon();
    final BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics iconGraphics = image.createGraphics();
    icon.paintIcon(slider, iconGraphics, 0, 0);
    // Make it brighter (very simple approach)
    final RescaleOp rescaleOp = new RescaleOp(2.0f, 50, null);
    rescaleOp.filter(image, image);

    ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
    op.filter(image, image);

    return new ImageIcon(image);
}
 
源代码6 项目: jdk8u-jdk   文件: ComponentColorModel.java
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;
}
 
源代码7 项目: Bytecoder   文件: ImageUtil.java
/**
 * Returns <code>true</code> if the given <code>ColorSpace</code> object is
 * an instance of <code>ICC_ColorSpace</code> but is not one of the standard
 * <code>ColorSpace</code>s returned by <code>ColorSpace.getInstance()</code>.
 *
 * @param cs The <code>ColorSpace</code> to test.
 */
public static boolean isNonStandardICCColorSpace(ColorSpace cs) {
    boolean retval = false;

    try {
        // Check the standard ColorSpaces in decreasing order of
        // likelihood except check CS_PYCC last as in some JREs
        // PYCC.pf used not to be installed.
        retval =
            (cs instanceof ICC_ColorSpace) &&
            !(cs.isCS_sRGB() ||
              cs.equals(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB)) ||
              cs.equals(ColorSpace.getInstance(ColorSpace.CS_GRAY)) ||
              cs.equals(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ)) ||
              cs.equals(ColorSpace.getInstance(ColorSpace.CS_PYCC)));
    } catch(IllegalArgumentException e) {
        // PYCC.pf not installed: ignore it - 'retval' is still 'false'.
    }

    return retval;
}
 
源代码8 项目: openjdk-jdk8u   文件: D3DGraphicsConfig.java
@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;
    }
}
 
源代码9 项目: jdk8u_jdk   文件: DataConversionTests.java
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};
}
 
源代码10 项目: ghidra   文件: BitmapResource.java
/**
 * @param buf
 * @return DataImage
 */
protected DataImage get18PlaneImage(MemBuffer buf) {
	// create the color model
	ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
	int[] nBits = { 8, 8, 8 };
	int[] bOffs = { 2, 1, 0 };
	ColorModel colorModel =
		new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE,
			DataBuffer.TYPE_BYTE);
	int w = getWidth();
	int h = getHeight();
	WritableRaster raster =
		Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);

	// create the image

	BufferedImage image =
		new BufferedImage(colorModel, raster, colorModel.isAlphaPremultiplied(), null);

	byte[] dbuf = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
	getPixelData(buf, dbuf);
	return new BitmapDataImage(image);
}
 
/**
 * Returns the custom buffered image, which mostly identical to
 * BufferedImage.(w,h,TYPE_3BYTE_BGR), but uses the bigger scanlineStride.
 * This means that the raster will have gaps, between the rows.
 */
private static BufferedImage makeCustomManagedBI() {
    int w = 511, h = 255;
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8};
    int[] bOffs = {2, 1, 0};
    ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false,
                                                    Transparency.OPAQUE,
                                                    DataBuffer.TYPE_BYTE);
    WritableRaster raster =
            Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h,
                                           w * 3 + 2, 3, bOffs, null);
    BufferedImage bi = new BufferedImage(colorModel, raster, true, null);
    SunWritableRaster.makeTrackable(raster.getDataBuffer());
    SunWritableRaster.markDirty(bi);
    return bi;
}
 
源代码12 项目: sambox   文件: PageDrawer.java
private BufferedImage create2ByteGrayAlphaImage(int width, int height)
{
    /**
     * gray + alpha
     */
    int[] bandOffsets = new int[] { 1, 0 };
    int bands = bandOffsets.length;

    /**
     * Color Model usesd for raw GRAY + ALPHA
     */
    final ColorModel CM_GRAY_ALPHA = new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_GRAY), true, false,
            Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE);

    // Init data buffer of type byte
    DataBuffer buffer = new DataBufferByte(width * height * bands);

    // Wrap the data buffer in a raster
    WritableRaster raster = Raster.createInterleavedRaster(buffer, width, height,
            width * bands, bands, bandOffsets, new Point(0, 0));

    // Create a custom BufferedImage with the raster and a suitable color model
    return new BufferedImage(CM_GRAY_ALPHA, raster, false, null);
}
 
源代码13 项目: openjdk-8   文件: JPEG.java
/**
 * Returns <code>true</code> if the given <code>ColorSpace</code>
 * object is an instance of ICC_ColorSpace but is not one of the
 * standard <code>ColorSpaces</code> returned by
 * <code>ColorSpace.getInstance()</code>.
 */
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;
}
 
源代码14 项目: openjdk-jdk8u-backup   文件: JPEGImageWriter.java
private int getSrcCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_RGBA;
            } else {
                retval = JPEG.JCS_RGB;
            }
            break;
        case ColorSpace.TYPE_YCbCr:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_3CLR:
            if (cs == JPEG.JCS.getYCC()) {
                if (alpha) {
                    retval = JPEG.JCS_YCCA;
                } else {
                    retval = JPEG.JCS_YCC;
                }
            }
        case ColorSpace.TYPE_CMYK:
            retval = JPEG.JCS_CMYK;
            break;
        }
    }
    return retval;
}
 
源代码15 项目: jdk8u-jdk   文件: X11GraphicsConfig.java
public static ComponentColorModel createABGRCCM() {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    int[] nBits = {8, 8, 8, 8};
    int[] bOffs = {3, 2, 1, 0};
    return new ComponentColorModel(cs, nBits, true, true,
                                   Transparency.TRANSLUCENT,
                                   DataBuffer.TYPE_BYTE);
}
 
源代码16 项目: jdk1.8-source-analysis   文件: Color.java
/**
 * Returns the <code>ColorSpace</code> of this <code>Color</code>.
 * @return this <code>Color</code> object's <code>ColorSpace</code>.
 */
public ColorSpace getColorSpace() {
    if (cs == null) {
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    }
    return cs;
}
 
源代码17 项目: hottub   文件: JPEG.java
/**
 * Returns <code>true</code> if the given imageType can be used
 * in a JFIF file.  If <code>input</code> is true, then the
 * image type is considered before colorspace conversion.
 */
static boolean isJFIFcompliant(ImageTypeSpecifier imageType,
                               boolean input) {
    ColorModel cm = imageType.getColorModel();
    // Can't have alpha
    if (cm.hasAlpha()) {
        return false;
    }
    // Gray is OK, always
    int numComponents = imageType.getNumComponents();
    if (numComponents == 1) {
        return true;
    }

    // If it isn't gray, it must have 3 channels
    if (numComponents != 3) {
        return false;
    }

    if (input) {
        // Must be RGB
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB) {
            return true;
        }
    } else {
        // Must be YCbCr
        if (cm.getColorSpace().getType() == ColorSpace.TYPE_YCbCr) {
            return true;
        }
    }

    return false;
}
 
源代码18 项目: jdk8u60   文件: JPEG.java
/**
 * Returns <code>true</code> if the given <code>ColorSpace</code>
 * object is an instance of ICC_ColorSpace but is not one of the
 * standard <code>ColorSpaces</code> returned by
 * <code>ColorSpace.getInstance()</code>.
 */
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;
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: JPEGImageWriter.java
private int getDefaultDestCSType(ColorModel cm) {
    int retval = JPEG.JCS_UNKNOWN;
    if (cm != null) {
        boolean alpha = cm.hasAlpha();
        ColorSpace cs = cm.getColorSpace();
        switch (cs.getType()) {
        case ColorSpace.TYPE_GRAY:
            retval = JPEG.JCS_GRAYSCALE;
            break;
        case ColorSpace.TYPE_RGB:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_YCbCr:
            if (alpha) {
                retval = JPEG.JCS_YCbCrA;
            } else {
                retval = JPEG.JCS_YCbCr;
            }
            break;
        case ColorSpace.TYPE_3CLR:
            if (cs == JPEG.JCS.getYCC()) {
                if (alpha) {
                    retval = JPEG.JCS_YCCA;
                } else {
                    retval = JPEG.JCS_YCC;
                }
            }
        case ColorSpace.TYPE_CMYK:
            retval = JPEG.JCS_YCCK;
            break;
        }
    }
    return retval;
}
 
源代码20 项目: jdk8u-jdk   文件: ComponentColorModel.java
private static int bitsHelper(int transferType,
                              ColorSpace colorSpace,
                              boolean hasAlpha) {
    int numBits = DataBuffer.getDataTypeSize(transferType);
    int numComponents = colorSpace.getNumComponents();
    if (hasAlpha) {
        ++numComponents;
    }
    return numBits * numComponents;
}
 
源代码21 项目: jdk8u60   文件: DataConversionTests.java
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] val = ictx.val;

    do {
        try {
            cs.toCIEXYZ(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
源代码22 项目: orbit-image-analysis   文件: TiledImageWriter.java
public TiledImageWriter(int width, int height, int imageType, int tileWidth, int tileHeight) {
      /*
       DiskMemImage.getCommonTileCache().setMemoryCapacity(AparUtils.DISK_IMAGE_CACHE);
 DiskMemImage.getCommonTileCache().setAutoFlushMemoryEnabled(AparUtils.DISK_IMAGE_AUTO_FLUSH);
 DiskMemImage.getCommonTileCache().setAutoFlushMemoryInterval(AparUtils.DISK_IMAGE_AUTO_FLUSH_TIME);
 DiskMemImage.getCommonTileCache().flush();
*/

      this.width = width;
      this.height = height;
      this.tileWidth = tileWidth;
      this.tileHeight = tileHeight;

      if (imageType == TiledImageWriter.IMAGE_RGBA) {
          colorModel = new ComponentColorModel(
                  ColorSpace.getInstance(ColorSpace.CS_sRGB),
                  new int[]{8, 8, 8, 8}, true, false,
                  Transparency.TRANSLUCENT,
                  DataBuffer.TYPE_BYTE);
      } else {
          colorModel = new ComponentColorModel(
                  ColorSpace.getInstance(ColorSpace.CS_sRGB),
                  new int[]{8, 8, 8}, false, false,
                  Transparency.OPAQUE,
                  DataBuffer.TYPE_BYTE);
      }


      //BufferedImage imgCol = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
      //colorModel = imgCol.getColorModel();
      sampleModel = colorModel.createCompatibleSampleModel(tileWidth, tileHeight);

      DiskMemImageOrbit dmi = new DiskMemImageOrbit(0, 0, width, height, 0, 0, sampleModel, colorModel);
      dmi.setUseCommonCache(true);
      setImage(dmi);

      // System.out.println("TiledImageWriter Info: ");
      // System.out.println(getTileInfo(image));
  }
 
源代码23 项目: commons-imaging   文件: ImageDumpTest.java
@Test
public void testDumpColorSpace() {
    final ImageDump imageDump = new ImageDump();
    final ColorSpace colorSpace = ColorSpace.getInstance(1004);
    imageDump.dumpColorSpace("Ku&]N>!4'C#Jzn+", colorSpace);

    assertEquals(3, colorSpace.getNumComponents());
}
 
源代码24 项目: jdk8u-dev-jdk   文件: DataConversionTests.java
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context) ctx;
    final ColorSpace cs = ictx.cs;

    final float[] rgb = ictx.rgb;
    do {
        try {
            cs.fromRGB(rgb);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
源代码25 项目: jdk8u-dev-jdk   文件: JPEG.java
public static ColorSpace getYCC() {
    if (!yccInited) {
        try {
            YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC);
        } catch (IllegalArgumentException e) {
            // PYCC.pf may not always be installed
        } finally {
            yccInited = true;
        }
    }
    return YCC;
}
 
源代码26 项目: jdk8u60   文件: DataConversionTests.java
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);
}
 
源代码27 项目: openjdk-jdk8u-backup   文件: CMMTests.java
protected static ColorSpace getColorSpace(TestEnvironment env) {
    ColorSpace cs;
    Boolean usePlatfrom = true; //(Boolean)env.getModifier(usePlatfromProfiles);

    int cs_code = env.getIntValue(csList);
    if (usePlatfrom) {
        cs = ColorSpace.getInstance(cs_code);
    } else {
        String resource = "profiles/";
        switch (cs_code) {
            case ColorSpace.CS_CIEXYZ:
                resource += "CIEXYZ.pf";
                break;
            case ColorSpace.CS_GRAY:
                resource += "GRAY.pf";
                break;
            case ColorSpace.CS_LINEAR_RGB:
                resource += "LINEAR_RGB.pf";
                break;
            case ColorSpace.CS_PYCC:
                resource += "PYCC.pf";
                break;
            case ColorSpace.CS_sRGB:
                resource += "sRGB.pf";
                break;
            default:
                throw new RuntimeException("Unknown color space: " + cs_code);
        }

        try {
            InputStream is = CMMTests.class.getResourceAsStream(resource);
            ICC_Profile p = ICC_Profile.getInstance(is);

            cs = new ICC_ColorSpace(p);
        } catch (IOException e) {
            throw new RuntimeException("Unable load profile from resource " + resource, e);
        }
    }
    return cs;
}
 
源代码28 项目: openjdk-8-source   文件: ColConvTest.java
static String getCSName(int cs) {
    switch(cs) {
        case ColorSpace.CS_GRAY:
            return "CS_GRAY";
        case ColorSpace.CS_CIEXYZ:
            return "CS_CIEXYZ";
        case ColorSpace.CS_LINEAR_RGB:
            return "CS_LINEAR_RGB";
        case ColorSpace.CS_PYCC:
            return "CS_PYCC";
        case ColorSpace.CS_sRGB:
            return "CS_sRGB";
    }
    return "UNKNOWN";
}
 
源代码29 项目: jdk8u-dev-jdk   文件: Color.java
/**
 * 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;
}
 
源代码30 项目: jdk8u60   文件: Color.java
/**
 * Creates a color in the specified <code>ColorSpace</code>
 * with the color components specified in the <code>float</code>
 * array and the specified alpha.  The number of components is
 * determined by the type of the <code>ColorSpace</code>.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the <code>ColorSpace</code> to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the <code>ColorSpace</code>
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         <code>components</code> array or <code>alpha</code> is
 *         outside of the range 0.0 to 1.0
 * @see #getComponents
 * @see #getColorComponents
 */
public Color(ColorSpace cspace, float components[], float alpha) {
    boolean rangeError = false;
    String badComponentString = "";
    int n = cspace.getNumComponents();
    fvalue = new float[n];
    for (int i = 0; i < n; i++) {
        if (components[i] < 0.0 || components[i] > 1.0) {
            rangeError = true;
            badComponentString = badComponentString + "Component " + i
                                 + " ";
        } else {
            fvalue[i] = components[i];
        }
    }
    if (alpha < 0.0 || alpha > 1.0) {
        rangeError = true;
        badComponentString = badComponentString + "Alpha";
    } else {
        falpha = alpha;
    }
    if (rangeError) {
        throw new IllegalArgumentException(
            "Color parameter outside of expected range: " +
            badComponentString);
    }
    frgbvalue = cspace.toRGB(fvalue);
    cs = cspace;
    value = ((((int)(falpha*255)) & 0xFF) << 24) |
            ((((int)(frgbvalue[0]*255)) & 0xFF) << 16) |
            ((((int)(frgbvalue[1]*255)) & 0xFF) << 8)  |
            ((((int)(frgbvalue[2]*255)) & 0xFF) << 0);
}
 
 类所在包
 同包方法