Remove unused _binary import (plus flake8)

This commit is contained in:
hugovk 2014-04-14 12:51:12 +03:00
parent 5cd454bde2
commit a97e5039d8

View File

@ -15,11 +15,12 @@
__version__ = "0.1" __version__ = "0.1"
from PIL import Image, ImageFile, _binary from PIL import Image, ImageFile
import struct import struct
import os import os
import io import io
def _parse_codestream(fp): def _parse_codestream(fp):
"""Parse the JPEG 2000 codestream to extract the size and component """Parse the JPEG 2000 codestream to extract the size and component
count from the SIZ marker segment, returning a PIL (size, mode) tuple.""" count from the SIZ marker segment, returning a PIL (size, mode) tuple."""
@ -28,7 +29,7 @@ def _parse_codestream(fp):
lsiz = struct.unpack('>H', hdr)[0] lsiz = struct.unpack('>H', hdr)[0]
siz = hdr + fp.read(lsiz - 2) siz = hdr + fp.read(lsiz - 2)
lsiz, rsiz, xsiz, ysiz, xosiz, yosiz, xtsiz, ytsiz, \ lsiz, rsiz, xsiz, ysiz, xosiz, yosiz, xtsiz, ytsiz, \
xtosiz, ytosiz, csiz \ xtosiz, ytosiz, csiz \
= struct.unpack('>HHIIIIIIIIH', siz[:38]) = struct.unpack('>HHIIIIIIIIH', siz[:38])
ssiz = [None]*csiz ssiz = [None]*csiz
xrsiz = [None]*csiz xrsiz = [None]*csiz
@ -51,6 +52,7 @@ def _parse_codestream(fp):
return (size, mode) return (size, mode)
def _parse_jp2_header(fp): def _parse_jp2_header(fp):
"""Parse the JP2 header box to extract size, component count and """Parse the JP2 header box to extract size, component count and
color space information, returning a PIL (size, mode) tuple.""" color space information, returning a PIL (size, mode) tuple."""
@ -90,7 +92,7 @@ def _parse_jp2_header(fp):
if tbox == b'ihdr': if tbox == b'ihdr':
height, width, nc, bpc, c, unkc, ipr \ height, width, nc, bpc, c, unkc, ipr \
= struct.unpack('>IIHBBBB', content) = struct.unpack('>IIHBBBB', content)
size = (width, height) size = (width, height)
if unkc: if unkc:
if nc == 1: if nc == 1:
@ -112,13 +114,13 @@ def _parse_jp2_header(fp):
elif nc == 4: elif nc == 4:
mode = 'RGBA' mode = 'RGBA'
break break
elif cs == 17: # grayscale elif cs == 17: # grayscale
if nc == 1: if nc == 1:
mode = 'L' mode = 'L'
elif nc == 2: elif nc == 2:
mode = 'LA' mode = 'LA'
break break
elif cs == 18: # sYCC elif cs == 18: # sYCC
if nc == 3: if nc == 3:
mode = 'RGB' mode = 'RGB'
elif nc == 4: elif nc == 4:
@ -127,6 +129,7 @@ def _parse_jp2_header(fp):
return (size, mode) return (size, mode)
## ##
# Image plugin for JPEG2000 images. # Image plugin for JPEG2000 images.
@ -180,10 +183,12 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
ImageFile.ImageFile.load(self) ImageFile.ImageFile.load(self)
def _accept(prefix): def _accept(prefix):
return (prefix[:4] == b'\xff\x4f\xff\x51' return (prefix[:4] == b'\xff\x4f\xff\x51'
or prefix[:12] == b'\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a') or prefix[:12] == b'\x00\x00\x00\x0cjP \x0d\x0a\x87\x0a')
# ------------------------------------------------------------ # ------------------------------------------------------------
# Save support # Save support
@ -228,7 +233,7 @@ def _save(im, fp, filename):
progression, progression,
cinema_mode, cinema_mode,
fd fd
) )
ImageFile._save(im, fp, [('jpeg2k', (0, 0)+im.size, 0, kind)]) ImageFile._save(im, fp, [('jpeg2k', (0, 0)+im.size, 0, kind)])