mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
code clean
This commit is contained in:
parent
6cd0e1757b
commit
a500ca1393
|
@ -370,7 +370,7 @@ class ArgStream(ChunkStream):
|
||||||
im1 = im1.chop_add_modulo(im0.crop(bbox))
|
im1 = im1.chop_add_modulo(im0.crop(bbox))
|
||||||
im0.paste(im1, bbox)
|
im0.paste(im1, bbox)
|
||||||
|
|
||||||
self.count = self.count - 1
|
self.count -= 1
|
||||||
|
|
||||||
if self.count == 0 and self.show:
|
if self.count == 0 and self.show:
|
||||||
self.im = self.images[self.id]
|
self.im = self.images[self.id]
|
||||||
|
|
|
@ -128,5 +128,5 @@ class BdfFontFile(FontFile.FontFile):
|
||||||
if not c:
|
if not c:
|
||||||
break
|
break
|
||||||
id, ch, (xy, dst, src), im = c
|
id, ch, (xy, dst, src), im = c
|
||||||
if ch >= 0 and ch < len(self.glyph):
|
if 0 <= ch < len(self.glyph):
|
||||||
self.glyph[ch] = xy, dst, src, im
|
self.glyph[ch] = xy, dst, src, im
|
||||||
|
|
|
@ -93,7 +93,7 @@ def Ghostscript(tile, size, fp, scale=1):
|
||||||
s = fp.read(100*1024)
|
s = fp.read(100*1024)
|
||||||
if not s:
|
if not s:
|
||||||
break
|
break
|
||||||
length = length - len(s)
|
length -= len(s)
|
||||||
f.write(s)
|
f.write(s)
|
||||||
|
|
||||||
# Build ghostscript command
|
# Build ghostscript command
|
||||||
|
@ -148,7 +148,7 @@ class PSFile:
|
||||||
def tell(self):
|
def tell(self):
|
||||||
pos = self.fp.tell()
|
pos = self.fp.tell()
|
||||||
if self.char:
|
if self.char:
|
||||||
pos = pos - 1
|
pos -= 1
|
||||||
return pos
|
return pos
|
||||||
def readline(self):
|
def readline(self):
|
||||||
s = b""
|
s = b""
|
||||||
|
|
|
@ -63,15 +63,12 @@ TAGS = {
|
||||||
0x0201: "JpegIFOffset",
|
0x0201: "JpegIFOffset",
|
||||||
0x0202: "JpegIFByteCount",
|
0x0202: "JpegIFByteCount",
|
||||||
0x0211: "YCbCrCoefficients",
|
0x0211: "YCbCrCoefficients",
|
||||||
0x0211: "YCbCrCoefficients",
|
|
||||||
0x0212: "YCbCrSubSampling",
|
0x0212: "YCbCrSubSampling",
|
||||||
0x0213: "YCbCrPositioning",
|
0x0213: "YCbCrPositioning",
|
||||||
0x0213: "YCbCrPositioning",
|
|
||||||
0x0214: "ReferenceBlackWhite",
|
|
||||||
0x0214: "ReferenceBlackWhite",
|
0x0214: "ReferenceBlackWhite",
|
||||||
0x1000: "RelatedImageFileFormat",
|
0x1000: "RelatedImageFileFormat",
|
||||||
0x1001: "RelatedImageLength",
|
0x1001: "RelatedImageLength", # FIXME / Dictionary contains duplicate keys
|
||||||
0x1001: "RelatedImageWidth",
|
0x1001: "RelatedImageWidth", # FIXME \ Dictionary contains duplicate keys
|
||||||
0x828d: "CFARepeatPatternDim",
|
0x828d: "CFARepeatPatternDim",
|
||||||
0x828e: "CFAPattern",
|
0x828e: "CFAPattern",
|
||||||
0x828f: "BatteryLevel",
|
0x828f: "BatteryLevel",
|
||||||
|
|
|
@ -105,7 +105,7 @@ class FliImageFile(ImageFile.ImageFile):
|
||||||
g = i8(s[n+1]) << shift
|
g = i8(s[n+1]) << shift
|
||||||
b = i8(s[n+2]) << shift
|
b = i8(s[n+2]) << shift
|
||||||
palette[i] = (r, g, b)
|
palette[i] = (r, g, b)
|
||||||
i = i + 1
|
i += 1
|
||||||
|
|
||||||
def seek(self, frame):
|
def seek(self, frame):
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ def puti16(fp, values):
|
||||||
# write network order (big-endian) 16-bit sequence
|
# write network order (big-endian) 16-bit sequence
|
||||||
for v in values:
|
for v in values:
|
||||||
if v < 0:
|
if v < 0:
|
||||||
v = v + 65536
|
v += 65536
|
||||||
fp.write(_binary.o16be(v))
|
fp.write(_binary.o16be(v))
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -63,7 +63,7 @@ class FontFile:
|
||||||
h = max(h, src[3] - src[1])
|
h = max(h, src[3] - src[1])
|
||||||
w = w + (src[2] - src[0])
|
w = w + (src[2] - src[0])
|
||||||
if w > WIDTH:
|
if w > WIDTH:
|
||||||
lines = lines + 1
|
lines += 1
|
||||||
w = (src[2] - src[0])
|
w = (src[2] - src[0])
|
||||||
maxwidth = max(maxwidth, w)
|
maxwidth = max(maxwidth, w)
|
||||||
|
|
||||||
|
|
|
@ -83,8 +83,8 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
size = max(self.size)
|
size = max(self.size)
|
||||||
i = 1
|
i = 1
|
||||||
while size > 64:
|
while size > 64:
|
||||||
size = size / 2
|
size /= 2
|
||||||
i = i + 1
|
i += 1
|
||||||
self.maxid = i - 1
|
self.maxid = i - 1
|
||||||
|
|
||||||
# mode. instead of using a single field for this, flashpix
|
# mode. instead of using a single field for this, flashpix
|
||||||
|
|
|
@ -275,7 +275,7 @@ def _save(im, fp, filename):
|
||||||
interlace = 0
|
interlace = 0
|
||||||
|
|
||||||
if interlace:
|
if interlace:
|
||||||
flags = flags | 64
|
flags |= 64
|
||||||
|
|
||||||
try:
|
try:
|
||||||
transparency = im.encoderinfo["transparency"]
|
transparency = im.encoderinfo["transparency"]
|
||||||
|
|
|
@ -68,7 +68,7 @@ class GradientFile:
|
||||||
x = i / float(entries-1)
|
x = i / float(entries-1)
|
||||||
|
|
||||||
while x1 < x:
|
while x1 < x:
|
||||||
ix = ix + 1
|
ix += 1
|
||||||
x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix]
|
x0, x1, xm, rgb0, rgb1, segment = self.gradient[ix]
|
||||||
|
|
||||||
w = x1 - x0
|
w = x1 - x0
|
||||||
|
|
|
@ -52,7 +52,7 @@ class GimpPaletteFile:
|
||||||
if 0 <= i <= 255:
|
if 0 <= i <= 255:
|
||||||
self.palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])
|
self.palette[i] = o8(v[0]) + o8(v[1]) + o8(v[2])
|
||||||
|
|
||||||
i = i + 1
|
i += 1
|
||||||
|
|
||||||
self.palette = b"".join(self.palette)
|
self.palette = b"".join(self.palette)
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ def read_32(fobj, start_length, size):
|
||||||
else:
|
else:
|
||||||
blocksize = byte + 1
|
blocksize = byte + 1
|
||||||
data.append(fobj.read(blocksize))
|
data.append(fobj.read(blocksize))
|
||||||
bytesleft = bytesleft - blocksize
|
bytesleft -= blocksize
|
||||||
if bytesleft <= 0:
|
if bytesleft <= 0:
|
||||||
break
|
break
|
||||||
if bytesleft != 0:
|
if bytesleft != 0:
|
||||||
|
@ -179,11 +179,11 @@ class IcnsFile:
|
||||||
i = HEADERSIZE
|
i = HEADERSIZE
|
||||||
while i < filesize:
|
while i < filesize:
|
||||||
sig, blocksize = nextheader(fobj)
|
sig, blocksize = nextheader(fobj)
|
||||||
i = i + HEADERSIZE
|
i += HEADERSIZE
|
||||||
blocksize = blocksize - HEADERSIZE
|
blocksize -= HEADERSIZE
|
||||||
dct[sig] = (i, blocksize)
|
dct[sig] = (i, blocksize)
|
||||||
fobj.seek(blocksize, 1)
|
fobj.seek(blocksize, 1)
|
||||||
i = i + blocksize
|
i += blocksize
|
||||||
|
|
||||||
def itersizes(self):
|
def itersizes(self):
|
||||||
sizes = []
|
sizes = []
|
||||||
|
|
|
@ -182,7 +182,7 @@ class ImImageFile(ImageFile.ImageFile):
|
||||||
self.info[k] = v
|
self.info[k] = v
|
||||||
|
|
||||||
if k in TAGS:
|
if k in TAGS:
|
||||||
n = n + 1
|
n += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from PIL import VERSION, PILLOW_VERSION, _plugins
|
from PIL import PILLOW_VERSION, _plugins
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ except ImportError:
|
||||||
builtins = __builtin__
|
builtins = __builtin__
|
||||||
|
|
||||||
from PIL import ImageMode
|
from PIL import ImageMode
|
||||||
from PIL._binary import i8, o8
|
from PIL._binary import i8
|
||||||
from PIL._util import isPath, isStringType
|
from PIL._util import isPath, isStringType
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
@ -434,9 +434,9 @@ def _getscaleoffset(expr):
|
||||||
data = expr(_E(stub)).data
|
data = expr(_E(stub)).data
|
||||||
try:
|
try:
|
||||||
(a, b, c) = data # simplified syntax
|
(a, b, c) = data # simplified syntax
|
||||||
if (a is stub and b == "__mul__" and isinstance(c, numbers.Number)):
|
if a is stub and b == "__mul__" and isinstance(c, numbers.Number):
|
||||||
return c, 0.0
|
return c, 0.0
|
||||||
if (a is stub and b == "__add__" and isinstance(c, numbers.Number)):
|
if a is stub and b == "__add__" and isinstance(c, numbers.Number):
|
||||||
return 1.0, c
|
return 1.0, c
|
||||||
except TypeError: pass
|
except TypeError: pass
|
||||||
try:
|
try:
|
||||||
|
@ -1972,7 +1972,6 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||||
|
|
||||||
.. versionadded:: 1.1.4
|
.. versionadded:: 1.1.4
|
||||||
"""
|
"""
|
||||||
"Load image from bytes or buffer"
|
|
||||||
|
|
||||||
# may pass tuple instead of argument list
|
# may pass tuple instead of argument list
|
||||||
if len(args) == 1 and isinstance(args[0], tuple):
|
if len(args) == 1 and isinstance(args[0], tuple):
|
||||||
|
|
|
@ -134,7 +134,7 @@ FLAGS = {
|
||||||
_MAX_FLAG = 0
|
_MAX_FLAG = 0
|
||||||
for flag in FLAGS.values():
|
for flag in FLAGS.values():
|
||||||
if isinstance(flag, int):
|
if isinstance(flag, int):
|
||||||
_MAX_FLAG = _MAX_FLAG | flag
|
_MAX_FLAG |= flag
|
||||||
|
|
||||||
# --------------------------------------------------------------------.
|
# --------------------------------------------------------------------.
|
||||||
# Experimental PIL-level API
|
# Experimental PIL-level API
|
||||||
|
@ -885,7 +885,7 @@ if __name__ == "__main__":
|
||||||
print("%s" %f)
|
print("%s" %f)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
exec ("doc = ImageCms.%s.__doc__" %(f))
|
exec ("doc = ImageCms.%s.__doc__" % f)
|
||||||
if "pyCMS" in doc:
|
if "pyCMS" in doc:
|
||||||
# so we don't get the __doc__ string for imported modules
|
# so we don't get the __doc__ string for imported modules
|
||||||
print(doc)
|
print(doc)
|
||||||
|
|
|
@ -502,5 +502,5 @@ def _safe_read(fp, size):
|
||||||
if not block:
|
if not block:
|
||||||
break
|
break
|
||||||
data.append(block)
|
data.append(block)
|
||||||
size = size - len(block)
|
size -= len(block)
|
||||||
return b"".join(data)
|
return b"".join(data)
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL import _imagingmath
|
from PIL import _imagingmath
|
||||||
import sys
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import builtins
|
import builtins
|
||||||
|
|
|
@ -94,7 +94,7 @@ def autocontrast(image, cutoff=0, ignore=None):
|
||||||
cut = cut - h[lo]
|
cut = cut - h[lo]
|
||||||
h[lo] = 0
|
h[lo] = 0
|
||||||
else:
|
else:
|
||||||
h[lo] = h[lo] - cut
|
h[lo] -= cut
|
||||||
cut = 0
|
cut = 0
|
||||||
if cut <= 0:
|
if cut <= 0:
|
||||||
break
|
break
|
||||||
|
@ -105,7 +105,7 @@ def autocontrast(image, cutoff=0, ignore=None):
|
||||||
cut = cut - h[hi]
|
cut = cut - h[hi]
|
||||||
h[hi] = 0
|
h[hi] = 0
|
||||||
else:
|
else:
|
||||||
h[hi] = h[hi] - cut
|
h[hi] -= cut
|
||||||
cut = 0
|
cut = 0
|
||||||
if cut <= 0:
|
if cut <= 0:
|
||||||
break
|
break
|
||||||
|
|
|
@ -17,7 +17,7 @@ from __future__ import print_function
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
if(sys.version_info >= (3, 3)):
|
if sys.version_info >= (3, 3):
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
else:
|
else:
|
||||||
from pipes import quote
|
from pipes import quote
|
||||||
|
@ -160,7 +160,7 @@ else:
|
||||||
# imagemagick's display command instead.
|
# imagemagick's display command instead.
|
||||||
command = executable = "xv"
|
command = executable = "xv"
|
||||||
if title:
|
if title:
|
||||||
command = command + " -name %s" % quote(title)
|
command += " -name %s" % quote(title)
|
||||||
return command, executable
|
return command, executable
|
||||||
|
|
||||||
if which("xv"):
|
if which("xv"):
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
from PIL import Image
|
|
||||||
import operator, math
|
import operator, math
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ class Stat:
|
||||||
for i in range(0, len(self.h), 256):
|
for i in range(0, len(self.h), 256):
|
||||||
sum = 0.0
|
sum = 0.0
|
||||||
for j in range(256):
|
for j in range(256):
|
||||||
sum = sum + j * self.h[i+j]
|
sum += j * self.h[i + j]
|
||||||
v.append(sum)
|
v.append(sum)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
@ -92,7 +91,7 @@ class Stat:
|
||||||
for i in range(0, len(self.h), 256):
|
for i in range(0, len(self.h), 256):
|
||||||
sum2 = 0.0
|
sum2 = 0.0
|
||||||
for j in range(256):
|
for j in range(256):
|
||||||
sum2 = sum2 + (j ** 2) * float(self.h[i+j])
|
sum2 += (j ** 2) * float(self.h[i + j])
|
||||||
v.append(sum2)
|
v.append(sum2)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
break
|
break
|
||||||
if s != sz:
|
if s != sz:
|
||||||
return 0
|
return 0
|
||||||
y = y + 1
|
y += 1
|
||||||
return y == size[1]
|
return y == size[1]
|
||||||
|
|
||||||
def _open(self):
|
def _open(self):
|
||||||
|
@ -187,7 +187,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
if not s:
|
if not s:
|
||||||
break
|
break
|
||||||
o.write(s)
|
o.write(s)
|
||||||
size = size - len(s)
|
size -= len(s)
|
||||||
o.close()
|
o.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -235,26 +235,26 @@ def getiptcinfo(im):
|
||||||
# parse the image resource block
|
# parse the image resource block
|
||||||
offset = 0
|
offset = 0
|
||||||
while app[offset:offset+4] == "8BIM":
|
while app[offset:offset+4] == "8BIM":
|
||||||
offset = offset + 4
|
offset += 4
|
||||||
# resource code
|
# resource code
|
||||||
code = JpegImagePlugin.i16(app, offset)
|
code = JpegImagePlugin.i16(app, offset)
|
||||||
offset = offset + 2
|
offset += 2
|
||||||
# resource name (usually empty)
|
# resource name (usually empty)
|
||||||
name_len = i8(app[offset])
|
name_len = i8(app[offset])
|
||||||
name = app[offset+1:offset+1+name_len]
|
name = app[offset+1:offset+1+name_len]
|
||||||
offset = 1 + offset + name_len
|
offset = 1 + offset + name_len
|
||||||
if offset & 1:
|
if offset & 1:
|
||||||
offset = offset + 1
|
offset += 1
|
||||||
# resource data block
|
# resource data block
|
||||||
size = JpegImagePlugin.i32(app, offset)
|
size = JpegImagePlugin.i32(app, offset)
|
||||||
offset = offset + 4
|
offset += 4
|
||||||
if code == 0x0404:
|
if code == 0x0404:
|
||||||
# 0x0404 contains IPTC/NAA data
|
# 0x0404 contains IPTC/NAA data
|
||||||
data = app[offset:offset+size]
|
data = app[offset:offset+size]
|
||||||
break
|
break
|
||||||
offset = offset + size
|
offset = offset + size
|
||||||
if offset & 1:
|
if offset & 1:
|
||||||
offset = offset + 1
|
offset += 1
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
__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
|
||||||
|
@ -45,7 +45,7 @@ def _parse_codestream(fp):
|
||||||
elif csiz == 3:
|
elif csiz == 3:
|
||||||
mode = 'RGB'
|
mode = 'RGB'
|
||||||
elif csiz == 4:
|
elif csiz == 4:
|
||||||
mode == 'RGBA'
|
mode = 'RGBA'
|
||||||
else:
|
else:
|
||||||
mode = None
|
mode = None
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ def _parse_jp2_header(fp):
|
||||||
if nc == 3:
|
if nc == 3:
|
||||||
mode = 'RGB'
|
mode = 'RGB'
|
||||||
elif nc == 4:
|
elif nc == 4:
|
||||||
mode == 'RGBA'
|
mode = 'RGBA'
|
||||||
break
|
break
|
||||||
|
|
||||||
return (size, mode)
|
return (size, mode)
|
||||||
|
|
|
@ -543,8 +543,8 @@ def _save(im, fp, filename):
|
||||||
i = 1
|
i = 1
|
||||||
for marker in markers:
|
for marker in markers:
|
||||||
size = struct.pack(">H", 2 + ICC_OVERHEAD_LEN + len(marker))
|
size = struct.pack(">H", 2 + ICC_OVERHEAD_LEN + len(marker))
|
||||||
extra = extra + (b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) + o8(len(markers)) + marker)
|
extra += b"\xFF\xE2" + size + b"ICC_PROFILE\0" + o8(i) + o8(len(markers)) + marker
|
||||||
i = i + 1
|
i += 1
|
||||||
|
|
||||||
# get keyword arguments
|
# get keyword arguments
|
||||||
im.encoderconfig = (
|
im.encoderconfig = (
|
||||||
|
|
|
@ -38,13 +38,13 @@ class BitStream:
|
||||||
self.bits = 0
|
self.bits = 0
|
||||||
continue
|
continue
|
||||||
self.bitbuffer = (self.bitbuffer << 8) + c
|
self.bitbuffer = (self.bitbuffer << 8) + c
|
||||||
self.bits = self.bits + 8
|
self.bits += 8
|
||||||
return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1
|
return self.bitbuffer >> (self.bits - bits) & (1 << bits) - 1
|
||||||
|
|
||||||
def skip(self, bits):
|
def skip(self, bits):
|
||||||
while self.bits < bits:
|
while self.bits < bits:
|
||||||
self.bitbuffer = (self.bitbuffer << 8) + i8(self.fp.read(1))
|
self.bitbuffer = (self.bitbuffer << 8) + i8(self.fp.read(1))
|
||||||
self.bits = self.bits + 8
|
self.bits += 8
|
||||||
self.bits = self.bits - bits
|
self.bits = self.bits - bits
|
||||||
|
|
||||||
def read(self, bits):
|
def read(self, bits):
|
||||||
|
|
|
@ -82,7 +82,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
sum = 0
|
sum = 0
|
||||||
for h in header:
|
for h in header:
|
||||||
sum = sum ^ h
|
sum ^= h
|
||||||
header[12] = sum # FIXME: is this the right field?
|
header[12] = sum # FIXME: is this the right field?
|
||||||
|
|
||||||
# header
|
# header
|
||||||
|
|
|
@ -285,15 +285,15 @@ def set_debug_mode(debug_mode):
|
||||||
MAGIC = b'\320\317\021\340\241\261\032\341'
|
MAGIC = b'\320\317\021\340\241\261\032\341'
|
||||||
|
|
||||||
#[PL]: added constants for Sector IDs (from AAF specifications)
|
#[PL]: added constants for Sector IDs (from AAF specifications)
|
||||||
MAXREGSECT = 0xFFFFFFFA; # maximum SECT
|
MAXREGSECT = 0xFFFFFFFA # maximum SECT
|
||||||
DIFSECT = 0xFFFFFFFC; # (-4) denotes a DIFAT sector in a FAT
|
DIFSECT = 0xFFFFFFFC # (-4) denotes a DIFAT sector in a FAT
|
||||||
FATSECT = 0xFFFFFFFD; # (-3) denotes a FAT sector in a FAT
|
FATSECT = 0xFFFFFFFD # (-3) denotes a FAT sector in a FAT
|
||||||
ENDOFCHAIN = 0xFFFFFFFE; # (-2) end of a virtual stream chain
|
ENDOFCHAIN = 0xFFFFFFFE # (-2) end of a virtual stream chain
|
||||||
FREESECT = 0xFFFFFFFF; # (-1) unallocated sector
|
FREESECT = 0xFFFFFFFF # (-1) unallocated sector
|
||||||
|
|
||||||
#[PL]: added constants for Directory Entry IDs (from AAF specifications)
|
#[PL]: added constants for Directory Entry IDs (from AAF specifications)
|
||||||
MAXREGSID = 0xFFFFFFFA; # maximum directory entry ID
|
MAXREGSID = 0xFFFFFFFA # maximum directory entry ID
|
||||||
NOSTREAM = 0xFFFFFFFF; # (-1) unallocated directory entry
|
NOSTREAM = 0xFFFFFFFF # (-1) unallocated directory entry
|
||||||
|
|
||||||
#[PL] object types in storage (from AAF specifications)
|
#[PL] object types in storage (from AAF specifications)
|
||||||
STGTY_EMPTY = 0 # empty directory entry (according to OpenOffice.org doc)
|
STGTY_EMPTY = 0 # empty directory entry (according to OpenOffice.org doc)
|
||||||
|
@ -308,15 +308,15 @@ STGTY_ROOT = 5 # element is a root storage
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# property types
|
# property types
|
||||||
|
|
||||||
VT_EMPTY=0; VT_NULL=1; VT_I2=2; VT_I4=3; VT_R4=4; VT_R8=5; VT_CY=6;
|
VT_EMPTY=0; VT_NULL=1; VT_I2=2; VT_I4=3; VT_R4=4; VT_R8=5; VT_CY=6
|
||||||
VT_DATE=7; VT_BSTR=8; VT_DISPATCH=9; VT_ERROR=10; VT_BOOL=11;
|
VT_DATE=7; VT_BSTR=8; VT_DISPATCH=9; VT_ERROR=10; VT_BOOL=11
|
||||||
VT_VARIANT=12; VT_UNKNOWN=13; VT_DECIMAL=14; VT_I1=16; VT_UI1=17;
|
VT_VARIANT=12; VT_UNKNOWN=13; VT_DECIMAL=14; VT_I1=16; VT_UI1=17
|
||||||
VT_UI2=18; VT_UI4=19; VT_I8=20; VT_UI8=21; VT_INT=22; VT_UINT=23;
|
VT_UI2=18; VT_UI4=19; VT_I8=20; VT_UI8=21; VT_INT=22; VT_UINT=23
|
||||||
VT_VOID=24; VT_HRESULT=25; VT_PTR=26; VT_SAFEARRAY=27; VT_CARRAY=28;
|
VT_VOID=24; VT_HRESULT=25; VT_PTR=26; VT_SAFEARRAY=27; VT_CARRAY=28
|
||||||
VT_USERDEFINED=29; VT_LPSTR=30; VT_LPWSTR=31; VT_FILETIME=64;
|
VT_USERDEFINED=29; VT_LPSTR=30; VT_LPWSTR=31; VT_FILETIME=64
|
||||||
VT_BLOB=65; VT_STREAM=66; VT_STORAGE=67; VT_STREAMED_OBJECT=68;
|
VT_BLOB=65; VT_STREAM=66; VT_STORAGE=67; VT_STREAMED_OBJECT=68
|
||||||
VT_STORED_OBJECT=69; VT_BLOB_OBJECT=70; VT_CF=71; VT_CLSID=72;
|
VT_STORED_OBJECT=69; VT_BLOB_OBJECT=70; VT_CF=71; VT_CLSID=72
|
||||||
VT_VECTOR=0x1000;
|
VT_VECTOR=0x1000
|
||||||
|
|
||||||
# map property id to name (for debugging purposes)
|
# map property id to name (for debugging purposes)
|
||||||
|
|
||||||
|
@ -1761,7 +1761,7 @@ class OleFileIO:
|
||||||
return: a dictionary of values indexed by id (integer)
|
return: a dictionary of values indexed by id (integer)
|
||||||
"""
|
"""
|
||||||
# make sure no_conversion is a list, just to simplify code below:
|
# make sure no_conversion is a list, just to simplify code below:
|
||||||
if no_conversion == None:
|
if no_conversion is None:
|
||||||
no_conversion = []
|
no_conversion = []
|
||||||
# stream path as a string to report exceptions:
|
# stream path as a string to report exceptions:
|
||||||
streampath = filename
|
streampath = filename
|
||||||
|
@ -1810,7 +1810,7 @@ class OleFileIO:
|
||||||
if type == VT_I2: # 16-bit signed integer
|
if type == VT_I2: # 16-bit signed integer
|
||||||
value = i16(s, offset+4)
|
value = i16(s, offset+4)
|
||||||
if value >= 32768:
|
if value >= 32768:
|
||||||
value = value - 65536
|
value -= 65536
|
||||||
elif type == VT_UI2: # 2-byte unsigned integer
|
elif type == VT_UI2: # 2-byte unsigned integer
|
||||||
value = i16(s, offset+4)
|
value = i16(s, offset+4)
|
||||||
elif type in (VT_I4, VT_INT, VT_ERROR):
|
elif type in (VT_I4, VT_INT, VT_ERROR):
|
||||||
|
@ -1856,7 +1856,7 @@ class OleFileIO:
|
||||||
else:
|
else:
|
||||||
# legacy code kept for backward compatibility: returns a
|
# legacy code kept for backward compatibility: returns a
|
||||||
# number of seconds since Jan 1,1601
|
# number of seconds since Jan 1,1601
|
||||||
value = value // 10000000 # seconds
|
value //= 10000000 # seconds
|
||||||
elif type == VT_UI1: # 1-byte unsigned integer
|
elif type == VT_UI1: # 1-byte unsigned integer
|
||||||
value = i8(s[offset+4])
|
value = i8(s[offset+4])
|
||||||
elif type == VT_CLSID:
|
elif type == VT_CLSID:
|
||||||
|
|
|
@ -172,21 +172,21 @@ def _save(im, fp, filename, check=0):
|
||||||
cols = im.size[0]
|
cols = im.size[0]
|
||||||
rows = im.size[1]
|
rows = im.size[1]
|
||||||
|
|
||||||
rowbytes = ((cols + (16//bpp - 1)) / (16 // bpp)) * 2;
|
rowbytes = ((cols + (16//bpp - 1)) / (16 // bpp)) * 2
|
||||||
transparent_index = 0
|
transparent_index = 0
|
||||||
compression_type = _COMPRESSION_TYPES["none"]
|
compression_type = _COMPRESSION_TYPES["none"]
|
||||||
|
|
||||||
flags = 0;
|
flags = 0
|
||||||
if im.mode == "P" and "custom-colormap" in im.info:
|
if im.mode == "P" and "custom-colormap" in im.info:
|
||||||
flags = flags & _FLAGS["custom-colormap"]
|
flags &= _FLAGS["custom-colormap"]
|
||||||
colormapsize = 4 * 256 + 2;
|
colormapsize = 4 * 256 + 2
|
||||||
colormapmode = im.palette.mode
|
colormapmode = im.palette.mode
|
||||||
colormap = im.getdata().getpalette()
|
colormap = im.getdata().getpalette()
|
||||||
else:
|
else:
|
||||||
colormapsize = 0
|
colormapsize = 0
|
||||||
|
|
||||||
if "offset" in im.info:
|
if "offset" in im.info:
|
||||||
offset = (rowbytes * rows + 16 + 3 + colormapsize) // 4;
|
offset = (rowbytes * rows + 16 + 3 + colormapsize) // 4
|
||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ def _save(im, fp, filename, check=0):
|
||||||
# bytes per plane
|
# bytes per plane
|
||||||
stride = (im.size[0] * bits + 7) // 8
|
stride = (im.size[0] * bits + 7) // 8
|
||||||
# stride should be even
|
# stride should be even
|
||||||
stride = stride + (stride % 2)
|
stride += stride % 2
|
||||||
# Stride needs to be kept in sync with the PcxEncode.c version.
|
# Stride needs to be kept in sync with the PcxEncode.c version.
|
||||||
# Ideally it should be passed in in the state, but the bytes value
|
# Ideally it should be passed in in the state, but the bytes value
|
||||||
# gets overwritten.
|
# gets overwritten.
|
||||||
|
|
|
@ -104,8 +104,8 @@ def _save(im, fp, filename):
|
||||||
r = i8(palette[i*3])
|
r = i8(palette[i*3])
|
||||||
g = i8(palette[i*3+1])
|
g = i8(palette[i*3+1])
|
||||||
b = i8(palette[i*3+2])
|
b = i8(palette[i*3+2])
|
||||||
colorspace = colorspace + "%02x%02x%02x " % (r, g, b)
|
colorspace += "%02x%02x%02x " % (r, g, b)
|
||||||
colorspace = colorspace + b"> ]"
|
colorspace += b"> ]"
|
||||||
procset = "/ImageI" # indexed color
|
procset = "/ImageI" # indexed color
|
||||||
elif im.mode == "RGB":
|
elif im.mode == "RGB":
|
||||||
filter = "/DCTDecode"
|
filter = "/DCTDecode"
|
||||||
|
|
|
@ -235,7 +235,7 @@ def _layerinfo(file):
|
||||||
if t:
|
if t:
|
||||||
tile.extend(t)
|
tile.extend(t)
|
||||||
layers[i] = name, mode, bbox, tile
|
layers[i] = name, mode, bbox, tile
|
||||||
i = i + 1
|
i += 1
|
||||||
|
|
||||||
return layers
|
return layers
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ def _maketile(file, mode, bbox, channels):
|
||||||
for channel in range(channels):
|
for channel in range(channels):
|
||||||
layer = mode[channel]
|
layer = mode[channel]
|
||||||
if mode == "CMYK":
|
if mode == "CMYK":
|
||||||
layer = layer + ";I"
|
layer += ";I"
|
||||||
tile.append(("raw", bbox, offset, layer))
|
tile.append(("raw", bbox, offset, layer))
|
||||||
offset = offset + xsize*ysize
|
offset = offset + xsize*ysize
|
||||||
|
|
||||||
|
@ -272,13 +272,13 @@ def _maketile(file, mode, bbox, channels):
|
||||||
for channel in range(channels):
|
for channel in range(channels):
|
||||||
layer = mode[channel]
|
layer = mode[channel]
|
||||||
if mode == "CMYK":
|
if mode == "CMYK":
|
||||||
layer = layer + ";I"
|
layer += ";I"
|
||||||
tile.append(
|
tile.append(
|
||||||
("packbits", bbox, offset, layer)
|
("packbits", bbox, offset, layer)
|
||||||
)
|
)
|
||||||
for y in range(ysize):
|
for y in range(ysize):
|
||||||
offset = offset + i16(bytecount[i:i+2])
|
offset = offset + i16(bytecount[i:i+2])
|
||||||
i = i + 2
|
i += 2
|
||||||
|
|
||||||
file.seek(offset)
|
file.seek(offset)
|
||||||
|
|
||||||
|
|
|
@ -167,7 +167,7 @@ def _save(im, fp, filename, check=0):
|
||||||
|
|
||||||
orientation = im.info.get("orientation", -1)
|
orientation = im.info.get("orientation", -1)
|
||||||
if orientation > 0:
|
if orientation > 0:
|
||||||
flags = flags | 0x20
|
flags |= 0x20
|
||||||
|
|
||||||
fp.write(b"\000" +
|
fp.write(b"\000" +
|
||||||
o8(colormaptype) +
|
o8(colormaptype) +
|
||||||
|
|
|
@ -554,12 +554,12 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
else:
|
else:
|
||||||
count = len(value)
|
count = len(value)
|
||||||
if typ == 5:
|
if typ == 5:
|
||||||
count = count // 2 # adjust for rational data field
|
count //= 2 # adjust for rational data field
|
||||||
|
|
||||||
append((tag, typ, count, o32(offset), data))
|
append((tag, typ, count, o32(offset), data))
|
||||||
offset = offset + len(data)
|
offset += len(data)
|
||||||
if offset & 1:
|
if offset & 1:
|
||||||
offset = offset + 1 # word padding
|
offset += 1 # word padding
|
||||||
|
|
||||||
# update strip offset data to point beyond auxiliary data
|
# update strip offset data to point beyond auxiliary data
|
||||||
if stripoffsets is not None:
|
if stripoffsets is not None:
|
||||||
|
@ -643,7 +643,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.fp.seek(self.__next)
|
self.fp.seek(self.__next)
|
||||||
self.tag.load(self.fp)
|
self.tag.load(self.fp)
|
||||||
self.__next = self.tag.next
|
self.__next = self.tag.next
|
||||||
self.__frame = self.__frame + 1
|
self.__frame += 1
|
||||||
self._setup()
|
self._setup()
|
||||||
|
|
||||||
def _tell(self):
|
def _tell(self):
|
||||||
|
@ -899,7 +899,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
y = y + h
|
y = y + h
|
||||||
if y >= self.size[1]:
|
if y >= self.size[1]:
|
||||||
x = y = 0
|
x = y = 0
|
||||||
l = l + 1
|
l += 1
|
||||||
a = None
|
a = None
|
||||||
elif TILEOFFSETS in self.tag:
|
elif TILEOFFSETS in self.tag:
|
||||||
# tiled image
|
# tiled image
|
||||||
|
@ -920,7 +920,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
x, y = 0, y + h
|
x, y = 0, y + h
|
||||||
if y >= self.size[1]:
|
if y >= self.size[1]:
|
||||||
x = y = 0
|
x = y = 0
|
||||||
l = l + 1
|
l += 1
|
||||||
a = None
|
a = None
|
||||||
else:
|
else:
|
||||||
if Image.DEBUG:
|
if Image.DEBUG:
|
||||||
|
@ -1092,7 +1092,7 @@ def _save(im, fp, filename):
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
_fp = os.dup(fp.fileno())
|
_fp = os.dup(fp.fileno())
|
||||||
|
|
||||||
blocklist = [STRIPOFFSETS, STRIPBYTECOUNTS, ROWSPERSTRIP, ICCPROFILE] # ICC Profile crashes.
|
blocklist = [STRIPOFFSETS, STRIPBYTECOUNTS, ROWSPERSTRIP, ICCPROFILE] # ICC Profile crashes.
|
||||||
atts={}
|
atts={}
|
||||||
# bits per sample is a single short in the tiff directory, not a list.
|
# bits per sample is a single short in the tiff directory, not a list.
|
||||||
atts[BITSPERSAMPLE] = bits[0]
|
atts[BITSPERSAMPLE] = bits[0]
|
||||||
|
|
|
@ -161,7 +161,7 @@ TAGS = {
|
||||||
50716: "BlackLevelDeltaV",
|
50716: "BlackLevelDeltaV",
|
||||||
50717: "WhiteLevel",
|
50717: "WhiteLevel",
|
||||||
50718: "DefaultScale",
|
50718: "DefaultScale",
|
||||||
50741: "BestQualityScale",
|
50741: "BestQualityScale", # FIXME! Dictionary contains duplicate keys 50741
|
||||||
50719: "DefaultCropOrigin",
|
50719: "DefaultCropOrigin",
|
||||||
50720: "DefaultCropSize",
|
50720: "DefaultCropSize",
|
||||||
50778: "CalibrationIlluminant1",
|
50778: "CalibrationIlluminant1",
|
||||||
|
@ -185,7 +185,7 @@ TAGS = {
|
||||||
50737: "ChromaBlurRadius",
|
50737: "ChromaBlurRadius",
|
||||||
50738: "AntiAliasStrength",
|
50738: "AntiAliasStrength",
|
||||||
50740: "DNGPrivateData",
|
50740: "DNGPrivateData",
|
||||||
50741: "MakerNoteSafety",
|
50741: "MakerNoteSafety", # FIXME! Dictionary contains duplicate keys 50741
|
||||||
|
|
||||||
#ImageJ
|
#ImageJ
|
||||||
50838: "ImageJMetaDataByteCounts", # private tag registered with Adobe
|
50838: "ImageJMetaDataByteCounts", # private tag registered with Adobe
|
||||||
|
|
|
@ -59,7 +59,7 @@ word = _binary.i16le
|
||||||
def short(c, o=0):
|
def short(c, o=0):
|
||||||
v = word(c, o)
|
v = word(c, o)
|
||||||
if v >= 32768:
|
if v >= 32768:
|
||||||
v = v - 65536
|
v -= 65536
|
||||||
return v
|
return v
|
||||||
|
|
||||||
dword = _binary.i32le
|
dword = _binary.i32le
|
||||||
|
|
|
@ -104,7 +104,7 @@ while True:
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
|
|
||||||
ix = ix + 1
|
ix += 1
|
||||||
|
|
||||||
if html:
|
if html:
|
||||||
html.write("</body>\n</html>\n")
|
html.write("</body>\n</html>\n")
|
||||||
|
|
|
@ -100,7 +100,7 @@ def makedelta(fp, sequence):
|
||||||
|
|
||||||
previous = im.copy()
|
previous = im.copy()
|
||||||
|
|
||||||
frames = frames + 1
|
frames += 1
|
||||||
|
|
||||||
fp.write(";")
|
fp.write(";")
|
||||||
|
|
||||||
|
|
|
@ -486,7 +486,7 @@ class PILDriver:
|
||||||
print("Stack: " + repr(self.stack))
|
print("Stack: " + repr(self.stack))
|
||||||
top = self.top()
|
top = self.top()
|
||||||
if not isinstance(top, str):
|
if not isinstance(top, str):
|
||||||
continue;
|
continue
|
||||||
funcname = "do_" + top
|
funcname = "do_" + top
|
||||||
if not hasattr(self, funcname):
|
if not hasattr(self, funcname):
|
||||||
continue
|
continue
|
||||||
|
@ -513,9 +513,9 @@ if __name__ == '__main__':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
line = input('pildriver> ');
|
line = input('pildriver> ')
|
||||||
else:
|
else:
|
||||||
line = raw_input('pildriver> ');
|
line = raw_input('pildriver> ')
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print("\nPILDriver says goodbye.")
|
print("\nPILDriver says goodbye.")
|
||||||
break
|
break
|
||||||
|
|
|
@ -57,7 +57,7 @@ for o, a in opt:
|
||||||
elif o == "-v":
|
elif o == "-v":
|
||||||
verify = 1
|
verify = 1
|
||||||
elif o == "-D":
|
elif o == "-D":
|
||||||
Image.DEBUG = Image.DEBUG + 1
|
Image.DEBUG += 1
|
||||||
|
|
||||||
def globfix(files):
|
def globfix(files):
|
||||||
# expand wildcards where necessary
|
# expand wildcards where necessary
|
||||||
|
|
|
@ -67,7 +67,7 @@ for file in files:
|
||||||
if not p.startswith('^'):
|
if not p.startswith('^'):
|
||||||
p = '^' + p
|
p = '^' + p
|
||||||
if not p.endswith('$'):
|
if not p.endswith('$'):
|
||||||
p = p + '$'
|
p += '$'
|
||||||
return p
|
return p
|
||||||
|
|
||||||
ignore_res = [re.compile(fix_re(p), re.MULTILINE) for p in ignore_pats]
|
ignore_res = [re.compile(fix_re(p), re.MULTILINE) for p in ignore_pats]
|
||||||
|
@ -99,7 +99,7 @@ for file in files:
|
||||||
print(result)
|
print(result)
|
||||||
failed.append(test)
|
failed.append(test)
|
||||||
else:
|
else:
|
||||||
success = success + 1
|
success += 1
|
||||||
|
|
||||||
print("-"*68)
|
print("-"*68)
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,8 @@ def _test_alpha_premult(op):
|
||||||
# create image with half white, half black, with the black half transparent.
|
# create image with half white, half black, with the black half transparent.
|
||||||
# do op,
|
# do op,
|
||||||
# there should be no darkness in the white section.
|
# there should be no darkness in the white section.
|
||||||
im = Image.new('RGBA', (10,10), (0,0,0,0));
|
im = Image.new('RGBA', (10,10), (0,0,0,0))
|
||||||
im2 = Image.new('RGBA', (5,10), (255,255,255,255));
|
im2 = Image.new('RGBA', (5,10), (255,255,255,255))
|
||||||
im.paste(im2, (0,0))
|
im.paste(im2, (0,0))
|
||||||
|
|
||||||
im = op(im, (40,10))
|
im = op(im, (40,10))
|
||||||
|
|
|
@ -21,7 +21,7 @@ def test_rgb():
|
||||||
|
|
||||||
def checkrgb(r,g,b):
|
def checkrgb(r,g,b):
|
||||||
val = ImageQt.rgb(r,g,b)
|
val = ImageQt.rgb(r,g,b)
|
||||||
val = val % 2**24 # drop the alpha
|
val %= 2 ** 24 # drop the alpha
|
||||||
assert_equal(val >> 16, r)
|
assert_equal(val >> 16, r)
|
||||||
assert_equal(((val >> 8 ) % 2**8), g)
|
assert_equal(((val >> 8 ) % 2**8), g)
|
||||||
assert_equal(val % 2**8, b)
|
assert_equal(val % 2**8, b)
|
||||||
|
|
|
@ -16,7 +16,7 @@ def test_sanity():
|
||||||
for frame in seq:
|
for frame in seq:
|
||||||
assert_image_equal(im, frame)
|
assert_image_equal(im, frame)
|
||||||
assert_equal(im.tell(), index)
|
assert_equal(im.tell(), index)
|
||||||
index = index + 1
|
index += 1
|
||||||
|
|
||||||
assert_equal(index, 1)
|
assert_equal(index, 1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user