Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large NDPI file fix #602

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ntrahearn
Copy link

Addresses issue #174 (and possibly others), regarding the reading of large NDPI files. This issue stems from the fact that classical TIFF (and by extension, NDPI) images only support up to 32 bit values for tagged metadata. However, due to the nature of whole slide image data, it isn't uncommon for the size of an NDPI to exceed the 32 bit range. This means that key metadata, such as the byte positions of image layers or their size in bytes, may be too large to store in a traditional TIFF IFD entry.

Currently OpenSlide relies on heuristics to determine the high bits of 64 bit addresses, which fail in some cases. However, this is unnecessary, as NDPI actually stores the high bits of the offset/value of each tag in 4 byte blocks immediately after the end of the IFD.

This fix modifies openslide-decode-tifflike.c to append these extra 4 bytes to each IFD entry's value/offset and, if necessary, modifies its type to LONG8.

This fix also modifies openslide-vendor-hamamatsu.c to construct correct restart marker addresses. Currently only the values in TIFF tag 65426 are used, which are only the lower 32 bits of each address. High bits are stored in TIFF tag 65432, so these are now appended before mcu_starts are calculated

@openslide-bot
Copy link
Member

openslide-bot commented May 15, 2024

DCO signed off ✔️

All commits have been signed off. You have certified to the terms of the Developer Certificate of Origin, version 1.1. In particular, you certify that this contribution has not been developed using information obtained under a non-disclosure agreement or other license terms that forbid you from contributing it under the GNU Lesser General Public License, version 2.1.

Addresses issue openslide#174 (and possibly others), regarding the reading of
large NDPI files.  This issue stems from the fact that classical TIFF
(and by extension, NDPI) images only support up to 32 bit values for
tagged metadata.  However, due to the nature of whole slide image data,
it isn't uncommon for the size of an NDPI to exceed the 32 bit range.
This means that key metadata, such as the byte positions of image layers
or their size in bytes, may be too large to store in a traditional TIFF
IFD entry.

Currently OpenSlide relies on heuristics to determine the high bits of 64
bit addresses, which fail in some cases.  However, this is unnecessary,
as NDPI actually stores the high bits of the offset/value of each tag in
4 byte blocks immediately after the end of the IFD.

This fix modifies openslide-decode-tifflike.c to append these extra 4
bytes to each IFD entry's value/offset and, if necessary, modifies its
type to LONG8.

This fix also modifies openslide-vendor-hamamatsu.c to construct correct
restart marker addresses.  Currently only the values in TIFF tag 65426
are used, which are only the lower 32 bits of each address.  High bits
are stored in TIFF tag 65432, so these are now appended before mcu_starts
are calculated.

Signed-off-by: Nick Trahearn <n.a.trahearn@gmail.com>
Signed-off-by: Benjamin Gilbert <bgilbert@cs.cmu.edu>
@bgilbert
Copy link
Member

Looks good, thank you! I've rebased, updated to the current internal API, and fixed up some formatting. I have a few more cleanup commits coming, and will fix the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Certain (very large) Hamamatsu NDPI files cannot be opened with OpenSlide
3 participants