3909N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 290N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 290N/A * This code is free software; you can redistribute it and/or modify it 290N/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 290N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 290N/A * This code is distributed in the hope that it will be useful, but WITHOUT 290N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 290N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 290N/A * version 2 for more details (a copy is included in the LICENSE file that 290N/A * accompanied this code). 290N/A * You should have received a copy of the GNU General Public License version 290N/A * 2 along with this work; if not, write to the Free Software Foundation, 290N/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 290N/A/* **************************************************************** 290N/A ****************************************************************** 290N/A ****************************************************************** 290N/A *** COPYRIGHT (c) Eastman Kodak Company, 1997 290N/A *** As an unpublished work pursuant to Title 17 of the United 290N/A *** States Code. All rights reserved. 290N/A ****************************************************************** 290N/A ****************************************************************** 290N/A ******************************************************************/ 290N/A * This class represents pixel data packed such that the N samples which make 290N/A * up a single pixel are stored in a single data array element, and each data 290N/A * data array element holds samples for only one pixel. 290N/A * {@link DataBuffer#TYPE_BYTE TYPE_BYTE}, 290N/A * {@link DataBuffer#TYPE_USHORT TYPE_USHORT}, 290N/A * {@link DataBuffer#TYPE_INT TYPE_INT} data types. 290N/A * All data array elements reside 290N/A * in the first bank of a DataBuffer. Accessor methods are provided so 290N/A * that the image data can be manipulated directly. Scanline stride is the 290N/A * number of data array elements between a given sample and the corresponding 290N/A * sample in the same column of the next scanline. Bit masks are the masks 290N/A * required to extract the samples representing the bands of the pixel. 290N/A * Bit offsets are the offsets in bits into the data array 290N/A * element of the samples representing the bands of the pixel. 290N/A * The following code illustrates extracting the bits of the sample 290N/A * representing band <code>b</code> for pixel <code>x,y</code> 290N/A * from DataBuffer <code>data</code>: 290N/A * int sample = data.getElem(y * scanlineStride + x); 290N/A * sample = (sample & bitMasks[b]) >>> bitOffsets[b]; 290N/A /** Bit masks for all bands of the image data. */ 290N/A /** Bit Offsets for all bands of the image data. */ 290N/A /** Bit sizes for all the bands of the image data. */ 290N/A /** Maximum bit size. */ 290N/A /** Line stride of the region of image data described by this 290N/A * SinglePixelPackedSampleModel. 290N/A * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands. 290N/A * Each sample is stored in a data array element in the position of 290N/A * its corresponding bit mask. Each bit mask must be contiguous and 3266N/A * masks must not overlap. Bit masks exceeding data type capacity are 290N/A * @param dataType The data type for storing samples. 290N/A * @param w The width (in pixels) of the region of the 290N/A * image data described. 290N/A * @param h The height (in pixels) of the region of the 290N/A * image data described. 290N/A * @param bitMasks The bit masks for all bands. 290N/A * @throws IllegalArgumentException if <code>dataType</code> is not 290N/A * either <code>DataBuffer.TYPE_BYTE</code>, 290N/A * <code>DataBuffer.TYPE_USHORT</code>, or 290N/A * <code>DataBuffer.TYPE_INT</code> 290N/A * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands 290N/A * and a scanline stride equal to scanlineStride data array elements. 290N/A * Each sample is stored in a data array element in the position of 290N/A * its corresponding bit mask. Each bit mask must be contiguous and 3266N/A * masks must not overlap. Bit masks exceeding data type capacity are 290N/A * @param dataType The data type for storing samples. 290N/A * @param w The width (in pixels) of the region of 290N/A * image data described. 290N/A * @param h The height (in pixels) of the region of 290N/A * image data described. 290N/A * @param scanlineStride The line stride of the image data. 290N/A * @param bitMasks The bit masks for all bands. 290N/A * @throws IllegalArgumentException if <code>w</code> or 290N/A * <code>h</code> is not greater than 0 290N/A * @throws IllegalArgumentException if any mask in 290N/A * <code>bitMask</code> is not contiguous 290N/A * @throws IllegalArgumentException if <code>dataType</code> is not 290N/A * either <code>DataBuffer.TYPE_BYTE</code>, 290N/A * <code>DataBuffer.TYPE_USHORT</code>, or 290N/A * <code>DataBuffer.TYPE_INT</code> 290N/A " must be contiguous");
290N/A * Returns the number of data elements needed to transfer one pixel 290N/A * via the getDataElements and setDataElements methods. 290N/A * For a SinglePixelPackedSampleModel, this is one. 290N/A * Returns the size of the buffer (in data array elements) 290N/A * needed for a data buffer that matches this 290N/A * SinglePixelPackedSampleModel. 290N/A * Creates a new SinglePixelPackedSampleModel with the specified 290N/A * width and height. The new SinglePixelPackedSampleModel will have the 290N/A * same storage data type and bit masks as this 290N/A * SinglePixelPackedSampleModel. 290N/A * @param w the width of the resulting <code>SampleModel</code> 290N/A * @param h the height of the resulting <code>SampleModel</code> 290N/A * @return a <code>SinglePixelPackedSampleModel</code> with the 290N/A * specified width and height. 290N/A * @throws IllegalArgumentException if <code>w</code> or 290N/A * <code>h</code> is not greater than 0 290N/A * Creates a DataBuffer that corresponds to this 290N/A * SinglePixelPackedSampleModel. The DataBuffer's data type and size 290N/A * will be consistent with this SinglePixelPackedSampleModel. The 290N/A * DataBuffer will have a single bank. 290N/A /** Returns the number of bits per sample for all bands. */ 290N/A /** Returns the number of bits per sample for the specified band. */ 290N/A /** Returns the offset (in data array elements) of pixel (x,y). 290N/A * The data element containing pixel <code>x,y</code> 290N/A * can be retrieved from a DataBuffer <code>data</code> with a 290N/A * SinglePixelPackedSampleModel <code>sppsm</code> as: 290N/A * data.getElem(sppsm.getOffset(x, y)); 290N/A * @param x the X coordinate of the specified pixel 290N/A * @param y the Y coordinate of the specified pixel 290N/A * @return the offset of the specified pixel. 290N/A /** Returns the bit offsets into the data array element representing 290N/A * a pixel for all bands. 290N/A * @return the bit offsets representing a pixel for all bands. 290N/A /** Returns the bit masks for all bands. 290N/A * @return the bit masks for all bands. 290N/A /** Returns the scanline stride of this SinglePixelPackedSampleModel. 290N/A * @return the scanline stride of this 290N/A * <code>SinglePixelPackedSampleModel</code>. 290N/A * This creates a new SinglePixelPackedSampleModel with a subset of the 290N/A * bands of this SinglePixelPackedSampleModel. The new 290N/A * SinglePixelPackedSampleModel can be used with any DataBuffer that the 290N/A * existing SinglePixelPackedSampleModel can be used with. The new 290N/A * an image with a subset of the bands of the original 290N/A * @exception RasterFormatException if the length of the bands argument is 290N/A * greater than the number of bands in 290N/A * Returns data for a single pixel in a primitive array of type 290N/A * TransferType. For a SinglePixelPackedSampleModel, the array will 290N/A * have one element, and the type will be the same as the storage 290N/A * data type. Generally, obj 290N/A * should be passed in as null, so that the Object will be created 290N/A * automatically and will be of the right primitive data type. 290N/A * The following code illustrates transferring data for one pixel from 290N/A * DataBuffer <code>db1</code>, whose storage layout is described by 290N/A * SinglePixelPackedSampleModel <code>sppsm1</code>, to 290N/A * DataBuffer <code>db2</code>, whose storage layout is described by 290N/A * SinglePixelPackedSampleModel <code>sppsm2</code>. 290N/A * The transfer will generally be more efficient than using 290N/A * SinglePixelPackedSampleModel sppsm1, sppsm2; 290N/A * DataBufferInt db1, db2; 290N/A * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 290N/A * the same number of bands, corresponding bands have the same number of 290N/A * bits per sample, and the TransferTypes are the same. 290N/A * If obj is non-null, it should be a primitive array of type TransferType. 290N/A * Otherwise, a ClassCastException is thrown. An 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * not in bounds, or if obj is non-null and is not large enough to hold 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param obj If non-null, a primitive array in which to return 290N/A * @param data The DataBuffer containing the image data. 290N/A * @return the data for the specified pixel. 290N/A * @see #setDataElements(int, int, Object, DataBuffer) 290N/A // Bounds check for 'b' will be performed automatically 290N/A (
"Coordinate out of bounds!");
290N/A * Returns all samples in for the specified pixel in an int array. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param iArray If non-null, returns the samples in this array 290N/A * @param data The DataBuffer containing the image data. 290N/A * @return all samples for the specified pixel. 290N/A * @see #setPixel(int, int, int[], DataBuffer) 290N/A (
"Coordinate out of bounds!");
290N/A * Returns all samples for the specified rectangle of pixels in 290N/A * an int array, one sample per array element. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the upper left pixel location. 290N/A * @param y The Y coordinate of the upper left pixel location. 290N/A * @param w The width of the pixel rectangle. 290N/A * @param h The height of the pixel rectangle. 290N/A * @param iArray If non-null, returns the samples in this array. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @return all samples for the specified region of pixels. 290N/A * @see #setPixels(int, int, int, int, int[], DataBuffer) 290N/A (
"Coordinate out of bounds!");
290N/A for (
int i =
0; i < h; i++) {
290N/A for (
int j =
0; j < w; j++) {
290N/A * Returns as int the sample in a specified band for the pixel 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param b The band to return. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @return the sample in a specified band for the specified 290N/A * @see #setSample(int, int, int, int, DataBuffer) 290N/A // Bounds check for 'b' will be performed automatically 290N/A (
"Coordinate out of bounds!");
290N/A * Returns the samples for a specified band for the specified rectangle 290N/A * of pixels in an int array, one sample per array element. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the upper left pixel location. 290N/A * @param y The Y coordinate of the upper left pixel location. 290N/A * @param w The width of the pixel rectangle. 290N/A * @param h The height of the pixel rectangle. 290N/A * @param b The band to return. 290N/A * @param iArray If non-null, returns the samples in this array. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @return the samples for the specified band for the specified 290N/A * @see #setSamples(int, int, int, int, int, int[], DataBuffer) 290N/A // Bounds check for 'b' will be performed automatically 290N/A (
"Coordinate out of bounds!");
290N/A for (
int i =
0; i < h; i++) {
290N/A for (
int j =
0; j < w; j++) {
290N/A * Sets the data for a single pixel in the specified DataBuffer from a 290N/A * primitive array of type TransferType. For a 290N/A * SinglePixelPackedSampleModel, only the first element of the array 290N/A * will hold valid data, and the type of the array must be the same as 290N/A * the storage data type of the SinglePixelPackedSampleModel. 290N/A * The following code illustrates transferring data for one pixel from 290N/A * DataBuffer <code>db1</code>, whose storage layout is described by 290N/A * SinglePixelPackedSampleModel <code>sppsm1</code>, 290N/A * to DataBuffer <code>db2</code>, whose storage layout is described by 290N/A * SinglePixelPackedSampleModel <code>sppsm2</code>. 290N/A * The transfer will generally be more efficient than using 290N/A * SinglePixelPackedSampleModel sppsm1, sppsm2; 290N/A * DataBufferInt db1, db2; 290N/A * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 290N/A * the same number of bands, corresponding bands have the same number of 290N/A * bits per sample, and the TransferTypes are the same. 290N/A * obj must be a primitive array of type TransferType. Otherwise, 290N/A * a ClassCastException is thrown. An 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * not in bounds, or if obj is not large enough to hold the pixel data. 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param obj A primitive array containing pixel data. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @see #getDataElements(int, int, Object, DataBuffer) 290N/A (
"Coordinate out of bounds!");
290N/A * Sets a pixel in the DataBuffer using an int array of samples for input. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param iArray The input samples in an int array. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @see #getPixel(int, int, int[], DataBuffer) 290N/A (
"Coordinate out of bounds!");
290N/A * Sets all samples for a rectangle of pixels from an int array containing 290N/A * one sample per array element. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the upper left pixel location. 290N/A * @param y The Y coordinate of the upper left pixel location. 290N/A * @param w The width of the pixel rectangle. 290N/A * @param h The height of the pixel rectangle. 290N/A * @param iArray The input samples in an int array. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @see #getPixels(int, int, int, int, int[], DataBuffer) 290N/A (
"Coordinate out of bounds!");
290N/A for (
int i =
0; i < h; i++) {
290N/A for (
int j =
0; j < w; j++) {
290N/A * Sets a sample in the specified band for the pixel located at (x,y) 290N/A * in the DataBuffer using an int for input. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the pixel location. 290N/A * @param y The Y coordinate of the pixel location. 290N/A * @param b The band to set. 290N/A * @param s The input sample as an int. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @see #getSample(int, int, int, DataBuffer) 290N/A // Bounds check for 'b' will be performed automatically 290N/A (
"Coordinate out of bounds!");
290N/A * Sets the samples in the specified band for the specified rectangle 290N/A * of pixels from an int array containing one sample per array element. 290N/A * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 290N/A * @param x The X coordinate of the upper left pixel location. 290N/A * @param y The Y coordinate of the upper left pixel location. 290N/A * @param w The width of the pixel rectangle. 290N/A * @param h The height of the pixel rectangle. 290N/A * @param b The band to set. 290N/A * @param iArray The input samples in an int array. 290N/A * @param data The DataBuffer containing the image data. 290N/A * @see #getSamples(int, int, int, int, int, int[], DataBuffer) 290N/A // Bounds check for 'b' will be performed automatically 290N/A (
"Coordinate out of bounds!");
290N/A for (
int i =
0; i < h; i++) {
290N/A for (
int j =
0; j < w; j++) {
290N/A // If we implement equals() we must also implement hashCode