Commits

Christian Tismer committed 3004bfd

a crazy little hack that makes ***PIL with G4 obsolete*** :-) :-) now I'm happy

Comments (0)

Files changed (1)

playground/piltest.py

 import sys, os
 from ddc import rootpath
 
-from warnings import warn
+"""
+Fake Imaging without PIL decoder
+--------------------------------
 
-def check_pil(warning=True):
+based upon information from
+http://www.awaresystems.be/imaging/tiff/faq.html
+
+This little hack finally enables the usage of PIL for the DDC
+project without compiling CCITT G4 support at all.
+
+The idea is simply to avoid any recoding of the tiff file.
+Instead, the position of the first IFD is changed to another
+one (the second by default). No other changes are made to the tiff
+data. Fortunately Qt is reading the IFP data correctly.
+
+"""
+
+def check_pil_fake():
     try:
         import Image
     except ImportError:
 
     imfile = os.path.join(rootpath, 'ddc/config/data/demo-g4-2pages.tiff')
     im = Image.open(imfile)
-    im.seek(1)
-    try:
-        im.load()
-    except IOError:
-        if warning:
-            warn('CCITT G4 support is not compiled/working')
-        return False
-    return True
+    pos = im._TiffImageFile__first
+    next = im._TiffImageFile__next
+    fp = im._TiffImageFile__fp
+    fp.seek(0)
+    data = fp.read()
+    ifd = next#-4
+    import struct
+    ifdbytes = struct.pack('I', ifd)
+    data = data[:4] + ifdbytes + data[8:]
+    file('look_page2.tiff', 'wb').write(data)
+    
 
 if __name__ == '__main__':
-    check_pil()
+    check_pil_fake()