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

Writing large TIFFs is not supported #80

Open
StephanPreibisch opened this issue Jan 19, 2023 · 5 comments
Open

Writing large TIFFs is not supported #80

StephanPreibisch opened this issue Jan 19, 2023 · 5 comments

Comments

@StephanPreibisch
Copy link

Hi, I wanted to use the TIFFImageWriter.java class to write large TIFFs in strips. However, the writing is limited to a maximal size of 2^31 pixels because the stripOffsets are written as int's and not as long's:

I wanted to ask if there is an easy fix for that? Just writings longs there does not work since it needs to be specified in the header somehow as well that longs are used for stripOffsets, but wasn't able to find out where this is defined.

Thanks so much,
Stephan

@StephanPreibisch StephanPreibisch changed the title Writing large TIFF's is not supported Writing large TIFFs is not supported Jan 19, 2023
@lbellonda
Copy link
Member

Hello, the field is already using a "long" value, I think. In the TIFF specifications the "long" value is a 32-bit (4-byte) unsigned integer. The header is defined at line 1372, TIFFField stripOffsetsField (and in some other location in same file) using TIFF.LONG type, so the only thing that you can check is if the long Java value is really converted to an unsigned 32bit integer.
The specification I found are at:
https://web.archive.org/web/20210108172855/https://www.adobe.io/open/standards/TIFF.html

Best regards

@StephanPreibisch
Copy link
Author

Correct, my bad, you would have to support BigTIFF (https://en.wikipedia.org/wiki/TIFF#BigTIFF). It is still a bug in a sense that your implementation is limited to 2^31 pixels, while it could be 2^32 -- you would need to cast the long into an int so that it is saved as an unsigned int, like we do it in ImgLib2:

https://github.com/imglib/imglib2/blob/078f5af1c64808227f4eff6e1bb73594e5f49588/src/main/java/net/imglib2/type/numeric/integer/UnsignedIntType.java#L86-L89

Thanks so much,
Stephan

@StephanPreibisch
Copy link
Author

Happy to make a pull-request if you like ... it would maybe also be better to throw an exception if the file size exceeds 2^32 pixels instead of silently failing?

@stain
Copy link
Member

stain commented Jan 20, 2023

Agree on throwing an exception if it's out of bounds.

If you want to support longs up to 2^32-1 without going for BigTiff, then I think you would have to fake the equivalent negative int (Note: NOT -pos), to be equivalent to flipping the uppermost bit only.

Somthing like long fred = MININT+ pos (with the correct off-by-one adjustments) to approach from the bottom before casting?

I think you can't write with java.io.DataOutputStream.writeLong, it would output 8 bytes instead of 4, which being big endian means a padding of 0s come before the then effectively unsigned int.

@Daniel-Alievsky
Copy link

Are there any plans to support BigTIFF in nearest future? Now I'm using SCIFIO for reading/writing large TIFF, and I would like to use JAI instead, but I need correctly process BigTIFF SVS files.

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

No branches or pull requests

4 participants