diff --git a/napari_tiff/napari_tiff_colormaps.py b/napari_tiff/napari_tiff_colormaps.py index 524d54a..ef89e6e 100644 --- a/napari_tiff/napari_tiff_colormaps.py +++ b/napari_tiff/napari_tiff_colormaps.py @@ -1,5 +1,5 @@ import numpy -from vispy.color import Colormap +from napari.utils import Colormap def alpha_colormap(bitspersample=8, samples=4): @@ -11,48 +11,6 @@ def alpha_colormap(bitspersample=8, samples=4): return Colormap(a) -def rgb_colormaps(bitspersample=8, samples=3): - """Return RGB colormaps.""" - n = 2**bitspersample - ramp = numpy.linspace(0.0, 1.0, n).astype("float32") - r = numpy.zeros((n, samples), dtype="float32") - r[:, 0] = ramp - g = numpy.zeros((n, samples), dtype="float32") - g[:, 1] = ramp - b = numpy.zeros((n, samples), dtype="float32") - b[:, 2] = ramp - if samples > 3: - r[:, 3:] = 1.0 - g[:, 3:] = 1.0 - b[:, 3:] = 1.0 - return [Colormap(r), Colormap(g), Colormap(b)] - - -def cmyk_colormaps(bitspersample=8, samples=3): - """Return CMYK colormaps.""" - n = 2**bitspersample - ramp = numpy.linspace(1.0, 0.0, n).astype("float32") - c = numpy.zeros((n, samples), dtype="float32") - c[:, 1] = ramp - c[:, 2] = ramp - m = numpy.zeros((n, samples), dtype="float32") - m[:, 0] = ramp - m[:, 2] = ramp - y = numpy.zeros((n, samples), dtype="float32") - y[:, 0] = ramp - y[:, 1] = ramp - k = numpy.zeros((n, samples), dtype="float32") - k[:, 0] = ramp - k[:, 1] = ramp - k[:, 2] = ramp - if samples > 3: - c[:, 3:] = 1.0 - m[:, 3:] = 1.0 - y[:, 3:] = 1.0 - k[:, 3:] = 1.0 - return [Colormap(c), Colormap(m), Colormap(y), Colormap(k)] - - def int_to_rgba(intrgba: int) -> tuple: signed = intrgba < 0 rgba = [x / 255 for x in intrgba.to_bytes(4, signed=signed, byteorder="big")] diff --git a/napari_tiff/napari_tiff_metadata.py b/napari_tiff/napari_tiff_metadata.py index 2ddd2c0..51e349a 100644 --- a/napari_tiff/napari_tiff_metadata.py +++ b/napari_tiff/napari_tiff_metadata.py @@ -3,13 +3,9 @@ import numpy from tifffile import PHOTOMETRIC, TiffFile, xml2dict from vispy.color import Colormap +from napari.utils.colormaps import ALL_COLORMAPS -from napari_tiff.napari_tiff_colormaps import ( - alpha_colormap, - cmyk_colormaps, - int_to_rgba, - rgb_colormaps, -) +from napari_tiff.napari_tiff_colormaps import alpha_colormap, int_to_rgba def get_metadata(tif: TiffFile) -> dict[str, Any]: @@ -75,7 +71,7 @@ def get_tiff_metadata(tif: TiffFile) -> dict[str, Any]: # CMYK channel_axis = axes.find("S") if channel_axis >= 0 and shape[channel_axis] >= 4: - colormap = cmyk_colormaps() + colormap = [ALL_COLORMAPS["cyan"], ALL_COLORMAPS["magenta"], ALL_COLORMAPS["yellow"], ALL_COLORMAPS["gray"]] name = ["Cyan", "Magenta", "Yellow", "Black"] visible = [False, False, False, True] blending = ["additive", "additive", "additive", "additive"] @@ -243,7 +239,7 @@ def get_imagej_metadata(tif: TiffFile) -> dict[str, Any]: rgb = False n = shape[channel_axis] visible = [True, True, True] - colormap = rgb_colormaps(samples=4)[:n] + colormap = [ALL_COLORMAPS["red"], ALL_COLORMAPS["green"], ALL_COLORMAPS["blue"]] name = ["Red", "Green", "Blue", "Alpha"][:n] blending = ["additive", "additive", "additive", "translucent"][:n] else: