@Override Raster generateRasterFromFile(File file, String tifName) { SeekableStream ss = null; try { InputStream is = new FileInputStream(file); ss = SeekableStream.wrapInputStream(is, true); TIFFImageDecoder imageDecoder = new TIFFImageDecoder(ss, new TIFFDecodeParam()); return imageDecoder.decodeAsRaster(); } catch (Exception e) { throw new RuntimeException("Can't decode " + file.getName(), e); } finally { if (ss != null) close(ss); } }
public void decode1D(byte[] buffer, byte[] compData, int startX, int height) { this.data = compData; int lineOffset = 0; int scanlineStride = (w + 7) / 8; bitPointer = 0; bytePointer = 0; for (int i = 0; i < height; i++) { decodeNextScanline(buffer, lineOffset, startX); lineOffset += scanlineStride; } }
private static boolean bilevelColorValue(byte[] r, byte[] g, byte[] b, int blackValue, int whiteValue) { return rgbIsValueAt(r, g, b, (byte) blackValue, 0) && rgbIsValueAt(r, g, b, (byte) whiteValue, 1); }
public void writeImage(RenderedImage image, ImageWriterParams params) throws IOException { if (encoder == null) { encodeParams = createTIFFEncodeParams(params); encoder = new TIFFImageEncoder(out, encodeParams); } context = encoder.encodeMultiple(context, image); }
public TIFFImageEncoder(OutputStream output, ImageEncodeParam param) { super(output, param); if (this.param == null) { this.param = new TIFFEncodeParam(); } }
public RenderedImage decodeAsRenderedImage(int page) throws IOException { if ((page < 0) || (page >= getNumPages())) { throw new IOException(PropertyUtil.getString("TIFFImageDecoder0")); } return new TIFFImage(input, (TIFFDecodeParam) param, page); } }
private ImageInfo(ImageInfoBuilder builder) { this.numExtraSamples = builder.numExtraSamples; this.extraSampleType = builder.extraSampleType; this.imageType = builder.imageType; this.colormapSize = builder.colormapSize; this.colormap = copyColormap(builder.colormap); this.tileWidth = builder.tileWidth; this.tileHeight = builder.tileHeight; this.numTiles = builder.numTiles; this.bytesPerRow = builder.bytesPerRow; this.bytesPerTile = builder.bytesPerTile; }
/** * Returns the value of index 0 of a given tag as a * byte. The caller is responsible for ensuring that the tag is * present and has type TIFFField.TIFF_SBYTE, TIFF_BYTE, or * TIFF_UNDEFINED. */ public byte getFieldAsByte(int tag) { return getFieldAsByte(tag, 0); }
/** * Returns the value of index 0 of a given tag as a float. The * caller is responsible for ensuring that the tag is present and * has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII). */ public float getFieldAsFloat(int tag) { return getFieldAsFloat(tag, 0); }
/** * Returns the value of index 0 of a given tag as a double. The * caller is responsible for ensuring that the tag is present and * has numeric type (all but TIFF_UNDEFINED and TIFF_ASCII). */ public double getFieldAsDouble(int tag) { return getFieldAsDouble(tag, 0); }
private static char[] createColormap(final int sizeOfColormap, byte[] r, byte[] g, byte[] b) { int redIndex = 0; int greenIndex = sizeOfColormap; int blueIndex = 2 * sizeOfColormap; char[] colormap = new char[sizeOfColormap * 3]; for (int i = 0; i < sizeOfColormap; i++) { // beware of sign extended bytes colormap[redIndex++] = convertColorToColormapChar(0xff & r[i]); colormap[greenIndex++] = convertColorToColormapChar(0xff & g[i]); colormap[blueIndex++] = convertColorToColormapChar(0xff & b[i]); } return colormap; }
public WritableRaster copyData(WritableRaster wr) { copyToRaster(wr); return wr; }
/** * Returns the value of index 0 of a given tag as a * long. The caller is responsible for ensuring that the tag is * present and has type TIFF_BYTE, TIFF_SBYTE, TIFF_UNDEFINED, * TIFF_SHORT, TIFF_SSHORT, TIFF_SLONG or TIFF_LONG. */ public long getFieldAsLong(int tag) { return getFieldAsLong(tag, 0); }
/** * Reads a private IFD from a given offset in the stream. This * method may be used to obtain IFDs that are referenced * only by private tag values. */ public TIFFDirectory getPrivateIFD(long offset) throws IOException { return new TIFFDirectory(stream, offset, 0); }
private static boolean isBlackZero(byte[] r, byte[] g, byte[] b) { return bilevelColorValue(r, g, b, 0, 0xff); }
/** * Performs PackBits compression on a tile of data. */ private static int compressPackBits(byte[] data, int numRows, long bytesPerRow, byte[] compData) { int inOffset = 0; int outOffset = 0; for (int i = 0; i < numRows; i++) { outOffset = packBits(data, inOffset, (int) bytesPerRow, compData, outOffset); inOffset += bytesPerRow; } return outOffset; }
public int getNumPages() throws IOException { return TIFFDirectory.getNumDirectories(input); }
private ImageInfo build() { return new ImageInfo(this); } }
@Override Raster generateRasterFromFile(File file, String tifName) { SeekableStream ss = null; try { InputStream is = new FileInputStream(file); ZipInputStream zis = new ZipInputStream(is); // find tif file in zip ZipEntry entry = zis.getNextEntry(); while (entry != null && !entry.getName().equals(tifName)) { entry = zis.getNextEntry(); } ss = SeekableStream.wrapInputStream(zis, true); TIFFImageDecoder imageDecoder = new TIFFImageDecoder(ss, new TIFFDecodeParam()); return imageDecoder.decodeAsRaster(); } catch (Exception e) { throw new RuntimeException("Can't decode " + tifName, e); } finally { if (ss != null) Helper.close(ss); } }
char[] getColormap() { return copyColormap(colormap); }