Java Code Examples for java.awt.color.ColorSpace#toRGB()

The following examples show how to use java.awt.color.ColorSpace#toRGB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Color.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: DataConversionTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 3
Source File: DataConversionTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 4
Source File: Color.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: DataConversionTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 6
Source File: Color.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a color in the specified {@code ColorSpace}
 * with the color components specified in the {@code float}
 * array and the specified alpha.  The number of components is
 * determined by the type of the {@code ColorSpace}.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the {@code ColorSpace} to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the {@code ColorSpace}
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         {@code components} array or {@code alpha} 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);
}
 
Example 7
Source File: Color.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: Color.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a color in the specified {@code ColorSpace}
 * with the color components specified in the {@code float}
 * array and the specified alpha.  The number of components is
 * determined by the type of the {@code ColorSpace}.  For
 * example, RGB requires 3 components, but CMYK requires 4
 * components.
 * @param cspace the {@code ColorSpace} to be used to
 *                  interpret the components
 * @param components an arbitrary number of color components
 *                      that is compatible with the {@code ColorSpace}
 * @param alpha alpha value
 * @throws IllegalArgumentException if any of the values in the
 *         {@code components} array or {@code alpha} 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);
}
 
Example 9
Source File: DataConversionTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 10
Source File: DataConversionTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 11
Source File: Color.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: DataConversionTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 13
Source File: Color.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: Color.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: DataConversionTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 16
Source File: Color.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: Color.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: Color.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 19
Source File: DataConversionTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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.toRGB(val);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
Example 20
Source File: ImageConvert.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static BufferedImage cmyk2rgb(final byte[] buffer, final int w,
        final int h) throws IOException {

    final ColorSpace CMYK = ImageValue.adobeCmykColorSpace();

    final int pixelCount = w * h * 4;
    int C, M, Y, K, lastC = -1, lastM = -1, lastY = -1, lastK = -1;

    int j = 0;
    float[] RGB = new float[]{0f, 0f, 0f};
    //turn YCC in Buffer to CYM using profile
    for (int i = 0; i < pixelCount; i = i + 4) {

        C = (buffer[i] & 255);
        M = (buffer[i + 1] & 255);
        Y = (buffer[i + 2] & 255);
        K = (buffer[i + 3] & 255);

        // System.out.println(C+" "+M+" "+Y+" "+K);
        if (C == lastC && M == lastM && Y == lastY && K == lastK) {
            //no change so use last value
        } else { //new value

            RGB = CMYK.toRGB(new float[]{C / 255f, M / 255f, Y / 255f, K / 255f});

            //flag so we can just reuse if next value the same
            lastC = C;
            lastM = M;
            lastY = Y;
            lastK = K;
        }

        //put back as CMY
        buffer[j] = (byte) (RGB[0] * 255f);
        buffer[j + 1] = (byte) (RGB[1] * 255f);
        buffer[j + 2] = (byte) (RGB[2] * 255f);

        j = j + 3;

    }

    /**
     * create CMYK raster from buffer
     */
    final Raster raster = Raster.createInterleavedRaster(new DataBufferByte(buffer, j), w, h, w * 3, 3, new int[]{0, 1, 2}, null);

    //data now sRGB so create image
    final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    image.setData(raster);

    return image;
}