Skip to content

Commit

Permalink
NDPI: check for tag 65432, representing the upper 32 bits of the mark…
Browse files Browse the repository at this point in the history
…er offsets
  • Loading branch information
melissalinkert committed Sep 25, 2023
1 parent 15c8d8b commit 3bb4a80
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion components/formats-gpl/src/loci/formats/in/NDPIReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class NDPIReader extends BaseTiffReader {
private static final int TISSUE_INDEX = 65425;
private static final int MARKER_TAG = 65426;
private static final int REFERENCE = 65427;
private static final int MARKER_TAG_HIGH_BYTES = 65432;
private static final int FILTER_SET_NAME = 65434;
private static final int EXPOSURE_RATIO = 65435;
private static final int RED_MULTIPLIER = 65436;
Expand Down Expand Up @@ -197,13 +198,28 @@ else if (useTiffParser(ifds.get(ifdIndex))) {
try {
service.close();
long[] markers = ifd.getIFDLongArray(MARKER_TAG);
long[] markerHighBytes = ifd.getIFDLongArray(MARKER_TAG_HIGH_BYTES);
if (!use64Bit) {
for (int i=0; i<markers.length; i++) {
markers[i] = markers[i] & 0xffffffffL;
}
}
else if (markerHighBytes != null) {
// 64-bit offsets expected
// markers need to be reconstructed from MARKER_TAG (lower 32 bits)
// and MARKER_TAG_HIGH_BYTES (upper 32 bits)
for (int i=0; i<markers.length; i++) {
if (i < markerHighBytes.length) {
markers[i] = markers[i] & 0xffffffffL;
markers[i] += (markerHighBytes[i] << 32);
}
}
}
else {
// might need to correct offset overflow by adding 4GB to offsets
// 64-bit offsets expected, but upper 32 bits not found
// this can happen in sub-resolution IFDs
// try to correct for offset overflow by adding 4GB to offsets, if appropriate
LOGGER.debug("Optional tag {} missing or unreadable", MARKER_TAG_HIGH_BYTES);
for (int i=1; i<markers.length; i++) {
if (markers[i] < markers[i - 1]) {
markers[i] += (long) Math.pow(2, 32);
Expand Down

0 comments on commit 3bb4a80

Please sign in to comment.