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

Fix #5302: Proper alpha-blending for jpeg#5324

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
tacaswell merged 5 commits intomatplotlib:masterfrommdboom:transparent-jpg
Oct 28, 2015

Conversation

mdboom
Copy link
Member

Saving a JPEG with an alpha channel doesn't look right -- I think pillow just removes the alpha channel altogether and uses the rest of the RGB values as-is.

This blends RGBA images onto a white background before saving.

This is JPEG-specific since it's our only raster output file format that doesn't support alpha blending. If we ever grow another (unlikely) this will need to be duplicated there.

@mdboommdboom added this to thenext bug fix release (2.0.1) milestoneOct 26, 2015
@QuLogic
Copy link
Member

Strangely, the image from#5302 is white in the transparent parts, so I'm not sure what Pillow is doing.

Anyway, 👍 from me, but I'm not sure where 2.0.1 fixes are going.

@mdboom
Copy link
MemberAuthor

This is passing and ready to merge.

@WeatherGod
Copy link
Member

Just curious. Do we want to hardcode a white background, or should we be getting the color from an rcParam?

@mdboom
Copy link
MemberAuthor

I think adding an rcParam would just add complication to this. We already have an rcParam for the figure background (savefig.facecolor). If the user really wants a different background color, they can just set that. Thisonly deals with the case where the background was accidentally set to transparent (throughsavefig.transparent or thetransparent kwarg) without realising that JPEG can't handle that.

@mdboom
Copy link
MemberAuthor

That said, I suppose it could go tosavefig.facecolor, which by default is white.

@WeatherGod
Copy link
Member

Right... that was the param I was thinking of.

On Tue, Oct 27, 2015 at 11:05 AM, Michael Droettboom <
notifications@github.com> wrote:

That said, I suppose it could go to savefig.facecolor, which by default
is white.


Reply to this email directly or view it on GitHub
#5324 (comment)
.

@mdboom
Copy link
MemberAuthor

This now gets the background color fromsavefig.facecolor as suggested by@WeatherGod.

@mdboom
Copy link
MemberAuthor

The test failures are puzzling, and I can't reproduce locally. 😢

@WeatherGod
Copy link
Member

Perhaps add a useful message for the assert so that we can see what the value is?

@WeatherGod
Copy link
Member

prints aren't getting caught by nosetests (I think it is some sort of option set by us). Add that stuff to the assert message so that the exception will print out the relevant message.

@cbreeden
Copy link

When I first tried coming up with a patch, I tried usingtostring_rgb from the renderer but that doesn't seem to be good enough. My guess is that RGB doesn't really 'flatten' the transparency regions when converting from RGBA, which I thought would've been the ideal solution, which I think would allow for figures to be given figure.facecolor and axes to be given axes.facecolor. But honestly I don't think anyone really uses transparency; except fornbagg that insists on having transparency in the figure.

I opened up a new issue related to this#5335.

@QuLogic
Copy link
Member

Printing does work; it's just muddled between the dots: "num colors: 181". It does not print the corner pixel because the colour count assert has already failed.

@mdboom
Copy link
MemberAuthor

@QuLogic: Thanks for catching that. My hunch is there is some variability because it's lossy JPEG. I'll just increase the range somewhat.

@mdboom
Copy link
MemberAuthor

@cbreeden: I suppose we could try to fixtostring_rgb as well, but it would need to have a background color as an argument added. I've created#5336 for that.

tacaswell added a commit that referenced this pull requestOct 28, 2015
@tacaswelltacaswell merged commitb9957b1 intomatplotlib:masterOct 28, 2015
@mdboommdboom deleted the transparent-jpg branchNovember 10, 2015 02:46
@tacaswell
Copy link
Member

Do we want to backport this to 2.x?

@efiring
Copy link
Member

Sounds reasonable to me; it can be viewed as a bugfix. But it also makes me wonder whether saving a jpg withtransparent=True, which this handles, should raise a warning.

@QuLogic
Copy link
Member

I guess this was not backported, then?

QuLogic pushed a commit to QuLogic/matplotlib that referenced this pull requestOct 16, 2016
Fixmatplotlib#5302: Proper alpha-blending for jpegConflicts:lib/matplotlib/tests/test_image.py
@QuLogicQuLogic mentioned this pull requestOct 16, 2016
@QuLogic
Copy link
Member

Backported to v2.x via1e437d3.

@QuLogicQuLogic modified the milestones:2.0.1 (next bug fix release),2.0 (style change major release)Dec 7, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
v2.0.0
Development

Successfully merging this pull request may close these issues.

6 participants
@mdboom@QuLogic@WeatherGod@cbreeden@tacaswell@efiring

[8]ページ先頭

©2009-2025 Movatter.jp