Skip to content

Commit

Permalink
Photoshop TIFF: fix plane reading with memoization
Browse files Browse the repository at this point in the history
Fixes ome#4033
  • Loading branch information
melissalinkert committed Aug 7, 2023
1 parent 19d7fb9 commit 42a7b7f
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions components/formats-gpl/src/loci/formats/in/PhotoshopTiffReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
offsetIndex += core.get(i, 0).sizeC;
}

openPixelTag();
tag.seek(layerOffset[offsetIndex]);

int bpp = FormatTools.getBytesPerPixel(getPixelType());
Expand Down Expand Up @@ -149,18 +150,7 @@ public void close(boolean fileOnly) throws IOException {
protected void initFile(String id) throws FormatException, IOException {
super.initFile(id);

Object sourceData = ifds.get(0).getIFDValue(IMAGE_SOURCE_DATA);
byte[] b = null;
if (sourceData instanceof byte[]) {
b = (byte[]) sourceData;
}
else if (sourceData instanceof TiffIFDEntry) {
b = (byte[]) tiffParser.getIFDValue((TiffIFDEntry) sourceData);
}
if (b == null) return;

tag = new RandomAccessInputStream(b);
tag.order(isLittleEndian());
openPixelTag();

String checkString = tag.readCString();

Expand Down Expand Up @@ -296,4 +286,22 @@ else if (compression[layer] == PACKBITS) {
}
}

private void openPixelTag() throws IOException {
if (tag != null) {
return;
}
Object sourceData = ifds.get(0).getIFDValue(IMAGE_SOURCE_DATA);
byte[] b = null;
if (sourceData instanceof byte[]) {
b = (byte[]) sourceData;
}
else if (sourceData instanceof TiffIFDEntry) {
b = (byte[]) tiffParser.getIFDValue((TiffIFDEntry) sourceData);
}
if (b == null) return;

tag = new RandomAccessInputStream(b);
tag.order(isLittleEndian());
}

}

0 comments on commit 42a7b7f

Please sign in to comment.