📄 raster.java
字号:
*/ public static WritableRaster createBandedRaster(int dataType, int w, int h, int bands, Point location) { if (bands < 1) { throw new ArrayIndexOutOfBoundsException("Number of bands ("+ bands+") must"+ " be greater than 0"); } int[] bankIndices = new int[bands]; int[] bandOffsets = new int[bands]; for (int i = 0; i < bands; i++) { bankIndices[i] = i; bandOffsets[i] = 0; } return createBandedRaster(dataType, w, h, w, bankIndices, bandOffsets, location); } /** * Creates a Raster based on a BandedSampleModel with the * specified data type, width, height, scanline stride, bank * indices and band offsets. The number of bands is inferred from * bankIndices.length and bandOffsets.length, which must be the * same. * * <p> The upper left corner of the Raster is given by the * location argument. The dataType parameter should be one of the * enumerated values defined in the DataBuffer class. * * <p> The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, * and TYPE_INT. * @param dataType the data type for storing samples * @param w the width in pixels of the image data * @param h the height in pixels of the image data * @param scanlineStride the line stride of the image data * @param bankIndices the bank indices for each band * @param bandOffsets the offsets of all bands * @param location the upper-left corner of the <code>Raster</code> * @return a WritableRaster object with the specified data type, * width, height, scanline stride, bank indices and band * offsets. * @throws RasterFormatException if <code>w</code> or <code>h</code> * is less than or equal to zero, or computing either * <code>location.x + w</code> or * <code>location.y + h</code> results in integer * overflow * @throws IllegalArgumentException if <code>dataType</code> is not * one of the supported data types, which are * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code> * or <code>DataBuffer.TYPE_INT</code> * @throws ArrayIndexOutOfBoundsException if <code>bankIndices</code> * or <code>bandOffsets</code> is <code>null</code> */ public static WritableRaster createBandedRaster(int dataType, int w, int h, int scanlineStride, int bankIndices[], int bandOffsets[], Point location) { DataBuffer d; int bands = bandOffsets.length; if (bankIndices == null) { throw new ArrayIndexOutOfBoundsException("Bank indices array is null"); } if (bandOffsets == null) { throw new ArrayIndexOutOfBoundsException("Band offsets array is null"); } // Figure out the #banks and the largest band offset int maxBank = bankIndices[0]; int maxBandOff = bandOffsets[0]; for (int i = 1; i < bands; i++) { if (bankIndices[i] > maxBank) { maxBank = bankIndices[i]; } if (bandOffsets[i] > maxBandOff) { maxBandOff = bandOffsets[i]; } } int banks = maxBank + 1; int size = maxBandOff + scanlineStride*(h-1) + (w-1) + 1; switch(dataType) { case DataBuffer.TYPE_BYTE: d = new DataBufferByte(size, banks); break; case DataBuffer.TYPE_USHORT: d = new DataBufferUShort(size, banks); break; case DataBuffer.TYPE_INT: d = new DataBufferInt(size, banks); break; default: throw new IllegalArgumentException("Unsupported data type " + dataType); } return createBandedRaster(d, w, h, scanlineStride, bankIndices, bandOffsets, location); } /** * Creates a Raster based on a SinglePixelPackedSampleModel with * the specified data type, width, height, and band masks. * The number of bands is inferred from bandMasks.length. * * <p> The upper left corner of the Raster is given by the * location argument. If location is null, (0, 0) will be used. * The dataType parameter should be one of the enumerated values * defined in the DataBuffer class. * * <p> The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, * and TYPE_INT. * @param dataType the data type for storing samples * @param w the width in pixels of the image data * @param h the height in pixels of the image data * @param bandMasks an array containing an entry for each band * @param location the upper-left corner of the <code>Raster</code> * @return a WritableRaster object with the specified data type, * width, height, and band masks. * @throws RasterFormatException if <code>w</code> or <code>h</code> * is less than or equal to zero, or computing either * <code>location.x + w</code> or * <code>location.y + h</code> results in integer * overflow * @throws IllegalArgumentException if <code>dataType</code> is not * one of the supported data types, which are * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code> * or <code>DataBuffer.TYPE_INT</code> */ public static WritableRaster createPackedRaster(int dataType, int w, int h, int bandMasks[], Point location) { DataBuffer d; switch(dataType) { case DataBuffer.TYPE_BYTE: d = new DataBufferByte(w*h); break; case DataBuffer.TYPE_USHORT: d = new DataBufferUShort(w*h); break; case DataBuffer.TYPE_INT: d = new DataBufferInt(w*h); break; default: throw new IllegalArgumentException("Unsupported data type " + dataType); } return createPackedRaster(d, w, h, w, bandMasks, location); } /** * Creates a Raster based on a packed SampleModel with the * specified data type, width, height, number of bands, and bits * per band. If the number of bands is one, the SampleModel will * be a MultiPixelPackedSampleModel. * * <p> If the number of bands is more than one, the SampleModel * will be a SinglePixelPackedSampleModel, with each band having * bitsPerBand bits. In either case, the requirements on dataType * and bitsPerBand imposed by the corresponding SampleModel must * be met. * * <p> The upper left corner of the Raster is given by the * location argument. If location is null, (0, 0) will be used. * The dataType parameter should be one of the enumerated values * defined in the DataBuffer class. * * <p> The only dataTypes supported currently are TYPE_BYTE, TYPE_USHORT, * and TYPE_INT. * @param dataType the data type for storing samples * @param w the width in pixels of the image data * @param h the height in pixels of the image data * @param bands the number of bands * @param bitsPerBand the number of bits per band * @param location the upper-left corner of the <code>Raster</code> * @return a WritableRaster object with the specified data type, * width, height, number of bands, and bits per band. * @throws RasterFormatException if <code>w</code> or <code>h</code> * is less than or equal to zero, or computing either * <code>location.x + w</code> or * <code>location.y + h</code> results in integer * overflow * @throws IllegalArgumentException if the product of * <code>bitsPerBand</code> and <code>bands</code> is * greater than the number of bits held by * <code>dataType</code> * @throws IllegalArgumentException if <code>bitsPerBand</code> or * <code>bands</code> is not greater than zero * @throws IllegalArgumentException if <code>dataType</code> is not * one of the supported data types, which are * <code>DataBuffer.TYPE_BYTE</code>, * <code>DataBuffer.TYPE_USHORT</code> * or <code>DataBuffer.TYPE_INT</code> */ public static WritableRaster createPackedRaster(int dataType, int w, int h, int bands, int bitsPerBand, Point location) { DataBuffer d; if (bands <= 0) { throw new IllegalArgumentException("Number of bands ("+bands+ ") must be greater than 0"); } if (bitsPerBand <= 0) { throw new IllegalArgumentException("Bits per band ("+bitsPerBand+ ") must be greater than 0"); } if (bands != 1) { int[] masks = new int[bands]; int mask = (1 << bitsPerBand) - 1; int shift = (bands-1)*bitsPerBand; /* Make sure the total mask size will fit in the data type */ if (shift+bitsPerBand > DataBuffer.getDataTypeSize(dataType)) { throw new IllegalArgumentException("bitsPerBand("+ bitsPerBand+") * bands is "+ " greater than data type "+ "size."); } switch(dataType) { case DataBuffer.TYPE_BYTE: case DataBuffer.TYPE_USHORT: case DataBuffer.TYPE_INT: break; default: throw new IllegalArgumentException("Unsupported data type " + dataType); } for (int i = 0; i < bands; i++) { masks[i] = mask << shift; shift = shift - bitsPerBand; } return createPackedRaster(dataType, w, h, masks, location); } else { double fw = w; switch(dataType) { case DataBuffer.TYPE_BYTE: d = new DataBufferByte((int)(Math.ceil(fw/(8/bitsPerBand)))*h); break; case DataBuffer.TYPE_USHORT: d = new DataBufferUShort((int)(Math.ceil(fw/(16/bitsPerBand)))*h); break; case DataBuffer.TYPE_INT: d = new DataBufferInt((int)(Math.ceil(fw/(32/bitsPerBand)))*h); break; default: throw new IllegalArgumentException("Unsupported data type " + dataType); } return createPackedRaster(d, w, h, bitsPerBand, location); } } /** * Creates a Raster based on a PixelInterleavedSampleModel with the * specified DataBuffer, width, height, scanline stride, pixel * stride, and band offsets. The number of bands is inferred from * bandOffsets.length. The upper left corner of the Raster * is given by the location argument. If location is null, (0, 0) * will be used. * <p> Note that interleaved <code>DataBuffer.TYPE_INT</code> * Rasters are not supported. To create a 1-band Raster of type * <code>DataBuffer.TYPE_INT</code>, use * Raster.createPackedRaster().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -