diff --git a/PIL/XVThumbImagePlugin.py b/PIL/XVThumbImagePlugin.py index 311e65dc0..9fe9ca131 100644 --- a/PIL/XVThumbImagePlugin.py +++ b/PIL/XVThumbImagePlugin.py @@ -23,6 +23,8 @@ __version__ = "0.1" o8 = _binary.o8 +_MAGIC = b"P7 332" + # standard color palette for thumbnails (RGB332) PALETTE = b"" for r in range(8): @@ -30,6 +32,9 @@ for r in range(8): for b in range(4): PALETTE = PALETTE + (o8((r*255)//7)+o8((g*255)//7)+o8((b*255)//3)) +def _accept(prefix): + return prefix[:6] == _MAGIC + ## # Image plugin for XV thumbnail images. @@ -42,8 +47,7 @@ class XVThumbImageFile(ImageFile.ImageFile): def _open(self): # check magic - s = self.fp.read(6) - if s != b"P7 332": + if self.fp.read(6) != _MAGIC: raise SyntaxError("not an XV thumbnail file") # Skip to beginning of next line @@ -72,4 +76,4 @@ class XVThumbImageFile(ImageFile.ImageFile): # -------------------------------------------------------------------- -Image.register_open(XVThumbImageFile.format, XVThumbImageFile) +Image.register_open(XVThumbImageFile.format, XVThumbImageFile, _accept)