Skip to content

Commit

Permalink
make the bad alpha feature opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Dec 12, 2023
1 parent d05b6a0 commit 7a474b2
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions glue/viewers/image/composite_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, **kwargs):

self._first = True
self._mode = 'color'
self._allow_bad_alpha = False

@property
def mode(self):
Expand Down Expand Up @@ -148,10 +149,14 @@ def __call__(self, bounds=None):
if hasattr(layer['cmap'], 'get_bad'):
bad_rgba = layer['cmap'].get_bad().tolist()
bad_color = bad_rgba[:3]
bad_alpha = bad_rgba[3]
layer_cmap = layer['cmap'].with_extremes(
bad=bad_color + [layer['alpha']]
)
bad_alpha = bad_rgba[3:]

if self._allow_bad_alpha:
bad_rgba = bad_color + bad_alpha

Check warning on line 155 in glue/viewers/image/composite_array.py

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/composite_array.py#L155

Added line #L155 was not covered by tests
else:
bad_rgba = bad_color + [layer['alpha']]

layer_cmap = layer['cmap'].with_extremes(bad=bad_rgba)
else:
layer_cmap = layer['cmap']

Expand All @@ -176,8 +181,9 @@ def __call__(self, bounds=None):
# Use traditional alpha compositing
alpha_plane = layer['alpha'] * plane[:, :, 3]

# ensure "bad" alpha is preserved:
alpha_plane[~np.isfinite(data)] *= bad_alpha
if self._allow_bad_alpha:
# ensure "bad" alpha is preserved:
alpha_plane[~np.isfinite(data)] *= bad_alpha

Check warning on line 186 in glue/viewers/image/composite_array.py

View check run for this annotation

Codecov / codecov/patch

glue/viewers/image/composite_array.py#L186

Added line #L186 was not covered by tests

plane[:, :, 0] = plane[:, :, 0] * alpha_plane
plane[:, :, 1] = plane[:, :, 1] * alpha_plane
Expand Down

0 comments on commit 7a474b2

Please sign in to comment.