public SampleModel getSampleModel() { if (sampleModel != null) return sampleModel; int realWidth = (int) Math.min(tileWidth, width); int realHeight = (int) Math.min(tileHeight, height); if (nComp == 1 && (maxDepth == 1 || maxDepth == 2 || maxDepth == 4)) sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, realWidth, realHeight, maxDepth); else if (maxDepth <= 8) sampleModel = new PixelInterleavedSampleModel( DataBuffer.TYPE_BYTE, realWidth, realHeight, nComp, realWidth * nComp, bandOffsets); else if (maxDepth <= 16) sampleModel = new PixelInterleavedSampleModel( isSigned ? DataBuffer.TYPE_SHORT : DataBuffer.TYPE_USHORT, realWidth, realHeight, nComp, realWidth * nComp, bandOffsets); else if (maxDepth <= 32) sampleModel = new PixelInterleavedSampleModel( DataBuffer.TYPE_INT, realWidth, realHeight, nComp, realWidth * nComp, bandOffsets); else throw new IllegalArgumentException(I18N.getString("J2KReadState11") + " " + +maxDepth); return sampleModel; }
private int getTileNum(int x, int y) { int num = (y - getMinTileY()) * getNumXTiles() + x - getMinTileX(); if (num < 0 || num >= getNumXTiles() * getNumYTiles()) throw new IllegalArgumentException(I18N.getString("RawRenderedImage0")); return num; }
private void checkSampleModel(SampleModel sm) { int type = sm.getDataType(); if (type < DataBuffer.TYPE_BYTE || type > DataBuffer.TYPE_INT || sm.getNumBands() != 1 || sm.getSampleSize(0) != 1) throw new IllegalArgumentException(I18N.getString("WBMPImageWriter2")); }
public void setOutput(Object output) { super.setOutput(output); // validates output if (output != null) { if (!(output instanceof ImageOutputStream)) throw new IllegalArgumentException(I18N.getString("WBMPImageWriter")); this.stream = (ImageOutputStream) output; } else this.stream = null; }
public synchronized Raster getTile(int tileX, int tileY) { if (currentTile != null && currentTileGrid.x == tileX && currentTileGrid.y == tileY) return currentTile; if (tileX >= getNumXTiles() || tileY >= getNumYTiles()) throw new IllegalArgumentException(I18N.getString("RawRenderedImage0")); try { iis.seek(position + (tileY * originalNumXTiles + tileX) * tileDataSize); int x = tileXToX(tileX); int y = tileYToY(tileY); currentTile = Raster.createWritableRaster(sampleModel, new Point(x, y)); if (noTransform) { switch (sampleModel.getDataType()) { case DataBuffer.TYPE_BYTE: byte[][] buf = ((DataBufferByte) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < buf.length; i++) iis.readFully(buf[i], 0, buf[i].length); break; case DataBuffer.TYPE_SHORT: short[][] sbuf = ((DataBufferShort) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < sbuf.length; i++) iis.readFully(sbuf[i], 0, sbuf[i].length); break; case DataBuffer.TYPE_USHORT: short[][] usbuf = ((DataBufferUShort) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < usbuf.length; i++) iis.readFully(usbuf[i], 0, usbuf[i].length); break; case DataBuffer.TYPE_INT: int[][] ibuf = ((DataBufferInt) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < ibuf.length; i++) iis.readFully(ibuf[i], 0, ibuf[i].length); break; case DataBuffer.TYPE_FLOAT: float[][] fbuf = ((DataBufferFloat) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < fbuf.length; i++) iis.readFully(fbuf[i], 0, fbuf[i].length); break; case DataBuffer.TYPE_DOUBLE: double[][] dbuf = ((DataBufferDouble) currentTile.getDataBuffer()).getBankData(); for (int i = 0; i < dbuf.length; i++) iis.readFully(dbuf[i], 0, dbuf[i].length); break; } } else { currentTile = readSubsampledRaster((WritableRaster) currentTile); } } catch (IOException e) { throw new RuntimeException(e); } if (currentTileGrid == null) currentTileGrid = new Point(tileX, tileY); else { currentTileGrid.x = tileX; currentTileGrid.y = tileY; } return currentTile; }
private void initGraphSource(RrdGraphDef graphDef, int height, boolean maxHidden) { final String dataSourceName = getDataSourceName(); final String average = "average"; graphDef.datasource(average, rrdFileName, dataSourceName, "AVERAGE"); graphDef.setMinValue(0); final String moyenneLabel = I18N.getString("Moyenne"); graphDef.area(average, getPaint(height), moyenneLabel); graphDef.gprint(average, "AVERAGE", moyenneLabel + ": %9.0f %S\\r"); // graphDef.gprint(average, "MIN", "Minimum: %9.0f %S\\r"); if (!maxHidden) { final String max = "max"; graphDef.datasource(max, rrdFileName, dataSourceName, "MAX"); final String maximumLabel = I18N.getString("Maximum"); graphDef.line(max, Color.BLUE, maximumLabel); graphDef.gprint(max, "MAX", maximumLabel + ": %9.0f %S\\r"); } // graphDef.comment("JRobin :: RRDTool Choice for the Java World"); }
/** * Constructs <code>J2KReadState</code>. * * @param iis The input stream. * @param param The reading parameters. * @param reader The <code>J2KImageReader</code> which holds this state. It is necessary for * processing abortion. * @throw IllegalArgumentException If the provided <code>iis</code>, or <code>param</code> is * <code>null</code>. */ public J2KReadState(ImageInputStream iis, J2KImageReadParamJava param, J2KImageReader reader) { if (iis == null || param == null) throw new IllegalArgumentException(I18N.getString("J2KReadState0")); this.iis = iis; this.j2krparam = param; this.reader = reader; initializeRead(0, param, null); }
/** Sets <code>packetPerTilePart</code> */ public void setPacketPerTilePart(int packetPerTilePart) { if (packetPerTilePart < 0) throw new IllegalArgumentException(I18N.getString("J2KImageWriteParamJava0")); this.packetPerTilePart = packetPerTilePart; if (packetPerTilePart > 0) { setSOP("true"); setEPH("true"); } }
String getLabel() { if (requestName == null) { // c'est un jrobin global issu soit de JavaInformations soit d'un Counter dans le Collector return I18N.getString(getName()); } // c'est un jrobin issu d'un CounterRequest dans le Collector final String shortRequestName = requestName.substring(0, Math.min(30, requestName.length())); // plus nécessaire: if (getName().startsWith("error")) { // c'est un jrobin issu d'un CounterRequest du Counter "error" // return I18N.getString("Erreurs_par_minute_pour") + ' ' + shortRequestName; } return I18N.getFormattedString("Temps_moyens_de", shortRequestName); }
/** Returns the data array from the <code>DataBuffer</code>. */ private static final Object getDataBufferData(DataBuffer db) { Object data; int dType = db.getDataType(); switch (dType) { case DataBuffer.TYPE_BYTE: data = ((DataBufferByte) db).getData(); break; case DataBuffer.TYPE_USHORT: data = ((DataBufferUShort) db).getData(); break; default: throw new IllegalArgumentException(I18N.getString("Generic0") + " " + dType); } return data; }
private Raster readSubsampledRaster(WritableRaster raster) throws IOException { if (raster == null) raster = Raster.createWritableRaster( sampleModel.createCompatibleSampleModel( destinationRegion.x + destinationRegion.width, destinationRegion.y + destinationRegion.height), new Point(destinationRegion.x, destinationRegion.y)); int numBands = sourceBands.length; int dataType = sampleModel.getDataType(); int sampleSizeBit = DataBuffer.getDataTypeSize(dataType); int sampleSizeByte = (sampleSizeBit + 7) / 8; Rectangle destRect = raster.getBounds().intersection(destinationRegion); int offx = destinationRegion.x; int offy = destinationRegion.y; int sourceSX = (destRect.x - offx) * scaleX + sourceOrigin.x; int sourceSY = (destRect.y - offy) * scaleY + sourceOrigin.y; int sourceEX = (destRect.width - 1) * scaleX + sourceSX; int sourceEY = (destRect.height - 1) * scaleY + sourceSY; int startXTile = sourceSX / tileWidth; int startYTile = sourceSY / tileHeight; int endXTile = sourceEX / tileWidth; int endYTile = sourceEY / tileHeight; startXTile = clip(startXTile, 0, maxXTile); startYTile = clip(startYTile, 0, maxYTile); endXTile = clip(endXTile, 0, maxXTile); endYTile = clip(endYTile, 0, maxYTile); int totalXTiles = getNumXTiles(); int totalYTiles = getNumYTiles(); int totalTiles = totalXTiles * totalYTiles; // The line buffer for the source byte[] pixbuf = null; // byte buffer for the decoded pixels. short[] spixbuf = null; // byte buffer for the decoded pixels. int[] ipixbuf = null; // byte buffer for the decoded pixels. float[] fpixbuf = null; // byte buffer for the decoded pixels. double[] dpixbuf = null; // byte buffer for the decoded pixels. // A flag to show the ComponentSampleModel has a single data bank boolean singleBank = true; int pixelStride = 0; int scanlineStride = 0; int bandStride = 0; int[] bandOffsets = null; int[] bankIndices = null; if (originalSampleModel instanceof ComponentSampleModel) { ComponentSampleModel csm = (ComponentSampleModel) originalSampleModel; bankIndices = csm.getBankIndices(); int maxBank = 0; for (int i = 0; i < bankIndices.length; i++) if (maxBank > bankIndices[i]) maxBank = bankIndices[i]; if (maxBank > 0) singleBank = false; pixelStride = csm.getPixelStride(); scanlineStride = csm.getScanlineStride(); bandOffsets = csm.getBandOffsets(); for (int i = 0; i < bandOffsets.length; i++) if (bandStride < bandOffsets[i]) bandStride = bandOffsets[i]; } else if (originalSampleModel instanceof MultiPixelPackedSampleModel) { scanlineStride = ((MultiPixelPackedSampleModel) originalSampleModel).getScanlineStride(); } else if (originalSampleModel instanceof SinglePixelPackedSampleModel) { pixelStride = 1; scanlineStride = ((SinglePixelPackedSampleModel) originalSampleModel).getScanlineStride(); } // The dstination buffer for the raster byte[] destPixbuf = null; // byte buffer for the decoded pixels. short[] destSPixbuf = null; // byte buffer for the decoded pixels. int[] destIPixbuf = null; // byte buffer for the decoded pixels. float[] destFPixbuf = null; // byte buffer for the decoded pixels. double[] destDPixbuf = null; // byte buffer for the decoded pixels. int[] destBandOffsets = null; int destPixelStride = 0; int destScanlineStride = 0; int destSX = 0; // The first pixel for the destionation if (raster.getSampleModel() instanceof ComponentSampleModel) { ComponentSampleModel csm = (ComponentSampleModel) raster.getSampleModel(); bankIndices = csm.getBankIndices(); destBandOffsets = csm.getBandOffsets(); destPixelStride = csm.getPixelStride(); destScanlineStride = csm.getScanlineStride(); destSX = csm.getOffset( raster.getMinX() - raster.getSampleModelTranslateX(), raster.getMinY() - raster.getSampleModelTranslateY()) - destBandOffsets[0]; switch (dataType) { case DataBuffer.TYPE_BYTE: destPixbuf = ((DataBufferByte) raster.getDataBuffer()).getData(); break; case DataBuffer.TYPE_SHORT: destSPixbuf = ((DataBufferShort) raster.getDataBuffer()).getData(); break; case DataBuffer.TYPE_USHORT: destSPixbuf = ((DataBufferUShort) raster.getDataBuffer()).getData(); break; case DataBuffer.TYPE_INT: destIPixbuf = ((DataBufferInt) raster.getDataBuffer()).getData(); break; case DataBuffer.TYPE_FLOAT: destFPixbuf = ((DataBufferFloat) raster.getDataBuffer()).getData(); break; case DataBuffer.TYPE_DOUBLE: destDPixbuf = ((DataBufferDouble) raster.getDataBuffer()).getData(); break; } } else if (raster.getSampleModel() instanceof SinglePixelPackedSampleModel) { numBands = 1; bankIndices = new int[] {0}; destBandOffsets = new int[numBands]; for (int i = 0; i < numBands; i++) destBandOffsets[i] = 0; destPixelStride = 1; destScanlineStride = ((SinglePixelPackedSampleModel) raster.getSampleModel()).getScanlineStride(); } // Start the data delivery to the cached consumers tile by tile for (int y = startYTile; y <= endYTile; y++) { if (reader.getAbortRequest()) break; // Loop on horizontal tiles for (int x = startXTile; x <= endXTile; x++) { if (reader.getAbortRequest()) break; long tilePosition = position + (y * originalNumXTiles + x) * tileDataSize; iis.seek(tilePosition); float percentage = (x - startXTile + y * totalXTiles) / totalXTiles; int startX = x * tileWidth; int startY = y * tileHeight; int cTileHeight = tileHeight; int cTileWidth = tileWidth; if (startY + cTileHeight >= originalDimension.height) cTileHeight = originalDimension.height - startY; if (startX + cTileWidth >= originalDimension.width) cTileWidth = originalDimension.width - startX; int tx = startX; int ty = startY; // If source start position calculated by taking subsampling // into account is after the tile's start X position, adjust // the start position accordingly if (sourceSX > startX) { cTileWidth += startX - sourceSX; tx = sourceSX; startX = sourceSX; } if (sourceSY > startY) { cTileHeight += startY - sourceSY; ty = sourceSY; startY = sourceSY; } // If source end position calculated by taking subsampling // into account is prior to the tile's end X position, adjust // the tile width to read accordingly if (sourceEX < startX + cTileWidth - 1) { cTileWidth += sourceEX - startX - cTileWidth + 1; } if (sourceEY < startY + cTileHeight - 1) { cTileHeight += sourceEY - startY - cTileHeight + 1; } // The start X in the destination int x1 = (startX + scaleX - 1 - sourceOrigin.x) / scaleX; int x2 = (startX + scaleX - 1 + cTileWidth - sourceOrigin.x) / scaleX; int lineLength = x2 - x1; x2 = (x2 - 1) * scaleX + sourceOrigin.x; int y1 = (startY + scaleY - 1 - sourceOrigin.y) / scaleY; startX = x1 * scaleX + sourceOrigin.x; startY = y1 * scaleY + sourceOrigin.y; // offx is destination.x x1 += offx; y1 += offy; tx -= x * tileWidth; ty -= y * tileHeight; if (sampleModel instanceof MultiPixelPackedSampleModel) { MultiPixelPackedSampleModel mppsm = (MultiPixelPackedSampleModel) originalSampleModel; iis.skipBytes(mppsm.getOffset(tx, ty) * sampleSizeByte); int readBytes = (mppsm.getOffset(x2, 0) - mppsm.getOffset(startX, 0) + 1) * sampleSizeByte; int skipLength = (scanlineStride * scaleY - readBytes) * sampleSizeByte; readBytes *= sampleSizeByte; if (pixbuf == null || pixbuf.length < readBytes) pixbuf = new byte[readBytes]; int bitoff = mppsm.getBitOffset(tx); for (int l = 0, m = y1; l < cTileHeight; l += scaleY, m++) { if (reader.getAbortRequest()) break; iis.readFully(pixbuf, 0, readBytes); if (scaleX == 1) { if (bitoff != 0) { int mask1 = (255 << bitoff) & 255; int mask2 = ~mask1 & 255; int shift = 8 - bitoff; int n = 0; for (; n < readBytes - 1; n++) pixbuf[n] = (byte) (((pixbuf[n] & mask2) << shift) | (pixbuf[n + 1] & mask1) >> bitoff); pixbuf[n] = (byte) ((pixbuf[n] & mask2) << shift); } } else { int bit = 7; int pos = 0; int mask = 128; for (int n = 0, n1 = startX & 7; n < lineLength; n++, n1 += scaleX) { pixbuf[pos] = (byte) ((pixbuf[pos] & ~(1 << bit)) | (((pixbuf[n1 >> 3] >> (7 - (n1 & 7))) & 1) << bit)); bit--; if (bit == -1) { bit = 7; pos++; } } } ImageUtil.setPackedBinaryData(pixbuf, raster, new Rectangle(x1, m, lineLength, 1)); iis.skipBytes(skipLength); if (destImage != null) reader.processImageUpdateWrapper( destImage, x1, m, cTileWidth, 1, 1, 1, destinationBands); reader.processImageProgressWrapper( percentage + (l - startY + 1.0F) / cTileHeight / totalTiles); } } else { int readLength, skipLength; if (pixelStride < scanlineStride) { readLength = cTileWidth * pixelStride; skipLength = (scanlineStride * scaleY - readLength) * sampleSizeByte; } else { readLength = cTileHeight * scanlineStride; skipLength = (pixelStride * scaleX - readLength) * sampleSizeByte; } // Allocate buffer for all the types switch (sampleModel.getDataType()) { case DataBuffer.TYPE_BYTE: if (pixbuf == null || pixbuf.length < readLength) pixbuf = new byte[readLength]; break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (spixbuf == null || spixbuf.length < readLength) spixbuf = new short[readLength]; break; case DataBuffer.TYPE_INT: if (ipixbuf == null || ipixbuf.length < readLength) ipixbuf = new int[readLength]; break; case DataBuffer.TYPE_FLOAT: if (fpixbuf == null || fpixbuf.length < readLength) fpixbuf = new float[readLength]; break; case DataBuffer.TYPE_DOUBLE: if (dpixbuf == null || dpixbuf.length < readLength) dpixbuf = new double[readLength]; break; } if (sampleModel instanceof PixelInterleavedSampleModel) { iis.skipBytes((tx * pixelStride + ty * scanlineStride) * sampleSizeByte); // variables for ther loop int outerFirst, outerSecond, outerStep, outerBound; int innerStep, innerStep1, outerStep1; if (pixelStride < scanlineStride) { outerFirst = 0; outerSecond = y1; outerStep = scaleY; outerBound = cTileHeight; innerStep = scaleX * pixelStride; innerStep1 = destPixelStride; outerStep1 = destScanlineStride; } else { outerFirst = 0; outerSecond = x1; outerStep = scaleX; outerBound = cTileWidth; innerStep = scaleY * scanlineStride; innerStep1 = destScanlineStride; outerStep1 = destPixelStride; } int destPos = destSX + (y1 - raster.getSampleModelTranslateY()) * destScanlineStride + (x1 - raster.getSampleModelTranslateX()) * destPixelStride; for (int l = outerFirst, m = outerSecond; l < outerBound; l += outerStep, m++) { if (reader.getAbortRequest()) break; switch (dataType) { case DataBuffer.TYPE_BYTE: if (innerStep == numBands && innerStep1 == numBands) iis.readFully(destPixbuf, destPos, readLength); else iis.readFully(pixbuf, 0, readLength); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (innerStep == numBands && innerStep1 == numBands) { iis.readFully(destSPixbuf, destPos, readLength); } else iis.readFully(spixbuf, 0, readLength); break; case DataBuffer.TYPE_INT: if (innerStep == numBands && innerStep1 == numBands) iis.readFully(destIPixbuf, destPos, readLength); else iis.readFully(ipixbuf, 0, readLength); break; case DataBuffer.TYPE_FLOAT: if (innerStep == numBands && innerStep1 == numBands) iis.readFully(destFPixbuf, destPos, readLength); else iis.readFully(fpixbuf, 0, readLength); break; case DataBuffer.TYPE_DOUBLE: if (innerStep == numBands && innerStep1 == numBands) iis.readFully(destDPixbuf, destPos, readLength); else iis.readFully(dpixbuf, 0, readLength); break; } if (innerStep != numBands || innerStep1 != numBands) for (int b = 0; b < numBands; b++) { int destBandOffset = destBandOffsets[destinationBands[b]]; destPos += destBandOffset; int sourceBandOffset = bandOffsets[sourceBands[b]]; switch (dataType) { case DataBuffer.TYPE_BYTE: for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destPixbuf[n] = pixbuf[m1 + sourceBandOffset]; } break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destSPixbuf[n] = spixbuf[m1 + sourceBandOffset]; } break; case DataBuffer.TYPE_INT: for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destIPixbuf[n] = ipixbuf[m1 + sourceBandOffset]; } break; case DataBuffer.TYPE_FLOAT: for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destFPixbuf[n] = fpixbuf[m1 + sourceBandOffset]; } break; case DataBuffer.TYPE_DOUBLE: for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destDPixbuf[n] = dpixbuf[m1 + sourceBandOffset]; } break; } destPos -= destBandOffset; } iis.skipBytes(skipLength); destPos += outerStep1; if (destImage != null) if (pixelStride < scanlineStride) reader.processImageUpdateWrapper( destImage, x1, m, outerBound, 1, 1, 1, destinationBands); else reader.processImageUpdateWrapper( destImage, m, y1, 1, outerBound, 1, 1, destinationBands); reader.processImageProgressWrapper(percentage + (l + 1.0F) / outerBound / totalTiles); } } else if (sampleModel instanceof BandedSampleModel || sampleModel instanceof SinglePixelPackedSampleModel || bandStride == 0) { boolean isBanded = sampleModel instanceof BandedSampleModel; int bandSize = (int) ImageUtil.getBandSize(originalSampleModel); for (int b = 0; b < numBands; b++) { iis.seek(tilePosition + bandSize * sourceBands[b] * sampleSizeByte); int destBandOffset = destBandOffsets[destinationBands[b]]; iis.skipBytes((ty * scanlineStride + tx * pixelStride) * sampleSizeByte); // variables for ther loop int outerFirst, outerSecond, outerStep, outerBound; int innerStep, innerStep1, outerStep1; if (pixelStride < scanlineStride) { outerFirst = 0; outerSecond = y1; outerStep = scaleY; outerBound = cTileHeight; innerStep = scaleX * pixelStride; innerStep1 = destPixelStride; outerStep1 = destScanlineStride; } else { outerFirst = 0; outerSecond = x1; outerStep = scaleX; outerBound = cTileWidth; innerStep = scaleY * scanlineStride; innerStep1 = destScanlineStride; outerStep1 = destPixelStride; } int destPos = destSX + (y1 - raster.getSampleModelTranslateY()) * destScanlineStride + (x1 - raster.getSampleModelTranslateX()) * destPixelStride + destBandOffset; int bank = bankIndices[destinationBands[b]]; switch (dataType) { case DataBuffer.TYPE_BYTE: destPixbuf = ((DataBufferByte) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_SHORT: destSPixbuf = ((DataBufferShort) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_USHORT: destSPixbuf = ((DataBufferUShort) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_INT: destIPixbuf = ((DataBufferInt) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_FLOAT: destFPixbuf = ((DataBufferFloat) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_DOUBLE: destDPixbuf = ((DataBufferDouble) raster.getDataBuffer()).getData(bank); break; } for (int l = outerFirst, m = outerSecond; l < outerBound; l += outerStep, m++) { if (reader.getAbortRequest()) break; switch (dataType) { case DataBuffer.TYPE_BYTE: if (innerStep == 1 && innerStep1 == 1) { iis.readFully(destPixbuf, destPos, readLength); } else { iis.readFully(pixbuf, 0, readLength); for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destPixbuf[n] = pixbuf[m1]; } } break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: if (innerStep == 1 && innerStep1 == 1) { iis.readFully(destSPixbuf, destPos, readLength); } else { iis.readFully(spixbuf, 0, readLength); for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destSPixbuf[n] = spixbuf[m1]; } } break; case DataBuffer.TYPE_INT: if (innerStep == 1 && innerStep1 == 1) { iis.readFully(destIPixbuf, destPos, readLength); } else { iis.readFully(ipixbuf, 0, readLength); for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destIPixbuf[n] = ipixbuf[m1]; } } break; case DataBuffer.TYPE_FLOAT: if (innerStep == 1 && innerStep1 == 1) { iis.readFully(destFPixbuf, destPos, readLength); } else { iis.readFully(fpixbuf, 0, readLength); for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destFPixbuf[n] = fpixbuf[m1]; } } break; case DataBuffer.TYPE_DOUBLE: if (innerStep == 1 && innerStep1 == 1) { iis.readFully(destDPixbuf, destPos, readLength); } else { iis.readFully(dpixbuf, 0, readLength); for (int m1 = 0, n = destPos; m1 < readLength; m1 += innerStep, n += innerStep1) { destDPixbuf[n] = dpixbuf[m1]; } } break; } iis.skipBytes(skipLength); destPos += outerStep1; if (destImage != null) { int[] destBands = new int[] {destinationBands[b]}; if (pixelStride < scanlineStride) reader.processImageUpdateWrapper( destImage, x1, m, outerBound, 1, 1, 1, destBands); else reader.processImageUpdateWrapper( destImage, m, y1, 1, outerBound, 1, 1, destBands); } reader.processImageProgressWrapper( (percentage + (l + 1.0F) / outerBound / numBands / totalTiles) * 100.0F); } } } else if (sampleModel instanceof ComponentSampleModel) { // for the other case, may slow // Allocate buffer for all the types int bufferSize = (int) tileDataSize; switch (sampleModel.getDataType()) { case DataBuffer.TYPE_BYTE: if (pixbuf == null || pixbuf.length < tileDataSize) pixbuf = new byte[(int) tileDataSize]; iis.readFully(pixbuf, 0, (int) tileDataSize); break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: bufferSize /= 2; if (spixbuf == null || spixbuf.length < bufferSize) spixbuf = new short[(int) bufferSize]; iis.readFully(spixbuf, 0, (int) bufferSize); break; case DataBuffer.TYPE_INT: bufferSize /= 4; if (ipixbuf == null || ipixbuf.length < bufferSize) ipixbuf = new int[(int) bufferSize]; iis.readFully(ipixbuf, 0, (int) bufferSize); break; case DataBuffer.TYPE_FLOAT: bufferSize /= 4; if (fpixbuf == null || fpixbuf.length < bufferSize) fpixbuf = new float[(int) bufferSize]; iis.readFully(fpixbuf, 0, (int) bufferSize); break; case DataBuffer.TYPE_DOUBLE: bufferSize /= 8; if (dpixbuf == null || dpixbuf.length < bufferSize) dpixbuf = new double[(int) bufferSize]; iis.readFully(dpixbuf, 0, (int) bufferSize); break; } for (int b = 0; b < numBands; b++) { int destBandOffset = destBandOffsets[destinationBands[b]]; int destPos = ((ComponentSampleModel) raster.getSampleModel()) .getOffset( x1 - raster.getSampleModelTranslateX(), y1 - raster.getSampleModelTranslateY(), destinationBands[b]); int bank = bankIndices[destinationBands[b]]; switch (dataType) { case DataBuffer.TYPE_BYTE: destPixbuf = ((DataBufferByte) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_SHORT: destSPixbuf = ((DataBufferShort) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_USHORT: destSPixbuf = ((DataBufferUShort) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_INT: destIPixbuf = ((DataBufferInt) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_FLOAT: destFPixbuf = ((DataBufferFloat) raster.getDataBuffer()).getData(bank); break; case DataBuffer.TYPE_DOUBLE: destDPixbuf = ((DataBufferDouble) raster.getDataBuffer()).getData(bank); break; } int srcPos = ((ComponentSampleModel) originalSampleModel).getOffset(tx, ty, sourceBands[b]); int skipX = scaleX * pixelStride; ; for (int l = 0, m = y1; l < cTileHeight; l += scaleY, m++) { if (reader.getAbortRequest()) break; switch (dataType) { case DataBuffer.TYPE_BYTE: for (int n = 0, m1 = srcPos, m2 = destPos; n < lineLength; n++, m1 += skipX, m2 += destPixelStride) destPixbuf[m2] = pixbuf[m1]; break; case DataBuffer.TYPE_SHORT: case DataBuffer.TYPE_USHORT: for (int n = 0, m1 = srcPos, m2 = destPos; n < lineLength; n++, m1 += skipX, m2 += destPixelStride) destSPixbuf[m2] = spixbuf[m1]; break; case DataBuffer.TYPE_INT: for (int n = 0, m1 = srcPos, m2 = destPos; n < lineLength; n++, m1 += skipX, m2 += destPixelStride) destIPixbuf[m2] = ipixbuf[m1]; break; case DataBuffer.TYPE_FLOAT: for (int n = 0, m1 = srcPos, m2 = destPos; n < lineLength; n++, m1 += skipX, m2 += destPixelStride) destFPixbuf[m2] = fpixbuf[m1]; break; case DataBuffer.TYPE_DOUBLE: for (int n = 0, m1 = srcPos, m2 = destPos; n < lineLength; n++, m1 += skipX, m2 += destPixelStride) destDPixbuf[m2] = dpixbuf[m1]; break; } destPos += destScanlineStride; srcPos += scanlineStride * scaleY; if (destImage != null) { int[] destBands = new int[] {destinationBands[b]}; reader.processImageUpdateWrapper( destImage, x1, m, cTileHeight, 1, 1, 1, destBands); } reader.processImageProgressWrapper( percentage + (l + 1.0F) / cTileHeight / numBands / totalTiles); } } } else { throw new IllegalArgumentException(I18N.getString("RawRenderedImage1")); } } } // End loop on horizontal tiles } // End loop on vertical tiles return raster; }
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException { if (stream == null) { throw new IllegalStateException(I18N.getString("WBMPImageWriter3")); } if (image == null) { throw new IllegalArgumentException(I18N.getString("WBMPImageWriter4")); } clearAbortRequest(); processImageStarted(0); if (param == null) param = getDefaultWriteParam(); RenderedImage input = null; Raster inputRaster = null; boolean writeRaster = image.hasRaster(); Rectangle sourceRegion = param.getSourceRegion(); SampleModel sampleModel = null; if (writeRaster) { inputRaster = image.getRaster(); sampleModel = inputRaster.getSampleModel(); } else { input = image.getRenderedImage(); sampleModel = input.getSampleModel(); inputRaster = input.getData(); } checkSampleModel(sampleModel); if (sourceRegion == null) sourceRegion = inputRaster.getBounds(); else sourceRegion = sourceRegion.intersection(inputRaster.getBounds()); if (sourceRegion.isEmpty()) throw new RuntimeException(I18N.getString("WBMPImageWriter1")); int scaleX = param.getSourceXSubsampling(); int scaleY = param.getSourceYSubsampling(); int xOffset = param.getSubsamplingXOffset(); int yOffset = param.getSubsamplingYOffset(); sourceRegion.translate(xOffset, yOffset); sourceRegion.width -= xOffset; sourceRegion.height -= yOffset; int minX = sourceRegion.x / scaleX; int minY = sourceRegion.y / scaleY; int w = (sourceRegion.width + scaleX - 1) / scaleX; int h = (sourceRegion.height + scaleY - 1) / scaleY; Rectangle destinationRegion = new Rectangle(minX, minY, w, h); sampleModel = sampleModel.createCompatibleSampleModel(w, h); SampleModel destSM = sampleModel; // If the data are not formatted nominally then reformat. if (sampleModel.getDataType() != DataBuffer.TYPE_BYTE || !(sampleModel instanceof MultiPixelPackedSampleModel) || ((MultiPixelPackedSampleModel) sampleModel).getDataBitOffset() != 0) { destSM = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE, w, h, 1, w + 7 >> 3, 0); } if (!destinationRegion.equals(sourceRegion)) { if (scaleX == 1 && scaleY == 1) inputRaster = inputRaster.createChild( inputRaster.getMinX(), inputRaster.getMinY(), w, h, minX, minY, null); else { WritableRaster ras = Raster.createWritableRaster(destSM, new Point(minX, minY)); byte[] data = ((DataBufferByte) ras.getDataBuffer()).getData(); for (int j = minY, y = sourceRegion.y, k = 0; j < minY + h; j++, y += scaleY) { for (int i = 0, x = sourceRegion.x; i < w; i++, x += scaleX) { int v = inputRaster.getSample(x, y, 0); data[k + (i >> 3)] |= v << (7 - (i & 7)); } k += w + 7 >> 3; } inputRaster = ras; } } // If the data are not formatted nominally then reformat. if (!destSM.equals(inputRaster.getSampleModel())) { WritableRaster raster = Raster.createWritableRaster( destSM, new Point(inputRaster.getMinX(), inputRaster.getMinY())); raster.setRect(inputRaster); inputRaster = raster; } // Check whether the image is white-is-zero. boolean isWhiteZero = false; if (!writeRaster && input.getColorModel() instanceof IndexColorModel) { IndexColorModel icm = (IndexColorModel) input.getColorModel(); isWhiteZero = icm.getRed(0) > icm.getRed(1); } // Get the line stride, bytes per row, and data array. int lineStride = ((MultiPixelPackedSampleModel) destSM).getScanlineStride(); int bytesPerRow = (w + 7) / 8; byte[] bdata = ((DataBufferByte) inputRaster.getDataBuffer()).getData(); // Write WBMP header. stream.write(0); // TypeField stream.write(0); // FixHeaderField stream.write(intToMultiByte(w)); // width stream.write(intToMultiByte(h)); // height // Write the data. if (!isWhiteZero && lineStride == bytesPerRow) { // Write the entire image. stream.write(bdata, 0, h * bytesPerRow); processImageProgress(100.0F); } else { // Write the image row-by-row. int offset = 0; if (!isWhiteZero) { // Black-is-zero for (int row = 0; row < h; row++) { if (abortRequested()) break; stream.write(bdata, offset, bytesPerRow); offset += lineStride; processImageProgress(100.0F * row / h); } } else { // White-is-zero: need to invert data. byte[] inverted = new byte[bytesPerRow]; for (int row = 0; row < h; row++) { if (abortRequested()) break; for (int col = 0; col < bytesPerRow; col++) { inverted[col] = (byte) (~(bdata[col + offset])); } stream.write(inverted, 0, bytesPerRow); offset += lineStride; processImageProgress(100.0F * row / h); } } } if (abortRequested()) processWriteAborted(); else { processImageComplete(); stream.flushBefore(stream.getStreamPosition()); } }
@Override public void run() { synchronized (gen) { gen.chartFile = null; } long jobId = gen.jobId; StartedJobInfo[] fullHistory = RunningJobsInfoDAO.getInstance().getFullJobHistory(jobId); LinkedList<Double> timeValues = new LinkedList<Double>(); LinkedList<Double> progressValues = new LinkedList<Double>(); LinkedList<Double> urlValues = new LinkedList<Double>(); for (StartedJobInfo sji : fullHistory) { timeValues.add((double) sji.getElapsedSeconds()); progressValues.add(sji.getProgress()); urlValues.add((double) sji.getQueuedFilesCount()); } // Refresh the history png image for the job. File pngFile = new File(gen.outputFolder, jobId + "-history.png"); File newPngFile; try { newPngFile = File.createTempFile(jobId + "-history", "." + System.currentTimeMillis() + ".png"); } catch (IOException e) { LOG.warn("Failed to create temp PNG file for job " + jobId); return; } long startTime = System.currentTimeMillis(); gen.generatePngChart( newPngFile, CHART_RESOLUTION[0], CHART_RESOLUTION[1], null, // no chart title I18N.getString(gen.locale, "running.job.details.chart.legend.crawlTime"), new String[] { I18N.getString(gen.locale, "running.job.details.chart.legend.progress"), I18N.getString(gen.locale, "running.job.details.chart.legend.queuedUris") }, NumberUtils.toPrimitiveArray(timeValues), new double[][] {new double[] {0, 100}, null}, new double[][] { NumberUtils.toPrimitiveArray(progressValues), NumberUtils.toPrimitiveArray(urlValues) }, new Color[] {Color.blue, Color.green.darker()}, new String[] {"%", ""}, false, Color.lightGray.brighter().brighter()); long genTime = System.currentTimeMillis() - startTime; LOG.info( "Generated history chart for job " + jobId + " in " + (genTime < TimeUtils.SECOND_IN_MILLIS ? genTime + " ms" : StringUtils.formatDuration(genTime / TimeUtils.SECOND_IN_MILLIS)) + "."); synchronized (gen) { // Overwrite old file, then delete temp file try { FileUtils.copyFile(newPngFile, pngFile); FileUtils.remove(newPngFile); } catch (IOFailure iof) { LOG.error("IOFailure while copying PNG file", iof); } gen.chartFile = pngFile; } }
private void initializeRead(int imageIndex, J2KImageReadParamJava param, J2KMetadata metadata) { try { iis.mark(); in = new IISRandomAccessIO(iis); // **** File Format **** // If the codestream is wrapped in the jp2 fileformat, Read the // file format wrapper ff = new FileFormatReader(in, metadata); ff.readFileFormat(); in.seek(ff.getFirstCodeStreamPos()); hi = new HeaderInfo(); try { hd = new HeaderDecoder(in, j2krparam, hi); } catch (EOFException e) { throw new RuntimeException(I18N.getString("J2KReadState2")); } catch (IOException ioe) { throw new RuntimeException(ioe); } this.width = hd.getImgWidth(); this.height = hd.getImgHeight(); Rectangle sourceRegion = param.getSourceRegion(); sourceOrigin = new Point(); sourceRegion = new Rectangle(hd.getImgULX(), hd.getImgULY(), this.width, this.height); // if the subsample rate for components are not consistent boolean compConsistent = true; stepX = hd.getCompSubsX(0); stepY = hd.getCompSubsY(0); for (int i = 1; i < nComp; i++) { if (stepX != hd.getCompSubsX(i) || stepY != hd.getCompSubsY(i)) throw new RuntimeException(I18N.getString("J2KReadState12")); } // Get minimum number of resolution levels available across // all tile-components. int minResLevels = hd.getDecoderSpecs().dls.getMin(); // Set current resolution level. this.resolution = param != null ? param.getResolution() : minResLevels; if (resolution < 0 || resolution > minResLevels) { resolution = minResLevels; } // Convert source region to lower resolution level. if (resolution != minResLevels || stepX != 1 || stepY != 1) { sourceRegion = J2KImageReader.getReducedRect(sourceRegion, minResLevels, resolution, stepX, stepY); } destinationRegion = (Rectangle) sourceRegion.clone(); J2KImageReader.computeRegionsWrapper( param, false, this.width, this.height, param.getDestination(), sourceRegion, destinationRegion); sourceOrigin = new Point(sourceRegion.x, sourceRegion.y); scaleX = param.getSourceXSubsampling(); scaleY = param.getSourceYSubsampling(); xOffset = param.getSubsamplingXOffset(); yOffset = param.getSubsamplingYOffset(); this.width = destinationRegion.width; this.height = destinationRegion.height; Point tileOffset = hd.getTilingOrigin(null); this.tileWidth = hd.getNomTileWidth(); this.tileHeight = hd.getNomTileHeight(); // Convert tile 0 to lower resolution level. if (resolution != minResLevels || stepX != 1 || stepY != 1) { Rectangle tileRect = new Rectangle(tileOffset); tileRect.width = tileWidth; tileRect.height = tileHeight; tileRect = J2KImageReader.getReducedRect(tileRect, minResLevels, resolution, stepX, stepY); tileOffset = tileRect.getLocation(); tileWidth = tileRect.width; tileHeight = tileRect.height; } tileXOffset = tileOffset.x; tileYOffset = tileOffset.y; // Set the tile step sizes. These values are used because it // is possible that tiles will be empty. In particular at lower // resolution levels when subsampling is used this may be the // case. This method of calculation will work at least for // Profile-0 images. if (tileWidth * (1 << (minResLevels - resolution)) * stepX > hd.getNomTileWidth()) { tileStepX = (tileWidth * (1 << (minResLevels - resolution)) * stepX + hd.getNomTileWidth() - 1) / hd.getNomTileWidth(); } else { tileStepX = 1; } if (tileHeight * (1 << (minResLevels - resolution)) * stepY > hd.getNomTileHeight()) { tileStepY = (tileHeight * (1 << (minResLevels - resolution)) * stepY + hd.getNomTileHeight() - 1) / hd.getNomTileHeight(); } else { tileStepY = 1; } if (!destinationRegion.equals(sourceRegion)) noTransform = false; // **** Header decoder **** // Instantiate header decoder and read main header decSpec = hd.getDecoderSpecs(); // **** Instantiate decoding chain **** // Get demixed bitdepths nComp = hd.getNumComps(); int[] depth = new int[nComp]; for (int i = 0; i < nComp; i++) depth[i] = hd.getOriginalBitDepth(i); // Get channel mapping ChannelDefinitionBox cdb = null; if (metadata != null) cdb = (ChannelDefinitionBox) metadata.getElement("JPEG2000ChannelDefinitionBox"); channelMap = new int[nComp]; if (cdb != null && metadata.getElement("JPEG2000PaletteBox") == null) { short[] assoc = cdb.getAssociation(); short[] types = cdb.getTypes(); short[] channels = cdb.getChannel(); for (int i = 0; i < types.length; i++) if (types[i] == 0) channelMap[channels[i]] = assoc[i] - 1; else if (types[i] == 1 || types[i] == 2) channelMap[channels[i]] = channels[i]; } else { for (int i = 0; i < nComp; i++) channelMap[i] = i; } // **** Bitstream reader **** try { boolean logJJ2000Messages = Boolean.getBoolean("jj2000.j2k.decoder.log"); breader = BitstreamReaderAgent.createInstance(in, hd, j2krparam, decSpec, logJJ2000Messages, hi); } catch (IOException e) { throw new RuntimeException( I18N.getString("J2KReadState3") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } catch (IllegalArgumentException e) { throw new RuntimeException( I18N.getString("J2KReadState4") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } // **** Entropy decoder **** try { entdec = hd.createEntropyDecoder(breader, j2krparam); } catch (IllegalArgumentException e) { throw new RuntimeException( I18N.getString("J2KReadState5") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } // **** ROI de-scaler **** try { roids = hd.createROIDeScaler(entdec, j2krparam, decSpec); } catch (IllegalArgumentException e) { throw new RuntimeException( I18N.getString("J2KReadState6") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } // **** Dequantizer **** try { deq = hd.createDequantizer(roids, depth, decSpec); } catch (IllegalArgumentException e) { throw new RuntimeException( I18N.getString("J2KReadState7") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } // **** Inverse wavelet transform *** try { // full page inverse wavelet transform invWT = InverseWT.createInstance(deq, decSpec); } catch (IllegalArgumentException e) { throw new RuntimeException( I18N.getString("J2KReadState8") + " " + ((e.getMessage() != null) ? (":\n" + e.getMessage()) : "")); } int res = breader.getImgRes(); int mrl = decSpec.dls.getMin(); invWT.setImgResLevel(res); // **** Data converter **** (after inverse transform module) converter = new ImgDataConverter(invWT, 0); // **** Inverse component transformation **** ictransf = new InvCompTransf(converter, decSpec, depth); // If the destination band is set used it sourceBands = j2krparam.getSourceBands(); if (sourceBands == null) { sourceBands = new int[nComp]; for (int i = 0; i < nComp; i++) sourceBands[i] = i; } nComp = sourceBands.length; destinationBands = j2krparam.getDestinationBands(); if (destinationBands == null) { destinationBands = new int[nComp]; for (int i = 0; i < nComp; i++) destinationBands[i] = i; } J2KImageReader.checkReadParamBandSettingsWrapper( param, hd.getNumComps(), destinationBands.length); levelShift = new int[nComp]; minValues = new int[nComp]; maxValues = new int[nComp]; fracBits = new int[nComp]; dataBlocks = new DataBlkInt[nComp]; depth = new int[nComp]; bandOffsets = new int[nComp]; maxDepth = 0; isSigned = false; for (int i = 0; i < nComp; i++) { depth[i] = hd.getOriginalBitDepth(sourceBands[i]); if (depth[i] > maxDepth) maxDepth = depth[i]; dataBlocks[i] = new DataBlkInt(); // XXX: may need to change if ChannelDefinition is used to // define the color channels, such as BGR order bandOffsets[i] = i; if (hd.isOriginalSigned(sourceBands[i])) isSigned = true; else { levelShift[i] = 1 << (ictransf.getNomRangeBits(sourceBands[i]) - 1); } // Get the number of bits in the image, and decide what the max // value should be, depending on whether it is signed or not int nomRangeBits = ictransf.getNomRangeBits(sourceBands[i]); maxValues[i] = (1 << (isSigned == true ? (nomRangeBits - 1) : nomRangeBits)) - 1; minValues[i] = isSigned ? -(maxValues[i] + 1) : 0; fracBits[i] = ictransf.getFixedPoint(sourceBands[i]); } iis.reset(); } catch (IllegalArgumentException e) { throw new RuntimeException(e.getMessage(), e); } catch (Error e) { if (e.getMessage() != null) throw new RuntimeException(e.getMessage(), e); else { throw new RuntimeException(I18N.getString("J2KReadState9"), e); } } catch (RuntimeException e) { if (e.getMessage() != null) throw new RuntimeException(I18N.getString("J2KReadState10") + " " + e.getMessage(), e); else { throw new RuntimeException(I18N.getString("J2KReadState10"), e); } } catch (Throwable e) { throw new RuntimeException(I18N.getString("J2KReadState10"), e); } }
public Raster getTile(int tileX, int tileY, WritableRaster raster) throws IOException { Point nT = ictransf.getNumTiles(null); if (noTransform) { if (tileX >= nT.x || tileY >= nT.y) throw new IllegalArgumentException(I18N.getString("J2KImageReader0")); ictransf.setTile(tileX * tileStepX, tileY * tileStepY); // The offset of the active tiles is the same for all components, // since we don't support different component dimensions. int tOffx; int tOffy; int cTileWidth; int cTileHeight; if (raster != null && (this.resolution < hd.getDecoderSpecs().dls.getMin()) || stepX != 1 || stepY != 1) { tOffx = raster.getMinX(); tOffy = raster.getMinY(); cTileWidth = Math.min(raster.getWidth(), ictransf.getTileWidth()); cTileHeight = Math.min(raster.getHeight(), ictransf.getTileHeight()); } else { tOffx = ictransf.getCompULX(0) - (ictransf.getImgULX() + ictransf.getCompSubsX(0) - 1) / ictransf.getCompSubsX(0) + destinationRegion.x; tOffy = ictransf.getCompULY(0) - (ictransf.getImgULY() + ictransf.getCompSubsY(0) - 1) / ictransf.getCompSubsY(0) + destinationRegion.y; cTileWidth = ictransf.getTileWidth(); cTileHeight = ictransf.getTileHeight(); } if (raster == null) raster = Raster.createWritableRaster(sampleModel, new Point(tOffx, tOffy)); int numBands = sampleModel.getNumBands(); if (tOffx + cTileWidth >= destinationRegion.width + destinationRegion.x) cTileWidth = destinationRegion.width + destinationRegion.x - tOffx; if (tOffy + cTileHeight >= destinationRegion.height + destinationRegion.y) cTileHeight = destinationRegion.height + destinationRegion.y - tOffy; // create the line buffer for pixel data if it is not large enough // or null if (pixbuf == null || pixbuf.length < cTileWidth * numBands) pixbuf = new int[cTileWidth * numBands]; boolean prog = false; // Deliver in lines to reduce memory usage for (int l = 0; l < cTileHeight; l++) { if (reader.getAbortRequest()) break; // Request line data for (int i = 0; i < numBands; i++) { if (reader.getAbortRequest()) break; DataBlkInt db = dataBlocks[i]; db.ulx = 0; db.uly = l; db.w = cTileWidth; db.h = 1; ictransf.getInternCompData(db, channelMap[sourceBands[i]]); prog = prog || db.progressive; int[] data = db.data; int k1 = db.offset + cTileWidth - 1; int fracBit = fracBits[i]; int lS = levelShift[i]; int min = minValues[i]; int max = maxValues[i]; if (ImageUtil.isBinary(sampleModel)) { // Force min max to 0 and 1. min = 0; max = 1; if (bytebuf == null || bytebuf.length < cTileWidth * numBands) bytebuf = new byte[cTileWidth * numBands]; for (int j = cTileWidth - 1; j >= 0; j--) { int tmp = (data[k1--] >> fracBit) + lS; bytebuf[j] = (byte) ((tmp < min) ? min : ((tmp > max) ? max : tmp)); } ImageUtil.setUnpackedBinaryData( bytebuf, raster, new Rectangle(tOffx, tOffy + l, cTileWidth, 1)); } else { for (int j = cTileWidth - 1; j >= 0; j--) { int tmp = (data[k1--] >> fracBit) + lS; pixbuf[j] = (tmp < min) ? min : ((tmp > max) ? max : tmp); } raster.setSamples(tOffx, tOffy + l, cTileWidth, 1, destinationBands[i], pixbuf); } } } } else { readSubsampledRaster(raster); } return raster; }