下面列出了怎么用javax.imageio.plugins.tiff.BaselineTIFFTagSet的API类实例代码及写法,或者点击链接到github查看源代码。
public IIOMetadata
getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
TIFFImageMetadata imageMetadata = new TIFFImageMetadata(tagSets);
if(imageType != null) {
TIFFImageMetadata im =
(TIFFImageMetadata)convertImageMetadata(imageMetadata,
imageType,
param);
if(im != null) {
imageMetadata = im;
}
}
return imageMetadata;
}
/**
* Converts a standard {@code javax_imageio_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the standard tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null}.
* @throws IllegalArgumentException if {@code inData} does not support
* the standard metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid standard metadata tree.
*/
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!inData.isStandardMetadataFormatSupported()) {
throw new IllegalArgumentException
("inData does not support standard metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
/**
* Converts a native
* {@code javax_imageio_tiff_image_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the native tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null} or does not support the native metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid native metadata tree.
*/
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
throw new IllegalArgumentException
("inData does not support native metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
private TIFFIFD readIFD(int imageIndex) throws IOException {
if (stream == null) {
throw new IllegalStateException("Output not set!");
}
if (imageIndex < 0) {
throw new IndexOutOfBoundsException("imageIndex < 0!");
}
stream.mark();
long[] ifdpos = new long[1];
long[] ifd = new long[1];
locateIFD(imageIndex, ifdpos, ifd);
if (ifd[0] == 0) {
stream.reset();
throw new IndexOutOfBoundsException
("imageIndex out of bounds!");
}
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
TIFFIFD rootIFD = new TIFFIFD(tagSets);
rootIFD.initialize(stream, true, false, false);
stream.reset();
return rootIFD;
}
/**
* Sets the value of the {@code metadata} field.
*
* <p> The implementation in this class also sets local options
* from the T4_OPTIONS field if it exists, and if it doesn't, adds
* it with default values.</p>
*
* @param metadata the {@code IIOMetadata} object for the
* image being written.
*
* @see #getMetadata()
*/
public void setMetadata(IIOMetadata metadata) {
super.setMetadata(metadata);
if (metadata instanceof TIFFImageMetadata) {
TIFFImageMetadata tim = (TIFFImageMetadata)metadata;
TIFFField f = tim.getTIFFField(BaselineTIFFTagSet.TAG_T4_OPTIONS);
if (f != null) {
int options = f.getAsInt(0);
is1DMode = (options & 0x1) == 0;
isEOLAligned = (options & 0x4) == 0x4;
} else {
long[] oarray = new long[1];
oarray[0] = (isEOLAligned ? 0x4 : 0x0) |
(is1DMode ? 0x0 : 0x1);
BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
TIFFField T4Options =
new TIFFField(base.getTag(BaselineTIFFTagSet.TAG_T4_OPTIONS),
TIFFTag.TIFF_LONG,
1,
oarray);
tim.rootIFD.addTIFFField(T4Options);
}
}
}
private long getTileOrStripOffset(int tileIndex) throws IIOException {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
}
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT);
}
if (f == null) {
throw new IIOException("Missing required strip or tile offsets field.");
}
return f.getAsLong(tileIndex);
}
protected void resetLocal() {
stream = null;
gotHeader = false;
imageReadParam = getDefaultReadParam();
streamMetadata = null;
currIndex = -1;
imageMetadata = null;
imageStartPosition = new ArrayList<Long>();
numImages = -1;
imageTypeMap = new HashMap<Integer, List<ImageTypeSpecifier>>();
width = -1;
height = -1;
numBands = -1;
tileOrStripWidth = -1;
tileOrStripHeight = -1;
planarConfiguration = BaselineTIFFTagSet.PLANAR_CONFIGURATION_CHUNKY;
}
public IIOMetadata
getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
TIFFImageMetadata imageMetadata = new TIFFImageMetadata(tagSets);
if(imageType != null) {
TIFFImageMetadata im =
(TIFFImageMetadata)convertImageMetadata(imageMetadata,
imageType,
param);
if(im != null) {
imageMetadata = im;
}
}
return imageMetadata;
}
/**
* Converts a standard {@code javax_imageio_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the standard tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null}.
* @throws IllegalArgumentException if {@code inData} does not support
* the standard metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid standard metadata tree.
*/
private TIFFImageMetadata convertStandardImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!inData.isStandardMetadataFormatSupported()) {
throw new IllegalArgumentException
("inData does not support standard metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = IIOMetadataFormatImpl.standardMetadataFormatName;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
/**
* Converts a native
* {@code javax_imageio_tiff_image_1.0} tree to a
* {@code TIFFImageMetadata} object.
*
* @param inData The metadata object.
* @return a {@code TIFFImageMetadata} or {@code null} if
* the native tree derived from the input object is {@code null}.
* @throws IllegalArgumentException if {@code inData} is
* {@code null} or does not support the native metadata format.
* @throws IIOInvalidTreeException if {@code inData} generates an
* invalid native metadata tree.
*/
private TIFFImageMetadata convertNativeImageMetadata(IIOMetadata inData)
throws IIOInvalidTreeException {
if(inData == null) {
throw new NullPointerException("inData == null!");
} else if(!Arrays.asList(inData.getMetadataFormatNames()).contains(
TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME)) {
throw new IllegalArgumentException
("inData does not support native metadata format!");
}
TIFFImageMetadata outData = null;
String formatName = TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME;
Node tree = inData.getAsTree(formatName);
if (tree != null) {
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
outData = new TIFFImageMetadata(tagSets);
outData.setFromTree(formatName, tree);
}
return outData;
}
private TIFFIFD readIFD(int imageIndex) throws IOException {
if (stream == null) {
throw new IllegalStateException("Output not set!");
}
if (imageIndex < 0) {
throw new IndexOutOfBoundsException("imageIndex < 0!");
}
stream.mark();
long[] ifdpos = new long[1];
long[] ifd = new long[1];
locateIFD(imageIndex, ifdpos, ifd);
if (ifd[0] == 0) {
stream.reset();
throw new IndexOutOfBoundsException
("imageIndex out of bounds!");
}
List<TIFFTagSet> tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
TIFFIFD rootIFD = new TIFFIFD(tagSets);
rootIFD.initialize(stream, true, false, false);
stream.reset();
return rootIFD;
}
private long getTileOrStripOffset(int tileIndex) throws IIOException {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_OFFSETS);
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_OFFSETS);
}
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT);
}
if (f == null) {
throw new IIOException("Missing required strip or tile offsets field.");
}
return f.getAsLong(tileIndex);
}
public TIFFYCbCrColorConverter(TIFFImageMetadata metadata) {
TIFFImageMetadata tmetadata = metadata;
TIFFField f =
tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS);
if (f != null && f.getCount() == 3) {
this.lumaRed = f.getAsFloat(0);
this.lumaGreen = f.getAsFloat(1);
this.lumaBlue = f.getAsFloat(2);
}
f =
tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE);
if (f != null && f.getCount() == 6) {
this.referenceBlackY = f.getAsFloat(0);
this.referenceWhiteY = f.getAsFloat(1);
this.referenceBlackCb = f.getAsFloat(2);
this.referenceWhiteCb = f.getAsFloat(3);
this.referenceBlackCr = f.getAsFloat(4);
this.referenceWhiteCr = f.getAsFloat(5);
}
}
public boolean canReplacePixels(int imageIndex) throws IOException {
if (getOutput() == null) {
throw new IllegalStateException("getOutput() == null!");
}
TIFFIFD rootIFD = readIFD(imageIndex);
TIFFField f = rootIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
int compression = f.getAsInt(0);
return compression == BaselineTIFFTagSet.COMPRESSION_NONE;
}
public void beginDecoding() {
// Initialize the JPEG reader if needed.
if(this.JPEGReader == null) {
// Get all JPEG readers.
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("jpeg");
if(!iter.hasNext()) {
throw new IllegalStateException("No JPEG readers found!");
}
// Initialize reader to the first one.
this.JPEGReader = iter.next();
this.JPEGParam = JPEGReader.getDefaultReadParam();
}
// Get the JPEGTables field.
TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
TIFFField f =
tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_TABLES);
if (f != null) {
this.hasJPEGTables = true;
this.tables = f.getAsBytes();
} else {
this.hasJPEGTables = false;
}
}
private static void initializeEssentialTags() {
Set<Integer> tags = essentialTags;
if (tags == null) {
essentialTags = tags = Set.of(
BaselineTIFFTagSet.TAG_BITS_PER_SAMPLE,
BaselineTIFFTagSet.TAG_COLOR_MAP,
BaselineTIFFTagSet.TAG_COMPRESSION,
BaselineTIFFTagSet.TAG_EXTRA_SAMPLES,
BaselineTIFFTagSet.TAG_FILL_ORDER,
BaselineTIFFTagSet.TAG_ICC_PROFILE,
BaselineTIFFTagSet.TAG_IMAGE_LENGTH,
BaselineTIFFTagSet.TAG_IMAGE_WIDTH,
BaselineTIFFTagSet.TAG_JPEG_AC_TABLES,
BaselineTIFFTagSet.TAG_JPEG_DC_TABLES,
BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT,
BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH,
BaselineTIFFTagSet.TAG_JPEG_PROC,
BaselineTIFFTagSet.TAG_JPEG_Q_TABLES,
BaselineTIFFTagSet.TAG_JPEG_RESTART_INTERVAL,
BaselineTIFFTagSet.TAG_JPEG_TABLES,
BaselineTIFFTagSet.TAG_PHOTOMETRIC_INTERPRETATION,
BaselineTIFFTagSet.TAG_PLANAR_CONFIGURATION,
BaselineTIFFTagSet.TAG_PREDICTOR,
BaselineTIFFTagSet.TAG_REFERENCE_BLACK_WHITE,
BaselineTIFFTagSet.TAG_ROWS_PER_STRIP,
BaselineTIFFTagSet.TAG_SAMPLES_PER_PIXEL,
BaselineTIFFTagSet.TAG_SAMPLE_FORMAT,
BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS,
BaselineTIFFTagSet.TAG_STRIP_OFFSETS,
BaselineTIFFTagSet.TAG_T4_OPTIONS,
BaselineTIFFTagSet.TAG_T6_OPTIONS,
BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS,
BaselineTIFFTagSet.TAG_TILE_LENGTH,
BaselineTIFFTagSet.TAG_TILE_OFFSETS,
BaselineTIFFTagSet.TAG_TILE_WIDTH,
BaselineTIFFTagSet.TAG_Y_CB_CR_COEFFICIENTS,
BaselineTIFFTagSet.TAG_Y_CB_CR_SUBSAMPLING
);
}
}
/**
* Invokes the superclass method and then sets instance variables on
* the basis of the metadata set on this decompressor.
*/
public void beginDecoding() {
super.beginDecoding();
if(metadata instanceof TIFFImageMetadata) {
TIFFImageMetadata tmetadata = (TIFFImageMetadata)metadata;
TIFFField f;
f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_FILL_ORDER);
this.fillOrder = f == null ?
BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT : f.getAsInt(0);
f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
this.compression = f == null ?
BaselineTIFFTagSet.COMPRESSION_CCITT_RLE : f.getAsInt(0);
f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T4_OPTIONS);
this.t4Options = f == null ? 0 : f.getAsInt(0);
this.oneD = (t4Options & 0x01);
// uncompressedMode - haven't dealt with this yet.
this.uncompressedMode = ((t4Options & 0x02) >> 1);
this.fillBits = ((t4Options & 0x04) >> 2);
f = tmetadata.getTIFFField(BaselineTIFFTagSet.TAG_T6_OPTIONS);
this.t6Options = f == null ? 0 : f.getAsInt(0);
} else {
this.fillOrder = BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT;
this.compression = BaselineTIFFTagSet.COMPRESSION_CCITT_RLE; // RLE
this.t4Options = 0; // Irrelevant as applies to T.4 only
this.oneD = 0; // One-dimensional
this.uncompressedMode = 0; // Not uncompressed mode
this.fillBits = 0; // No fill bits
this.t6Options = 0;
}
}
public void decodeRaw(byte[] b, int dstOffset,
int pixelBitStride, // will always be 1
int scanlineStride) throws IOException {
this.buffer = b;
this.w = srcWidth;
this.h = srcHeight;
this.bitsPerScanline = scanlineStride*8;
this.lineBitNum = 8*dstOffset;
this.data = new byte[byteCount];
this.bitPointer = 0;
this.bytePointer = 0;
this.prevChangingElems = new int[w + 1];
this.currChangingElems = new int[w + 1];
stream.seek(offset);
stream.readFully(data);
if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_RLE) {
decodeRLE();
} else if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_T_4) {
decodeT4();
} else if (compression == BaselineTIFFTagSet.COMPRESSION_CCITT_T_6) {
this.uncompressedMode = ((t6Options & 0x02) >> 1);
decodeT6();
} else {
throw new IIOException("Unknown compression type " + compression);
}
}
public boolean isRandomAccessEasy(int imageIndex) throws IOException {
if (currIndex != -1) {
seekToImage(currIndex);
return getCompression() == BaselineTIFFTagSet.COMPRESSION_NONE;
} else {
return false;
}
}
public TIFFDeflateDecompressor(int predictor) throws IIOException {
inflater = new Inflater();
if (predictor != BaselineTIFFTagSet.PREDICTOR_NONE &&
predictor !=
BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {
throw new IIOException("Illegal value for Predictor in " +
"TIFF file");
}
this.predictor = predictor;
}
public TIFFLZWDecompressor(int predictor, int fillOrder)
throws IIOException {
super();
if (predictor != BaselineTIFFTagSet.PREDICTOR_NONE &&
predictor !=
BaselineTIFFTagSet.PREDICTOR_HORIZONTAL_DIFFERENCING) {
throw new IIOException("Illegal value for Predictor in " +
"TIFF file");
}
this.predictor = predictor;
flipBits = fillOrder == BaselineTIFFTagSet.FILL_ORDER_RIGHT_TO_LEFT;
}
private long getTileOrStripByteCount(int tileIndex) throws IOException {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
if (f == null) {
f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
}
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
}
long tileOrStripByteCount;
if (f != null) {
tileOrStripByteCount = f.getAsLong(tileIndex);
} else {
processWarningOccurred("TIFF directory contains neither StripByteCounts nor TileByteCounts field: attempting to calculate from strip or tile width and height.");
// Initialize to number of bytes per strip or tile assuming
// no compression.
int bitsPerPixel = bitsPerSample[0];
for (int i = 1; i < samplesPerPixel; i++) {
bitsPerPixel += bitsPerSample[i];
}
int bytesPerRow = (getTileOrStripWidth() * bitsPerPixel + 7) / 8;
tileOrStripByteCount = bytesPerRow * getTileOrStripHeight();
// Clamp to end of stream if possible.
long streamLength = stream.length();
if (streamLength != -1) {
tileOrStripByteCount
= Math.min(tileOrStripByteCount,
streamLength - getTileOrStripOffset(tileIndex));
} else {
processWarningOccurred("Stream length is unknown: cannot clamp estimated strip or tile byte count to EOF.");
}
}
return tileOrStripByteCount;
}
public int encode(byte[] b, int off,
int width, int height,
int[] bitsPerSample,
int scanlineStride) throws IOException {
if (bitsPerSample.length != 1 || bitsPerSample[0] != 1) {
throw new IIOException(
"Bits per sample must be 1 for T6 compression!");
}
if (metadata instanceof TIFFImageMetadata) {
TIFFImageMetadata tim = (TIFFImageMetadata)metadata;
long[] options = new long[1];
options[0] = 0;
BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();
TIFFField T6Options =
new TIFFField(base.getTag(BaselineTIFFTagSet.TAG_T6_OPTIONS),
TIFFTag.TIFF_LONG,
1,
options);
tim.rootIFD.addTIFFField(T6Options);
}
// See comment in TIFFT4Compressor
int maxBits = 9*((width + 1)/2) + 2;
int bufSize = (maxBits + 7)/8;
bufSize = height*(bufSize + 2) + 12;
byte[] compData = new byte[bufSize];
int bytes = encodeT6(b, scanlineStride, 8*off, width, height,
compData);
stream.write(compData, 0, bytes);
return bytes;
}
private void readMetadata() throws IIOException {
if (stream == null) {
throw new IllegalStateException("Input not set!");
}
if (imageMetadata != null) {
return;
}
try {
// Create an object to store the image metadata
List<TIFFTagSet> tagSets;
boolean readUnknownTags = false;
if (imageReadParam instanceof TIFFImageReadParam) {
TIFFImageReadParam tp = (TIFFImageReadParam)imageReadParam;
tagSets = tp.getAllowedTagSets();
readUnknownTags = tp.getReadUnknownTags();
} else {
tagSets = new ArrayList<TIFFTagSet>(1);
tagSets.add(BaselineTIFFTagSet.getInstance());
}
this.imageMetadata = new TIFFImageMetadata(tagSets);
imageMetadata.initializeFromStream(stream, ignoreMetadata,
readUnknownTags);
} catch (IIOException iioe) {
throw iioe;
} catch (IOException ioe) {
throw new IIOException("I/O error reading image metadata!", ioe);
}
}
private int getTileOrStripHeight() {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_LENGTH);
if (f != null) {
return f.getAsInt(0);
}
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_ROWS_PER_STRIP);
// Default for ROWS_PER_STRIP is 2^32 - 1, i.e., infinity
int h = (f == null) ? -1 : f.getAsInt(0);
return (h == -1) ? getHeight() : h;
}
private long getTileOrStripByteCount(int tileIndex) throws IOException {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_BYTE_COUNTS);
if (f == null) {
f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_STRIP_BYTE_COUNTS);
}
if (f == null) {
f = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
}
long tileOrStripByteCount;
if (f != null) {
tileOrStripByteCount = f.getAsLong(tileIndex);
} else {
processWarningOccurred("TIFF directory contains neither StripByteCounts nor TileByteCounts field: attempting to calculate from strip or tile width and height.");
// Initialize to number of bytes per strip or tile assuming
// no compression.
int bitsPerPixel = bitsPerSample[0];
for (int i = 1; i < samplesPerPixel; i++) {
bitsPerPixel += bitsPerSample[i];
}
int bytesPerRow = (getTileOrStripWidth() * bitsPerPixel + 7) / 8;
tileOrStripByteCount = bytesPerRow * getTileOrStripHeight();
// Clamp to end of stream if possible.
long streamLength = stream.length();
if (streamLength != -1) {
tileOrStripByteCount
= Math.min(tileOrStripByteCount,
streamLength - getTileOrStripOffset(tileIndex));
} else {
processWarningOccurred("Stream length is unknown: cannot clamp estimated strip or tile byte count to EOF.");
}
}
return tileOrStripByteCount;
}
private int getCompression() {
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
if (f == null) {
return BaselineTIFFTagSet.COMPRESSION_NONE;
} else {
return f.getAsInt(0);
}
}
public boolean isRandomAccessEasy(int imageIndex) throws IOException {
if (currIndex != -1) {
seekToImage(currIndex);
return getCompression() == BaselineTIFFTagSet.COMPRESSION_NONE;
} else {
return false;
}
}
public boolean isImageTiled(int imageIndex) throws IOException {
seekToImage(imageIndex);
TIFFField f
= imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH);
return f != null;
}
public boolean canReplacePixels(int imageIndex) throws IOException {
if (getOutput() == null) {
throw new IllegalStateException("getOutput() == null!");
}
TIFFIFD rootIFD = readIFD(imageIndex);
TIFFField f = rootIFD.getTIFFField(BaselineTIFFTagSet.TAG_COMPRESSION);
int compression = f.getAsInt(0);
return compression == BaselineTIFFTagSet.COMPRESSION_NONE;
}