List of usage examples for java.awt.image SampleModel getTransferType
public int getTransferType()
From source file:org.geoserver.jai.ConcurrentTileFactory.java
/** * Builds a new tile, eventually recycling the data array backing it *///from ww w . j a v a2 s. c om public WritableRaster createTile(SampleModel sampleModel, Point location) { // sanity checks if (sampleModel == null) { throw new NullPointerException("sampleModel cannot be null"); } if (location == null) { location = new Point(0, 0); } DataBuffer db = null; // get the three elements making the key into the recycled array map int type = sampleModel.getTransferType(); long numBanks = 0; long size = 0; if (sampleModel instanceof ComponentSampleModel) { ComponentSampleModel csm = (ComponentSampleModel) sampleModel; numBanks = getNumBanksCSM(csm); size = getBufferSizeCSM(csm); } else if (sampleModel instanceof MultiPixelPackedSampleModel) { MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) sampleModel; numBanks = 1; int dataTypeSize = DataBuffer.getDataTypeSize(type); size = mppsm.getScanlineStride() * mppsm.getHeight() + (mppsm.getDataBitOffset() + dataTypeSize - 1) / dataTypeSize; } else if (sampleModel instanceof SinglePixelPackedSampleModel) { SinglePixelPackedSampleModel sppsm = (SinglePixelPackedSampleModel) sampleModel; numBanks = 1; size = sppsm.getScanlineStride() * (sppsm.getHeight() - 1) + sppsm.getWidth(); } if (size > 0) { // try to build a new data buffer starting from Object array = recycledArrays.getRecycledArray(type, numBanks, size); if (array != null) { switch (type) { case DataBuffer.TYPE_BYTE: { byte[][] bankData = (byte[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], (byte) 0); } db = new DataBufferByte(bankData, (int) size); } break; case DataBuffer.TYPE_USHORT: { short[][] bankData = (short[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], (short) 0); } db = new DataBufferUShort(bankData, (int) size); } break; case DataBuffer.TYPE_SHORT: { short[][] bankData = (short[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], (short) 0); } db = new DataBufferShort(bankData, (int) size); } break; case DataBuffer.TYPE_INT: { int[][] bankData = (int[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], 0); } db = new DataBufferInt(bankData, (int) size); } break; case DataBuffer.TYPE_FLOAT: { float[][] bankData = (float[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], 0.0F); } db = DataBufferUtils.createDataBufferFloat(bankData, (int) size); } break; case DataBuffer.TYPE_DOUBLE: { double[][] bankData = (double[][]) array; for (int i = 0; i < numBanks; i++) { Arrays.fill(bankData[i], 0.0); } db = DataBufferUtils.createDataBufferDouble(bankData, (int) size); } break; default: throw new IllegalArgumentException("Unknown array type"); } } } if (db == null) { db = sampleModel.createDataBuffer(); } return Raster.createWritableRaster(sampleModel, db, location); }