diff --git a/CHANGES.md b/CHANGES.md index 4f9d67cc..e5afc31c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ +# 6.2.8 (2023-12-11) + +* apply `discrete` colormap when the provided colormap does not have 256 values + # 6.2.7 (2023-11-29) * Adjusting dataset latitude for WarpedVRT parameters calculation when EPSG:4326 dataset latitudes overflows EPSG:3857 min/max latitude (https://github.com/cogeotiff/rio-tiler/pull/660) diff --git a/rio_tiler/colormap.py b/rio_tiler/colormap.py index 437676d0..8c0fa7af 100644 --- a/rio_tiler/colormap.py +++ b/rio_tiler/colormap.py @@ -103,11 +103,11 @@ def apply_cmap(data: numpy.ndarray, colormap: ColorMapType) -> DataMaskType: if isinstance(colormap, Sequence): return apply_intervals_cmap(data, colormap) - # if colormap has more than 256 values OR its `max` key >= 256 we can't use + # if colormap has less or more than 256 values OR its `max` key >= 256 we can't use # rio_tiler.colormap.make_lut, because we don't want to create a `lookup table` # with more than 256 entries (256 x 4) array. In this case we use `apply_discrete_cmap` # which can work with arbitrary colormap dict. - if len(colormap) > 256 or max(colormap) >= 256 or min(colormap) < 0: + if len(colormap) != 256 or max(colormap) >= 256 or min(colormap) < 0: return apply_discrete_cmap(data, colormap) lookup_table = make_lut(colormap) diff --git a/tests/test_cmap.py b/tests/test_cmap.py index 56a2f322..f21ba33f 100644 --- a/tests/test_cmap.py +++ b/tests/test_cmap.py @@ -151,6 +151,9 @@ def test_apply_discrete_cmap(): mask[2:5, 2:5] = 255 mask[5:, 5:] = 255 numpy.testing.assert_array_equal(m, mask) + dd, mm = colormap.apply_cmap(data, cm) + numpy.testing.assert_array_equal(dd, d) + numpy.testing.assert_array_equal(mm, m) data = data.astype("uint16") d, m = colormap.apply_discrete_cmap(data, cm)