Java Code Examples for java.awt.color.ColorSpace#TYPE_RGB

The following examples show how to use java.awt.color.ColorSpace#TYPE_RGB . 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: ImageDump.java    From commons-imaging with Apache License 2.0 6 votes vote down vote up
private String colorSpaceTypeToName(final ColorSpace cs) {
    // System.out.println(prefix + ": " + "type: "
    // + cs.getType() );
    switch (cs.getType()) {
    case ColorSpace.TYPE_CMYK:
        return "TYPE_CMYK";
    case ColorSpace.TYPE_RGB:
        return "TYPE_RGB";

    case ColorSpace.CS_sRGB:
        return "CS_sRGB";
    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";
    default:
        return "unknown";
    }
}
 
Example 2
Source File: JPEG.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: JFIFMarkerSegment.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example 4
Source File: JPEGImageWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: JPEGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: JPEGImageWriter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: JPEG.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: JPEGImageWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: JPEGImageWriter.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: JPEG.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: BufferedBufImgOps.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**************************** RescaleOp support *****************************/

    public static boolean isRescaleOpValid(RescaleOp rop,
                                           BufferedImage srcImg)
    {
        int numFactors = rop.getNumFactors();
        ColorModel srcCM = srcImg.getColorModel();

        if (srcCM instanceof IndexColorModel) {
            throw new
                IllegalArgumentException("Rescaling cannot be "+
                                         "performed on an indexed image");
        }
        if (numFactors != 1 &&
            numFactors != srcCM.getNumColorComponents() &&
            numFactors != srcCM.getNumComponents())
        {
            throw new IllegalArgumentException("Number of scaling constants "+
                                               "does not equal the number of"+
                                               " of color or color/alpha "+
                                               " components");
        }

        int csType = srcCM.getColorSpace().getType();
        if (csType != ColorSpace.TYPE_RGB &&
            csType != ColorSpace.TYPE_GRAY)
        {
            // Not prepared to deal with other color spaces
            return false;
        }

        if (numFactors == 2 || numFactors > 4) {
            // Not really prepared to handle this at the native level, so...
            return false;
        }

        return true;
    }
 
Example 12
Source File: JPEGImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private int getDestCSType(ImageTypeSpecifier destType) {
ColorModel cm = destType.getColorModel();
boolean alpha = cm.hasAlpha();
ColorSpace cs = cm.getColorSpace();
int retval = JPEG.JCS_UNKNOWN;
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;
}
 
Example 13
Source File: JPEGImageWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: ImageTypeSpecifier.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public Packed(ColorSpace colorSpace,
              int redMask,
              int greenMask,
              int blueMask,
              int alphaMask, // 0 if no alpha
              int transferType,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (colorSpace.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException
            ("colorSpace is not of type TYPE_RGB!");
    }
    if (transferType != DataBuffer.TYPE_BYTE &&
        transferType != DataBuffer.TYPE_USHORT &&
        transferType != DataBuffer.TYPE_INT) {
        throw new IllegalArgumentException
            ("Bad value for transferType!");
    }
    if (redMask == 0 && greenMask == 0 &&
        blueMask == 0 && alphaMask == 0) {
        throw new IllegalArgumentException
            ("No mask has at least 1 bit set!");
    }
    this.colorSpace = colorSpace;
    this.redMask = redMask;
    this.greenMask = greenMask;
    this.blueMask = blueMask;
    this.alphaMask = alphaMask;
    this.transferType = transferType;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    int bits = 32;
    this.colorModel =
        new DirectColorModel(colorSpace,
                             bits,
                             redMask, greenMask, blueMask,
                             alphaMask, isAlphaPremultiplied,
                             transferType);
    this.sampleModel = colorModel.createCompatibleSampleModel(1, 1);
}
 
Example 15
Source File: ImageTypeSpecifier.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Packed(ColorSpace colorSpace,
              int redMask,
              int greenMask,
              int blueMask,
              int alphaMask, // 0 if no alpha
              int transferType,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (colorSpace.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException
            ("colorSpace is not of type TYPE_RGB!");
    }
    if (transferType != DataBuffer.TYPE_BYTE &&
        transferType != DataBuffer.TYPE_USHORT &&
        transferType != DataBuffer.TYPE_INT) {
        throw new IllegalArgumentException
            ("Bad value for transferType!");
    }
    if (redMask == 0 && greenMask == 0 &&
        blueMask == 0 && alphaMask == 0) {
        throw new IllegalArgumentException
            ("No mask has at least 1 bit set!");
    }
    this.colorSpace = colorSpace;
    this.redMask = redMask;
    this.greenMask = greenMask;
    this.blueMask = blueMask;
    this.alphaMask = alphaMask;
    this.transferType = transferType;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    int bits = 32;
    this.colorModel =
        new DirectColorModel(colorSpace,
                             bits,
                             redMask, greenMask, blueMask,
                             alphaMask, isAlphaPremultiplied,
                             transferType);
    this.sampleModel = colorModel.createCompatibleSampleModel(1, 1);
}
 
Example 16
Source File: Debug.java    From Pixelitor with GNU General Public License v3.0 4 votes vote down vote up
static String colorSpaceTypeAsString(int type) {
    switch (type) {
        case ColorSpace.TYPE_2CLR:
            return "2CLR";
        case ColorSpace.TYPE_3CLR:
            return "3CLR";
        case ColorSpace.TYPE_4CLR:
            return "4CLR";
        case ColorSpace.TYPE_5CLR:
            return "5CLR";
        case ColorSpace.TYPE_6CLR:
            return "6CLR";
        case ColorSpace.TYPE_7CLR:
            return "7CLR";
        case ColorSpace.TYPE_8CLR:
            return "8CLR";
        case ColorSpace.TYPE_9CLR:
            return "9CLR";
        case ColorSpace.TYPE_ACLR:
            return "ACLR";
        case ColorSpace.TYPE_BCLR:
            return "BCLR";
        case ColorSpace.TYPE_CCLR:
            return "CCLR";
        case ColorSpace.TYPE_CMY:
            return "CMY";
        case ColorSpace.TYPE_CMYK:
            return "CMYK";
        case ColorSpace.TYPE_DCLR:
            return "DCLR";
        case ColorSpace.TYPE_ECLR:
            return "ECLR";
        case ColorSpace.TYPE_FCLR:
            return "FCLR";
        case ColorSpace.TYPE_GRAY:
            return "GRAY";
        case ColorSpace.TYPE_HLS:
            return "HLS";
        case ColorSpace.TYPE_HSV:
            return "HSV";
        case ColorSpace.TYPE_Lab:
            return "Lab";
        case ColorSpace.TYPE_Luv:
            return "Luv";
        case ColorSpace.TYPE_RGB:
            return "RGB";
        case ColorSpace.TYPE_XYZ:
            return "XYZ";
        case ColorSpace.TYPE_YCbCr:
            return "YCbCr";
        case ColorSpace.TYPE_Yxy:
            return "Yxy";
        default:
            return "unrecognized (" + type + ")";
    }
}
 
Example 17
Source File: ImageTypeSpecifier.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
public Packed(ColorSpace colorSpace,
              int redMask,
              int greenMask,
              int blueMask,
              int alphaMask, // 0 if no alpha
              int transferType,
              boolean isAlphaPremultiplied) {
    if (colorSpace == null) {
        throw new IllegalArgumentException("colorSpace == null!");
    }
    if (colorSpace.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException
            ("colorSpace is not of type TYPE_RGB!");
    }
    if (transferType != DataBuffer.TYPE_BYTE &&
        transferType != DataBuffer.TYPE_USHORT &&
        transferType != DataBuffer.TYPE_INT) {
        throw new IllegalArgumentException
            ("Bad value for transferType!");
    }
    if (redMask == 0 && greenMask == 0 &&
        blueMask == 0 && alphaMask == 0) {
        throw new IllegalArgumentException
            ("No mask has at least 1 bit set!");
    }
    this.colorSpace = colorSpace;
    this.redMask = redMask;
    this.greenMask = greenMask;
    this.blueMask = blueMask;
    this.alphaMask = alphaMask;
    this.transferType = transferType;
    this.isAlphaPremultiplied = isAlphaPremultiplied;

    int bits = 32;
    this.colorModel =
        new DirectColorModel(colorSpace,
                             bits,
                             redMask, greenMask, blueMask,
                             alphaMask, isAlphaPremultiplied,
                             transferType);
    this.sampleModel = colorModel.createCompatibleSampleModel(1, 1);
}
 
Example 18
Source File: PackedColorModel.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a <code>PackedColorModel</code> from the specified
 * masks which indicate which bits in an <code>int</code> pixel
 * representation contain the alpha, red, green and blue color samples.
 * Color components are in the specified <code>ColorSpace</code>, which
 * must be of type ColorSpace.TYPE_RGB.  All of the bits in each
 * mask must be contiguous and fit in the specified number of
 * least significant bits of an <code>int</code> pixel representation.  If
 * <code>amask</code> is 0, there is no alpha.  If there is alpha,
 * the <code>boolean</code> <code>isAlphaPremultiplied</code>
 * specifies how to interpret color and alpha samples
 * in pixel values.  If the <code>boolean</code> is <code>true</code>,
 * color samples are assumed to have been multiplied by the alpha sample.
 * The transparency, <code>trans</code>, specifies what alpha values
 * can be represented by this color model.
 * The transfer type is the type of primitive array used to represent
 * pixel values.
 * @param space the specified <code>ColorSpace</code>
 * @param bits the number of bits in the pixel values
 * @param rmask specifies the mask representing
 *         the bits of the pixel values that represent the red
 *         color component
 * @param gmask specifies the mask representing
 *         the bits of the pixel values that represent the green
 *         color component
 * @param bmask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the blue color component
 * @param amask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the alpha component
 * @param isAlphaPremultiplied <code>true</code> if color samples are
 *        premultiplied by the alpha sample; <code>false</code> otherwise
 * @param trans specifies the alpha value that can be represented by
 *        this color model
 * @param transferType the type of array used to represent pixel values
 * @throws IllegalArgumentException if <code>space</code> is not a
 *         TYPE_RGB space
 * @see ColorSpace
 */
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
                        int bmask, int amask,
                        boolean isAlphaPremultiplied,
                        int trans, int transferType) {
    super (bits, PackedColorModel.createBitsArray(rmask, gmask, bmask,
                                                  amask),
           space, (amask == 0 ? false : true),
           isAlphaPremultiplied, trans, transferType);

    if (space.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException("ColorSpace must be TYPE_RGB.");
    }
    maskArray = new int[numComponents];
    maskOffsets = new int[numComponents];
    scaleFactors = new float[numComponents];

    DecomposeMask(rmask, 0, "red");

    DecomposeMask(gmask, 1, "green");

    DecomposeMask(bmask, 2, "blue");

    if (amask != 0) {
        DecomposeMask(amask, 3, "alpha");
        if (nBits[3] == 1) {
            transparency = Transparency.BITMASK;
        }
    }
}
 
Example 19
Source File: PackedColorModel.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a <code>PackedColorModel</code> from the specified
 * masks which indicate which bits in an <code>int</code> pixel
 * representation contain the alpha, red, green and blue color samples.
 * Color components are in the specified <code>ColorSpace</code>, which
 * must be of type ColorSpace.TYPE_RGB.  All of the bits in each
 * mask must be contiguous and fit in the specified number of
 * least significant bits of an <code>int</code> pixel representation.  If
 * <code>amask</code> is 0, there is no alpha.  If there is alpha,
 * the <code>boolean</code> <code>isAlphaPremultiplied</code>
 * specifies how to interpret color and alpha samples
 * in pixel values.  If the <code>boolean</code> is <code>true</code>,
 * color samples are assumed to have been multiplied by the alpha sample.
 * The transparency, <code>trans</code>, specifies what alpha values
 * can be represented by this color model.
 * The transfer type is the type of primitive array used to represent
 * pixel values.
 * @param space the specified <code>ColorSpace</code>
 * @param bits the number of bits in the pixel values
 * @param rmask specifies the mask representing
 *         the bits of the pixel values that represent the red
 *         color component
 * @param gmask specifies the mask representing
 *         the bits of the pixel values that represent the green
 *         color component
 * @param bmask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the blue color component
 * @param amask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the alpha component
 * @param isAlphaPremultiplied <code>true</code> if color samples are
 *        premultiplied by the alpha sample; <code>false</code> otherwise
 * @param trans specifies the alpha value that can be represented by
 *        this color model
 * @param transferType the type of array used to represent pixel values
 * @throws IllegalArgumentException if <code>space</code> is not a
 *         TYPE_RGB space
 * @see ColorSpace
 */
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
                        int bmask, int amask,
                        boolean isAlphaPremultiplied,
                        int trans, int transferType) {
    super (bits, PackedColorModel.createBitsArray(rmask, gmask, bmask,
                                                  amask),
           space, (amask == 0 ? false : true),
           isAlphaPremultiplied, trans, transferType);

    if (space.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException("ColorSpace must be TYPE_RGB.");
    }
    maskArray = new int[numComponents];
    maskOffsets = new int[numComponents];
    scaleFactors = new float[numComponents];

    DecomposeMask(rmask, 0, "red");

    DecomposeMask(gmask, 1, "green");

    DecomposeMask(bmask, 2, "blue");

    if (amask != 0) {
        DecomposeMask(amask, 3, "alpha");
        if (nBits[3] == 1) {
            transparency = Transparency.BITMASK;
        }
    }
}
 
Example 20
Source File: PackedColorModel.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Constructs a <code>PackedColorModel</code> from the specified
 * masks which indicate which bits in an <code>int</code> pixel
 * representation contain the alpha, red, green and blue color samples.
 * Color components are in the specified <code>ColorSpace</code>, which
 * must be of type ColorSpace.TYPE_RGB.  All of the bits in each
 * mask must be contiguous and fit in the specified number of
 * least significant bits of an <code>int</code> pixel representation.  If
 * <code>amask</code> is 0, there is no alpha.  If there is alpha,
 * the <code>boolean</code> <code>isAlphaPremultiplied</code>
 * specifies how to interpret color and alpha samples
 * in pixel values.  If the <code>boolean</code> is <code>true</code>,
 * color samples are assumed to have been multiplied by the alpha sample.
 * The transparency, <code>trans</code>, specifies what alpha values
 * can be represented by this color model.
 * The transfer type is the type of primitive array used to represent
 * pixel values.
 * @param space the specified <code>ColorSpace</code>
 * @param bits the number of bits in the pixel values
 * @param rmask specifies the mask representing
 *         the bits of the pixel values that represent the red
 *         color component
 * @param gmask specifies the mask representing
 *         the bits of the pixel values that represent the green
 *         color component
 * @param bmask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the blue color component
 * @param amask specifies the mask representing
 *         the bits of the pixel values that represent
 *         the alpha component
 * @param isAlphaPremultiplied <code>true</code> if color samples are
 *        premultiplied by the alpha sample; <code>false</code> otherwise
 * @param trans specifies the alpha value that can be represented by
 *        this color model
 * @param transferType the type of array used to represent pixel values
 * @throws IllegalArgumentException if <code>space</code> is not a
 *         TYPE_RGB space
 * @see ColorSpace
 */
public PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
                        int bmask, int amask,
                        boolean isAlphaPremultiplied,
                        int trans, int transferType) {
    super (bits, PackedColorModel.createBitsArray(rmask, gmask, bmask,
                                                  amask),
           space, (amask == 0 ? false : true),
           isAlphaPremultiplied, trans, transferType);

    if (space.getType() != ColorSpace.TYPE_RGB) {
        throw new IllegalArgumentException("ColorSpace must be TYPE_RGB.");
    }
    maskArray = new int[numComponents];
    maskOffsets = new int[numComponents];
    scaleFactors = new float[numComponents];

    DecomposeMask(rmask, 0, "red");

    DecomposeMask(gmask, 1, "green");

    DecomposeMask(bmask, 2, "blue");

    if (amask != 0) {
        DecomposeMask(amask, 3, "alpha");
        if (nBits[3] == 1) {
            transparency = Transparency.BITMASK;
        }
    }
}