Skip to content

Commit

Permalink
Merge pull request #4075 from melissalinkert/gh-4033
Browse files Browse the repository at this point in the history
Photoshop TIFF: fix plane reading with memoization
  • Loading branch information
dgault authored Nov 15, 2023
2 parents 9817469 + 42a7b7f commit 0026ed8
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 0026ed8

Please sign in to comment.