2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 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 * 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 * 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. 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 0N/A//import javax.imageio.ImageTypeSpecifier; 0N/A public static void main(String[] args) { 0N/A ImageTypeSpecifier bilevel = 0N/A ImageTypeSpecifier.createIndexed(new byte[] {(byte)0, (byte)255}, 0N/A new byte[] {(byte)0, (byte)255}, 0N/A new byte[] {(byte)0, (byte)255}, 0N/A DataBuffer.TYPE_BYTE); 0N/A ImageTypeSpecifier gray = 0N/A ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false); 0N/A ImageTypeSpecifier grayAlpha = 0N/A ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, false, 0N/A ImageTypeSpecifier rgb = 0N/A ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_sRGB), 0N/A new int[] {0, 1, 2}, 0N/A DataBuffer.TYPE_BYTE, 0N/A ImageTypeSpecifier rgba = 0N/A ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_sRGB), 0N/A new int[] {0, 1, 2, 3}, 0N/A DataBuffer.TYPE_BYTE, 0N/A ImageTypeSpecifier packed = 0N/A ImageTypeSpecifier.createPacked(ColorSpace.getInstance(ColorSpace.CS_sRGB), 0N/A DataBuffer.TYPE_BYTE, 0N/A SampleModel bandedSM = 0N/A new java.awt.image.BandedSampleModel(DataBuffer.TYPE_BYTE, 0N/A System.out.println(createColorModel(bilevel.getSampleModel())); 0N/A System.out.println(createColorModel(gray.getSampleModel())); 0N/A System.out.println(createColorModel(grayAlpha.getSampleModel())); 0N/A System.out.println(createColorModel(rgb.getSampleModel())); 0N/A System.out.println(createColorModel(rgba.getSampleModel())); 0N/A System.out.println(createColorModel(packed.getSampleModel())); 0N/A System.out.println(createColorModel(bandedSM)); 0N/A * Creates a <code>ColorModel</code> that may be used with the 0N/A * specified <code>SampleModel</code>. If a suitable 0N/A * <code>ColorModel</code> cannot be found, this method returns 0N/A * <code>null</code>. 0N/A * <p> Suitable <code>ColorModel</code>s are guaranteed to exist 0N/A * for all instances of <code>ComponentSampleModel</code>. 0N/A * For 1- and 3- banded <code>SampleModel</code>s, the returned 0N/A * <code>ColorModel</code> will be opaque. For 2- and 4-banded 0N/A * <code>SampleModel</code>s, the output will use alpha transparency 0N/A * which is not premultiplied. 1- and 2-banded data will use a 0N/A * grayscale <code>ColorSpace</code>, and 3- and 4-banded data a sRGB 0N/A * <code>ColorSpace</code>. Data with 5 or more bands will have a 0N/A * <code>BogusColorSpace</code>.</p> 0N/A * <p>An instance of <code>DirectColorModel</code> will be created for 0N/A * instances of <code>SinglePixelPackedSampleModel</code> with no more 0N/A * <p>An instance of <code>IndexColorModel</code> will be created for 0N/A * instances of <code>MultiPixelPackedSampleModel</code>. The colormap 0N/A * will be a grayscale ramp with <code>1 << numberOfBits</code> 0N/A * entries ranging from zero to at most 255.</p> 0N/A * @return An instance of <code>ColorModel</code> that is suitable for 0N/A * the supplied <code>SampleModel</code>, or <code>null</code>. 0N/A * @throws IllegalArgumentException If <code>sampleModel</code> is 0N/A * <code>null</code>. 0N/A // Check the parameter. 0N/A // Get the data type. 0N/A // Check the data type 0N/A // Return null for other types. 0N/A // The return variable. 0N/A // Get the sample size. 0N/A // Create a Component ColorModel. 0N/A // Get the number of bands. 0N/A // Determine the color space. 0N/A // Load the colormap with a ramp. 0N/A * For the case of binary data (<code>isBinary()</code> returns 0N/A * <code>true</code>), return the binary data as a packed byte array. 0N/A * The data will be packed as eight bits per byte with no bit offset, 0N/A * i.e., the first bit in each image line will be the left-most of the 0N/A * first byte of the line. The line stride in bytes will be 0N/A * <code>(int)((getWidth()+7)/8)</code>. The length of the returned 0N/A * array will be the line stride multiplied by <code>getHeight()</code> 0N/A * @return the binary data as a packed array of bytes with zero offset 0N/A * of <code>null</code> if the data are not binary. 0N/A * @throws IllegalArgumentException if <code>isBinary()</code> returns 0N/A * <code>false</code> with the <code>SampleModel</code> of the 0N/A * supplied <code>Raster</code> as argument. 0N/A }
else {
// bitOffset != 0 0N/A }
else {
// bitOffset % 8 != 0 0N/A * Returns the binary data unpacked into an array of bytes. 0N/A * The line stride will be the width of the <code>Raster</code>. 0N/A * @throws IllegalArgumentException if <code>isBinary()</code> returns 0N/A * <code>false</code> with the <code>SampleModel</code> of the 0N/A * supplied <code>Raster</code> as argument. 0N/A * Sets the supplied <code>Raster</code>'s data from an array 0N/A * of packed binary data of the form returned by 0N/A * <code>getPackedBinaryData()</code>. 0N/A * @throws IllegalArgumentException if <code>isBinary()</code> returns 0N/A * <code>false</code> with the <code>SampleModel</code> of the 0N/A * supplied <code>Raster</code> as argument. 0N/A // Optimal case: simply return. 0N/A }
else {
// bitOffset != 0 0N/A }
else {
// bitOffset % 8 != 0 0N/A // when all the bits in this BYTE will be set 0N/A // into the data buffer. 0N/A // All the "leftShift" high bits will be set 0N/A // into the data buffer. But not all the 0N/A // "rightShift" low bits will be set. 0N/A // Less than "leftShift" high bits will be set. 0N/A // This BYTE is set into one SHORT 0N/A // Mask the bits to be set. 0N/A // This BYTE will be set into two SHORTs 0N/A // This BYTE will be set into two SHORTs; 0N/A // But not all the low bits will be set into SHORT 0N/A // Only some of the high bits will be set into 0N/A // This BYTE is set into one INT 0N/A // Mask the bits to be set. 0N/A // All the bits of this BYTE will be set into two INTs 0N/A // This BYTE will be set into two INTs; 0N/A // But not all the low bits will be set into INT 0N/A // Only some of the high bits will be set into INT 0N/A * Copies data into the packed array of the <code>Raster</code> 0N/A * from an array of unpacked data of the form returned by 0N/A * <code>getUnpackedBinaryData()</code>. 0N/A * <p> If the data are binary, then the target bit will be set if 0N/A * and only if the corresponding byte is non-zero. 0N/A * @throws IllegalArgumentException if <code>isBinary()</code> returns 0N/A * <code>false</code> with the <code>SampleModel</code> of the 0N/A * supplied <code>Raster</code> as argument. 0N/A (
short)(
0x00000001 <<
0N/A //dataType == DataBuffer.TYPE_SHORT || 0N/A * Tests whether the color indices represent a gray-scale image. 0N/A * @param r The red channel color indices. 0N/A * @param g The green channel color indices. 0N/A * @param b The blue channel color indices. 0N/A * @return If all the indices have 256 entries, and are identical mappings, 0N/A * return <code>true</code>; otherwise, return <code>false</code>. 0N/A /** Converts the provided object to <code>String</code> */ 0N/A /** Checks that the provided <code>ImageWriter</code> can encode 0N/A * the provided <code>ImageTypeSpecifier</code> or not. If not, an 0N/A * <code>IIOException</code> will be thrown. 0N/A * @param writer The provided <code>ImageWriter</code>. 0N/A * @param type The image to be tested. 0N/A * @throws IIOException If the writer cannot encoded the provided image. 0N/A /** Checks that the provided <code>ImageWriter</code> can encode 0N/A * the provided <code>ColorModel</code> and <code>SampleModel</code>. 0N/A * If not, an <code>IIOException</code> will be thrown. 0N/A * @param writer The provided <code>ImageWriter</code>. 0N/A * @param colorModel The provided <code>ColorModel</code>. 0N/A * @param sampleModel The provided <code>SampleModel</code>. 0N/A * @throws IIOException If the writer cannot encoded the provided image. 0N/A * Returns whether the image has contiguous data across rows. 0N/A // Ensure image rows samples are stored contiguously 0N/A // in a single bank. 0N/A // Otherwise true if and only if it's a bilevel image with 0N/A // a MultiPixelPackedSampleModel, 1 bit per pixel, and 1 bit