/** * Returns the value of a particular index 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, int index) { Integer i = (Integer)fieldIndex.get(tag); byte [] b = (fields[i]).getAsBytes(); return b[index]; }
/** * Return as a long[] the value of a TIFF_LONG or TIFF_SHORT field. */ private long[] getFieldAsLongs(TIFFField field) { long[] value = null; if (field.getType() == TIFFField.TIFF_SHORT) { char[] charValue = field.getAsChars(); value = new long[charValue.length]; for (int i = 0; i < charValue.length; i++) { value[i] = charValue[i] & 0xffff; } } else if (field.getType() == TIFFField.TIFF_LONG) { value = field.getAsLongs(); } else { throw new RuntimeException(PropertyUtil.getString("TIFFImage18") + ": " + field.getType()); } return value; }
/** * Returns the value of a particular index 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, int index) { Integer i = (Integer)fieldIndex.get(tag); return fields[i].getAsDouble(index); }
int dataType = field.getType(); int count = field.getCount(); case TIFFField.TIFF_SBYTE: case TIFFField.TIFF_UNDEFINED: byte[] bytes = field.getAsBytes(); for (int i = 0; i < count; i++) { output.write(bytes[i]); char[] chars = field.getAsChars(); for (int i = 0; i < count; i++) { writeUnsignedShort(chars[i]); short[] shorts = field.getAsShorts(); for (int i = 0; i < count; i++) { writeUnsignedShort(shorts[i]); long[] longs = field.getAsLongs(); for (int i = 0; i < count; i++) { writeLong(longs[i]); float[] floats = field.getAsFloats(); for (int i = 0; i < count; i++) { int intBits = Float.floatToIntBits(floats[i]); double[] doubles = field.getAsDoubles(); for (int i = 0; i < count; i++) { long longBits = Double.doubleToLongBits(doubles[i]);
private void writeValuesAsFourBytes(TIFFField field) throws IOException { int dataType = field.getType(); int count = field.getCount(); byte[] bytes = field.getAsBytes(); if (count > 4) { count = 4; char[] chars = field.getAsChars(); if (count > 2) { count = 2; long[] longs = field.getAsLongs();
int samplesPerPixel = sfield == null ? 1 : (int)sfield.getAsLong(0); char[] planarConfiguration = planarConfigurationField == null ? new char[] {1} : planarConfigurationField.getAsChars(); char[] bitsPerSample = null; if (bitsField != null) { bitsPerSample = bitsField.getAsChars(); } else { bitsPerSample = new char[] {1}; sampleFormat = sampleFormatField.getAsChars(); compression = compField == null ? COMP_NONE : compField.getAsInt(0); photometricType = 0; // White is zero } else { photometricType = photometricTypeField.getAsInt(0); int extraSamples = efield == null ? 0 : (int)efield.getAsLong(0); (int)dir.getFieldAsLong(TIFFImageDecoder.TIFF_TILE_LENGTH); tileOffsets = (dir.getField(TIFFImageDecoder.TIFF_TILE_OFFSETS)).getAsLongs(); tileByteCounts = getFieldAsLongs(dir.getField(TIFFImageDecoder.TIFF_TILE_BYTE_COUNTS)); : bounds.height;
yRes = xRes; } else { xRes = fldx.getAsFloat(0); yRes = fldy.getAsFloat(0); int compression = fld.getAsInt(0); if (log.isTraceEnabled()) { log.trace("TIFF compression: " + compression); stripCount = 1; } else { stripCount = (int)Math.ceil(size.getHeightPx() / (double)fld.getAsLong(0));
compression = fld.getAsInt(0); switch (compression) { case COMPRESSION_CCITT_1D: long t4Options = fld.getAsLong(0); if ((t4Options & 0x01) != 0) { fillOrder = fld.getAsInt(0); stripCount = 1; } else { stripCount = (int)(info.getSize().getHeightPx() / fld.getAsLong(0)); "ImageLoader doesn't support multiple strips"); stripOffset = dir.getField(TIFFImageDecoder.TIFF_STRIP_OFFSETS).getAsLong(0); stripLength = dir.getField(TIFFImageDecoder.TIFF_STRIP_BYTE_COUNTS).getAsLong(0); } finally { in.reset();
fields.add(new TIFFField(TIFFImageDecoder.TIFF_IMAGE_WIDTH, TIFFField.TIFF_LONG, 1, new long[] {width})); fields.add(new TIFFField(TIFFImageDecoder.TIFF_IMAGE_LENGTH, TIFFField.TIFF_LONG, 1, new long[] {height})); fields.add(new TIFFField(TIFFImageDecoder.TIFF_BITS_PER_SAMPLE, TIFFField.TIFF_SHORT, numBands, shortSampleSize)); fields.add(new TIFFField(TIFFImageDecoder.TIFF_COMPRESSION, TIFFField.TIFF_SHORT, 1, new char[] {(char)compression.getValue()})); new TIFFField(TIFFImageDecoder.TIFF_PHOTOMETRIC_INTERPRETATION, TIFFField.TIFF_SHORT, 1, new char[] {(char) imageInfo.getType().getPhotometricInterpretation()})); fields.add(new TIFFField(TIFFImageDecoder.TIFF_STRIP_OFFSETS, TIFFField.TIFF_LONG, numTiles, tileOffsets)); fields.add(new TIFFField(TIFFImageDecoder.TIFF_SAMPLES_PER_PIXEL, TIFFField.TIFF_SHORT, 1, new char[] {(char)numBands})); fields.add(new TIFFField(TIFFImageDecoder.TIFF_ROWS_PER_STRIP,
long [] yRational = {numPixY, denom}; TIFFField [] fields = { new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT, TIFFField.TIFF_SHORT, 1, new char[] {(char)params.getResolutionUnit().getValue()}), new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION, TIFFField.TIFF_RATIONAL, 1, new long[][] {xRational}), new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION, TIFFField.TIFF_RATIONAL, 1, new long[][] {yRational})
/** * Returns the value of a particular index 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, int index) { Integer i = (Integer)fieldIndex.get(tag); return fields[i].getAsFloat(index); }
/** * Returns the value of a particular index 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, int index) { Integer i = (Integer)fieldIndex.get(tag); return (fields[i]).getAsLong(index); }
fields[i] = new TIFFField(tag, type, count, obj); stream.seek(nextTagOffset);