Cosmetic refactoring.
# POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------------
-'''Read GIF control data.
+"""Read GIF control data.
http://www.w3.org/Graphics/GIF/spec-gif89a.txt
-'''
+"""
from __future__ import print_function
from __future__ import division
from builtins import object
@@ -48,28 +48,34 @@ import struct
from pyglet.image.codecs import ImageDecodeException
+
class GIFStream(object):
def __init__(self):
self.images = []
+
class GIFImage(object):
delay = None
+
class GraphicsScope(object):
delay = None
+
# Appendix A.
LABEL_EXTENSION_INTRODUCER = 0x21
LABEL_GRAPHIC_CONTROL_EXTENSION = 0xf9
LABEL_IMAGE_DESCRIPTOR = 0x2c
LABEL_TRAILER = 0x3b
-def unpack(format, file):
- size = struct.calcsize(format)
+
+def unpack(fmt, file):
+ size = struct.calcsize(fmt)
data = file.read(size)
if len(data) < size:
raise ImageDecodeException('Unexpected EOF')
- return struct.unpack(format, data)
+ return struct.unpack(fmt, data)
+
def read_byte(file):
data = file.read(1)
@@ -77,11 +83,12 @@ def read_byte(file):
raise ImageDecodeException('Unexpected EOF')
return ord(data)
+
def read(file):
- '''Read a GIF file stream.
+ """Read a GIF file stream.
:rtype: GIFStream
- '''
+ """
# 17. Header
signature = file.read(3)
version = file.read(3)
@@ -125,6 +132,7 @@ def read(file):
return stream
+
def skip_data_sub_blocks(file):
# 15. Data sub-blocks
block_size = read_byte(file)
@@ -132,6 +140,7 @@ def skip_data_sub_blocks(file):
data = file.read(block_size)
block_size = read_byte(file)
+
def read_table_based_image(file, stream, graphics_scope):
gif_image = GIFImage()
stream.images.append(gif_image)
@@ -155,6 +164,7 @@ def read_table_based_image(file, stream, graphics_scope):
lzw_code_size = file.read(1)
skip_data_sub_blocks(file)
+
def read_graphic_control_extension(file, stream, graphics_scope):
# 23. Graphic control extension
(block_size,
