Skip to content

feat: Sprite-based colormap - #447

Merged
kylebarron merged 11 commits into
mainfrom
kyle/colormap-sprite
Apr 20, 2026
Merged

kylebarron merged 11 commits into
mainfrom
kyle/colormap-sprite

Conversation

@kylebarron

@kylebarron kylebarron commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Instead of loading colormap textures separately, one texture for every colormap, we now support sprite based colormaps. This means that all colormaps are saved into a single image, and then we switch the y-index to swap between colormaps with no overhead.

image

The generated default colormap with 107 different colormaps is still just 16kb, and doesn't have a bundle size impact unless the user explicitly imports it.

Change list

  • Python script to generate stacked colormap
  • Use a Texture2DArray to support many stacked colormaps as a single texture object
  • Utilities to generate and consume the colormap texture
  • Generated Typescript colormap index for good type hinting. This is alphabetical

kylebarron and others added 10 commits April 20, 2026 11:51
Unifies Colormap shader module around sampler2DArray with a shipped
matplotlib/rio-tiler sprite, so colormap switching becomes a uniform
update rather than a texture rebind or fetch.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The loader helper returns a Texture directly, not { texture, index }.
Update the testing section to match and note that URL / ArrayBuffer
normalization paths need browser APIs beyond jsdom.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
decodeColormapSprite runs without a Device and can start at app boot;
createColormapTexture is a synchronous GPU upload that pairs with it.
Update the spec's API shape, consumer examples, testing notes, and
files-changed list.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The shader now binds a sampler2DArray and samples one layer per fragment
using a new colormapIndex uniform (i32, defaults to 0). The reversed
uniform carries over unchanged. Callers upgrade by uploading their
colormap LUT as a 1-layer 2D-array texture; the default colormapIndex
means single-colormap call sites need no further change.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Generator now writes a JSDoc block in front of each public export in
colormap-names.ts so the constants appear with full hover docs in
editors and in generated API docs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Takes an already-decoded ImageData (from decodeColormapSprite or any
other source the consumer brings) and uploads it to a sampler2DArray
Texture with clamp-to-edge addressing. Validates width == 256 to catch
mis-shaped sprites at upload time.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Accepts an ArrayBuffer, Uint8Array, or ImageBitmap and returns a
Promise<ImageData>. No Device required, so callers can decode at app
startup in parallel with device initialization and pair the result with
createColormapTexture once the device is ready.

Skip a string/URL overload to avoid disambiguating URL vs base64 vs
data-URL inputs; consumers call fetch themselves and pass the bytes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Add COLORMAP_INDEX / ColormapName, createColormapTexture, and
decodeColormapSprite / ColormapSpriteSource to the gpu-modules barrel,
expose dist/gpu-modules/colormaps.png via a new subpath export, and copy
the PNG into dist/ as part of the build.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@github-actions github-actions Bot added the feat label Apr 20, 2026
@kylebarron
kylebarron merged commit 29a437d into main Apr 20, 2026
5 checks passed
@kylebarron
kylebarron deleted the kyle/colormap-sprite branch April 20, 2026 16:47
@ds-release-bot ds-release-bot Bot mentioned this pull request Apr 20, 2026
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.

1 participant