Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Rewrite the tk C blitting code #10680

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

Merged
merged 1 commit into from
Apr 4, 2018
Merged

Rewrite the tk C blitting code #10680

merged 1 commit into from
Apr 4, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 5, 2018

... to use the standard Python C-API rather than the tk API.

We do not need to support colormodes other than 2 (i.e. RGBA)
(previously there was 0 = grayscale, 1 = RGB) so it was simpler to just
deprecate the previous function and move everything to a new private one
(matplotlib.backends._backend_tk.blit).

Followup to #10486 (comment).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added the GUI: tk label Mar 5, 2018
@anntzer anntzer added this to the v3.0 milestone Mar 5, 2018
src/_tkagg.cpp Outdated
int height, width;
unsigned char *data_ptr;
int x1, x2, y1, y2;
if (!PyArg_ParseTuple(args, "O(iin)(iiii)",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a function name here?

src/_tkagg.cpp Outdated
}
PyObject *py_photo_name;
char const *photo_name;
Tk_PhotoHandle photo;
Copy link
Member

@QuLogic QuLogic Mar 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and these too?
(edit: oops, should go below the next)

src/_tkagg.cpp Outdated
&x1, &x2, &y1, &y2)) {
goto exit;
}
PyObject *py_tk, *py_interpaddr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should all have defaults?

@anntzer
Copy link
Contributor Author

anntzer commented Mar 5, 2018

all comments handled

src/_tkagg.cpp Outdated
block.height = y2 - y1;
block.pitch = 4 * width;
block.pixelSize = 4;
block.offset[0] = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use this to avoid the buf.take copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@anntzer anntzer mentioned this pull request Apr 1, 2018
6 tasks
@tacaswell
Copy link
Member

@mattip Can you verify that this still works with pypy?

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modulo confirmation that this still works on pypy

@anntzer
Copy link
Contributor Author

anntzer commented Apr 1, 2018

Moved some more work to Python's side, avoiding any need for refcounting at all in the C extension.

@mattip
Copy link
Contributor

mattip commented Apr 1, 2018

works fine on PyPy just like before the PR (with the nightly builds, not the latest release)

Thanks for pinging me

src/_tkagg.cpp Outdated
@@ -203,9 +203,49 @@ static PyObject *_tkinit(PyObject *self, PyObject *args)
return Py_None;
}

static PyObject *mpl_tk_blit(PyObject *self, PyObject *args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opening function braces go on a new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, fixed

@tacaswell
Copy link
Member

@mattip 2.2.2 does not work on pypy?

... to use the standard Python C-API rather than the tk API.

We do not need to support colormodes other than 2 (i.e. RGBA)
(previously there was 0 = grayscale, 1 = RGB) so it was simpler to just
deprecate the previous function and move everything to a new private one
(matplotlib.backends._backend_tk.blit).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants