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 direct colormap #6461

Merged
merged 9 commits into from Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion napari/_vispy/layers/image.py
Expand Up @@ -323,11 +323,14 @@ def downsample_texture(
"r8": np.dtype(np.uint8),
"r16": np.dtype(np.uint16),
"r32f": np.dtype(np.float32),
None: np.dtype(np.float32),
}

_DTYPE_TO_VISPY_FORMAT = {v: k for k, v in _VISPY_FORMAT_TO_DTYPE.items()}

# this is moved after reverse mapping is defined
# to always have non None values in _DTYPE_TO_VISPY_FORMAT
_VISPY_FORMAT_TO_DTYPE[None] = np.dtype(np.float32)


def get_dtype_from_vispy_texture_format(format_str: str) -> np.dtype:
"""Get the numpy dtype from a vispy texture format string.
Expand Down
3 changes: 2 additions & 1 deletion napari/_vispy/layers/labels.py
Expand Up @@ -401,7 +401,7 @@
if use_selection:
keys = np.full((1, 1), selection, dtype=vispy_texture_dtype)
values = np.zeros((1, 1, 4), dtype=vispy_texture_dtype)
values[0, 0] = color_dict[selection]
values[0, 0] = color_dict.get(selection, color_dict[None])

Check warning on line 404 in napari/_vispy/layers/labels.py

View check run for this annotation

Codecov / codecov/patch

napari/_vispy/layers/labels.py#L404

Added line #L404 was not covered by tests
return keys, values, False

if empty_val is _UNSET:
Expand Down Expand Up @@ -524,6 +524,7 @@
interpolation='nearest',
)
self.node.shared_program['LUT_shape'] = key_texture.shape
self.node.shared_program['color_count'] = len(color_dict)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this only silence openGL warning

else:
self.node.cmap = VispyColormap(*colormap)

Expand Down