mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-07 06:33:10 +03:00
pep8
This commit is contained in:
parent
e835dd70a1
commit
f4071ade0a
|
@ -34,7 +34,8 @@
|
||||||
|
|
||||||
__version__ = "0.6"
|
__version__ = "0.6"
|
||||||
|
|
||||||
import array, struct
|
import array
|
||||||
|
import struct
|
||||||
from PIL import Image, ImageFile, _binary
|
from PIL import Image, ImageFile, _binary
|
||||||
from PIL.JpegPresets import presets
|
from PIL.JpegPresets import presets
|
||||||
from PIL._util import isStringType
|
from PIL._util import isStringType
|
||||||
|
@ -44,6 +45,7 @@ o8 = _binary.o8
|
||||||
i16 = _binary.i16be
|
i16 = _binary.i16be
|
||||||
i32 = _binary.i32be
|
i32 = _binary.i32be
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parser
|
# Parser
|
||||||
|
|
||||||
|
@ -51,6 +53,7 @@ def Skip(self, marker):
|
||||||
n = i16(self.fp.read(2))-2
|
n = i16(self.fp.read(2))-2
|
||||||
ImageFile._safe_read(self.fp, n)
|
ImageFile._safe_read(self.fp, n)
|
||||||
|
|
||||||
|
|
||||||
def APP(self, marker):
|
def APP(self, marker):
|
||||||
#
|
#
|
||||||
# Application marker. Store these in the APP dictionary.
|
# Application marker. Store these in the APP dictionary.
|
||||||
|
@ -108,16 +111,17 @@ def APP(self, marker):
|
||||||
else:
|
else:
|
||||||
self.info["adobe_transform"] = adobe_transform
|
self.info["adobe_transform"] = adobe_transform
|
||||||
|
|
||||||
|
|
||||||
def COM(self, marker):
|
def COM(self, marker):
|
||||||
#
|
#
|
||||||
# Comment marker. Store these in the APP dictionary.
|
# Comment marker. Store these in the APP dictionary.
|
||||||
|
|
||||||
n = i16(self.fp.read(2))-2
|
n = i16(self.fp.read(2))-2
|
||||||
s = ImageFile._safe_read(self.fp, n)
|
s = ImageFile._safe_read(self.fp, n)
|
||||||
|
|
||||||
self.app["COM"] = s # compatibility
|
self.app["COM"] = s # compatibility
|
||||||
self.applist.append(("COM", s))
|
self.applist.append(("COM", s))
|
||||||
|
|
||||||
|
|
||||||
def SOF(self, marker):
|
def SOF(self, marker):
|
||||||
#
|
#
|
||||||
# Start of frame marker. Defines the size and mode of the
|
# Start of frame marker. Defines the size and mode of the
|
||||||
|
@ -165,6 +169,7 @@ def SOF(self, marker):
|
||||||
# 4-tuples: id, vsamp, hsamp, qtable
|
# 4-tuples: id, vsamp, hsamp, qtable
|
||||||
self.layer.append((t[0], i8(t[1])//16, i8(t[1]) & 15, i8(t[2])))
|
self.layer.append((t[0], i8(t[1])//16, i8(t[1]) & 15, i8(t[2])))
|
||||||
|
|
||||||
|
|
||||||
def DQT(self, marker):
|
def DQT(self, marker):
|
||||||
#
|
#
|
||||||
# Define quantization table. Support baseline 8-bit tables
|
# Define quantization table. Support baseline 8-bit tables
|
||||||
|
@ -261,6 +266,7 @@ MARKER = {
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[0:1] == b"\377"
|
return prefix[0:1] == b"\377"
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for JPEG and JFIF images.
|
# Image plugin for JPEG and JFIF images.
|
||||||
|
|
||||||
|
@ -348,7 +354,8 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||||
|
|
||||||
import tempfile, os
|
import tempfile
|
||||||
|
import os
|
||||||
f, path = tempfile.mkstemp()
|
f, path = tempfile.mkstemp()
|
||||||
os.close(f)
|
os.close(f)
|
||||||
if os.path.exists(self.filename):
|
if os.path.exists(self.filename):
|
||||||
|
@ -359,8 +366,10 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
try:
|
try:
|
||||||
self.im = Image.core.open_ppm(path)
|
self.im = Image.core.open_ppm(path)
|
||||||
finally:
|
finally:
|
||||||
try: os.unlink(path)
|
try:
|
||||||
except: pass
|
os.unlink(path)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.mode = self.im.mode
|
self.mode = self.im.mode
|
||||||
self.size = self.im.size
|
self.size = self.im.size
|
||||||
|
@ -377,6 +386,7 @@ def _getexif(self):
|
||||||
# version.
|
# version.
|
||||||
from PIL import TiffImagePlugin
|
from PIL import TiffImagePlugin
|
||||||
import io
|
import io
|
||||||
|
|
||||||
def fixup(value):
|
def fixup(value):
|
||||||
if len(value) == 1:
|
if len(value) == 1:
|
||||||
return value[0]
|
return value[0]
|
||||||
|
@ -446,16 +456,19 @@ samplings = {
|
||||||
(2, 2, 1, 1, 1, 1): 2,
|
(2, 2, 1, 1, 1, 1): 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def convert_dict_qtables(qtables):
|
def convert_dict_qtables(qtables):
|
||||||
qtables = [qtables[key] for key in range(len(qtables)) if key in qtables]
|
qtables = [qtables[key] for key in range(len(qtables)) if key in qtables]
|
||||||
for idx, table in enumerate(qtables):
|
for idx, table in enumerate(qtables):
|
||||||
qtables[idx] = [table[i] for i in zigzag_index]
|
qtables[idx] = [table[i] for i in zigzag_index]
|
||||||
return qtables
|
return qtables
|
||||||
|
|
||||||
|
|
||||||
def get_sampling(im):
|
def get_sampling(im):
|
||||||
sampling = im.layer[0][1:3] + im.layer[1][1:3] + im.layer[2][1:3]
|
sampling = im.layer[0][1:3] + im.layer[1][1:3] + im.layer[2][1:3]
|
||||||
return samplings.get(sampling, -1)
|
return samplings.get(sampling, -1)
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -568,10 +581,9 @@ def _save(im, fp, filename):
|
||||||
info.get("exif", b"")
|
info.get("exif", b"")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# if we optimize, libjpeg needs a buffer big enough to hold the whole image
|
||||||
# if we optimize, libjpeg needs a buffer big enough to hold the whole image in a shot.
|
# in a shot. Guessing on the size, at im.size bytes. (raw pizel size is
|
||||||
# Guessing on the size, at im.size bytes. (raw pizel size is channels*size, this
|
# channels*size, this is a value that's been used in a django patch.
|
||||||
# is a value that's been used in a django patch.
|
|
||||||
# https://github.com/jdriscoll/django-imagekit/issues/50
|
# https://github.com/jdriscoll/django-imagekit/issues/50
|
||||||
bufsize = 0
|
bufsize = 0
|
||||||
if "optimize" in info or "progressive" in info or "progression" in info:
|
if "optimize" in info or "progressive" in info or "progression" in info:
|
||||||
|
@ -586,13 +598,16 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
|
ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
|
||||||
|
|
||||||
|
|
||||||
def _save_cjpeg(im, fp, filename):
|
def _save_cjpeg(im, fp, filename):
|
||||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
# ALTERNATIVE: handle JPEGs via the IJG command line utilities.
|
||||||
import os
|
import os
|
||||||
file = im._dump()
|
file = im._dump()
|
||||||
os.system("cjpeg %s >%s" % (file, filename))
|
os.system("cjpeg %s >%s" % (file, filename))
|
||||||
try: os.unlink(file)
|
try:
|
||||||
except: pass
|
os.unlink(file)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# -------------------------------------------------------------------q-
|
# -------------------------------------------------------------------q-
|
||||||
# Registry stuff
|
# Registry stuff
|
||||||
|
|
Loading…
Reference in New Issue
Block a user