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 tiffs with alpha channel #385

Closed
timhj opened this issue Aug 17, 2023 · 5 comments
Closed

Writing tiffs with alpha channel #385

timhj opened this issue Aug 17, 2023 · 5 comments

Comments

@timhj
Copy link
Contributor

timhj commented Aug 17, 2023

Using writeArrayBuffer to write a GeoTIFF from a canvas object with a transparent background results in the the alpha channel being replaced with white in the resulting TIFF.

The SamplesPerPixel is set to 4 in the metadata to specify RGBA but the alpha channel is missing in the resulting tiff.
I imagine this is because writing transparency is not supported by geotiff.js.

If that's the case is it possible to add in support for alpha channel writing?

@DanielJDufour
Copy link
Contributor

Hi, @timhj . That's an excellent question. geotiffwriter.js is still in beta, so there are definitely things that are missing. Could you try to add ExtraSamples: 1 or ExtraSamples: 2 to the metadata you are passing in to the writer and see if that fixes it?

@DanielJDufour
Copy link
Contributor

Technically speaking if you need a quick workaround you could also define a no-data value and use that like transparency. Most applications won't display those values, but it's a far from perfect workaround.

And here's a few more notes in case you are curious:

References:

Technically speaking there's another way to add transparency information to a geotiff, but that's not supported either. That involves creating a separate transparency mask image. However, that would involve adding support to geotiffwriter for writing multiple images for one geotiff file and that is not currently supported either.

@daumann currently has a promising PR out adding more bit-depth options when writing: #366

Things are looking up! Seems like there's a lot of momentum around geotiff writing at the moment! :-)

@timhj
Copy link
Contributor Author

timhj commented Aug 18, 2023

@DanielJDufour - Extra Samples: 1 makes no difference but interestingly ExtraSamples: 2 makes semi-transparency work, you can see underlying map through the edges of heatmap elements in this screengrab:
Screenshot 2023-08-18 at 7 10 32 am
As soon as the image data gets to full transparency [0,0,0,0] the pixels are treated as white by QGIS. While it's possible to mask out the white in GIS software, it would be better if the transparency was automatically recognised.

Is it the WriteArrayBuffer in GeoTIFF.js that's flattening/transposing no data pixels to white and dropping the alpha channel?

@DanielJDufour
Copy link
Contributor

writeArrayBuffer shouldn't be changing any values, but there always could be a bug.

Would you be able to write a test or provide the code you are using? I think it'll make the debugging process easier.

@timhj
Copy link
Contributor Author

timhj commented Jun 19, 2024

@DanielJDufour - This was resolved without any issue in the library. Setting an incorrect PhotometricInterpretation value for metadata was the cause of the issue.

@timhj timhj closed this as completed Jun 19, 2024
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

2 participants