Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reuse png metadata handling of imsave() in FigureCanvasAgg.print_png().#15435

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 4 commits intomatplotlib:masterfromanntzer:reuse-imsave
May 29, 2020

Conversation

anntzer
Copy link
Contributor

This avoids duplicating the conversion of metadata to PngInfo and
revealed a bug in the priority betweenmetadata andpil_kwargs in
imsave(). (That bug is also fixed for 3.2 in#15434; this PR effectively
tests that.)

Note that becausenp.asarray(self.buffer_rgba()) is already a RGBA
uint8 array, there is no colormapping step happening in imsave().

Ideally mplcairo should also be able to use imsave() for saving to png.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 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
Copy link
ContributorAuthor

Now also includes the warning on metadata/pnginfo collision suggested in#15434 (comment). This effectively requires moving the generation of the Software tag to imsave (as we otherwise don't know whether the tag was autogenerated or provided by the user).

Copy link
Member

@timhoffmtimhoffm left a comment

Choose a reason for hiding this comment

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

This is a rather big change just for removing the duplication of metadata and pil_kwargs merging. In particular, replacing a simpleImage.save() with the more generalmpl.image.imsave()feels a bit risky and obscures the actual quite simple call (I didn't easily manage to follow ifimsave() with the given parameters is equivalent to the original code).

Extracting a_merge_metadata_pil_kwargs() function seems to be a simpler solution. - Or did I miss any other important stuff thatimsave() is now doing?

@anntzer
Copy link
ContributorAuthor

The calls are equivalent, although I readily admit that it's not obvious to follow them (the relevant point is at

and which just returns the RGBA array as is).

As suggested above one of the reasons to move the pil_kwargs handling logic in imsave() is to let mplcairo also take advantage of it (well, if I need to call private APIs in mplcairo I can do it too :) but I'd rather not).

@anntzeranntzer added this to thev3.3.0 milestoneJan 15, 2020
@anntzeranntzer added the Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labelJan 15, 2020
@anntzer
Copy link
ContributorAuthor

Not urgent by any means, but does need to get into 3.3 to prevent a (subtle) regression against 3.2, for which the same issue was fixed in#15434, so tagging as release critical.

@tacaswell
Copy link
Member

Would this be fixed by merging 3.2.x into master?

If not this needs a re-base.

@anntzer
Copy link
ContributorAuthor

rebased

# semantics of duplicate keys in pnginfo is unclear.
if "pnginfo" in pil_kwargs:
if metadata:
cbook._warn_external("'metadata' is overridden by the "
Copy link
Member

Choose a reason for hiding this comment

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

I could also see a case for raising, but warning seems like a step in the right direction.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I left this as is but can raise too, just pick one.

This avoids duplicating the conversion of metadata to PngInfo andrevealed a bug in the priority between `metadata` and `pil_kwargs` inimsave().Note that because `np.asarray(self.buffer_rgba())` is already a RGBAuint8 array, there is no colormapping step happening in imsave().Ideally mplcairo should also be able to use imsave() for saving to png.
@QuLogicQuLogic merged commitda3baa1 intomatplotlib:masterMay 29, 2020
@anntzeranntzer deleted the reuse-imsave branchMay 29, 2020 22:46
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@timhoffmtimhoffmtimhoffm left review comments

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Labels
Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Milestone
v3.3.0
Development

Successfully merging this pull request may close these issues.

4 participants
@anntzer@tacaswell@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp