Skip to content

fix(deck.gl-geotiff): read alpha from the alpha band, not the band count - #732

Merged
kylebarron merged 1 commit into
mainfrom
kyle/alpha-from-colorinterp
Oct 16, 2026
Merged

kylebarron merged 1 commit into
mainfrom
kyle/alpha-from-colorinterp

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

The default COG pipeline drew the fourth band of any 4-band RGB image as alpha. NAIP's fourth band is near-infrared (ExtraSamples 0, "unspecified"), so water and shadows, which reflect little near-infrared, were drawn see-through. A gray+alpha image lost its alpha instead: its two-channel texture samples the alpha band into color.g, and BlackIsZero or WhiteIsZero then writes the gray value over it.

The pipeline now decides from the bands' color interpretation (#317):

  • An RGB image whose fourth band isn't alpha is drawn opaque, with a new Opaque module.
  • A gray image whose second band is alpha gets a new GrayAlpha module, which moves that band into alpha before the gray-to-RGB module runs.
  • RGBA images, and gray images whose second band isn't alpha, are drawn as before.

Both modules are exported from @developmentseed/deck.gl-raster/gpu-modules, next to BlackIsZero and the other color modules.

colorInterp now counts associated (premultiplied) alpha as alpha, as GDAL does; it counted only unassociated alpha. Without this, the pipeline would have drawn associated-alpha images opaque. Their color is still not un-premultiplied, as before. ColorInterp is now exported from @developmentseed/geotiff, since the public colorInterp getter returns it.

Checked in Chrome with cog-basic, temporarily pointed at a 4-band NAIP COG and at a gray+alpha COG whose left half has alpha 0. Before, the NAIP reservoir showed the basemap's water through the image and the gray image's transparent half was drawn; after, the reservoir is opaque and that half is transparent. The 3-band NAIP COG already in cog-basic renders pixel-identical before and after.

Closes #187, closes #361

🤖 Written by Claude Code

The default COG pipeline drew the fourth band of any 4-band RGB image as
alpha, so NAIP's near-infrared band made water and shadows see-through.
A gray+alpha image lost its alpha, because BlackIsZero or WhiteIsZero
wrote the gray value over the alpha band in `color.g`.

The pipeline now decides from the bands' color interpretation: an RGB
image whose fourth band isn't alpha is drawn opaque with a new `Opaque`
module, and a gray image's alpha band is moved into alpha first with a
new `GrayAlpha` module. `colorInterp` now counts associated alpha as
alpha, as GDAL does, and `ColorInterp` is exported from
@developmentseed/geotiff.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the fix label Oct 16, 2026

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kylebarron
kylebarron merged commit 2d73c67 into main Oct 16, 2026
3 checks passed
@kylebarron
kylebarron deleted the kyle/alpha-from-colorinterp branch October 16, 2026 19:20
kylebarron added a commit to thatbudakguy/deck.gl-raster that referenced this pull request Oct 22, 2026
Resolve import conflicts with developmentseed#716 and developmentseed#732: keep main's new imports
alongside `toPixelInterleaved`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle alpha band in default render pipeline of COG Handle ExtraSamples in GeoTIFF tag

1 participant