288 throw new IndexOutOfBoundsException("imageIndex out of bounds!"); 289 } 290 291 readMetadata(); 292 293 initializeFromMetadata(); 294 } 295 296 // Stream must be positioned at start of IFD for 'currIndex' 297 private void readMetadata() throws IIOException { 298 if (stream == null) { 299 throw new IllegalStateException("Input not set!"); 300 } 301 302 if (imageMetadata != null) { 303 return; 304 } 305 try { 306 // Create an object to store the image metadata 307 List<TIFFTagSet> tagSets; 308 if (imageReadParam instanceof TIFFImageReadParam) { 309 tagSets 310 = ((TIFFImageReadParam) imageReadParam).getAllowedTagSets(); 311 } else { 312 tagSets = new ArrayList<TIFFTagSet>(1); 313 tagSets.add(BaselineTIFFTagSet.getInstance()); 314 } 315 316 this.imageMetadata = new TIFFImageMetadata(tagSets); 317 imageMetadata.initializeFromStream(stream, ignoreMetadata); 318 } catch (IIOException iioe) { 319 throw iioe; 320 } catch (IOException ioe) { 321 throw new IIOException("I/O error reading image metadata!", ioe); 322 } 323 } 324 325 private int getWidth() { 326 return this.width; 327 } 328 329 private int getHeight() { 330 return this.height; 331 } 332 333 // Returns tile width if image is tiled, else image width 334 private int getTileOrStripWidth() { 335 TIFFField f 336 = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH); 337 return (f == null) ? getWidth() : f.getAsInt(0); | 288 throw new IndexOutOfBoundsException("imageIndex out of bounds!"); 289 } 290 291 readMetadata(); 292 293 initializeFromMetadata(); 294 } 295 296 // Stream must be positioned at start of IFD for 'currIndex' 297 private void readMetadata() throws IIOException { 298 if (stream == null) { 299 throw new IllegalStateException("Input not set!"); 300 } 301 302 if (imageMetadata != null) { 303 return; 304 } 305 try { 306 // Create an object to store the image metadata 307 List<TIFFTagSet> tagSets; 308 boolean readUnknownTags = false; 309 if (imageReadParam instanceof TIFFImageReadParam) { 310 TIFFImageReadParam tp = (TIFFImageReadParam)imageReadParam; 311 tagSets = tp.getAllowedTagSets(); 312 readUnknownTags = tp.getReadUnknownTags(); 313 } else { 314 tagSets = new ArrayList<TIFFTagSet>(1); 315 tagSets.add(BaselineTIFFTagSet.getInstance()); 316 } 317 318 this.imageMetadata = new TIFFImageMetadata(tagSets); 319 imageMetadata.initializeFromStream(stream, ignoreMetadata, 320 readUnknownTags); 321 } catch (IIOException iioe) { 322 throw iioe; 323 } catch (IOException ioe) { 324 throw new IIOException("I/O error reading image metadata!", ioe); 325 } 326 } 327 328 private int getWidth() { 329 return this.width; 330 } 331 332 private int getHeight() { 333 return this.height; 334 } 335 336 // Returns tile width if image is tiled, else image width 337 private int getTileOrStripWidth() { 338 TIFFField f 339 = imageMetadata.getTIFFField(BaselineTIFFTagSet.TAG_TILE_WIDTH); 340 return (f == null) ? getWidth() : f.getAsInt(0); |