Search in sources :

Example 11 with ColorTransform

use of sun.java2d.cmm.ColorTransform in project jdk8u_jdk by JetBrains.

the class ColorModel method getGray16TosRGB8LUT.

/*
     * Return a byte LUT that converts 16-bit gray values in the grayCS
     * ColorSpace to the appropriate 8-bit sRGB value.  I.e., if lut
     * is the byte array returned by this method and sval = lut[gval],
     * then the sRGB triple (sval,sval,sval) is the best match to gval.
     * Cache references to any computed LUT in a Map.
     */
static byte[] getGray16TosRGB8LUT(ICC_ColorSpace grayCS) {
    if (isLinearGRAYspace(grayCS)) {
        return getLinearRGB16TosRGB8LUT();
    }
    if (g16Tos8Map != null) {
        byte[] g16Tos8LUT = g16Tos8Map.get(grayCS);
        if (g16Tos8LUT != null) {
            return g16Tos8LUT;
        }
    }
    short[] tmp = new short[65536];
    for (int i = 0; i <= 65535; i++) {
        tmp[i] = (short) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace srgbCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
    transformList[0] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    tmp = t.colorConvert(tmp, null);
    byte[] g16Tos8LUT = new byte[65536];
    for (int i = 0, j = 2; i <= 65535; i++, j += 3) {
        // All three components of tmp should be equal, since
        // the input color space to colorConvert is a gray scale
        // space.  However, there are slight anomalies in the results.
        // Copy tmp starting at index 2, since colorConvert seems
        // to be slightly more accurate for the third component!
        // scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
        g16Tos8LUT[i] = (byte) (((float) (tmp[j] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
    }
    if (g16Tos8Map == null) {
        g16Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    g16Tos8Map.put(grayCS, g16Tos8LUT);
    return g16Tos8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 12 with ColorTransform

use of sun.java2d.cmm.ColorTransform in project jdk8u_jdk by JetBrains.

the class ColorModel method getLinearGray16ToOtherGray8LUT.

/*
     * Return a byte LUT that converts 16-bit gray values in the CS_GRAY
     * linear gray ColorSpace to the appropriate 8-bit value in the
     * grayCS ColorSpace.  Cache references to any computed LUT in a Map.
     */
static byte[] getLinearGray16ToOtherGray8LUT(ICC_ColorSpace grayCS) {
    if (lg16Toog8Map != null) {
        byte[] lg16Toog8LUT = lg16Toog8Map.get(grayCS);
        if (lg16Toog8LUT != null) {
            return lg16Toog8LUT;
        }
    }
    short[] tmp = new short[65536];
    for (int i = 0; i <= 65535; i++) {
        tmp[i] = (short) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace lgCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
    transformList[0] = mdl.createTransform(lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    tmp = t.colorConvert(tmp, null);
    byte[] lg16Toog8LUT = new byte[65536];
    for (int i = 0; i <= 65535; i++) {
        // scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
        lg16Toog8LUT[i] = (byte) (((float) (tmp[i] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
    }
    if (lg16Toog8Map == null) {
        lg16Toog8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    lg16Toog8Map.put(grayCS, lg16Toog8LUT);
    return lg16Toog8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Example 13 with ColorTransform

use of sun.java2d.cmm.ColorTransform in project jdk8u_jdk by JetBrains.

the class ICC_ColorSpace method fromCIEXYZ.

/**
     * Transforms a color value assumed to be in the CS_CIEXYZ conversion
     * color space into this ColorSpace.
     * <p>
     * This method transforms color values using relative colorimetry,
     * as defined by the ICC Specification.  This
     * means that the XYZ argument values taken by this method are represented
     * relative to the D50 white point of the CS_CIEXYZ color space.
     * This representation is useful in a two-step color conversion
     * process in which colors are transformed from an input color
     * space to CS_CIEXYZ and then to an output color space.  The color
     * values returned by this method are not those that would produce
     * the XYZ value passed to the method when measured by a colorimeter.
     * If you have XYZ values corresponding to measurements made using
     * current CIE recommended practices, they must be converted to D50
     * relative values before being passed to this method.
     * The paragraphs below explain this in more detail.
     * <p>
     * The ICC standard uses a device independent color space (DICS) as the
     * mechanism for converting color from one device to another device.  In
     * this architecture, colors are converted from the source device's color
     * space to the ICC DICS and then from the ICC DICS to the destination
     * device's color space.  The ICC standard defines device profiles which
     * contain transforms which will convert between a device's color space
     * and the ICC DICS.  The overall conversion of colors from a source
     * device to colors of a destination device is done by connecting the
     * device-to-DICS transform of the profile for the source device to the
     * DICS-to-device transform of the profile for the destination device.
     * For this reason, the ICC DICS is commonly referred to as the profile
     * connection space (PCS).  The color space used in the methods
     * toCIEXYZ and fromCIEXYZ is the CIEXYZ PCS defined by the ICC
     * Specification.  This is also the color space represented by
     * ColorSpace.CS_CIEXYZ.
     * <p>
     * The XYZ values of a color are often represented as relative to some
     * white point, so the actual meaning of the XYZ values cannot be known
     * without knowing the white point of those values.  This is known as
     * relative colorimetry.  The PCS uses a white point of D50, so the XYZ
     * values of the PCS are relative to D50.  For example, white in the PCS
     * will have the XYZ values of D50, which is defined to be X=.9642,
     * Y=1.000, and Z=0.8249.  This white point is commonly used for graphic
     * arts applications, but others are often used in other applications.
     * <p>
     * To quantify the color characteristics of a device such as a printer
     * or monitor, measurements of XYZ values for particular device colors
     * are typically made.  For purposes of this discussion, the term
     * device XYZ values is used to mean the XYZ values that would be
     * measured from device colors using current CIE recommended practices.
     * <p>
     * Converting between device XYZ values and the PCS XYZ values taken as
     * arguments by this method corresponds to converting between the device's
     * color space, as represented by CIE colorimetric values, and the PCS.
     * There are many factors involved in this process, some of which are quite
     * subtle.  The most important, however, is the adjustment made to account
     * for differences between the device's white point and the white point of
     * the PCS.  There are many techniques for doing this and it is the
     * subject of much current research and controversy.  Some commonly used
     * methods are XYZ scaling, the von Kries transform, and the Bradford
     * transform.  The proper method to use depends upon each particular
     * application.
     * <p>
     * The simplest method is XYZ scaling.  In this method each device XYZ
     * value is  converted to a PCS XYZ value by multiplying it by the ratio
     * of the PCS white point (D50) to the device white point.
     * <pre>
     *
     * Xd, Yd, Zd are the device XYZ values
     * Xdw, Ydw, Zdw are the device XYZ white point values
     * Xp, Yp, Zp are the PCS XYZ values
     * Xd50, Yd50, Zd50 are the PCS XYZ white point values
     *
     * Xp = Xd * (Xd50 / Xdw)
     * Yp = Yd * (Yd50 / Ydw)
     * Zp = Zd * (Zd50 / Zdw)
     *
     * </pre>
     * <p>
     * Conversion from the PCS to the device would be done by inverting these
     * equations:
     * <pre>
     *
     * Xd = Xp * (Xdw / Xd50)
     * Yd = Yp * (Ydw / Yd50)
     * Zd = Zp * (Zdw / Zd50)
     *
     * </pre>
     * <p>
     * Note that the media white point tag in an ICC profile is not the same
     * as the device white point.  The media white point tag is expressed in
     * PCS values and is used to represent the difference between the XYZ of
     * device illuminant and the XYZ of the device media when measured under
     * that illuminant.  The device white point is expressed as the device
     * XYZ values corresponding to white displayed on the device.  For
     * example, displaying the RGB color (1.0, 1.0, 1.0) on an sRGB device
     * will result in a measured device XYZ value of D65.  This will not
     * be the same as the media white point tag XYZ value in the ICC
     * profile for an sRGB device.
     * <p>
     * @param colorvalue a float array with length of at least 3.
     * @return a float array with length equal to the number of
     *         components in this ColorSpace.
     * @throws ArrayIndexOutOfBoundsException if array length is not
     * at least 3.
     */
public float[] fromCIEXYZ(float[] colorvalue) {
    if (xyz2this == null) {
        ColorTransform[] transformList = new ColorTransform[2];
        ICC_ColorSpace xyzCS = (ICC_ColorSpace) ColorSpace.getInstance(CS_CIEXYZ);
        PCMM mdl = CMSManager.getModule();
        transformList[0] = mdl.createTransform(xyzCS.getProfile(), ColorTransform.Any, ColorTransform.In);
        try {
            transformList[1] = mdl.createTransform(thisProfile, ICC_Profile.icRelativeColorimetric, ColorTransform.Out);
        } catch (CMMException e) {
            transformList[1] = CMSManager.getModule().createTransform(thisProfile, ColorTransform.Any, ColorTransform.Out);
        }
        xyz2this = mdl.createTransform(transformList);
        if (needScaleInit) {
            setComponentScaling();
        }
    }
    short[] tmp = new short[3];
    float ALMOST_TWO = 1.0f + (32767.0f / 32768.0f);
    float factor = 65535.0f / ALMOST_TWO;
    // For CIEXYZ, min = 0.0, max = ALMOST_TWO for all components
    for (int i = 0; i < 3; i++) {
        tmp[i] = (short) ((colorvalue[i] * factor) + 0.5f);
    }
    tmp = xyz2this.colorConvert(tmp, null);
    int nc = this.getNumComponents();
    float[] result = new float[nc];
    for (int i = 0; i < nc; i++) {
        result[i] = (((float) (tmp[i] & 0xffff)) / 65535.0f) * diffMinMax[i] + minVal[i];
    }
    return result;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) PCMM(sun.java2d.cmm.PCMM)

Example 14 with ColorTransform

use of sun.java2d.cmm.ColorTransform in project checker-framework by typetools.

the class ColorModel method getGray16TosRGB8LUT.

/*
     * Return a byte LUT that converts 16-bit gray values in the grayCS
     * ColorSpace to the appropriate 8-bit sRGB value.  I.e., if lut
     * is the byte array returned by this method and sval = lut[gval],
     * then the sRGB triple (sval,sval,sval) is the best match to gval.
     * Cache references to any computed LUT in a Map.
     */
static byte[] getGray16TosRGB8LUT(ICC_ColorSpace grayCS) {
    if (isLinearGRAYspace(grayCS)) {
        return getLinearRGB16TosRGB8LUT();
    }
    if (g16Tos8Map != null) {
        byte[] g16Tos8LUT = g16Tos8Map.get(grayCS);
        if (g16Tos8LUT != null) {
            return g16Tos8LUT;
        }
    }
    short[] tmp = new short[65536];
    for (int i = 0; i <= 65535; i++) {
        tmp[i] = (short) i;
    }
    ColorTransform[] transformList = new ColorTransform[2];
    PCMM mdl = CMSManager.getModule();
    ICC_ColorSpace srgbCS = (ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
    transformList[0] = mdl.createTransform(grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
    transformList[1] = mdl.createTransform(srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
    ColorTransform t = mdl.createTransform(transformList);
    tmp = t.colorConvert(tmp, null);
    byte[] g16Tos8LUT = new byte[65536];
    for (int i = 0, j = 2; i <= 65535; i++, j += 3) {
        // All three components of tmp should be equal, since
        // the input color space to colorConvert is a gray scale
        // space.  However, there are slight anomalies in the results.
        // Copy tmp starting at index 2, since colorConvert seems
        // to be slightly more accurate for the third component!
        // scale unsigned short (0 - 65535) to unsigned byte (0 - 255)
        g16Tos8LUT[i] = (byte) (((float) (tmp[j] & 0xffff)) * (1.0f / 257.0f) + 0.5f);
    }
    if (g16Tos8Map == null) {
        g16Tos8Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, byte[]>(2));
    }
    g16Tos8Map.put(grayCS, g16Tos8LUT);
    return g16Tos8LUT;
}
Also used : ColorTransform(sun.java2d.cmm.ColorTransform) ICC_ColorSpace(java.awt.color.ICC_ColorSpace) PCMM(sun.java2d.cmm.PCMM) WeakHashMap(java.util.WeakHashMap)

Aggregations

ColorTransform (sun.java2d.cmm.ColorTransform)14 PCMM (sun.java2d.cmm.PCMM)14 ICC_ColorSpace (java.awt.color.ICC_ColorSpace)8 WeakHashMap (java.util.WeakHashMap)8 Point (java.awt.Point)2