Skip to content

Commit

Permalink
DAS-2276: clarify comment and rename variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
flamingbear committed Dec 17, 2024
1 parent 8d8968c commit 41bad90
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions hybig/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,30 @@ def image_driver(mime: str) -> str:
def prepare_raster_for_writing(
raster: ndarray,
driver: str,
input_bands: int,
band_count: int,
) -> tuple[ndarray, dict | None]:
"""Remove alpha layer if writing a jpeg."""
"""Standardize raster data for writing to browse image.
Args:
raster: Input raster data array
driver: Output image format ('JPEG' or 'PNG')
band_count: Number of bands in original input data
The function handles two special cases:
- JPEG output with 4-band data -> Drop alpha channel and return 3-band RGB
- PNG output with single-band data -> Convert to paletted format
Returns:
tuple: (prepared_raster, color_map) where:
- prepared_raster is the processed ndarray
- color_map is either None or a dict mapping palette indices to RGBA values
"""
if driver == 'JPEG' and raster.shape[0] == 4:
return raster[0:3, :, :], None

if driver == 'PNG' and input_bands == 1:
if driver == 'PNG' and band_count == 1:
# we only paletize single band input data
return palettize_raster(raster)

Expand Down

0 comments on commit 41bad90

Please sign in to comment.