Skip to content

use png when converting from a QImage to a Pillow Image - #1429

Merged
wiredfool merged 2 commits into
python-pillow:masterfrom
ericfrederich:conversion
Sep 20, 2015
Merged

wiredfool merged 2 commits into
python-pillow:masterfrom
ericfrederich:conversion

Conversation

@ericfrederich

Copy link
Copy Markdown
Contributor

ppm doesn't have an alpha channel
png has alpha channel, should be able to convert back and forth now
without losing anything

@hugovk

hugovk commented Sep 16, 2015

Copy link
Copy Markdown
Member

@ericfrederich The build fails:
https://travis-ci.org/python-pillow/Pillow/jobs/80514177#L2224

The others pass, but the failing Python2.7_with_system_site_packages is the only one to test with Qt.

@ericfrederich

Copy link
Copy Markdown
Contributor Author

@hugovk Please review again. It no longer errors out.

My goal was to preserve alpha while round tripping. This now works so I'd appreciate the merge.

I added tests for this an discovered a bug.
Essentially Qt's QImage wants data to be 32-bit aligned.
This happens by chance depending on the mode and dimensions.
In the cases where it doesn't happen by chance I commented out the failing combinations.

I will write the code to guarantee the alignment and then cleanup the test file.

@wiredfool

Copy link
Copy Markdown
Member

Is this going to require zlib to work?

@ericfrederich

Copy link
Copy Markdown
Contributor Author

@wiredfool Can you explain what you mean with zlib?

This pull request "works" as good as it did before and adds the ability to round-trip images with alpha channels.

The fix I'm talking about implementing (later tonight perhaps) shouldn't require zlib.
Everything I've seen has been working with raw data.

@wiredfool

Copy link
Copy Markdown
Member

Because png has a dependency on zlib.

@ericfrederich

Copy link
Copy Markdown
Contributor Author

@wiredfool this fix is about round-tripping between PIL and Qt. I couldn't imagine a system which has Qt but no zlib. How would you suggest to preserve alpha?

Images in Qt show up incorrectly if each line is not aligned to 32 bits.

It is pretty common for an image's lines to be 32-bit alinged by chance.
Obviously any 32-bit image will not have any problem.
For the bug to manifest itself you'd need...
* a 1-bit image whose width is not a multiple of 32
* an 8-bit image who width is not a multiple of 4

Testing more images now and added a 7x13 png test image
@ericfrederich
ericfrederich force-pushed the conversion branch 2 times, most recently from eaf0041 to e67a4c4 Compare September 18, 2015 20:15
@ericfrederich

Copy link
Copy Markdown
Contributor Author

I rebased this on top of #1430 since some tests depended on it which had to be commented out.
This ordering of the two is now cleaner.

@wiredfool

Copy link
Copy Markdown
Member

Looks like zlib is required for qt, so as long as we have a functioning pillow install, this should work. However, since we don't actually compile against qt (its just a runtime thing), a badly installed pillow that doesn't have any of the optional C dependencies would break here. On the other hand, I'm really pushing for zlib as a required dependency.

wiredfool added a commit that referenced this pull request Sep 20, 2015
use png when converting from a QImage to a Pillow Image
@wiredfool
wiredfool merged commit eaabb21 into python-pillow:master Sep 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants