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

The following examples show how to use java.awt.color.ColorSpace#getType() . 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: JPEGImageWriter.java    From Bytecoder with Apache License 2.0 6 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:
        retval = JPEG.JCS_RGB;
        break;
    case ColorSpace.TYPE_YCbCr:
        retval = JPEG.JCS_YCbCr;
        break;
    case ColorSpace.TYPE_CMYK:
        retval = JPEG.JCS_CMYK;
        break;
    }
return retval;
}
 
Example 3
Source File: JPEGImageWriter.java    From jdk8u_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 4
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 5
Source File: JPEGImageWriter.java    From openjdk-jdk8u 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 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 7
Source File: JPEGImageWriter.java    From JDKSourceCode1.8 with MIT License 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 8
Source File: JPEGImageWriter.java    From openjdk-8-source 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 9
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 10
Source File: JPEGImageWriter.java    From jdk8u60 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 11
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 12
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 13
Source File: JPEGImageWriter.java    From openjdk-jdk8u-backup 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 14
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 15
Source File: LosslessFactory.java    From sambox with Apache License 2.0 4 votes vote down vote up
private PDImageXObject preparePredictorPDImage(FastByteArrayOutputStream stream,
        int bitsPerComponent) throws IOException
{
    int h = image.getHeight();
    int w = image.getWidth();

    ColorSpace srcCspace = image.getColorModel().getColorSpace();
    int srcCspaceType = srcCspace.getType();
    PDColorSpace pdColorSpace = srcCspaceType == ColorSpace.TYPE_CMYK
            ? PDDeviceCMYK.INSTANCE : (srcCspaceType == ColorSpace.TYPE_GRAY
                    ? PDDeviceGray.INSTANCE : PDDeviceRGB.INSTANCE);

    // Encode the image profile if the image has one
    if (srcCspace instanceof ICC_ColorSpace)
    {
        ICC_Profile profile = ((ICC_ColorSpace) srcCspace).getProfile();
        // We only encode a color profile if it is not sRGB
        if (profile != ICC_Profile.getInstance(ColorSpace.CS_sRGB))
        {
            PDICCBased pdProfile = new PDICCBased();
            OutputStream outputStream = pdProfile.getPDStream()
                    .createOutputStream(COSName.FLATE_DECODE);
            outputStream.write(profile.getData());
            outputStream.close();
            pdProfile.getPDStream().getCOSObject().setInt(COSName.N,
                    srcCspace.getNumComponents());
            pdProfile.getPDStream().getCOSObject().setItem(COSName.ALTERNATE,
                    srcCspaceType == ColorSpace.TYPE_GRAY ? COSName.DEVICEGRAY
                            : (srcCspaceType == ColorSpace.TYPE_CMYK ? COSName.DEVICECMYK
                                    : COSName.DEVICERGB));
            pdColorSpace = pdProfile;
        }
    }

    PDImageXObject imageXObject = new PDImageXObject(
            new ByteArrayInputStream(stream.toByteArray()), COSName.FLATE_DECODE, w, h,
            bitsPerComponent, pdColorSpace);

    COSDictionary decodeParms = new COSDictionary();
    decodeParms.setItem(COSName.BITS_PER_COMPONENT, COSInteger.get(bitsPerComponent));
    decodeParms.setItem(COSName.PREDICTOR, COSInteger.get(15));
    decodeParms.setItem(COSName.COLUMNS, COSInteger.get(w));
    decodeParms.setItem(COSName.COLORS, COSInteger.get(srcCspace.getNumComponents()));
    imageXObject.getCOSObject().setItem(COSName.DECODE_PARMS, decodeParms);

    if (image.getTransparency() != Transparency.OPAQUE)
    {
        PDImageXObject pdMask = prepareImageXObject(alphaImageData, image.getWidth(),
                image.getHeight(), 8 * bytesPerComponent, PDDeviceGray.INSTANCE);
        imageXObject.getCOSObject().setItem(COSName.SMASK, pdMask);
    }
    return imageXObject;
}
 
Example 16
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 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: ImageTypeSpecifier.java    From openjdk-8-source 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 19
Source File: PackedColorModel.java    From jdk8u-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 hottub 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;
        }
    }
}