eschneiderSA / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

False "ImageDecodeException: Not a GIF stream" in python3.x #718

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Have you tried Pyglet 1.2 alpha1 or the repository code?
tried default branch, changeset: 489162ee33f1, Sat Mar 29 14:05:01 2014 +0000

What steps will reproduce the problem?
1. apply 2to3
3. try to load any gif image

Paste in the traceback or error message:
pyglet/pyglet/image/codecs/gdkpixbuf2.py in decode_animation(self, file, 
filename)
    119         # Extract GIF control data.  If it's not a GIF, this method will
    120         # raise.
--> 121         gif_stream = gif.read(file)
    122         delays = [image.delay for image in gif_stream.images]
    123

pyglet/pyglet/image/codecs/gif.py in read(file)
     81     # 17. Header
     82     signature = file.read(3)
     83     version = file.read(3)
     84     if signature != 'GIF':
---> 85         raise ImageDecodeException('Not a GIF stream')
     86
     87     stream = GIFStream()

ImageDecodeException: Not a GIF stream

As file is opened in a bytes mode, `signature != 'GIF'` will always produce 
True in python3.x.

Proposed fix:
diff --git a/pyglet/image/codecs/gif.py b/pyglet/image/codecs/gif.py
--- a/pyglet/image/codecs/gif.py
+++ b/pyglet/image/codecs/gif.py
@@ -81,7 +81,7 @@
     #17. Header
     signature = file.read(3)
     version = file.read(3)
-    if signature != 'GIF':
+    if signature != b'GIF':
         raise ImageDecodeException('Not a GIF stream')

     stream = GIFStream()

Original issue reported on code.google.com by Risimi...@gmail.com on 29 Mar 2014 at 5:57

GoogleCodeExporter commented 8 years ago
Thanks for the report!

Original comment by useboxnet on 29 Mar 2014 at 6:40

GoogleCodeExporter commented 8 years ago
I can't reproduce it with Python 3.3.2, but I'm adding your change and I'm 
going to include a test for the GIF codec in gdkpixbuf2.

Thanks for the report!

Original comment by useboxnet on 1 Apr 2014 at 4:05

GoogleCodeExporter commented 8 years ago
This issue was closed by revision cf08d3d4b601.

Original comment by useboxnet on 1 Apr 2014 at 4:54