0N/A/*
2362N/A * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio;
0N/A
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Transparency;
0N/Aimport java.awt.image.BandedSampleModel;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.color.ColorSpace;
0N/Aimport java.awt.image.IndexColorModel;
0N/Aimport java.awt.image.ComponentColorModel;
0N/Aimport java.awt.image.DataBuffer;
0N/Aimport java.awt.image.DirectColorModel;
0N/Aimport java.awt.image.MultiPixelPackedSampleModel;
0N/Aimport java.awt.image.PixelInterleavedSampleModel;
0N/Aimport java.awt.image.SinglePixelPackedSampleModel;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.awt.image.SampleModel;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport java.util.Hashtable;
0N/A
0N/A/**
0N/A * A class that allows the format of an image (in particular, its
0N/A * <code>SampleModel</code> and <code>ColorModel</code>) to be
0N/A * specified in a convenient manner.
0N/A *
0N/A */
0N/Apublic class ImageTypeSpecifier {
0N/A
0N/A /**
0N/A * The <code>ColorModel</code> to be used as a prototype.
0N/A */
0N/A protected ColorModel colorModel;
0N/A
0N/A /**
0N/A * A <code>SampleModel</code> to be used as a prototype.
0N/A */
0N/A protected SampleModel sampleModel;
0N/A
0N/A /**
0N/A * Cached specifiers for all of the standard
0N/A * <code>BufferedImage</code> types.
0N/A */
0N/A private static ImageTypeSpecifier[] BISpecifier;
989N/A private static ColorSpace sRGB;
0N/A // Initialize the standard specifiers
0N/A static {
989N/A sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
0N/A
0N/A BISpecifier =
0N/A new ImageTypeSpecifier[BufferedImage.TYPE_BYTE_INDEXED + 1];
0N/A }
0N/A
0N/A /**
0N/A * A constructor to be used by inner subclasses only.
0N/A */
0N/A private ImageTypeSpecifier() {}
0N/A
0N/A /**
0N/A * Constructs an <code>ImageTypeSpecifier</code> directly
0N/A * from a <code>ColorModel</code> and a <code>SampleModel</code>.
0N/A * It is the caller's responsibility to supply compatible
0N/A * parameters.
0N/A *
0N/A * @param colorModel a <code>ColorModel</code>.
0N/A * @param sampleModel a <code>SampleModel</code>.
0N/A *
0N/A * @exception IllegalArgumentException if either parameter is
0N/A * <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>sampleModel</code>
0N/A * is not compatible with <code>colorModel</code>.
0N/A */
0N/A public ImageTypeSpecifier(ColorModel colorModel, SampleModel sampleModel) {
0N/A if (colorModel == null) {
0N/A throw new IllegalArgumentException("colorModel == null!");
0N/A }
0N/A if (sampleModel == null) {
0N/A throw new IllegalArgumentException("sampleModel == null!");
0N/A }
0N/A if (!colorModel.isCompatibleSampleModel(sampleModel)) {
0N/A throw new IllegalArgumentException
0N/A ("sampleModel is incompatible with colorModel!");
0N/A }
0N/A this.colorModel = colorModel;
0N/A this.sampleModel = sampleModel;
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>ImageTypeSpecifier</code> from a
0N/A * <code>RenderedImage</code>. If a <code>BufferedImage</code> is
0N/A * being used, one of the factory methods
0N/A * <code>createFromRenderedImage</code> or
0N/A * <code>createFromBufferedImageType</code> should be used instead in
0N/A * order to get a more accurate result.
0N/A *
0N/A * @param image a <code>RenderedImage</code>.
0N/A *
0N/A * @exception IllegalArgumentException if the argument is
0N/A * <code>null</code>.
0N/A */
0N/A public ImageTypeSpecifier(RenderedImage image) {
0N/A if (image == null) {
0N/A throw new IllegalArgumentException("image == null!");
0N/A }
0N/A colorModel = image.getColorModel();
0N/A sampleModel = image.getSampleModel();
0N/A }
0N/A
0N/A // Packed
0N/A
0N/A static class Packed extends ImageTypeSpecifier {
0N/A ColorSpace colorSpace;
0N/A int redMask;
0N/A int greenMask;
0N/A int blueMask;
0N/A int alphaMask;
0N/A int transferType;
0N/A boolean isAlphaPremultiplied;
0N/A
0N/A public Packed(ColorSpace colorSpace,
0N/A int redMask,
0N/A int greenMask,
0N/A int blueMask,
0N/A int alphaMask, // 0 if no alpha
0N/A int transferType,
0N/A boolean isAlphaPremultiplied) {
0N/A if (colorSpace == null) {
0N/A throw new IllegalArgumentException("colorSpace == null!");
0N/A }
0N/A if (colorSpace.getType() != ColorSpace.TYPE_RGB) {
0N/A throw new IllegalArgumentException
0N/A ("colorSpace is not of type TYPE_RGB!");
0N/A }
0N/A if (transferType != DataBuffer.TYPE_BYTE &&
0N/A transferType != DataBuffer.TYPE_USHORT &&
0N/A transferType != DataBuffer.TYPE_INT) {
0N/A throw new IllegalArgumentException
0N/A ("Bad value for transferType!");
0N/A }
0N/A if (redMask == 0 && greenMask == 0 &&
0N/A blueMask == 0 && alphaMask == 0) {
0N/A throw new IllegalArgumentException
0N/A ("No mask has at least 1 bit set!");
0N/A }
0N/A this.colorSpace = colorSpace;
0N/A this.redMask = redMask;
0N/A this.greenMask = greenMask;
0N/A this.blueMask = blueMask;
0N/A this.alphaMask = alphaMask;
0N/A this.transferType = transferType;
0N/A this.isAlphaPremultiplied = isAlphaPremultiplied;
0N/A
0N/A int bits = 32;
0N/A this.colorModel =
0N/A new DirectColorModel(colorSpace,
0N/A bits,
0N/A redMask, greenMask, blueMask,
0N/A alphaMask, isAlphaPremultiplied,
0N/A transferType);
0N/A this.sampleModel = colorModel.createCompatibleSampleModel(1, 1);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for a packed image format that will use a
0N/A * <code>DirectColorModel</code> and a packed
0N/A * <code>SampleModel</code> to store each pixel packed into in a
0N/A * single byte, short, or int.
0N/A *
0N/A * @param colorSpace the desired <code>ColorSpace</code>.
0N/A * @param redMask a contiguous mask indicated the position of the
0N/A * red channel.
0N/A * @param greenMask a contiguous mask indicated the position of the
0N/A * green channel.
0N/A * @param blueMask a contiguous mask indicated the position of the
0N/A * blue channel.
0N/A * @param alphaMask a contiguous mask indicated the position of the
0N/A * alpha channel.
0N/A * @param transferType the desired <code>SampleModel</code> transfer type.
0N/A * @param isAlphaPremultiplied <code>true</code> if the color channels
0N/A * will be premultipled by the alpha channel.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>colorSpace</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>colorSpace</code>
0N/A * is not of type <code>TYPE_RGB</code>.
0N/A * @exception IllegalArgumentException if no mask has at least 1
0N/A * bit set.
0N/A * @exception IllegalArgumentException if
0N/A * <code>transferType</code> if not one of
0N/A * <code>DataBuffer.TYPE_BYTE</code>,
0N/A * <code>DataBuffer.TYPE_USHORT</code>, or
0N/A * <code>DataBuffer.TYPE_INT</code>.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createPacked(ColorSpace colorSpace,
0N/A int redMask,
0N/A int greenMask,
0N/A int blueMask,
0N/A int alphaMask, // 0 if no alpha
0N/A int transferType,
0N/A boolean isAlphaPremultiplied) {
0N/A return new ImageTypeSpecifier.Packed(colorSpace,
0N/A redMask,
0N/A greenMask,
0N/A blueMask,
0N/A alphaMask, // 0 if no alpha
0N/A transferType,
0N/A isAlphaPremultiplied);
0N/A }
0N/A
0N/A static ColorModel createComponentCM(ColorSpace colorSpace,
0N/A int numBands,
0N/A int dataType,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied) {
0N/A int transparency =
0N/A hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
0N/A
0N/A int[] numBits = new int[numBands];
0N/A int bits = DataBuffer.getDataTypeSize(dataType);
0N/A
0N/A for (int i = 0; i < numBands; i++) {
0N/A numBits[i] = bits;
0N/A }
0N/A
0N/A return new ComponentColorModel(colorSpace,
0N/A numBits,
0N/A hasAlpha,
0N/A isAlphaPremultiplied,
0N/A transparency,
0N/A dataType);
0N/A }
0N/A
0N/A // Interleaved
0N/A
0N/A static class Interleaved extends ImageTypeSpecifier {
0N/A ColorSpace colorSpace;
0N/A int[] bandOffsets;
0N/A int dataType;
0N/A boolean hasAlpha;
0N/A boolean isAlphaPremultiplied;
0N/A
0N/A public Interleaved(ColorSpace colorSpace,
0N/A int[] bandOffsets,
0N/A int dataType,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied) {
0N/A if (colorSpace == null) {
0N/A throw new IllegalArgumentException("colorSpace == null!");
0N/A }
0N/A if (bandOffsets == null) {
0N/A throw new IllegalArgumentException("bandOffsets == null!");
0N/A }
0N/A int numBands = colorSpace.getNumComponents() +
0N/A (hasAlpha ? 1 : 0);
0N/A if (bandOffsets.length != numBands) {
0N/A throw new IllegalArgumentException
0N/A ("bandOffsets.length is wrong!");
0N/A }
0N/A if (dataType != DataBuffer.TYPE_BYTE &&
0N/A dataType != DataBuffer.TYPE_SHORT &&
0N/A dataType != DataBuffer.TYPE_USHORT &&
0N/A dataType != DataBuffer.TYPE_INT &&
0N/A dataType != DataBuffer.TYPE_FLOAT &&
0N/A dataType != DataBuffer.TYPE_DOUBLE) {
0N/A throw new IllegalArgumentException
0N/A ("Bad value for dataType!");
0N/A }
0N/A this.colorSpace = colorSpace;
0N/A this.bandOffsets = (int[])bandOffsets.clone();
0N/A this.dataType = dataType;
0N/A this.hasAlpha = hasAlpha;
0N/A this.isAlphaPremultiplied = isAlphaPremultiplied;
0N/A
0N/A this.colorModel =
0N/A ImageTypeSpecifier.createComponentCM(colorSpace,
0N/A bandOffsets.length,
0N/A dataType,
0N/A hasAlpha,
0N/A isAlphaPremultiplied);
0N/A
0N/A int minBandOffset = bandOffsets[0];
0N/A int maxBandOffset = minBandOffset;
0N/A for (int i = 0; i < bandOffsets.length; i++) {
0N/A int offset = bandOffsets[i];
0N/A minBandOffset = Math.min(offset, minBandOffset);
0N/A maxBandOffset = Math.max(offset, maxBandOffset);
0N/A }
0N/A int pixelStride = maxBandOffset - minBandOffset + 1;
0N/A
0N/A int w = 1;
0N/A int h = 1;
0N/A this.sampleModel =
0N/A new PixelInterleavedSampleModel(dataType,
0N/A w, h,
0N/A pixelStride,
0N/A w*pixelStride,
0N/A bandOffsets);
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if ((o == null) ||
0N/A !(o instanceof ImageTypeSpecifier.Interleaved)) {
0N/A return false;
0N/A }
0N/A
0N/A ImageTypeSpecifier.Interleaved that =
0N/A (ImageTypeSpecifier.Interleaved)o;
0N/A
0N/A if ((!(this.colorSpace.equals(that.colorSpace))) ||
0N/A (this.dataType != that.dataType) ||
0N/A (this.hasAlpha != that.hasAlpha) ||
0N/A (this.isAlphaPremultiplied != that.isAlphaPremultiplied) ||
0N/A (this.bandOffsets.length != that.bandOffsets.length)) {
0N/A return false;
0N/A }
0N/A
0N/A for (int i = 0; i < bandOffsets.length; i++) {
0N/A if (this.bandOffsets[i] != that.bandOffsets[i]) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A return true;
0N/A }
0N/A
0N/A public int hashCode() {
0N/A return (super.hashCode() +
0N/A (4 * bandOffsets.length) +
0N/A (25 * dataType) +
0N/A (hasAlpha ? 17 : 18));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for an interleaved image format that will
0N/A * use a <code>ComponentColorModel</code> and a
0N/A * <code>PixelInterleavedSampleModel</code> to store each pixel
0N/A * component in a separate byte, short, or int.
0N/A *
0N/A * @param colorSpace the desired <code>ColorSpace</code>.
0N/A * @param bandOffsets an array of <code>int</code>s indicating the
0N/A * offsets for each band.
0N/A * @param dataType the desired data type, as one of the enumerations
0N/A * from the <code>DataBuffer</code> class.
0N/A * @param hasAlpha <code>true</code> if an alpha channel is desired.
0N/A * @param isAlphaPremultiplied <code>true</code> if the color channels
0N/A * will be premultipled by the alpha channel.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>colorSpace</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>bandOffsets</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>dataType</code> is
0N/A * not one of the legal <code>DataBuffer.TYPE_*</code> constants.
0N/A * @exception IllegalArgumentException if
0N/A * <code>bandOffsets.length</code> does not equal the number of
0N/A * color space components, plus 1 if <code>hasAlpha</code> is
0N/A * <code>true</code>.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createInterleaved(ColorSpace colorSpace,
0N/A int[] bandOffsets,
0N/A int dataType,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied) {
0N/A return new ImageTypeSpecifier.Interleaved(colorSpace,
0N/A bandOffsets,
0N/A dataType,
0N/A hasAlpha,
0N/A isAlphaPremultiplied);
0N/A }
0N/A
0N/A // Banded
0N/A
0N/A static class Banded extends ImageTypeSpecifier {
0N/A ColorSpace colorSpace;
0N/A int[] bankIndices;
0N/A int[] bandOffsets;
0N/A int dataType;
0N/A boolean hasAlpha;
0N/A boolean isAlphaPremultiplied;
0N/A
0N/A public Banded(ColorSpace colorSpace,
0N/A int[] bankIndices,
0N/A int[] bandOffsets,
0N/A int dataType,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied) {
0N/A if (colorSpace == null) {
0N/A throw new IllegalArgumentException("colorSpace == null!");
0N/A }
0N/A if (bankIndices == null) {
0N/A throw new IllegalArgumentException("bankIndices == null!");
0N/A }
0N/A if (bandOffsets == null) {
0N/A throw new IllegalArgumentException("bandOffsets == null!");
0N/A }
0N/A if (bankIndices.length != bandOffsets.length) {
0N/A throw new IllegalArgumentException
0N/A ("bankIndices.length != bandOffsets.length!");
0N/A }
0N/A if (dataType != DataBuffer.TYPE_BYTE &&
0N/A dataType != DataBuffer.TYPE_SHORT &&
0N/A dataType != DataBuffer.TYPE_USHORT &&
0N/A dataType != DataBuffer.TYPE_INT &&
0N/A dataType != DataBuffer.TYPE_FLOAT &&
0N/A dataType != DataBuffer.TYPE_DOUBLE) {
0N/A throw new IllegalArgumentException
0N/A ("Bad value for dataType!");
0N/A }
0N/A int numBands = colorSpace.getNumComponents() +
0N/A (hasAlpha ? 1 : 0);
0N/A if (bandOffsets.length != numBands) {
0N/A throw new IllegalArgumentException
0N/A ("bandOffsets.length is wrong!");
0N/A }
0N/A
0N/A this.colorSpace = colorSpace;
0N/A this.bankIndices = (int[])bankIndices.clone();
0N/A this.bandOffsets = (int[])bandOffsets.clone();
0N/A this.dataType = dataType;
0N/A this.hasAlpha = hasAlpha;
0N/A this.isAlphaPremultiplied = isAlphaPremultiplied;
0N/A
0N/A this.colorModel =
0N/A ImageTypeSpecifier.createComponentCM(colorSpace,
0N/A bankIndices.length,
0N/A dataType,
0N/A hasAlpha,
0N/A isAlphaPremultiplied);
0N/A
0N/A int w = 1;
0N/A int h = 1;
0N/A this.sampleModel = new BandedSampleModel(dataType,
0N/A w, h,
0N/A w,
0N/A bankIndices,
0N/A bandOffsets);
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if ((o == null) ||
0N/A !(o instanceof ImageTypeSpecifier.Banded)) {
0N/A return false;
0N/A }
0N/A
0N/A ImageTypeSpecifier.Banded that =
0N/A (ImageTypeSpecifier.Banded)o;
0N/A
0N/A if ((!(this.colorSpace.equals(that.colorSpace))) ||
0N/A (this.dataType != that.dataType) ||
0N/A (this.hasAlpha != that.hasAlpha) ||
0N/A (this.isAlphaPremultiplied != that.isAlphaPremultiplied) ||
0N/A (this.bankIndices.length != that.bankIndices.length) ||
0N/A (this.bandOffsets.length != that.bandOffsets.length)) {
0N/A return false;
0N/A }
0N/A
0N/A for (int i = 0; i < bankIndices.length; i++) {
0N/A if (this.bankIndices[i] != that.bankIndices[i]) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A for (int i = 0; i < bandOffsets.length; i++) {
0N/A if (this.bandOffsets[i] != that.bandOffsets[i]) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A return true;
0N/A }
0N/A
0N/A public int hashCode() {
0N/A return (super.hashCode() +
0N/A (3 * bandOffsets.length) +
0N/A (7 * bankIndices.length) +
0N/A (21 * dataType) +
0N/A (hasAlpha ? 19 : 29));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for a banded image format that will use a
0N/A * <code>ComponentColorModel</code> and a
0N/A * <code>BandedSampleModel</code> to store each channel in a
0N/A * separate array.
0N/A *
0N/A * @param colorSpace the desired <code>ColorSpace</code>.
0N/A * @param bankIndices an array of <code>int</code>s indicating the
0N/A * bank in which each band will be stored.
0N/A * @param bandOffsets an array of <code>int</code>s indicating the
0N/A * starting offset of each band within its bank.
0N/A * @param dataType the desired data type, as one of the enumerations
0N/A * from the <code>DataBuffer</code> class.
0N/A * @param hasAlpha <code>true</code> if an alpha channel is desired.
0N/A * @param isAlphaPremultiplied <code>true</code> if the color channels
0N/A * will be premultipled by the alpha channel.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>colorSpace</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>bankIndices</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>bandOffsets</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if the lengths of
0N/A * <code>bankIndices</code> and <code>bandOffsets</code> differ.
0N/A * @exception IllegalArgumentException if
0N/A * <code>bandOffsets.length</code> does not equal the number of
0N/A * color space components, plus 1 if <code>hasAlpha</code> is
0N/A * <code>true</code>.
0N/A * @exception IllegalArgumentException if <code>dataType</code> is
0N/A * not one of the legal <code>DataBuffer.TYPE_*</code> constants.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createBanded(ColorSpace colorSpace,
0N/A int[] bankIndices,
0N/A int[] bandOffsets,
0N/A int dataType,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied) {
0N/A return new ImageTypeSpecifier.Banded(colorSpace,
0N/A bankIndices,
0N/A bandOffsets,
0N/A dataType,
0N/A hasAlpha,
0N/A isAlphaPremultiplied);
0N/A }
0N/A
0N/A // Grayscale
0N/A
0N/A static class Grayscale extends ImageTypeSpecifier {
0N/A int bits;
0N/A int dataType;
0N/A boolean isSigned;
0N/A boolean hasAlpha;
0N/A boolean isAlphaPremultiplied;
0N/A
0N/A public Grayscale(int bits,
0N/A int dataType,
0N/A boolean isSigned,
0N/A boolean hasAlpha,
0N/A boolean isAlphaPremultiplied)
0N/A {
0N/A if (bits != 1 && bits != 2 && bits != 4 &&
0N/A bits != 8 && bits != 16)
0N/A {
0N/A throw new IllegalArgumentException("Bad value for bits!");
0N/A }
0N/A if (dataType != DataBuffer.TYPE_BYTE &&
0N/A dataType != DataBuffer.TYPE_SHORT &&
0N/A dataType != DataBuffer.TYPE_USHORT)
0N/A {
0N/A throw new IllegalArgumentException
0N/A ("Bad value for dataType!");
0N/A }
0N/A if (bits > 8 && dataType == DataBuffer.TYPE_BYTE) {
0N/A throw new IllegalArgumentException
0N/A ("Too many bits for dataType!");
0N/A }
0N/A
0N/A this.bits = bits;
0N/A this.dataType = dataType;
0N/A this.isSigned = isSigned;
0N/A this.hasAlpha = hasAlpha;
0N/A this.isAlphaPremultiplied = isAlphaPremultiplied;
0N/A
0N/A ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_GRAY);
0N/A
0N/A if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
0N/A (bits == 16 &&
0N/A (dataType == DataBuffer.TYPE_SHORT ||
0N/A dataType == DataBuffer.TYPE_USHORT))) {
0N/A // Use component color model & sample model
0N/A
0N/A int numBands = hasAlpha ? 2 : 1;
0N/A int transparency =
0N/A hasAlpha ? Transparency.TRANSLUCENT : Transparency.OPAQUE;
0N/A
0N/A
0N/A int[] nBits = new int[numBands];
0N/A nBits[0] = bits;
0N/A if (numBands == 2) {
0N/A nBits[1] = bits;
0N/A }
0N/A this.colorModel =
0N/A new ComponentColorModel(colorSpace,
0N/A nBits,
0N/A hasAlpha,
0N/A isAlphaPremultiplied,
0N/A transparency,
0N/A dataType);
0N/A
0N/A int[] bandOffsets = new int[numBands];
0N/A bandOffsets[0] = 0;
0N/A if (numBands == 2) {
0N/A bandOffsets[1] = 1;
0N/A }
0N/A
0N/A int w = 1;
0N/A int h = 1;
0N/A this.sampleModel =
0N/A new PixelInterleavedSampleModel(dataType,
0N/A w, h,
0N/A numBands, w*numBands,
0N/A bandOffsets);
0N/A } else {
0N/A int numEntries = 1 << bits;
0N/A byte[] arr = new byte[numEntries];
0N/A for (int i = 0; i < numEntries; i++) {
0N/A arr[i] = (byte)(i*255/(numEntries - 1));
0N/A }
0N/A this.colorModel =
0N/A new IndexColorModel(bits, numEntries, arr, arr, arr);
0N/A
0N/A this.sampleModel =
0N/A new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for a grayscale image format that will pack
0N/A * pixels of the given bit depth into array elements of
0N/A * the specified data type.
0N/A *
0N/A * @param bits the number of bits per gray value (1, 2, 4, 8, or 16).
0N/A * @param dataType the desired data type, as one of the enumerations
0N/A * from the <code>DataBuffer</code> class.
0N/A * @param isSigned <code>true</code> if negative values are to
0N/A * be represented.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * not one of 1, 2, 4, 8, or 16.
0N/A * @exception IllegalArgumentException if <code>dataType</code> is
0N/A * not one of <code>DataBuffer.TYPE_BYTE</code>,
0N/A * <code>DataBuffer.TYPE_SHORT</code>, or
0N/A * <code>DataBuffer.TYPE_USHORT</code>.
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * larger than the bit size of the given <code>dataType</code>.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createGrayscale(int bits,
0N/A int dataType,
0N/A boolean isSigned) {
0N/A return new ImageTypeSpecifier.Grayscale(bits,
0N/A dataType,
0N/A isSigned,
0N/A false,
0N/A false);
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for a grayscale plus alpha image format
0N/A * that will pack pixels of the given bit depth into array
0N/A * elements of the specified data type.
0N/A *
0N/A * @param bits the number of bits per gray value (1, 2, 4, 8, or 16).
0N/A * @param dataType the desired data type, as one of the enumerations
0N/A * from the <code>DataBuffer</code> class.
0N/A * @param isSigned <code>true</code> if negative values are to
0N/A * be represented.
0N/A * @param isAlphaPremultiplied <code>true</code> if the luminance channel
0N/A * will be premultipled by the alpha channel.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * not one of 1, 2, 4, 8, or 16.
0N/A * @exception IllegalArgumentException if <code>dataType</code> is
0N/A * not one of <code>DataBuffer.TYPE_BYTE</code>,
0N/A * <code>DataBuffer.TYPE_SHORT</code>, or
0N/A * <code>DataBuffer.TYPE_USHORT</code>.
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * larger than the bit size of the given <code>dataType</code>.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createGrayscale(int bits,
0N/A int dataType,
0N/A boolean isSigned,
0N/A boolean isAlphaPremultiplied) {
0N/A return new ImageTypeSpecifier.Grayscale(bits,
0N/A dataType,
0N/A isSigned,
0N/A true,
0N/A isAlphaPremultiplied);
0N/A }
0N/A
0N/A // Indexed
0N/A
0N/A static class Indexed extends ImageTypeSpecifier {
0N/A byte[] redLUT;
0N/A byte[] greenLUT;
0N/A byte[] blueLUT;
0N/A byte[] alphaLUT = null;
0N/A int bits;
0N/A int dataType;
0N/A
0N/A public Indexed(byte[] redLUT,
0N/A byte[] greenLUT,
0N/A byte[] blueLUT,
0N/A byte[] alphaLUT,
0N/A int bits,
0N/A int dataType) {
0N/A if (redLUT == null || greenLUT == null || blueLUT == null) {
0N/A throw new IllegalArgumentException("LUT is null!");
0N/A }
0N/A if (bits != 1 && bits != 2 && bits != 4 &&
0N/A bits != 8 && bits != 16) {
0N/A throw new IllegalArgumentException("Bad value for bits!");
0N/A }
0N/A if (dataType != DataBuffer.TYPE_BYTE &&
0N/A dataType != DataBuffer.TYPE_SHORT &&
0N/A dataType != DataBuffer.TYPE_USHORT &&
0N/A dataType != DataBuffer.TYPE_INT) {
0N/A throw new IllegalArgumentException
0N/A ("Bad value for dataType!");
0N/A }
0N/A if ((bits > 8 && dataType == DataBuffer.TYPE_BYTE) ||
0N/A (bits > 16 && dataType != DataBuffer.TYPE_INT)) {
0N/A throw new IllegalArgumentException
0N/A ("Too many bits for dataType!");
0N/A }
0N/A
0N/A int len = 1 << bits;
0N/A if (redLUT.length != len ||
0N/A greenLUT.length != len ||
0N/A blueLUT.length != len ||
0N/A (alphaLUT != null && alphaLUT.length != len)) {
0N/A throw new IllegalArgumentException("LUT has improper length!");
0N/A }
0N/A this.redLUT = (byte[])redLUT.clone();
0N/A this.greenLUT = (byte[])greenLUT.clone();
0N/A this.blueLUT = (byte[])blueLUT.clone();
0N/A if (alphaLUT != null) {
0N/A this.alphaLUT = (byte[])alphaLUT.clone();
0N/A }
0N/A this.bits = bits;
0N/A this.dataType = dataType;
0N/A
0N/A if (alphaLUT == null) {
0N/A this.colorModel = new IndexColorModel(bits,
0N/A redLUT.length,
0N/A redLUT,
0N/A greenLUT,
0N/A blueLUT);
0N/A } else {
0N/A this.colorModel = new IndexColorModel(bits,
0N/A redLUT.length,
0N/A redLUT,
0N/A greenLUT,
0N/A blueLUT,
0N/A alphaLUT);
0N/A }
0N/A
0N/A if ((bits == 8 && dataType == DataBuffer.TYPE_BYTE) ||
0N/A (bits == 16 &&
0N/A (dataType == DataBuffer.TYPE_SHORT ||
0N/A dataType == DataBuffer.TYPE_USHORT))) {
0N/A int[] bandOffsets = { 0 };
0N/A this.sampleModel =
0N/A new PixelInterleavedSampleModel(dataType,
0N/A 1, 1, 1, 1,
0N/A bandOffsets);
0N/A } else {
0N/A this.sampleModel =
0N/A new MultiPixelPackedSampleModel(dataType, 1, 1, bits);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a specifier for an indexed-color image format that will pack
0N/A * index values of the given bit depth into array elements of
0N/A * the specified data type.
0N/A *
0N/A * @param redLUT an array of <code>byte</code>s containing
0N/A * the red values for each index.
0N/A * @param greenLUT an array of <code>byte</code>s containing * the
0N/A * green values for each index.
0N/A * @param blueLUT an array of <code>byte</code>s containing the
0N/A * blue values for each index.
0N/A * @param alphaLUT an array of <code>byte</code>s containing the
0N/A * alpha values for each index, or <code>null</code> to create a
0N/A * fully opaque LUT.
0N/A * @param bits the number of bits in each index.
0N/A * @param dataType the desired output type, as one of the enumerations
0N/A * from the <code>DataBuffer</code> class.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>redLUT</code> is
0N/A * <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>greenLUT</code> is
0N/A * <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>blueLUT</code> is
0N/A * <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * not one of 1, 2, 4, 8, or 16.
0N/A * @exception IllegalArgumentException if the
0N/A * non-<code>null</code> LUT parameters do not have lengths of
0N/A * exactly <code>1 << bits</code>.
0N/A * @exception IllegalArgumentException if <code>dataType</code> is
0N/A * not one of <code>DataBuffer.TYPE_BYTE</code>,
0N/A * <code>DataBuffer.TYPE_SHORT</code>,
0N/A * <code>DataBuffer.TYPE_USHORT</code>,
0N/A * or <code>DataBuffer.TYPE_INT</code>.
0N/A * @exception IllegalArgumentException if <code>bits</code> is
0N/A * larger than the bit size of the given <code>dataType</code>.
0N/A */
0N/A public static ImageTypeSpecifier
0N/A createIndexed(byte[] redLUT,
0N/A byte[] greenLUT,
0N/A byte[] blueLUT,
0N/A byte[] alphaLUT,
0N/A int bits,
0N/A int dataType) {
0N/A return new ImageTypeSpecifier.Indexed(redLUT,
0N/A greenLUT,
0N/A blueLUT,
0N/A alphaLUT,
0N/A bits,
0N/A dataType);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>ImageTypeSpecifier</code> that encodes
0N/A * one of the standard <code>BufferedImage</code> types
0N/A * (other than <code>TYPE_CUSTOM</code>).
0N/A *
0N/A * @param bufferedImageType an int representing one of the standard
0N/A * <code>BufferedImage</code> types.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if
0N/A * <code>bufferedImageType</code> is not one of the standard
0N/A * types, or is equal to <code>TYPE_CUSTOM</code>.
0N/A *
0N/A * @see java.awt.image.BufferedImage
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_BGR
0N/A * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
0N/A * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
0N/A * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
0N/A */
0N/A public static
0N/A ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
0N/A if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
0N/A bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
989N/A return getSpecifier(bufferedImageType);
0N/A } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
0N/A throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
0N/A } else {
0N/A throw new IllegalArgumentException("Invalid BufferedImage type!");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>ImageTypeSpecifier</code> that encodes the
0N/A * layout of a <code>RenderedImage</code> (which may be a
0N/A * <code>BufferedImage</code>).
0N/A *
0N/A * @param image a <code>RenderedImage</code>.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code> with the desired
0N/A * characteristics.
0N/A *
0N/A * @exception IllegalArgumentException if <code>image</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public static
0N/A ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
0N/A if (image == null) {
0N/A throw new IllegalArgumentException("image == null!");
0N/A }
0N/A
0N/A if (image instanceof BufferedImage) {
0N/A int bufferedImageType = ((BufferedImage)image).getType();
0N/A if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
989N/A return getSpecifier(bufferedImageType);
0N/A }
0N/A }
0N/A
0N/A return new ImageTypeSpecifier(image);
0N/A }
0N/A
0N/A /**
0N/A * Returns an int containing one of the enumerated constant values
0N/A * describing image formats from <code>BufferedImage</code>.
0N/A *
0N/A * @return an <code>int</code> representing a
0N/A * <code>BufferedImage</code> type.
0N/A *
0N/A * @see java.awt.image.BufferedImage
0N/A * @see java.awt.image.BufferedImage#TYPE_CUSTOM
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
0N/A * @see java.awt.image.BufferedImage#TYPE_INT_BGR
0N/A * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
0N/A * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
0N/A * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
0N/A * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
0N/A * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
0N/A */
0N/A public int getBufferedImageType() {
0N/A BufferedImage bi = createBufferedImage(1, 1);
0N/A return bi.getType();
0N/A }
0N/A
0N/A /**
0N/A * Return the number of color components
0N/A * specified by this object. This is the same value as returned by
0N/A * <code>ColorModel.getNumComponents</code>
0N/A *
0N/A * @return the number of components in the image.
0N/A */
0N/A public int getNumComponents() {
0N/A return colorModel.getNumComponents();
0N/A }
0N/A
0N/A /**
0N/A * Return the number of bands
0N/A * specified by this object. This is the same value as returned by
0N/A * <code>SampleModel.getNumBands</code>
0N/A *
0N/A * @return the number of bands in the image.
0N/A */
0N/A public int getNumBands() {
0N/A return sampleModel.getNumBands();
0N/A }
0N/A
0N/A /**
0N/A * Return the number of bits used to represent samples of the given band.
0N/A *
0N/A * @param band the index of the band to be queried, as an
0N/A * int.
0N/A *
0N/A * @return an int specifying a number of bits.
0N/A *
0N/A * @exception IllegalArgumentException if <code>band</code> is
0N/A * negative or greater than the largest band index.
0N/A */
0N/A public int getBitsPerBand(int band) {
0N/A if (band < 0 | band >= getNumBands()) {
0N/A throw new IllegalArgumentException("band out of range!");
0N/A }
0N/A return sampleModel.getSampleSize(band);
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>SampleModel</code> based on the settings
0N/A * encapsulated within this object. The width and height of the
0N/A * <code>SampleModel</code> will be set to arbitrary values.
0N/A *
0N/A * @return a <code>SampleModel</code> with arbitrary dimensions.
0N/A */
0N/A public SampleModel getSampleModel() {
0N/A return sampleModel;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>SampleModel</code> based on the settings
0N/A * encapsulated within this object. The width and height of the
0N/A * <code>SampleModel</code> will be set to the supplied values.
0N/A *
0N/A * @param width the desired width of the returned <code>SampleModel</code>.
0N/A * @param height the desired height of the returned
0N/A * <code>SampleModel</code>.
0N/A *
0N/A * @return a <code>SampleModel</code> with the given dimensions.
0N/A *
0N/A * @exception IllegalArgumentException if either <code>width</code> or
0N/A * <code>height</code> are negative or zero.
0N/A * @exception IllegalArgumentException if the product of
0N/A * <code>width</code> and <code>height</code> is greater than
0N/A * <code>Integer.MAX_VALUE</code>
0N/A */
0N/A public SampleModel getSampleModel(int width, int height) {
0N/A if ((long)width*height > Integer.MAX_VALUE) {
0N/A throw new IllegalArgumentException
0N/A ("width*height > Integer.MAX_VALUE!");
0N/A }
0N/A return sampleModel.createCompatibleSampleModel(width, height);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ColorModel</code> specified by this object.
0N/A *
0N/A * @return a <code>ColorModel</code>.
0N/A */
0N/A public ColorModel getColorModel() {
0N/A return colorModel;
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>BufferedImage</code> with a given width and
0N/A * height according to the specification embodied in this object.
0N/A *
0N/A * @param width the desired width of the returned
0N/A * <code>BufferedImage</code>.
0N/A * @param height the desired height of the returned
0N/A * <code>BufferedImage</code>.
0N/A *
0N/A * @return a new <code>BufferedImage</code>
0N/A *
0N/A * @exception IllegalArgumentException if either <code>width</code> or
0N/A * <code>height</code> are negative or zero.
0N/A * @exception IllegalArgumentException if the product of
0N/A * <code>width</code> and <code>height</code> is greater than
0N/A * <code>Integer.MAX_VALUE</code>, or if the number of array
0N/A * elements needed to store the image is greater than
0N/A * <code>Integer.MAX_VALUE</code>.
0N/A */
0N/A public BufferedImage createBufferedImage(int width, int height) {
0N/A try {
0N/A SampleModel sampleModel = getSampleModel(width, height);
0N/A WritableRaster raster =
0N/A Raster.createWritableRaster(sampleModel,
0N/A new Point(0, 0));
0N/A return new BufferedImage(colorModel, raster,
0N/A colorModel.isAlphaPremultiplied(),
0N/A new Hashtable());
0N/A } catch (NegativeArraySizeException e) {
0N/A // Exception most likely thrown from a DataBuffer constructor
0N/A throw new IllegalArgumentException
0N/A ("Array size > Integer.MAX_VALUE!");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the given <code>Object</code> is
0N/A * an <code>ImageTypeSpecifier</code> and has a
0N/A * <code>SampleModel</code> and <code>ColorModel</code> that are
0N/A * equal to those of this object.
0N/A *
0N/A * @param o the <code>Object</code> to be compared for equality.
0N/A *
0N/A * @return <code>true</code> if the given object is an equivalent
0N/A * <code>ImageTypeSpecifier</code>.
0N/A */
0N/A public boolean equals(Object o) {
0N/A if ((o == null) || !(o instanceof ImageTypeSpecifier)) {
0N/A return false;
0N/A }
0N/A
0N/A ImageTypeSpecifier that = (ImageTypeSpecifier)o;
0N/A return (colorModel.equals(that.colorModel)) &&
0N/A (sampleModel.equals(that.sampleModel));
0N/A }
0N/A
0N/A /**
0N/A * Returns the hash code for this ImageTypeSpecifier.
0N/A *
0N/A * @return a hash code for this ImageTypeSpecifier
0N/A */
0N/A public int hashCode() {
0N/A return (9 * colorModel.hashCode()) + (14 * sampleModel.hashCode());
0N/A }
989N/A
989N/A private static ImageTypeSpecifier getSpecifier(int type) {
989N/A if (BISpecifier[type] == null) {
989N/A BISpecifier[type] = createSpecifier(type);
989N/A }
989N/A return BISpecifier[type];
989N/A }
989N/A
989N/A private static ImageTypeSpecifier createSpecifier(int type) {
989N/A switch(type) {
989N/A case BufferedImage.TYPE_INT_RGB:
989N/A return createPacked(sRGB,
989N/A 0x00ff0000,
989N/A 0x0000ff00,
989N/A 0x000000ff,
989N/A 0x0,
989N/A DataBuffer.TYPE_INT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_INT_ARGB:
989N/A return createPacked(sRGB,
989N/A 0x00ff0000,
989N/A 0x0000ff00,
989N/A 0x000000ff,
989N/A 0xff000000,
989N/A DataBuffer.TYPE_INT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_INT_ARGB_PRE:
989N/A return createPacked(sRGB,
989N/A 0x00ff0000,
989N/A 0x0000ff00,
989N/A 0x000000ff,
989N/A 0xff000000,
989N/A DataBuffer.TYPE_INT,
989N/A true);
989N/A
989N/A case BufferedImage.TYPE_INT_BGR:
989N/A return createPacked(sRGB,
989N/A 0x000000ff,
989N/A 0x0000ff00,
989N/A 0x00ff0000,
989N/A 0x0,
989N/A DataBuffer.TYPE_INT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_3BYTE_BGR:
989N/A return createInterleaved(sRGB,
989N/A new int[] { 2, 1, 0 },
989N/A DataBuffer.TYPE_BYTE,
989N/A false,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_4BYTE_ABGR:
989N/A return createInterleaved(sRGB,
989N/A new int[] { 3, 2, 1, 0 },
989N/A DataBuffer.TYPE_BYTE,
989N/A true,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_4BYTE_ABGR_PRE:
989N/A return createInterleaved(sRGB,
989N/A new int[] { 3, 2, 1, 0 },
989N/A DataBuffer.TYPE_BYTE,
989N/A true,
989N/A true);
989N/A
989N/A case BufferedImage.TYPE_USHORT_565_RGB:
989N/A return createPacked(sRGB,
989N/A 0xF800,
989N/A 0x07E0,
989N/A 0x001F,
989N/A 0x0,
989N/A DataBuffer.TYPE_USHORT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_USHORT_555_RGB:
989N/A return createPacked(sRGB,
989N/A 0x7C00,
989N/A 0x03E0,
989N/A 0x001F,
989N/A 0x0,
989N/A DataBuffer.TYPE_USHORT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_BYTE_GRAY:
989N/A return createGrayscale(8,
989N/A DataBuffer.TYPE_BYTE,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_USHORT_GRAY:
989N/A return createGrayscale(16,
989N/A DataBuffer.TYPE_USHORT,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_BYTE_BINARY:
989N/A return createGrayscale(1,
989N/A DataBuffer.TYPE_BYTE,
989N/A false);
989N/A
989N/A case BufferedImage.TYPE_BYTE_INDEXED:
989N/A {
989N/A
989N/A BufferedImage bi =
989N/A new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
989N/A IndexColorModel icm = (IndexColorModel)bi.getColorModel();
989N/A int mapSize = icm.getMapSize();
989N/A byte[] redLUT = new byte[mapSize];
989N/A byte[] greenLUT = new byte[mapSize];
989N/A byte[] blueLUT = new byte[mapSize];
989N/A byte[] alphaLUT = new byte[mapSize];
989N/A
989N/A icm.getReds(redLUT);
989N/A icm.getGreens(greenLUT);
989N/A icm.getBlues(blueLUT);
989N/A icm.getAlphas(alphaLUT);
989N/A
989N/A return createIndexed(redLUT, greenLUT, blueLUT, alphaLUT,
989N/A 8,
989N/A DataBuffer.TYPE_BYTE);
989N/A }
989N/A default:
989N/A throw new IllegalArgumentException("Invalid BufferedImage type!");
989N/A }
989N/A }
989N/A
0N/A}