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

fix: support 1 band palleted grey scale TDE-601 #269

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/gdal/gdal_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def get_gdal_band_offset(file: str, info: Optional[GdalInfo] = None) -> List[str
get_log().warn(
"gdal_info_bands_failed", band_red=band_red is None, band_green=band_green is None, band_blue=band_blue is None
)

# Not enough bands for RGB assume it is grey scale
if len(bands) < 3:
return ["-b", "1", "-b", "1", "-b", "1"] + alpha_band_info

# Could be RGB assume it is RGB
return ["-b", "1", "-b", "2", "-b", "3"] + alpha_band_info

return ["-b", str(band_red["band"]), "-b", str(band_green["band"]), "-b", str(band_blue["band"])] + alpha_band_info
13 changes: 12 additions & 1 deletion scripts/gdal/tests/gdal_bands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,20 @@ def test_gdal_rgb_bands_detection() -> None:
assert " ".join(bands) == "-b 1 -b 2 -b 3"


def test_gdal_default_grey_scale() -> None:
gdalinfo = fake_gdal_info()
add_band(gdalinfo, color_interpretation="Pallette")

bands = get_gdal_band_offset("some_file.tiff", gdalinfo)

assert " ".join(bands) == "-b 1 -b 1 -b 1"


def test_gdal_default_rgb() -> None:
gdalinfo = fake_gdal_info()
add_band(gdalinfo, color_interpretation="unknown")
add_band(gdalinfo, color_interpretation="R")
add_band(gdalinfo, color_interpretation="G")
add_band(gdalinfo, color_interpretation="B")

bands = get_gdal_band_offset("some_file.tiff", gdalinfo)

Expand Down