Repository navigation
Update for checking whether colors have an alpha channel #27327
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
Changes from 1 commit
0586383
9719b60
77e759f
5d7edca
e7220c8
0cf3612
e2099e6
5ac2c0f
212363e
73127eb
c3cf8d4
b81786c
80d422d
bbe6fa2
de5e42d
0813e13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,8 +233,36 @@ def is_color_like(c): | |
|
|
||
| def _has_alpha_channel(c): | ||
| """Return whether *c* is a color with an alpha channel.""" | ||
| # 4-element sequences are interpreted as r, g, b, a | ||
| return not isinstance(c, str) and len(c) == 4 | ||
| # If c is not a color, it doesn't have an alpha channel | ||
| if not is_color_like(c): | ||
| return False | ||
|
|
||
| # if c is a hex, it has an alpha channel when it has 4 (or 8) digits after '#' | ||
| if isinstance(c, str) and c[0] == '#' and (len(c) == 5 or len(c) == 9): | ||
| # example: '#fff8' or '#0f0f0f80' | ||
| return True | ||
|
|
||
| # if c isn't a string, it can be an RGB(A) or a color-alpha tuple | ||
| if not isinstance(c, str): | ||
|
landoskape marked this conversation as resolved.
Resolved
|
||
| # if it has length 4, it has an alpha channel | ||
| if len(c) == 4: | ||
| # example: [0.5, 0.5, 0.5, 0.5] | ||
| return True | ||
|
|
||
| # if it has length 2, the 2nd element isn't None, and the 1st element has len=3 | ||
|
landoskape marked this conversation as resolved.
Resolved
|
||
| if len(c) == 2 and (c[1] is not None or len(c[0]) == 4): | ||
|
landoskape marked this conversation as resolved.
Resolved
|
||
| # example: ([0.5, 0.5, 0.5, 0.5], None) or ('r', 0.5) | ||
| return True | ||
|
|
||
| # otherwise it doesn't have an alpha channel | ||
| return False | ||
|
|
||
|
|
||
| def _has_alpha_channel_array(cseq): | ||
|
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. This is not used anywhere right now. Therefore, we don't need it here.
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. It is now deprecated (I added the standard _api.deprecated decorator). In addition I added a deprecation file in the doc/ folder.
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. Um, you've just introduced this function and immediately deprecated it?!? You should simply not add it to the PR. |
||
| """Return whether each element in *cseq* is a color with an alpha channel""" | ||
| if is_color_like(cseq): | ||
| cseq = [cseq] # force it to be a sequence | ||
| return [_has_alpha_channel(c) for c in cseq] | ||
|
|
||
|
|
||
| def _check_color_like(**kwargs): | ||
|
|
||
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.
One should probably check the code if this has already been called. Since this is a private method one can require that it is checked.
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.
Hm, I'm sure I know how to do that or what you mean. Would you explain a little more?
(also, thanks for the comments, as always)