38 import java.util.Arrays; 39 40 /** 41 * This class represents pixel data packed such that the N samples which make 42 * up a single pixel are stored in a single data array element, and each data 43 * data array element holds samples for only one pixel. 44 * This class supports 45 * {@link DataBuffer#TYPE_BYTE TYPE_BYTE}, 46 * {@link DataBuffer#TYPE_USHORT TYPE_USHORT}, 47 * {@link DataBuffer#TYPE_INT TYPE_INT} data types. 48 * All data array elements reside 49 * in the first bank of a DataBuffer. Accessor methods are provided so 50 * that the image data can be manipulated directly. Scanline stride is the 51 * number of data array elements between a given sample and the corresponding 52 * sample in the same column of the next scanline. Bit masks are the masks 53 * required to extract the samples representing the bands of the pixel. 54 * Bit offsets are the offsets in bits into the data array 55 * element of the samples representing the bands of the pixel. 56 * <p> 57 * The following code illustrates extracting the bits of the sample 58 * representing band <code>b</code> for pixel <code>x,y</code> 59 * from DataBuffer <code>data</code>: 60 * <pre>{@code 61 * int sample = data.getElem(y * scanlineStride + x); 62 * sample = (sample & bitMasks[b]) >>> bitOffsets[b]; 63 * }</pre> 64 */ 65 66 public class SinglePixelPackedSampleModel extends SampleModel 67 { 68 /** Bit masks for all bands of the image data. */ 69 private int bitMasks[]; 70 71 /** Bit Offsets for all bands of the image data. */ 72 private int bitOffsets[]; 73 74 /** Bit sizes for all the bands of the image data. */ 75 private int bitSizes[]; 76 77 /** Maximum bit size. */ 78 private int maxBitSize; 79 83 private int scanlineStride; 84 85 private static native void initIDs(); 86 static { 87 ColorModel.loadLibraries(); 88 initIDs(); 89 } 90 91 /** 92 * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands. 93 * Each sample is stored in a data array element in the position of 94 * its corresponding bit mask. Each bit mask must be contiguous and 95 * masks must not overlap. Bit masks exceeding data type capacity are 96 * truncated. 97 * @param dataType The data type for storing samples. 98 * @param w The width (in pixels) of the region of the 99 * image data described. 100 * @param h The height (in pixels) of the region of the 101 * image data described. 102 * @param bitMasks The bit masks for all bands. 103 * @throws IllegalArgumentException if <code>dataType</code> is not 104 * either <code>DataBuffer.TYPE_BYTE</code>, 105 * <code>DataBuffer.TYPE_USHORT</code>, or 106 * <code>DataBuffer.TYPE_INT</code> 107 */ 108 public SinglePixelPackedSampleModel(int dataType, int w, int h, 109 int bitMasks[]) { 110 this(dataType, w, h, w, bitMasks); 111 if (dataType != DataBuffer.TYPE_BYTE && 112 dataType != DataBuffer.TYPE_USHORT && 113 dataType != DataBuffer.TYPE_INT) { 114 throw new IllegalArgumentException("Unsupported data type "+ 115 dataType); 116 } 117 } 118 119 /** 120 * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands 121 * and a scanline stride equal to scanlineStride data array elements. 122 * Each sample is stored in a data array element in the position of 123 * its corresponding bit mask. Each bit mask must be contiguous and 124 * masks must not overlap. Bit masks exceeding data type capacity are 125 * truncated. 126 * @param dataType The data type for storing samples. 127 * @param w The width (in pixels) of the region of 128 * image data described. 129 * @param h The height (in pixels) of the region of 130 * image data described. 131 * @param scanlineStride The line stride of the image data. 132 * @param bitMasks The bit masks for all bands. 133 * @throws IllegalArgumentException if <code>w</code> or 134 * <code>h</code> is not greater than 0 135 * @throws IllegalArgumentException if any mask in 136 * <code>bitMask</code> is not contiguous 137 * @throws IllegalArgumentException if <code>dataType</code> is not 138 * either <code>DataBuffer.TYPE_BYTE</code>, 139 * <code>DataBuffer.TYPE_USHORT</code>, or 140 * <code>DataBuffer.TYPE_INT</code> 141 */ 142 public SinglePixelPackedSampleModel(int dataType, int w, int h, 143 int scanlineStride, int bitMasks[]) { 144 super(dataType, w, h, bitMasks.length); 145 if (dataType != DataBuffer.TYPE_BYTE && 146 dataType != DataBuffer.TYPE_USHORT && 147 dataType != DataBuffer.TYPE_INT) { 148 throw new IllegalArgumentException("Unsupported data type "+ 149 dataType); 150 } 151 this.dataType = dataType; 152 this.bitMasks = bitMasks.clone(); 153 this.scanlineStride = scanlineStride; 154 155 this.bitOffsets = new int[numBands]; 156 this.bitSizes = new int[numBands]; 157 158 int maxMask = (int)((1L << DataBuffer.getDataTypeSize(dataType)) - 1); 159 160 this.maxBitSize = 0; 191 */ 192 public int getNumDataElements() { 193 return 1; 194 } 195 196 /** 197 * Returns the size of the buffer (in data array elements) 198 * needed for a data buffer that matches this 199 * SinglePixelPackedSampleModel. 200 */ 201 private long getBufferSize() { 202 long size = scanlineStride * (height-1) + width; 203 return size; 204 } 205 206 /** 207 * Creates a new SinglePixelPackedSampleModel with the specified 208 * width and height. The new SinglePixelPackedSampleModel will have the 209 * same storage data type and bit masks as this 210 * SinglePixelPackedSampleModel. 211 * @param w the width of the resulting <code>SampleModel</code> 212 * @param h the height of the resulting <code>SampleModel</code> 213 * @return a <code>SinglePixelPackedSampleModel</code> with the 214 * specified width and height. 215 * @throws IllegalArgumentException if <code>w</code> or 216 * <code>h</code> is not greater than 0 217 */ 218 public SampleModel createCompatibleSampleModel(int w, int h) { 219 SampleModel sampleModel = new SinglePixelPackedSampleModel(dataType, w, h, 220 bitMasks); 221 return sampleModel; 222 } 223 224 /** 225 * Creates a DataBuffer that corresponds to this 226 * SinglePixelPackedSampleModel. The DataBuffer's data type and size 227 * will be consistent with this SinglePixelPackedSampleModel. The 228 * DataBuffer will have a single bank. 229 */ 230 public DataBuffer createDataBuffer() { 231 DataBuffer dataBuffer = null; 232 233 int size = (int)getBufferSize(); 234 switch (dataType) { 235 case DataBuffer.TYPE_BYTE: 236 dataBuffer = new DataBufferByte(size); 239 dataBuffer = new DataBufferUShort(size); 240 break; 241 case DataBuffer.TYPE_INT: 242 dataBuffer = new DataBufferInt(size); 243 break; 244 } 245 return dataBuffer; 246 } 247 248 /** Returns the number of bits per sample for all bands. */ 249 public int[] getSampleSize() { 250 return bitSizes.clone(); 251 } 252 253 /** Returns the number of bits per sample for the specified band. */ 254 public int getSampleSize(int band) { 255 return bitSizes[band]; 256 } 257 258 /** Returns the offset (in data array elements) of pixel (x,y). 259 * The data element containing pixel <code>x,y</code> 260 * can be retrieved from a DataBuffer <code>data</code> with a 261 * SinglePixelPackedSampleModel <code>sppsm</code> as: 262 * <pre> 263 * data.getElem(sppsm.getOffset(x, y)); 264 * </pre> 265 * @param x the X coordinate of the specified pixel 266 * @param y the Y coordinate of the specified pixel 267 * @return the offset of the specified pixel. 268 */ 269 public int getOffset(int x, int y) { 270 int offset = y * scanlineStride + x; 271 return offset; 272 } 273 274 /** Returns the bit offsets into the data array element representing 275 * a pixel for all bands. 276 * @return the bit offsets representing a pixel for all bands. 277 */ 278 public int [] getBitOffsets() { 279 return bitOffsets.clone(); 280 } 281 282 /** Returns the bit masks for all bands. 283 * @return the bit masks for all bands. 284 */ 285 public int [] getBitMasks() { 286 return bitMasks.clone(); 287 } 288 289 /** Returns the scanline stride of this SinglePixelPackedSampleModel. 290 * @return the scanline stride of this 291 * <code>SinglePixelPackedSampleModel</code>. 292 */ 293 public int getScanlineStride() { 294 return scanlineStride; 295 } 296 297 /** 298 * This creates a new SinglePixelPackedSampleModel with a subset of the 299 * bands of this SinglePixelPackedSampleModel. The new 300 * SinglePixelPackedSampleModel can be used with any DataBuffer that the 301 * existing SinglePixelPackedSampleModel can be used with. The new 302 * SinglePixelPackedSampleModel/DataBuffer combination will represent 303 * an image with a subset of the bands of the original 304 * SinglePixelPackedSampleModel/DataBuffer combination. 305 * @exception RasterFormatException if the length of the bands argument is 306 * greater than the number of bands in 307 * the sample model. 308 */ 309 public SampleModel createSubsetSampleModel(int bands[]) { 310 if (bands.length > numBands) 311 throw new RasterFormatException("There are only " + 312 numBands + 313 " bands"); 314 int newBitMasks[] = new int[bands.length]; 315 for (int i=0; i<bands.length; i++) 316 newBitMasks[i] = bitMasks[bands[i]]; 317 318 return new SinglePixelPackedSampleModel(this.dataType, width, height, 319 this.scanlineStride, newBitMasks); 320 } 321 322 /** 323 * Returns data for a single pixel in a primitive array of type 324 * TransferType. For a SinglePixelPackedSampleModel, the array will 325 * have one element, and the type will be the same as the storage 326 * data type. Generally, obj 327 * should be passed in as null, so that the Object will be created 328 * automatically and will be of the right primitive data type. 329 * <p> 330 * The following code illustrates transferring data for one pixel from 331 * DataBuffer <code>db1</code>, whose storage layout is described by 332 * SinglePixelPackedSampleModel <code>sppsm1</code>, to 333 * DataBuffer <code>db2</code>, whose storage layout is described by 334 * SinglePixelPackedSampleModel <code>sppsm2</code>. 335 * The transfer will generally be more efficient than using 336 * getPixel/setPixel. 337 * <pre> 338 * SinglePixelPackedSampleModel sppsm1, sppsm2; 339 * DataBufferInt db1, db2; 340 * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 341 * db1), db2); 342 * </pre> 343 * Using getDataElements/setDataElements to transfer between two 344 * DataBuffer/SampleModel pairs is legitimate if the SampleModels have 345 * the same number of bands, corresponding bands have the same number of 346 * bits per sample, and the TransferTypes are the same. 347 * <p> 348 * If obj is non-null, it should be a primitive array of type TransferType. 349 * Otherwise, a ClassCastException is thrown. An 350 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 351 * not in bounds, or if obj is non-null and is not large enough to hold 352 * the pixel data. 353 * @param x The X coordinate of the pixel location. 354 * @param y The Y coordinate of the pixel location. 549 550 for (int i = 0; i < h; i++) { 551 for (int j = 0; j < w; j++) { 552 int value = data.getElem(lineOffset+j); 553 samples[dstOffset++] = 554 ((value & bitMasks[b]) >>> bitOffsets[b]); 555 } 556 lineOffset += scanlineStride; 557 } 558 return samples; 559 } 560 561 /** 562 * Sets the data for a single pixel in the specified DataBuffer from a 563 * primitive array of type TransferType. For a 564 * SinglePixelPackedSampleModel, only the first element of the array 565 * will hold valid data, and the type of the array must be the same as 566 * the storage data type of the SinglePixelPackedSampleModel. 567 * <p> 568 * The following code illustrates transferring data for one pixel from 569 * DataBuffer <code>db1</code>, whose storage layout is described by 570 * SinglePixelPackedSampleModel <code>sppsm1</code>, 571 * to DataBuffer <code>db2</code>, whose storage layout is described by 572 * SinglePixelPackedSampleModel <code>sppsm2</code>. 573 * The transfer will generally be more efficient than using 574 * getPixel/setPixel. 575 * <pre> 576 * SinglePixelPackedSampleModel sppsm1, sppsm2; 577 * DataBufferInt db1, db2; 578 * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 579 * db1), db2); 580 * </pre> 581 * Using getDataElements/setDataElements to transfer between two 582 * DataBuffer/SampleModel pairs is legitimate if the SampleModels have 583 * the same number of bands, corresponding bands have the same number of 584 * bits per sample, and the TransferTypes are the same. 585 * <p> 586 * obj must be a primitive array of type TransferType. Otherwise, 587 * a ClassCastException is thrown. An 588 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 589 * not in bounds, or if obj is not large enough to hold the pixel data. 590 * @param x The X coordinate of the pixel location. 591 * @param y The Y coordinate of the pixel location. 592 * @param obj A primitive array containing pixel data. | 38 import java.util.Arrays; 39 40 /** 41 * This class represents pixel data packed such that the N samples which make 42 * up a single pixel are stored in a single data array element, and each data 43 * data array element holds samples for only one pixel. 44 * This class supports 45 * {@link DataBuffer#TYPE_BYTE TYPE_BYTE}, 46 * {@link DataBuffer#TYPE_USHORT TYPE_USHORT}, 47 * {@link DataBuffer#TYPE_INT TYPE_INT} data types. 48 * All data array elements reside 49 * in the first bank of a DataBuffer. Accessor methods are provided so 50 * that the image data can be manipulated directly. Scanline stride is the 51 * number of data array elements between a given sample and the corresponding 52 * sample in the same column of the next scanline. Bit masks are the masks 53 * required to extract the samples representing the bands of the pixel. 54 * Bit offsets are the offsets in bits into the data array 55 * element of the samples representing the bands of the pixel. 56 * <p> 57 * The following code illustrates extracting the bits of the sample 58 * representing band {@code b} for pixel {@code x,y} 59 * from DataBuffer {@code data}: 60 * <pre>{@code 61 * int sample = data.getElem(y * scanlineStride + x); 62 * sample = (sample & bitMasks[b]) >>> bitOffsets[b]; 63 * }</pre> 64 */ 65 66 public class SinglePixelPackedSampleModel extends SampleModel 67 { 68 /** Bit masks for all bands of the image data. */ 69 private int bitMasks[]; 70 71 /** Bit Offsets for all bands of the image data. */ 72 private int bitOffsets[]; 73 74 /** Bit sizes for all the bands of the image data. */ 75 private int bitSizes[]; 76 77 /** Maximum bit size. */ 78 private int maxBitSize; 79 83 private int scanlineStride; 84 85 private static native void initIDs(); 86 static { 87 ColorModel.loadLibraries(); 88 initIDs(); 89 } 90 91 /** 92 * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands. 93 * Each sample is stored in a data array element in the position of 94 * its corresponding bit mask. Each bit mask must be contiguous and 95 * masks must not overlap. Bit masks exceeding data type capacity are 96 * truncated. 97 * @param dataType The data type for storing samples. 98 * @param w The width (in pixels) of the region of the 99 * image data described. 100 * @param h The height (in pixels) of the region of the 101 * image data described. 102 * @param bitMasks The bit masks for all bands. 103 * @throws IllegalArgumentException if {@code dataType} is not 104 * either {@code DataBuffer.TYPE_BYTE}, 105 * {@code DataBuffer.TYPE_USHORT}, or 106 * {@code DataBuffer.TYPE_INT} 107 */ 108 public SinglePixelPackedSampleModel(int dataType, int w, int h, 109 int bitMasks[]) { 110 this(dataType, w, h, w, bitMasks); 111 if (dataType != DataBuffer.TYPE_BYTE && 112 dataType != DataBuffer.TYPE_USHORT && 113 dataType != DataBuffer.TYPE_INT) { 114 throw new IllegalArgumentException("Unsupported data type "+ 115 dataType); 116 } 117 } 118 119 /** 120 * Constructs a SinglePixelPackedSampleModel with bitMasks.length bands 121 * and a scanline stride equal to scanlineStride data array elements. 122 * Each sample is stored in a data array element in the position of 123 * its corresponding bit mask. Each bit mask must be contiguous and 124 * masks must not overlap. Bit masks exceeding data type capacity are 125 * truncated. 126 * @param dataType The data type for storing samples. 127 * @param w The width (in pixels) of the region of 128 * image data described. 129 * @param h The height (in pixels) of the region of 130 * image data described. 131 * @param scanlineStride The line stride of the image data. 132 * @param bitMasks The bit masks for all bands. 133 * @throws IllegalArgumentException if {@code w} or 134 * {@code h} is not greater than 0 135 * @throws IllegalArgumentException if any mask in 136 * {@code bitMask} is not contiguous 137 * @throws IllegalArgumentException if {@code dataType} is not 138 * either {@code DataBuffer.TYPE_BYTE}, 139 * {@code DataBuffer.TYPE_USHORT}, or 140 * {@code DataBuffer.TYPE_INT} 141 */ 142 public SinglePixelPackedSampleModel(int dataType, int w, int h, 143 int scanlineStride, int bitMasks[]) { 144 super(dataType, w, h, bitMasks.length); 145 if (dataType != DataBuffer.TYPE_BYTE && 146 dataType != DataBuffer.TYPE_USHORT && 147 dataType != DataBuffer.TYPE_INT) { 148 throw new IllegalArgumentException("Unsupported data type "+ 149 dataType); 150 } 151 this.dataType = dataType; 152 this.bitMasks = bitMasks.clone(); 153 this.scanlineStride = scanlineStride; 154 155 this.bitOffsets = new int[numBands]; 156 this.bitSizes = new int[numBands]; 157 158 int maxMask = (int)((1L << DataBuffer.getDataTypeSize(dataType)) - 1); 159 160 this.maxBitSize = 0; 191 */ 192 public int getNumDataElements() { 193 return 1; 194 } 195 196 /** 197 * Returns the size of the buffer (in data array elements) 198 * needed for a data buffer that matches this 199 * SinglePixelPackedSampleModel. 200 */ 201 private long getBufferSize() { 202 long size = scanlineStride * (height-1) + width; 203 return size; 204 } 205 206 /** 207 * Creates a new SinglePixelPackedSampleModel with the specified 208 * width and height. The new SinglePixelPackedSampleModel will have the 209 * same storage data type and bit masks as this 210 * SinglePixelPackedSampleModel. 211 * @param w the width of the resulting {@code SampleModel} 212 * @param h the height of the resulting {@code SampleModel} 213 * @return a {@code SinglePixelPackedSampleModel} with the 214 * specified width and height. 215 * @throws IllegalArgumentException if {@code w} or 216 * {@code h} is not greater than 0 217 */ 218 public SampleModel createCompatibleSampleModel(int w, int h) { 219 SampleModel sampleModel = new SinglePixelPackedSampleModel(dataType, w, h, 220 bitMasks); 221 return sampleModel; 222 } 223 224 /** 225 * Creates a DataBuffer that corresponds to this 226 * SinglePixelPackedSampleModel. The DataBuffer's data type and size 227 * will be consistent with this SinglePixelPackedSampleModel. The 228 * DataBuffer will have a single bank. 229 */ 230 public DataBuffer createDataBuffer() { 231 DataBuffer dataBuffer = null; 232 233 int size = (int)getBufferSize(); 234 switch (dataType) { 235 case DataBuffer.TYPE_BYTE: 236 dataBuffer = new DataBufferByte(size); 239 dataBuffer = new DataBufferUShort(size); 240 break; 241 case DataBuffer.TYPE_INT: 242 dataBuffer = new DataBufferInt(size); 243 break; 244 } 245 return dataBuffer; 246 } 247 248 /** Returns the number of bits per sample for all bands. */ 249 public int[] getSampleSize() { 250 return bitSizes.clone(); 251 } 252 253 /** Returns the number of bits per sample for the specified band. */ 254 public int getSampleSize(int band) { 255 return bitSizes[band]; 256 } 257 258 /** Returns the offset (in data array elements) of pixel (x,y). 259 * The data element containing pixel {@code x,y} 260 * can be retrieved from a DataBuffer {@code data} with a 261 * SinglePixelPackedSampleModel {@code sppsm} as: 262 * <pre> 263 * data.getElem(sppsm.getOffset(x, y)); 264 * </pre> 265 * @param x the X coordinate of the specified pixel 266 * @param y the Y coordinate of the specified pixel 267 * @return the offset of the specified pixel. 268 */ 269 public int getOffset(int x, int y) { 270 int offset = y * scanlineStride + x; 271 return offset; 272 } 273 274 /** Returns the bit offsets into the data array element representing 275 * a pixel for all bands. 276 * @return the bit offsets representing a pixel for all bands. 277 */ 278 public int [] getBitOffsets() { 279 return bitOffsets.clone(); 280 } 281 282 /** Returns the bit masks for all bands. 283 * @return the bit masks for all bands. 284 */ 285 public int [] getBitMasks() { 286 return bitMasks.clone(); 287 } 288 289 /** Returns the scanline stride of this SinglePixelPackedSampleModel. 290 * @return the scanline stride of this 291 * {@code SinglePixelPackedSampleModel}. 292 */ 293 public int getScanlineStride() { 294 return scanlineStride; 295 } 296 297 /** 298 * This creates a new SinglePixelPackedSampleModel with a subset of the 299 * bands of this SinglePixelPackedSampleModel. The new 300 * SinglePixelPackedSampleModel can be used with any DataBuffer that the 301 * existing SinglePixelPackedSampleModel can be used with. The new 302 * SinglePixelPackedSampleModel/DataBuffer combination will represent 303 * an image with a subset of the bands of the original 304 * SinglePixelPackedSampleModel/DataBuffer combination. 305 * @exception RasterFormatException if the length of the bands argument is 306 * greater than the number of bands in 307 * the sample model. 308 */ 309 public SampleModel createSubsetSampleModel(int bands[]) { 310 if (bands.length > numBands) 311 throw new RasterFormatException("There are only " + 312 numBands + 313 " bands"); 314 int newBitMasks[] = new int[bands.length]; 315 for (int i=0; i<bands.length; i++) 316 newBitMasks[i] = bitMasks[bands[i]]; 317 318 return new SinglePixelPackedSampleModel(this.dataType, width, height, 319 this.scanlineStride, newBitMasks); 320 } 321 322 /** 323 * Returns data for a single pixel in a primitive array of type 324 * TransferType. For a SinglePixelPackedSampleModel, the array will 325 * have one element, and the type will be the same as the storage 326 * data type. Generally, obj 327 * should be passed in as null, so that the Object will be created 328 * automatically and will be of the right primitive data type. 329 * <p> 330 * The following code illustrates transferring data for one pixel from 331 * DataBuffer {@code db1}, whose storage layout is described by 332 * SinglePixelPackedSampleModel {@code sppsm1}, to 333 * DataBuffer {@code db2}, whose storage layout is described by 334 * SinglePixelPackedSampleModel {@code sppsm2}. 335 * The transfer will generally be more efficient than using 336 * getPixel/setPixel. 337 * <pre> 338 * SinglePixelPackedSampleModel sppsm1, sppsm2; 339 * DataBufferInt db1, db2; 340 * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 341 * db1), db2); 342 * </pre> 343 * Using getDataElements/setDataElements to transfer between two 344 * DataBuffer/SampleModel pairs is legitimate if the SampleModels have 345 * the same number of bands, corresponding bands have the same number of 346 * bits per sample, and the TransferTypes are the same. 347 * <p> 348 * If obj is non-null, it should be a primitive array of type TransferType. 349 * Otherwise, a ClassCastException is thrown. An 350 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 351 * not in bounds, or if obj is non-null and is not large enough to hold 352 * the pixel data. 353 * @param x The X coordinate of the pixel location. 354 * @param y The Y coordinate of the pixel location. 549 550 for (int i = 0; i < h; i++) { 551 for (int j = 0; j < w; j++) { 552 int value = data.getElem(lineOffset+j); 553 samples[dstOffset++] = 554 ((value & bitMasks[b]) >>> bitOffsets[b]); 555 } 556 lineOffset += scanlineStride; 557 } 558 return samples; 559 } 560 561 /** 562 * Sets the data for a single pixel in the specified DataBuffer from a 563 * primitive array of type TransferType. For a 564 * SinglePixelPackedSampleModel, only the first element of the array 565 * will hold valid data, and the type of the array must be the same as 566 * the storage data type of the SinglePixelPackedSampleModel. 567 * <p> 568 * The following code illustrates transferring data for one pixel from 569 * DataBuffer {@code db1}, whose storage layout is described by 570 * SinglePixelPackedSampleModel {@code sppsm1}, 571 * to DataBuffer {@code db2}, whose storage layout is described by 572 * SinglePixelPackedSampleModel {@code sppsm2}. 573 * The transfer will generally be more efficient than using 574 * getPixel/setPixel. 575 * <pre> 576 * SinglePixelPackedSampleModel sppsm1, sppsm2; 577 * DataBufferInt db1, db2; 578 * sppsm2.setDataElements(x, y, sppsm1.getDataElements(x, y, null, 579 * db1), db2); 580 * </pre> 581 * Using getDataElements/setDataElements to transfer between two 582 * DataBuffer/SampleModel pairs is legitimate if the SampleModels have 583 * the same number of bands, corresponding bands have the same number of 584 * bits per sample, and the TransferTypes are the same. 585 * <p> 586 * obj must be a primitive array of type TransferType. Otherwise, 587 * a ClassCastException is thrown. An 588 * ArrayIndexOutOfBoundsException may be thrown if the coordinates are 589 * not in bounds, or if obj is not large enough to hold the pixel data. 590 * @param x The X coordinate of the pixel location. 591 * @param y The Y coordinate of the pixel location. 592 * @param obj A primitive array containing pixel data. |