Example usage for java.awt.image ColorModel getNormalizedComponents

List of usage examples for java.awt.image ColorModel getNormalizedComponents

Introduction

In this page you can find the example usage for java.awt.image ColorModel getNormalizedComponents.

Prototype

public float[] getNormalizedComponents(int[] components, int offset, float[] normComponents, int normOffset) 

Source Link

Document

Returns an array of all of the color/alpha components in normalized form, given an unnormalized component array.

Usage

From source file:ComponentTest.java

public static void main(String[] args) {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE,
            DataBuffer.TYPE_BYTE);

    Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0);
    float[] components = fifty.getComponents(null);
    System.out.print("Original normalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(components[i] + " ");
    System.out.println();//from   w w  w  .  ja  v  a2s .c  om
    int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0);
    System.out.print("Original unnormalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(unnormalized[i] + " ");
    System.out.println();
    Object pixel = cm.getDataElements(unnormalized, 0, (Object) null);
    System.out.print("Pixel samples: ");
    byte[] pixelBytes = (byte[]) pixel;
    for (int i = 0; i < 3; i++)
        System.out.print(pixelBytes[i] + " ");
    System.out.println();

    unnormalized = cm.getComponents(pixel, null, 0);
    System.out.print("Derived unnormalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(unnormalized[i] + " ");
    System.out.println();
    components = cm.getNormalizedComponents(unnormalized, 0, null, 0);
    System.out.print("Derived normalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(components[i] + " ");
    System.out.println();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(cs, new int[] { 5, 6, 5 }, false, false, Transparency.OPAQUE,
            DataBuffer.TYPE_BYTE);

    Color fifty = new Color(cs, new float[] { 1.0f, 1.0f, 1.0f }, 0);
    float[] components = fifty.getComponents(null);
    System.out.print("Original normalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(components[i] + " ");
    System.out.println();/*www  . j a  va 2 s .  co m*/
    int[] unnormalized = cm.getUnnormalizedComponents(components, 0, null, 0);
    System.out.print("Original unnormalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(unnormalized[i] + " ");
    System.out.println();

    Object pixel = cm.getDataElements(unnormalized, 0, (Object) null);
    System.out.print("Pixel samples: ");
    byte[] pixelBytes = (byte[]) pixel;
    for (int i = 0; i < 3; i++)
        System.out.print(pixelBytes[i] + " ");
    System.out.println();

    unnormalized = cm.getComponents(pixel, null, 0);
    System.out.print("Derived unnormalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(unnormalized[i] + " ");
    System.out.println();
    components = cm.getNormalizedComponents(unnormalized, 0, null, 0);
    System.out.print("Derived normalized components: ");
    for (int i = 0; i < 3; i++)
        System.out.print(components[i] + " ");
}