-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
2 draw optimization -- pre-parse colors, short-circuit path construction code #3393
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 all commits
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 |
---|---|---|
|
@@ -785,6 +785,7 @@ def copy_properties(self, gc): | |
self._linewidth = gc._linewidth | ||
self._rgb = gc._rgb | ||
self._orig_color = gc._orig_color | ||
assert isinstance(self._orig_color, tuple) and len(self._orig_color)==4, 'internal colors must be RGBA 4-tuples' | ||
self._hatch = gc._hatch | ||
self._url = gc._url | ||
self._gid = gc._gid | ||
|
@@ -918,7 +919,7 @@ def set_alpha(self, alpha): | |
else: | ||
self._alpha = 1.0 | ||
self._forced_alpha = False | ||
self.set_foreground(self._orig_color) | ||
self.set_foreground(self._orig_color, isRGBA=True) | ||
|
||
def set_antialiased(self, b): | ||
""" | ||
|
@@ -980,20 +981,24 @@ def set_foreground(self, fg, isRGBA=False): | |
|
||
If you know fg is rgba, set ``isRGBA=True`` for efficiency. | ||
""" | ||
self._orig_color = fg | ||
if self._forced_alpha: | ||
if self._forced_alpha and isRGBA: | ||
self._rgb = tuple(fg[:3] + (self._alpha,)) | ||
elif self._forced_alpha: | ||
self._rgb = colors.colorConverter.to_rgba(fg, self._alpha) | ||
elif isRGBA: | ||
self._rgb = fg | ||
else: | ||
self._rgb = colors.colorConverter.to_rgba(fg) | ||
self._orig_color = self._rgb | ||
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 seems like a change in behaviour to me. Previously, That said, I don't see why we need 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. @tacaswell , I agree that _orig_color should be deleted, but I say that with some trepidation since the relationships of _alpha, _forced_alpha, _rgb, _orig_color are scary to me in the code before this patch. Whether or not all 4 are geniunely needed, I don't know, but I'm sure they are named very sub-optimally. For instance, "_rgb" should really be "_rgba" as you note. I'm going to investigate this point further right now. 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. I would advise writing a lot of unit tests. Thinking about this on the train this morning what I suspect happened (and it might be worth doing some code forensics to check) is that originally mpl only did RGB and the alpha was added by setting RGB -> RGB * A rather than carrying around RGBA values (I have read a bit of the math behind how alpha blending works, but have not internalized it yet, but both schemes give the same result, but are more/less annoying to work with is different cases, or something...). So the naming |
||
assert isinstance(self._orig_color, tuple) and len(self._orig_color)==4, 'internal colors must be RGBA 4-tuples' | ||
|
||
def set_graylevel(self, frac): | ||
""" | ||
Set the foreground color to be a gray level with *frac* | ||
""" | ||
self._orig_color = frac | ||
self._rgb = (frac, frac, frac, self._alpha) | ||
self._orig_color = self._rgb | ||
assert isinstance(self._orig_color, tuple) and len(self._orig_color)==4, 'internal colors must be RGBA 4-tuples' | ||
|
||
def set_joinstyle(self, js): | ||
""" | ||
|
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.
I think this logic can be simplified and move the
set_foreground
call up into the if-block as if_forced_alpha
isFalse
andinRGBA
is true, then the call is a no-op.