-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Change {FigureCanvasAgg,RendererAgg}.buffer_rgba to return a memoryview. #11735
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
`FigureCanvasAgg.buffer_rgba` and `RendererAgg.buffer_rgba` now return a memoryview | ||
``````````````````````````````````````````````````````````````````````````````````` | ||
|
||
The ``buffer_rgba`` method now allows direct access to the renderer's | ||
underlying buffer (as a ``(m, n, 4)``-shape memoryview) rather than copying the | ||
data to a new bytestring. This is consistent with the behavior on Py2, where a | ||
buffer object was returned. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,14 +265,14 @@ def points_to_pixels(self, points): | |
""" | ||
return points * self.dpi / 72 | ||
|
||
def tostring_rgb(self): | ||
return self._renderer.tostring_rgb() | ||
def buffer_rgba(self): | ||
return memoryview(self._renderer) | ||
|
||
def tostring_argb(self): | ||
return self._renderer.tostring_argb() | ||
return np.asarray(self._renderer).take([3, 0, 1, 2], axis=2).tobytes() | ||
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. Did you take a look at uses of this and 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. Here there is no change to the return type, it was a bytes, it's still a bytes. There's a change in the return type of |
||
|
||
def buffer_rgba(self): | ||
return self._renderer.buffer_rgba() | ||
def tostring_rgb(self): | ||
return np.asarray(self._renderer).take([0, 1, 2], axis=2).tobytes() | ||
|
||
def clear(self): | ||
self._renderer.clear() | ||
|
@@ -421,40 +421,39 @@ def get_renderer(self, cleared=False): | |
return self.renderer | ||
|
||
def tostring_rgb(self): | ||
'''Get the image as an RGB byte string. | ||
"""Get the image as an RGB byte string. | ||
|
||
`draw` must be called at least once before this function will work and | ||
to update the renderer for any subsequent changes to the Figure. | ||
|
||
Returns | ||
------- | ||
bytes | ||
''' | ||
""" | ||
return self.renderer.tostring_rgb() | ||
|
||
def tostring_argb(self): | ||
'''Get the image as an ARGB byte string | ||
"""Get the image as an ARGB byte string. | ||
|
||
`draw` must be called at least once before this function will work and | ||
to update the renderer for any subsequent changes to the Figure. | ||
|
||
Returns | ||
------- | ||
bytes | ||
|
||
''' | ||
""" | ||
return self.renderer.tostring_argb() | ||
|
||
def buffer_rgba(self): | ||
'''Get the image as an RGBA byte string. | ||
"""Get the image as a memoryview to the renderer's buffer. | ||
|
||
`draw` must be called at least once before this function will work and | ||
to update the renderer for any subsequent changes to the Figure. | ||
|
||
Returns | ||
------- | ||
bytes | ||
''' | ||
memoryview | ||
""" | ||
return self.renderer.buffer_rgba() | ||
|
||
def print_raw(self, filename_or_obj, *args, **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.
Wowzers. Good catch.