From zpincus at stanford.edu Mon Dec 8 01:07:39 2003 From: zpincus at stanford.edu (Zachary Pincus) Date: Mon Dec 8 01:07:44 2003 Subject: [Image-SIG] 16-bit TIFF decoding and endianness problem Message-ID: I've encountered an issue in PIL-1.1.4 having to do with decoding 16-bit TIFFs. Specifically, it appears that the TIFF decoder does not properly process the byte ordering of 16-bit integers in TIFF files. The decoder can detect big-endian files, but then decodes them in a little-endian manner. Problem: -------- I have a TIFF that uses 16 bit unsigned integers stored in big-endian format. The first bytes of the TIFF file are ASCII "MM" which indicates the fact that the format is indeed in "Motorola" (big-endian) format. So the file itself conforms to the spec vis a vis endianness. (TIFF spec is here: http://partners.adobe.com/asn/developer/pdfs/tn/TIFF6.pdf -- see page 13ff.) Nevertheless, when I open the file with PIL, the image's mode is "I;16" -- not "I;16B" Further, pixels retrieved with the getpixel() method are incorrect and reflect an inappropriate byte-swap. (E.g. the correct value of a certain pixel is 1001 [0x03E9], but the returned value is 59651 [0xE903].) I can get PIL to treat the data properly by grabbing the raw data with the tostring() method and then feeding it back into the raw decoder with the proper parameters. (See below.) So the decoder will work fine when it knows the endianness of the image. It appears that it just doesn't detect the TIFF endianness properly. >>> test16b = Image.open("/Volumes/Atlotl/zpincus/Desktop/sample1imagesPhase.tif") >>> test16b.getpixel((0,0)) 59651 >>> #This is the wrong value. It should be 1001. >>> test16b.mode 'I;16' >>> #This is the wrong mode. It shoule be I;16B >>> raw16b = test16b.tostring() >>> new16b = Image.fromstring("I;16B", test16b.size, raw16b) >>> new16b.getpixel((0,0)) 1001 >>> new16b.mode 'I;16B' Strangely, the test16b.ifd object (of class ImageFileDirectory, defined in TiffImagePlugin.py) knows what format the file is in! >>> test16b.ifd.i16 #this is the 16-byte reader We can see that the i16 pointer is directed at the ib16 function (which reads big-endian 16-bit bytes) defined in TiffImagePlugin. I tested ib16 and it works correctly. Moreover, the ifd object knows the right endian-ness prefix. >>> test16b.ifd.prefix 'MM' So somehow, in a place I cannot find, this knowledge of the byte ordering is being ignored. Sorry I don't know the code well enough to find it. Finally, I can send anyone who wishes to look into this problem some sample 16-bit TIFF images. Zach Pincus Program in Biomedical Informatics Stanford University School of Medicine From ewc at axelero.hu Wed Dec 10 05:06:48 2003 From: ewc at axelero.hu (ewc@axelero.hu) Date: Wed Dec 10 05:06:52 2003 Subject: [Image-SIG] Tiff g3 Message-ID: <189053848.20031210110648@axelero.hu> Hello, does anybody have TIFF G3 compression implemented for PIL? Thanks in advance, Thomas From fredrik at pythonware.com Thu Dec 11 04:47:38 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu Dec 11 04:47:46 2003 Subject: [Image-SIG] Re: Tiff g3 References: <189053848.20031210110648@axelero.hu> Message-ID: "Thomas" wrote: > does anybody have TIFF G3 compression implemented for PIL? this might be helpful: http://mail.python.org/pipermail/image-sig/2003-July/002354.html From ewc at axelero.hu Thu Dec 11 05:58:50 2003 From: ewc at axelero.hu (ewc@axelero.hu) Date: Thu Dec 11 05:58:50 2003 Subject: [Image-SIG] Re: Tiff g3 In-Reply-To: References: <189053848.20031210110648@axelero.hu> Message-ID: <1317430682.20031211115850@axelero.hu> Hello Fredrik, many thanks! Does anybody know when will be a new PIL available including this patch? I applied a patch. I was able to open TIFF G3 files but got this when I tryed to save: Traceback (most recent call last): File "./tiff.py", line 36, in ? im.save("/tmp/test_o.tiff") File "/usr/local/lib/python2.3/site-packages/PIL/Image.py", line 1136, in save SAVE[string.upper(format)](self, fp, filename) File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 684, in _save offset = ifd.save(fp) File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 357, in save data = string.join(map(o32, value), "") File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 55, in ol32 return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255) TypeError: unsupported operand type(s) for &: 'str' and 'int' Does anybody know what's wrong? Thanks, Thomas Thursday, December 11, 2003, 10:47:38 AM, you wrote: FL> "Thomas" wrote: >> does anybody have TIFF G3 compression implemented for PIL? FL> this might be helpful: FL> http://mail.python.org/pipermail/image-sig/2003-July/002354.html FL> From ewc at axelero.hu Thu Dec 11 07:41:25 2003 From: ewc at axelero.hu (ewc@axelero.hu) Date: Thu Dec 11 07:41:26 2003 Subject: [Image-SIG] Re: Tiff g3 In-Reply-To: <1317430682.20031211115850@axelero.hu> References: <189053848.20031210110648@axelero.hu> <1317430682.20031211115850@axelero.hu> Message-ID: <1866762759.20031211134125@axelero.hu> Hello, I found, that the mentioned problem is because of RESOLUTION_UNIT tag. It looks like it has wrong number. Around line 635 in TiffImagePlugin.py: # additions written by Greg Couch, gregc@cgl.ucsf.edu # inspired by image-sig posting from Kevin Cazabon, kcazabon@home.com if hasattr(im, 'tag'): # preserve tags from original TIFF image file for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION): if im.tag.tagdata.has_key(key): ifd[key] = im.tag.tagdata.get(key) here, ifd[key] gets vaule: (3, '\x02\x00') and ol32 doesn't like this. When I reqrite ifd[key] = 0x2, it is OK (I know, this is a very ugly hack). Other: I wanted to save tiff files in G3 format, is it hard to build it into this patch? I mean using libtiff for this work also. Thanks in advance, Thomas Thursday, December 11, 2003, 11:58:50 AM, you wrote: eah> Hello Fredrik, eah> many thanks! eah> Does anybody know when will be a new PIL available including this eah> patch? eah> I applied a patch. I was able to open TIFF G3 files but got this when eah> I tryed to save: eah> Traceback (most recent call last): eah> File "./tiff.py", line 36, in ? eah> im.save("/tmp/test_o.tiff") eah> File "/usr/local/lib/python2.3/site-packages/PIL/Image.py", line 1136, in save eah> SAVE[string.upper(format)](self, fp, filename) eah> File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 684, in _save eah> offset = ifd.save(fp) eah> File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 357, in save eah> data = string.join(map(o32, value), "") eah> File "/usr/local/lib/python2.3/site-packages/PIL/TiffImagePlugin.py", line 55, in ol32 eah> return chr(i&255) + chr(i>>8&255) + chr(i>>16&255) + chr(i>>24&255) eah> TypeError: unsupported operand type(s) for &: 'str' and 'int' eah> Does anybody know what's wrong? eah> Thanks, eah> Thomas eah> Thursday, December 11, 2003, 10:47:38 AM, you wrote: FL>> "Thomas" wrote: >>> does anybody have TIFF G3 compression implemented for PIL? FL>> this might be helpful: FL>> http://mail.python.org/pipermail/image-sig/2003-July/002354.html FL>> From borge.kjeldstad at whiteflower.no Thu Dec 11 09:14:43 2003 From: borge.kjeldstad at whiteflower.no (=?iso-8859-1?Q?B=F8rge_Kjeldstad?=) Date: Thu Dec 11 09:27:03 2003 Subject: [Image-SIG] Installing PIL on zope2.6.1 Message-ID: <001c01c3bff1$229cf0c0$2900000a@borge> Hello ! I would like to install PIL to use it with zope2.6.1 on a windows xp OS. But how will I do that? I have downloaded this: Python Imaging Library 1.1.4 for Python 2.1 (Windows only) (398k EXE) and try to run it, but when I am asked to type in "Installation Directory" I do not know what directory to type in. Further I am also not allowed to type anything - the cursor does not respond to my typing... Thanks and Cheers! B?rge From fredrik at pythonware.com Thu Dec 11 09:52:38 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu Dec 11 09:52:48 2003 Subject: [Image-SIG] Re: Installing PIL on zope2.6.1 References: <001c01c3bff1$229cf0c0$2900000a@borge> Message-ID: Børge Kjeldstad wrote: > I would like to install PIL to use it with zope2.6.1 > on a windows xp OS. But how will I do that? > > I have downloaded this: > Python Imaging Library 1.1.4 for Python 2.1 (Windows only) (398k EXE) > and try to run it, but when I am asked to type in "Installation > Directory" > I do not know what directory to type in. Further I am also not allowed > to type anything - the cursor does not respond to my typing... there's a brief note on the download page that says: If the Windows installer cannot find a Python interpreter, you may have to register your interpreter first. which points to this page: http://www.effbot.org/zone/python-register.htm From vpastukhov at naumen.ru Thu Dec 11 11:00:37 2003 From: vpastukhov at naumen.ru (Vladimir Pastukhov) Date: Thu Dec 11 11:00:56 2003 Subject: [Image-SIG] Re: Tiff g3 In-Reply-To: <1866762759.20031211134125@axelero.hu> References: <189053848.20031210110648@axelero.hu> <1317430682.20031211115850@axelero.hu> <1866762759.20031211134125@axelero.hu> Message-ID: <3FD894A5.3090309@naumen.ru> Hello, ewc@axelero.hu wrote: > Hello, > > I found, that the mentioned problem is because of RESOLUTION_UNIT tag. > It looks like it has wrong number. Around line 635 in ... > When I reqrite ifd[key] = 0x2, it is OK (I know, this is a very ugly > hack). You can try a better fix from the attached file. > I wanted to save tiff files in G3 format, is it hard to build it into > this patch? I mean using libtiff for this work also. The work can take from 2 to 5 days depending on your knowledge of PIL and libtiff internals, and C. I have no plans for adding group3/4 encoding, at least until our customers require it (not likely). Best regards, -- Vladimir Pastukhov NauDoc CMS/DMS Senior Developer NAUMEN Company http://www.naumen.com -------------- next part -------------- --- TiffImagePlugin.py.orig Tue Jul 29 20:00:25 2003 +++ TiffImagePlugin.py Thu Dec 11 20:34:08 2003 @@ -345,7 +345,7 @@ elif tag in (X_RESOLUTION, Y_RESOLUTION): # identify rational data fields typ = 5 - continue + value = reduce(lambda a,b: a+b, value) else: typ = 3 for v in value: @@ -631,8 +631,10 @@ if hasattr(im, 'tag'): # preserve tags from original TIFF image file for key in (RESOLUTION_UNIT, X_RESOLUTION, Y_RESOLUTION): - if im.tag.tagdata.has_key(key): - ifd[key] = im.tag.tagdata.get(key) + try: + ifd[key] = im.tag[key] + except KeyError: + pass if im.encoderinfo.has_key("description"): ifd[IMAGEDESCRIPTION] = im.encoderinfo["description"] if im.encoderinfo.has_key("resolution"): From ewc at axelero.hu Thu Dec 11 11:52:55 2003 From: ewc at axelero.hu (ewc@axelero.hu) Date: Thu Dec 11 11:52:57 2003 Subject: [Image-SIG] Re: Tiff g3 In-Reply-To: <3FD894A5.3090309@naumen.ru> References: <189053848.20031210110648@axelero.hu> <1317430682.20031211115850@axelero.hu> <1866762759.20031211134125@axelero.hu> <3FD894A5.3090309@naumen.ru> Message-ID: <632429241.20031211175255@axelero.hu> Hello Vladimir, thank you for your fast response, fast bugfix. Regards, Thomas Thursday, December 11, 2003, 5:00:37 PM, you wrote: VP> Hello, VP> ewc@axelero.hu wrote: >> Hello, >> >> I found, that the mentioned problem is because of RESOLUTION_UNIT tag. >> It looks like it has wrong number. Around line 635 in VP> ... >> When I reqrite ifd[key] = 0x2, it is OK (I know, this is a very ugly >> hack). VP> You can try a better fix from the attached file. >> I wanted to save tiff files in G3 format, is it hard to build it into >> this patch? I mean using libtiff for this work also. VP> The work can take from 2 to 5 days depending on your VP> knowledge of PIL and libtiff internals, and C. I have VP> no plans for adding group3/4 encoding, at least until VP> our customers require it (not likely). VP> Best regards, VP> VP>-- VP>Vladimir Pastukhov VP>NauDoc CMS/DMS Senior Developer VP>NAUMEN Company http://www.naumen.com From rmccain at 3dex.com Fri Dec 12 11:57:16 2003 From: rmccain at 3dex.com (rmccain@3dex.com) Date: Fri Dec 12 12:31:40 2003 Subject: [Image-SIG] Photoshop Image Message-ID: <59334.66.210.250.35.1071248236.squirrel@66.210.250.50> I am having a little trouble opening Photoshop images that have a transparent background with the Python Imaging Library. Now it will open Photoshop files, but it crashes if they have a transparent background. Does anyone know if there is a workaround for this or if maybe I am doing something wrong. Thanks in advance for the help From info at haist.net Sat Dec 20 06:38:31 2003 From: info at haist.net (markus haist) Date: Sat Dec 20 06:41:14 2003 Subject: [Image-SIG] Imaging 1.1.4 --problem-- Message-ID: <1071920311.10115.8.camel@linux.local> hi I'm trying to install PIL 1.1.4 on SuSE 8.2, Python 2.3 the core libimaging compilation seems to work fine. but when I try run make (after make-f Makefile.pre.in boot), it keeps giving me the following error message gcc -pthread -fPIC -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/local/include/python2.3 -I/usr/local/include/python2.3 @DEFS@ -IlibImaging -I/usr/local/include -I/usr/local/include -c ././_imaging.c -o ./_imaging.o gcc: cannot specify -o with -c or -S and multiple compilations make: *** [_imaging.o] Error 1 any ideas ? thx in advance markus From joelrodrigues at Phreaker.net Sun Dec 21 05:15:53 2003 From: joelrodrigues at Phreaker.net (Joel Rodrigues) Date: Sun Dec 21 05:17:47 2003 Subject: [Image-SIG] COM blocks in jpeg files Message-ID: Hello, Is there any way to read & write comment blocks in jpeg files within Python ? The only way I've been able to see doing it is using the system jpeg utilities rdjpgcom & wrjpgcom. Something like (not elegant I imagine, so any help would be nice) : >>> import os, string >>> cmd = 'wrjpgcom -c "this Joel rodrigues" canon-ixus.jpg > canon-ixus_out.jpg' >>> handle = os.popen(cmd, 'r') >>> os.popen(cmd, 'r') canon-ixus_out.jpg', mode 'r' at 0x4d7760> and >>> cmd2 = 'rdjpgcom canon-ixus_out.jpg' >>> handle = os.popen(cmd2, 'r') >>> print handle >>> print string.join(handle.readlines()) this Joel rodrigues Any thoughts / advice will be much appreciated. Cheers, Joel From fredrik at pythonware.com Sun Dec 21 08:16:48 2003 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun Dec 21 08:18:09 2003 Subject: [Image-SIG] Re: Imaging 1.1.4 --problem-- References: <1071920311.10115.8.camel@linux.local> Message-ID: "markus haist" wrote: > I'm trying to install PIL 1.1.4 on SuSE 8.2, Python 2.3 > > the core libimaging compilation seems to work fine. > > but when I try run make (after make-f Makefile.pre.in boot), it keeps > giving me the following error message > > > gcc -pthread -fPIC -DNDEBUG -g -O3 -Wall -Wstrict-prototypes > -I/usr/local/include/python2.3 -I/usr/local/include/python2.3 @DEFS@ > -IlibImaging -I/usr/local/include -I/usr/local/include -c ././_imaging.c > -o ./_imaging.o > > gcc: cannot specify -o with -c or -S and multiple compilations > make: *** [_imaging.o] Error 1 note that the @DEFS@ directive hasn't been expanded. I don't have time to double check, but I suspect that the Makefile.pre.in approach simply doesn't work under Python 2.3. try building using setup.py instead (see the README for details). From gerrit at nl.linux.org Tue Dec 23 17:17:24 2003 From: gerrit at nl.linux.org (Gerrit Holl) Date: Tue Dec 23 17:18:45 2003 Subject: [Image-SIG] PIL: jpeg comment Message-ID: <20031223221724.GA2701@nl.linux.org> Hi, how do I read a JPEG comment with the Python Imaging Library? yours, Gerrit Holl. -- Asperger's Syndrome - a personal approach: http://people.nl.linux.org/~gerrit/english/