fix: write ExtraSamples Tiff tag when needed - #3614
Open
dsamaey wants to merge 6 commits into
Open
Conversation
pomadchin
self-requested a review
July 11, 2026 21:48
Member
|
Thanks for the PR and sorry for the delay; will review shortly! |
pomadchin
requested changes
Jul 18, 2026
pomadchin
left a comment
Member
There was a problem hiding this comment.
LGTM! A solid improvement; I left a couple of comments; out of main gotchas
- ExtraSamplesTag is SHORTs
- We don't preserve the tag not on round trips (read + write with on actions in between), it might be a good idea to make it a part of the GeoTiffOptions
Let me know what you think / or I can help once have a bit of time!
| if (geoTiff.options.colorSpace == ColorSpace.RGB && geoTiff.options.rgbChannels > 3) { | ||
| bytes(0) = 2 // next band acts as alpha channel for RGB | ||
| } | ||
| fieldValues += TiffTagFieldValue(ExtraSamplesTag, BytesFieldType, extraBands, bytes) |
Member
There was a problem hiding this comment.
I'm reading https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf and it should be ShortsFieldType!
| if (extraBands > 0) { | ||
| val bytes = new Array[Byte](extraBands) | ||
| if (geoTiff.options.colorSpace == ColorSpace.RGB && geoTiff.options.rgbChannels > 3) { | ||
| bytes(0) = 2 // next band acts as alpha channel for RGB |
Member
There was a problem hiding this comment.
- 0 - unspecified data
- 1 - associated alpha
- 2 - unassociated alpha
|
|
||
| addToPurge(path) | ||
| val tiffTags = TiffTags.read(path) | ||
| val samples = tiffTags.nonBasicTags.extraSamples |
Member
There was a problem hiding this comment.
our tiff does not preserve those 🤔 we could put it into options on read?
| addToPurge(path) | ||
| val tiffTags = TiffTags.read(path) | ||
| val samples = tiffTags.nonBasicTags.extraSamples | ||
| samples.get should equal(Array(0)) |
Member
There was a problem hiding this comment.
^ "multi-tag.tif has 2 set for the extra samples tag
|
|
||
| override def afterAll() = purge | ||
| override def afterAll() = { | ||
| println("done :)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds the missing ExtraSamples Tiff tag when writing GeoTIFF files. Without this ExtraSamples tag the files are actually corrupt (but most tools are lenient enough to just give a warning and guess the correct values).
Checklist
Notes
Caveat : when writing RGB files with 4 bands, it is assumed that the 4th band is the alpha channel (RGBA).
Closes #3613