| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -7,6 +7,7 @@ | |
| import math | ||
| import os | ||
| import logging | ||
| from numbers import Number | ||
| from pathlib import Path | ||
| import urllib.parse | ||
|
|
||
| Expand Down Expand Up | @@ -95,7 +96,7 @@ def composite_images(images, renderer, magnification=1.0): | |
| if data is not None: | ||
| x *= magnification | ||
| y *= magnification | ||
| parts.append((data, x, y, image.get_alpha() or 1.0)) | ||
| parts.append((data, x, y, image._get_scalar_alpha())) | ||
| bboxes.append( | ||
| Bbox([[x, y], [x + data.shape[1], y + data.shape[0]]])) | ||
|
|
||
| Expand Down Expand Up | @@ -281,9 +282,29 @@ def set_alpha(self, alpha): | |
| ---------- | ||
| alpha : float | ||
| """ | ||
| martist.Artist.set_alpha(self, alpha) | ||
| if alpha is not None and not isinstance(alpha, Number): | ||
| alpha = np.asarray(alpha) | ||
| if alpha.ndim != 2: | ||
| raise TypeError('alpha must be a float, two-dimensional ' | ||
| 'array, or None') | ||
| self._alpha = alpha | ||
| self.pchanged() | ||
| self.stale = True | ||
| self._imcache = None | ||
|
|
||
| def _get_scalar_alpha(self): | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis appears to just return 1 for alpha-arrays. IMHO this needs documentation: What's the purpose of this function and why this kind of handling of alpha-arrays?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityAdded a description.
Sorry, something went wrong.
All reactions
|
||
| """ | ||
| Get a scalar alpha value to be applied to the artist as a whole. | ||
|
|
||
| If the alpha value is a matrix, the method returns 1.0 because pixels | ||
| have individual alpha values (see `~._ImageBase._make_image` for | ||
| details). If the alpha value is a scalar, the method returns said value | ||
| to be applied to the artist as a whole because pixels do not have | ||
| individual alpha values. | ||
| """ | ||
| return 1.0 if self._alpha is None or np.ndim(self._alpha) > 0 \ | ||
| else self._alpha | ||
|
|
||
| def changed(self): | ||
| """ | ||
| Call this whenever the mappable is changed so observers can | ||
| Expand Down Expand Up | @@ -487,14 +508,17 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, | |
| # pixel it will be between [0, 1] (such as a rotated image). | ||
| out_mask = np.isnan(out_alpha) | ||
| out_alpha[out_mask] = 1 | ||
| # Apply the pixel-by-pixel alpha values if present | ||
| alpha = self.get_alpha() | ||
| if alpha is not None and np.ndim(alpha) > 0: | ||
| out_alpha *= _resample(self, alpha, out_shape, | ||
| t, resample=True) | ||
| # mask and run through the norm | ||
| output = self.norm(np.ma.masked_array(A_resampled, out_mask)) | ||
| else: | ||
| if A.shape[2] == 3: | ||
| A = _rgb_to_rgba(A) | ||
| alpha = self.get_alpha() | ||
| if alpha is None: | ||
| alpha = 1 | ||
| alpha = self._get_scalar_alpha() | ||
| output_alpha = _resample( # resample alpha channel | ||
| self, A[..., 3], out_shape, t, alpha=alpha) | ||
| output = _resample( # resample rgb channels | ||
| Expand All | @@ -509,9 +533,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, | |
|
|
||
| # Apply alpha *after* if the input was greyscale without a mask | ||
| if A.ndim == 2: | ||
| alpha = self.get_alpha() | ||
| if alpha is None: | ||
| alpha = 1 | ||
| alpha = self._get_scalar_alpha() | ||
| alpha_channel = output[:, :, 3] | ||
| alpha_channel[:] = np.asarray( | ||
| np.asarray(alpha_channel, np.float32) * out_alpha * alpha, | ||
| Expand Down Expand Up | @@ -593,7 +615,7 @@ def draw(self, renderer, *args, **kwargs): | |
| # actually render the image. | ||
| gc = renderer.new_gc() | ||
| self._set_gc_clip(gc) | ||
| gc.set_alpha(self.get_alpha()) | ||
| gc.set_alpha(self._get_scalar_alpha()) | ||
| gc.set_url(self.get_url()) | ||
| gc.set_gid(self.get_gid()) | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI have dropped This parameter is ignored for RGBA input data. because it appears to be respected by the released matplotlib==3.1.1.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.