Discussion:
PIL 1.1.6 and convert cmyk jpegs to rgb and writing png files
Michael van Tellingen
2008-12-12 16:34:50 UTC
Permalink
Hello,

I'm currently writing a webapplication which processes images uploaded
by users and i'm running into two problems:
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html

- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
images and while doing so my complete python application becomes
really slow, I don't have this problem when
I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?

Thanks,
Michael van Tellingen
_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Kevin Cazabon
2008-12-12 16:55:42 UTC
Permalink
A couple years ago, a few of us worked on adding multi-threading
support to key routines in PIL - focusing on the ones that would most
likely be CPU intensive or long duration operations. It's a simple
fix to release the GIL before starting the op, and re-acquire before
returning - look at the C code for resize, for example. We didn't
get it implemented everywhere, but many of the "expensive" operations
are now covered. I'm sure Fred would gladly accept patches to add
support elsewhere.

Kevin.
Post by Michael van Tellingen
Hello,
I'm currently writing a webapplication which processes images uploaded
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html
- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
images and while doing so my complete python application becomes
really slow, I don't have this problem when
I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?
Thanks,
Michael van Tellingen
_______________________________________________
http://mail.python.org/mailman/listinfo/image-sig
_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Kevin Cazabon
2008-12-12 16:56:30 UTC
Permalink
Post by Kevin Cazabon
A couple years ago, a few of us worked on adding multi-threading
support to key routines in PIL - focusing on the ones that would
most likely be CPU intensive or long duration operations. It's a
simple fix to release the GIL before starting the op, and re-acquire
before returning - look at the C code for resize, for example. We
didn't get it implemented everywhere, but many of the "expensive"
operations are now covered. I'm sure Fred would gladly accept
patches to add support elsewhere.
Kevin.
Post by Michael van Tellingen
Hello,
I'm currently writing a webapplication which processes images
uploaded
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html
- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
images and while doing so my complete python application becomes
really slow, I don't have this problem when
I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?
Thanks,
Michael van Tellingen
_______________________________________________
http://mail.python.org/mailman/listinfo/image-sig
_______________________________________________
Image-SIG maillist - Image-***@python.org
http://mail.python.org/mailman/listinfo/image-sig
Michael van Tellingen
2008-12-15 08:53:05 UTC
Permalink
A couple years ago, a few of us worked on adding multi-threading support to
key routines in PIL - focusing on the ones that would most likely be CPU
intensive or long duration operations. It's a simple fix to release the GIL
before starting the op, and re-acquire before returning - look at the C code
for resize, for example. We didn't get it implemented everywhere, but many
of the "expensive" operations are now covered. I'm sure Fred would gladly
accept patches to add support elsewhere.
Kevin.
Hi Kevin, thanks for the quick reply. I've followed your advice and it
was simpler then I thought. I've attached two patches to this email.
One diff is your old patch I was using to correctly convert CMYK
images to RGB. The other one drops the GIL when saving png images.

Could these be committed to the PIL svn repo after a review?

Thanks,
Michael
Post by Michael van Tellingen
Hello,
I'm currently writing a webapplication which processes images uploaded
- Converting a CMYK jpeg image to RGB results in the wrong colors
used, i've solved this by patching PIL with the
file attached to
http://mail.python.org/pipermail/image-sig/2006-April/003871.html
- It seems that writing a PNG image requires the GIL. I convert all
uploaded images in a separate thread to PNG
images and while doing so my complete python application becomes
really slow, I don't have this problem when
I convert it to JPEG or TIFF. Is this correct? And if so, how hard
would it be to solve this problem?
Thanks,
Michael van Tellingen
_______________________________________________
http://mail.python.org/mailman/listinfo/image-sig
Paul Egan
2009-03-03 17:56:42 UTC
Permalink
Just in case this CMYK patch does make it into the PIL svn repo...
there's a small bug: before calling invert, self.im should be checked.
This is necessary because the ImageFile.Parser.feed method tries an
open() to see if the image is complete.

Attached is an updated patch.

Loading...