mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Use logging instead of print.
cf. #1191. Only TiffImagePlugin and OLEFileIO still rely on (their own) DEBUG flag. I left TiffImagePlugin as it is because I hope #1059 gets merged in first, and OLEFileIO because it uses its own logic. Untested, as usual.
This commit is contained in:
parent
96944e2dd6
commit
4e754e9c55
20
PIL/Image.py
20
PIL/Image.py
|
@ -28,8 +28,11 @@ from __future__ import print_function
|
||||||
|
|
||||||
from PIL import VERSION, PILLOW_VERSION, _plugins
|
from PIL import VERSION, PILLOW_VERSION, _plugins
|
||||||
|
|
||||||
|
import logging
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class DecompressionBombWarning(RuntimeWarning):
|
class DecompressionBombWarning(RuntimeWarning):
|
||||||
pass
|
pass
|
||||||
|
@ -138,11 +141,6 @@ def isImageType(t):
|
||||||
"""
|
"""
|
||||||
return hasattr(t, "im")
|
return hasattr(t, "im")
|
||||||
|
|
||||||
#
|
|
||||||
# Debug level
|
|
||||||
|
|
||||||
DEBUG = 0
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Constants (also defined in _imagingmodule.c!)
|
# Constants (also defined in _imagingmodule.c!)
|
||||||
|
|
||||||
|
@ -386,13 +384,10 @@ def init():
|
||||||
|
|
||||||
for plugin in _plugins:
|
for plugin in _plugins:
|
||||||
try:
|
try:
|
||||||
if DEBUG:
|
logger.debug("Importing %s", plugin)
|
||||||
print("Importing %s" % plugin)
|
|
||||||
__import__("PIL.%s" % plugin, globals(), locals(), [])
|
__import__("PIL.%s" % plugin, globals(), locals(), [])
|
||||||
except ImportError:
|
except ImportError as e:
|
||||||
if DEBUG:
|
logger.debug("Image: failed to import %s: %s", plugin, e)
|
||||||
print("Image: failed to import", end=' ')
|
|
||||||
print(plugin, ":", sys.exc_info()[1])
|
|
||||||
|
|
||||||
if OPEN or SAVE:
|
if OPEN or SAVE:
|
||||||
_initialized = 2
|
_initialized = 2
|
||||||
|
@ -554,8 +549,7 @@ class Image(object):
|
||||||
try:
|
try:
|
||||||
self.fp.close()
|
self.fp.close()
|
||||||
except Exception as msg:
|
except Exception as msg:
|
||||||
if DEBUG:
|
logger.debug("Error closing: %s" % msg)
|
||||||
print("Error closing: %s" % msg)
|
|
||||||
|
|
||||||
# Instead of simply setting to None, we're setting up a
|
# Instead of simply setting to None, we're setting up a
|
||||||
# deferred error that will better explain that the core image
|
# deferred error that will better explain that the core image
|
||||||
|
|
|
@ -30,10 +30,13 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from PIL._util import isPath
|
from PIL._util import isPath
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
MAXBLOCK = 65536
|
MAXBLOCK = 65536
|
||||||
|
|
||||||
SAFEBLOCK = 1024*1024
|
SAFEBLOCK = 1024*1024
|
||||||
|
@ -95,21 +98,11 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._open()
|
self._open()
|
||||||
except IndexError as v: # end of data
|
except (IndexError, # end of data
|
||||||
if Image.DEBUG > 1:
|
TypeError, # end of data (ord)
|
||||||
traceback.print_exc()
|
KeyError, # unsupported mode
|
||||||
raise SyntaxError(v)
|
EOFError) as v: # got header but not the first frame
|
||||||
except TypeError as v: # end of data (ord)
|
logger.exception("%s")
|
||||||
if Image.DEBUG > 1:
|
|
||||||
traceback.print_exc()
|
|
||||||
raise SyntaxError(v)
|
|
||||||
except KeyError as v: # unsupported mode
|
|
||||||
if Image.DEBUG > 1:
|
|
||||||
traceback.print_exc()
|
|
||||||
raise SyntaxError(v)
|
|
||||||
except EOFError as v: # got header but not the first frame
|
|
||||||
if Image.DEBUG > 1:
|
|
||||||
traceback.print_exc()
|
|
||||||
raise SyntaxError(v)
|
raise SyntaxError(v)
|
||||||
|
|
||||||
if not self.mode or self.size[0] <= 0:
|
if not self.mode or self.size[0] <= 0:
|
||||||
|
|
|
@ -27,8 +27,11 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import logging
|
||||||
from PIL import Image, ImageFile, ImagePalette, _binary
|
from PIL import Image, ImageFile, ImagePalette, _binary
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
i8 = _binary.i8
|
i8 = _binary.i8
|
||||||
i16 = _binary.i16le
|
i16 = _binary.i16le
|
||||||
o8 = _binary.o8
|
o8 = _binary.o8
|
||||||
|
@ -59,17 +62,15 @@ class PcxImageFile(ImageFile.ImageFile):
|
||||||
bbox = i16(s, 4), i16(s, 6), i16(s, 8)+1, i16(s, 10)+1
|
bbox = i16(s, 4), i16(s, 6), i16(s, 8)+1, i16(s, 10)+1
|
||||||
if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]:
|
if bbox[2] <= bbox[0] or bbox[3] <= bbox[1]:
|
||||||
raise SyntaxError("bad PCX image size")
|
raise SyntaxError("bad PCX image size")
|
||||||
if Image.DEBUG:
|
logger.debug("BBox: %s %s %s %s", *bbox)
|
||||||
print("BBox: %s %s %s %s" % bbox)
|
|
||||||
|
|
||||||
# format
|
# format
|
||||||
version = i8(s[1])
|
version = i8(s[1])
|
||||||
bits = i8(s[3])
|
bits = i8(s[3])
|
||||||
planes = i8(s[65])
|
planes = i8(s[65])
|
||||||
stride = i16(s, 66)
|
stride = i16(s, 66)
|
||||||
if Image.DEBUG:
|
logger.debug("PCX version %s, bits %s, planes %s, stride %s",
|
||||||
print("PCX version %s, bits %s, planes %s, stride %s" %
|
version, bits, planes, stride)
|
||||||
(version, bits, planes, stride))
|
|
||||||
|
|
||||||
self.info["dpi"] = i16(s, 12), i16(s, 14)
|
self.info["dpi"] = i16(s, 12), i16(s, 14)
|
||||||
|
|
||||||
|
@ -107,8 +108,7 @@ class PcxImageFile(ImageFile.ImageFile):
|
||||||
self.size = bbox[2]-bbox[0], bbox[3]-bbox[1]
|
self.size = bbox[2]-bbox[0], bbox[3]-bbox[1]
|
||||||
|
|
||||||
bbox = (0, 0) + self.size
|
bbox = (0, 0) + self.size
|
||||||
if Image.DEBUG:
|
logger.debug("size: %sx%s", *self.size)
|
||||||
print("size: %sx%s" % self.size)
|
|
||||||
|
|
||||||
self.tile = [("pcx", bbox, self.fp.tell(), (rawmode, planes * stride))]
|
self.tile = [("pcx", bbox, self.fp.tell(), (rawmode, planes * stride))]
|
||||||
|
|
||||||
|
@ -144,9 +144,8 @@ def _save(im, fp, filename, check=0):
|
||||||
# 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.
|
||||||
|
|
||||||
if Image.DEBUG:
|
logger.debug("PcxImagePlugin._save: xwidth: %d, bits: %d, stride: %d",
|
||||||
print("PcxImagePlugin._save: xwidth: %d, bits: %d, stride: %d" % (
|
im.size[0], bits, stride)
|
||||||
im.size[0], bits, stride))
|
|
||||||
|
|
||||||
# under windows, we could determine the current screen size with
|
# under windows, we could determine the current screen size with
|
||||||
# "Image.core.display_mode()[1]", but I think that's overkill...
|
# "Image.core.display_mode()[1]", but I think that's overkill...
|
||||||
|
|
|
@ -35,10 +35,13 @@ from __future__ import print_function
|
||||||
|
|
||||||
__version__ = "0.9"
|
__version__ = "0.9"
|
||||||
|
|
||||||
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import zlib
|
||||||
|
|
||||||
from PIL import Image, ImageFile, ImagePalette, _binary
|
from PIL import Image, ImageFile, ImagePalette, _binary
|
||||||
import zlib
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
i8 = _binary.i8
|
i8 = _binary.i8
|
||||||
i16 = _binary.i16be
|
i16 = _binary.i16be
|
||||||
|
@ -129,8 +132,7 @@ class ChunkStream(object):
|
||||||
def call(self, cid, pos, length):
|
def call(self, cid, pos, length):
|
||||||
"Call the appropriate chunk handler"
|
"Call the appropriate chunk handler"
|
||||||
|
|
||||||
if Image.DEBUG:
|
logger.debug("STREAM %s %s %s", cid, pos, length)
|
||||||
print("STREAM", cid, pos, length)
|
|
||||||
return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
|
return getattr(self, "chunk_" + cid.decode('ascii'))(pos, length)
|
||||||
|
|
||||||
def crc(self, cid, data):
|
def crc(self, cid, data):
|
||||||
|
@ -293,9 +295,8 @@ class PngStream(ChunkStream):
|
||||||
# Compression method 1 byte (0)
|
# Compression method 1 byte (0)
|
||||||
# Compressed profile n bytes (zlib with deflate compression)
|
# Compressed profile n bytes (zlib with deflate compression)
|
||||||
i = s.find(b"\0")
|
i = s.find(b"\0")
|
||||||
if Image.DEBUG:
|
logger.debug("iCCP profile name %s", s[:i])
|
||||||
print("iCCP profile name", s[:i])
|
logger.debug("Compression method %s", i8(s[i]))
|
||||||
print("Compression method", i8(s[i]))
|
|
||||||
comp_method = i8(s[i])
|
comp_method = i8(s[i])
|
||||||
if comp_method != 0:
|
if comp_method != 0:
|
||||||
raise SyntaxError("Unknown compression method %s in iCCP chunk" %
|
raise SyntaxError("Unknown compression method %s in iCCP chunk" %
|
||||||
|
@ -507,8 +508,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if Image.DEBUG:
|
logger.debug("%s %s %s (unknown)", cid, pos, length)
|
||||||
print(cid, pos, length, "(unknown)")
|
|
||||||
s = ImageFile._safe_read(self.fp, length)
|
s = ImageFile._safe_read(self.fp, length)
|
||||||
|
|
||||||
self.png.crc(cid, s)
|
self.png.crc(cid, s)
|
||||||
|
|
|
@ -22,10 +22,14 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from cffi import FFI
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
DEBUG = 0
|
from cffi import FFI
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
defs = """
|
defs = """
|
||||||
struct Pixel_RGBA {
|
struct Pixel_RGBA {
|
||||||
|
@ -50,8 +54,7 @@ class PyAccess(object):
|
||||||
self.xsize = vals['xsize']
|
self.xsize = vals['xsize']
|
||||||
self.ysize = vals['ysize']
|
self.ysize = vals['ysize']
|
||||||
|
|
||||||
if DEBUG:
|
logger.debug("%s", vals)
|
||||||
print(vals)
|
|
||||||
self._post_init()
|
self._post_init()
|
||||||
|
|
||||||
def _post_init(self):
|
def _post_init(self):
|
||||||
|
@ -305,11 +308,9 @@ else:
|
||||||
def new(img, readonly=False):
|
def new(img, readonly=False):
|
||||||
access_type = mode_map.get(img.mode, None)
|
access_type = mode_map.get(img.mode, None)
|
||||||
if not access_type:
|
if not access_type:
|
||||||
if DEBUG:
|
logger.debug("PyAccess Not Implemented: %s", img.mode)
|
||||||
print("PyAccess Not Implemented: %s" % img.mode)
|
|
||||||
return None
|
return None
|
||||||
if DEBUG:
|
logger.debug("New PyAccess: %s", img.mode)
|
||||||
print("New PyAccess: %s" % img.mode)
|
|
||||||
return access_type(img, readonly)
|
return access_type(img, readonly)
|
||||||
|
|
||||||
# End of file
|
# End of file
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
__version__ = "1.3.5"
|
__version__ = "1.3.5"
|
||||||
|
DEBUG = False # Needs to be merged with the new logging approach.
|
||||||
|
|
||||||
from PIL import Image, ImageFile
|
from PIL import Image, ImageFile
|
||||||
from PIL import ImagePalette
|
from PIL import ImagePalette
|
||||||
|
@ -434,7 +435,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
tag, typ = i16(ifd), i16(ifd, 2)
|
tag, typ = i16(ifd), i16(ifd, 2)
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
from PIL import TiffTags
|
from PIL import TiffTags
|
||||||
tagname = TiffTags.TAGS.get(tag, "unknown")
|
tagname = TiffTags.TAGS.get(tag, "unknown")
|
||||||
typname = TiffTags.TYPES.get(typ, "unknown")
|
typname = TiffTags.TYPES.get(typ, "unknown")
|
||||||
|
@ -444,7 +445,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
try:
|
try:
|
||||||
dispatch = self.load_dispatch[typ]
|
dispatch = self.load_dispatch[typ]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("- unsupported type", typ)
|
print("- unsupported type", typ)
|
||||||
continue # ignore unsupported type
|
continue # ignore unsupported type
|
||||||
|
|
||||||
|
@ -455,10 +456,10 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
# Get and expand tag value
|
# Get and expand tag value
|
||||||
if size > 4:
|
if size > 4:
|
||||||
here = fp.tell()
|
here = fp.tell()
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("Tag Location: %s" % here)
|
print("Tag Location: %s" % here)
|
||||||
fp.seek(i32(ifd, 8))
|
fp.seek(i32(ifd, 8))
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("Data Location: %s" % fp.tell())
|
print("Data Location: %s" % fp.tell())
|
||||||
data = ImageFile._safe_read(fp, size)
|
data = ImageFile._safe_read(fp, size)
|
||||||
fp.seek(here)
|
fp.seek(here)
|
||||||
|
@ -474,7 +475,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
self.tagdata[tag] = data
|
self.tagdata[tag] = data
|
||||||
self.tagtype[tag] = typ
|
self.tagtype[tag] = typ
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK,
|
if tag in (COLORMAP, IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK,
|
||||||
ICCPROFILE, XMP):
|
ICCPROFILE, XMP):
|
||||||
print("- value: <table: %d bytes>" % size)
|
print("- value: <table: %d bytes>" % size)
|
||||||
|
@ -517,7 +518,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
if tag in self.tagtype:
|
if tag in self.tagtype:
|
||||||
typ = self.tagtype[tag]
|
typ = self.tagtype[tag]
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("Tag %s, Type: %s, Value: %s" % (tag, typ, value))
|
print ("Tag %s, Type: %s, Value: %s" % (tag, typ, value))
|
||||||
|
|
||||||
if typ == 1:
|
if typ == 1:
|
||||||
|
@ -571,7 +572,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
else:
|
else:
|
||||||
data = b"".join(map(o32, value))
|
data = b"".join(map(o32, value))
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
from PIL import TiffTags
|
from PIL import TiffTags
|
||||||
tagname = TiffTags.TAGS.get(tag, "unknown")
|
tagname = TiffTags.TAGS.get(tag, "unknown")
|
||||||
typname = TiffTags.TYPES.get(typ, "unknown")
|
typname = TiffTags.TYPES.get(typ, "unknown")
|
||||||
|
@ -608,7 +609,7 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
|
|
||||||
# pass 2: write directory to file
|
# pass 2: write directory to file
|
||||||
for tag, typ, count, value, data in directory:
|
for tag, typ, count, value, data in directory:
|
||||||
if Image.DEBUG > 1:
|
if DEBUG > 1:
|
||||||
print(tag, typ, count, repr(value), repr(data))
|
print(tag, typ, count, repr(value), repr(data))
|
||||||
fp.write(o16(tag) + o16(typ) + o32(count) + value)
|
fp.write(o16(tag) + o16(typ) + o32(count) + value)
|
||||||
|
|
||||||
|
@ -651,7 +652,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self._frame_pos = []
|
self._frame_pos = []
|
||||||
self._n_frames = None
|
self._n_frames = None
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("*** TiffImageFile._open ***")
|
print ("*** TiffImageFile._open ***")
|
||||||
print ("- __first:", self.__first)
|
print ("- __first:", self.__first)
|
||||||
print ("- ifh: ", ifh)
|
print ("- ifh: ", ifh)
|
||||||
|
@ -685,7 +686,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
while len(self._frame_pos) <= frame:
|
while len(self._frame_pos) <= frame:
|
||||||
if not self.__next:
|
if not self.__next:
|
||||||
raise EOFError("no more images in TIFF file")
|
raise EOFError("no more images in TIFF file")
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("Seeking to frame %s, on frame %s, __next %s, location: %s" %
|
print("Seeking to frame %s, on frame %s, __next %s, location: %s" %
|
||||||
(frame, self.__frame, self.__next, self.fp.tell()))
|
(frame, self.__frame, self.__next, self.fp.tell()))
|
||||||
# reset python3 buffered io handle in case fp
|
# reset python3 buffered io handle in case fp
|
||||||
|
@ -693,7 +694,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.fp.tell()
|
self.fp.tell()
|
||||||
self.fp.seek(self.__next)
|
self.fp.seek(self.__next)
|
||||||
self._frame_pos.append(self.__next)
|
self._frame_pos.append(self.__next)
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("Loading tags, location: %s" % self.fp.tell())
|
print("Loading tags, location: %s" % self.fp.tell())
|
||||||
self.tag.load(self.fp)
|
self.tag.load(self.fp)
|
||||||
self.__next = self.tag.next
|
self.__next = self.tag.next
|
||||||
|
@ -771,19 +772,19 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# Rearranging for supporting byteio items, since they have a fileno
|
# Rearranging for supporting byteio items, since they have a fileno
|
||||||
# that returns an IOError if there's no underlying fp. Easier to
|
# that returns an IOError if there's no underlying fp. Easier to
|
||||||
# deal with here by reordering.
|
# deal with here by reordering.
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("have getvalue. just sending in a string from getvalue")
|
print ("have getvalue. just sending in a string from getvalue")
|
||||||
n, err = decoder.decode(self.fp.getvalue())
|
n, err = decoder.decode(self.fp.getvalue())
|
||||||
elif hasattr(self.fp, "fileno"):
|
elif hasattr(self.fp, "fileno"):
|
||||||
# we've got a actual file on disk, pass in the fp.
|
# we've got a actual file on disk, pass in the fp.
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("have fileno, calling fileno version of the decoder.")
|
print ("have fileno, calling fileno version of the decoder.")
|
||||||
self.fp.seek(0)
|
self.fp.seek(0)
|
||||||
# 4 bytes, otherwise the trace might error out
|
# 4 bytes, otherwise the trace might error out
|
||||||
n, err = decoder.decode(b"fpfp")
|
n, err = decoder.decode(b"fpfp")
|
||||||
else:
|
else:
|
||||||
# we have something else.
|
# we have something else.
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("don't have fileno or getvalue. just reading")
|
print ("don't have fileno or getvalue. just reading")
|
||||||
# UNDONE -- so much for that buffer size thing.
|
# UNDONE -- so much for that buffer size thing.
|
||||||
n, err = decoder.decode(self.fp.read())
|
n, err = decoder.decode(self.fp.read())
|
||||||
|
@ -821,7 +822,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
fillorder = getscalar(FILLORDER, 1)
|
fillorder = getscalar(FILLORDER, 1)
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("*** Summary ***")
|
print("*** Summary ***")
|
||||||
print("- compression:", self._compression)
|
print("- compression:", self._compression)
|
||||||
print("- photometric_interpretation:", photo)
|
print("- photometric_interpretation:", photo)
|
||||||
|
@ -833,7 +834,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
ysize = getscalar(IMAGELENGTH)
|
ysize = getscalar(IMAGELENGTH)
|
||||||
self.size = xsize, ysize
|
self.size = xsize, ysize
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("- size:", self.size)
|
print("- size:", self.size)
|
||||||
|
|
||||||
format = getscalar(SAMPLEFORMAT, 1)
|
format = getscalar(SAMPLEFORMAT, 1)
|
||||||
|
@ -844,16 +845,16 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.tag.get(BITSPERSAMPLE, (1,)),
|
self.tag.get(BITSPERSAMPLE, (1,)),
|
||||||
self.tag.get(EXTRASAMPLES, ())
|
self.tag.get(EXTRASAMPLES, ())
|
||||||
)
|
)
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("format key:", key)
|
print("format key:", key)
|
||||||
try:
|
try:
|
||||||
self.mode, rawmode = OPEN_INFO[key]
|
self.mode, rawmode = OPEN_INFO[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("- unsupported format")
|
print("- unsupported format")
|
||||||
raise SyntaxError("unknown pixel mode")
|
raise SyntaxError("unknown pixel mode")
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("- raw mode:", rawmode)
|
print("- raw mode:", rawmode)
|
||||||
print("- pil mode:", self.mode)
|
print("- pil mode:", self.mode)
|
||||||
|
|
||||||
|
@ -893,7 +894,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
"tiff_sgilog",
|
"tiff_sgilog",
|
||||||
"tiff_sgilog24",
|
"tiff_sgilog24",
|
||||||
"tiff_raw_16"]:
|
"tiff_raw_16"]:
|
||||||
# if Image.DEBUG:
|
# if DEBUG:
|
||||||
# print "Activating g4 compression for whole file"
|
# print "Activating g4 compression for whole file"
|
||||||
|
|
||||||
# Decoder expects entire file as one tile.
|
# Decoder expects entire file as one tile.
|
||||||
|
@ -934,7 +935,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
self.tag.get(BITSPERSAMPLE, (1,)),
|
self.tag.get(BITSPERSAMPLE, (1,)),
|
||||||
self.tag.get(EXTRASAMPLES, ())
|
self.tag.get(EXTRASAMPLES, ())
|
||||||
)
|
)
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("format key:", key)
|
print("format key:", key)
|
||||||
# this should always work, since all the
|
# this should always work, since all the
|
||||||
# fillorder==2 modes have a corresponding
|
# fillorder==2 modes have a corresponding
|
||||||
|
@ -963,7 +964,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
(self._compression,
|
(self._compression,
|
||||||
(0, min(y, ysize), w, min(y+h, ysize)),
|
(0, min(y, ysize), w, min(y+h, ysize)),
|
||||||
offsets[i], a))
|
offsets[i], a))
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("tiles: ", self.tile)
|
print ("tiles: ", self.tile)
|
||||||
y = y + h
|
y = y + h
|
||||||
if y >= self.size[1]:
|
if y >= self.size[1]:
|
||||||
|
@ -992,7 +993,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
l += 1
|
l += 1
|
||||||
a = None
|
a = None
|
||||||
else:
|
else:
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("- unsupported data organization")
|
print("- unsupported data organization")
|
||||||
raise SyntaxError("unknown data organization")
|
raise SyntaxError("unknown data organization")
|
||||||
|
|
||||||
|
@ -1073,7 +1074,7 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
# write any arbitrary tags passed in as an ImageFileDirectory
|
# write any arbitrary tags passed in as an ImageFileDirectory
|
||||||
info = im.encoderinfo.get("tiffinfo", {})
|
info = im.encoderinfo.get("tiffinfo", {})
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print("Tiffinfo Keys: %s" % info.keys)
|
print("Tiffinfo Keys: %s" % info.keys)
|
||||||
keys = list(info.keys())
|
keys = list(info.keys())
|
||||||
for key in keys:
|
for key in keys:
|
||||||
|
@ -1148,7 +1149,7 @@ def _save(im, fp, filename):
|
||||||
ifd[COMPRESSION] = COMPRESSION_INFO_REV.get(compression, 1)
|
ifd[COMPRESSION] = COMPRESSION_INFO_REV.get(compression, 1)
|
||||||
|
|
||||||
if libtiff:
|
if libtiff:
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print ("Saving using libtiff encoder")
|
print ("Saving using libtiff encoder")
|
||||||
print (ifd.items())
|
print (ifd.items())
|
||||||
_fp = 0
|
_fp = 0
|
||||||
|
@ -1206,7 +1207,7 @@ def _save(im, fp, filename):
|
||||||
# int or similar
|
# int or similar
|
||||||
atts[k] = v
|
atts[k] = v
|
||||||
|
|
||||||
if Image.DEBUG:
|
if DEBUG:
|
||||||
print (atts)
|
print (atts)
|
||||||
|
|
||||||
# libtiff always expects the bytes in native order.
|
# libtiff always expects the bytes in native order.
|
||||||
|
|
|
@ -21,6 +21,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
import getopt
|
import getopt
|
||||||
import glob
|
import glob
|
||||||
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
@ -42,6 +43,7 @@ except getopt.error as v:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
verbose = quiet = verify = 0
|
verbose = quiet = verify = 0
|
||||||
|
logging_level = "WARNING"
|
||||||
|
|
||||||
for o, a in opt:
|
for o, a in opt:
|
||||||
if o == "-f":
|
if o == "-f":
|
||||||
|
@ -58,7 +60,9 @@ for o, a in opt:
|
||||||
elif o == "-v":
|
elif o == "-v":
|
||||||
verify = 1
|
verify = 1
|
||||||
elif o == "-D":
|
elif o == "-D":
|
||||||
Image.DEBUG += 1
|
logging_level = "DEBUG"
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging_level)
|
||||||
|
|
||||||
|
|
||||||
def globfix(files):
|
def globfix(files):
|
||||||
|
|
|
@ -15,9 +15,6 @@ from PIL import Image, ImageTk
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
Image.DEBUG = 0
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# an image animation player
|
# an image animation player
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from helper import unittest, PillowTestCase, hopper, py3
|
from helper import unittest, PillowTestCase, hopper, py3
|
||||||
|
|
||||||
import os
|
|
||||||
import io
|
import io
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin
|
from PIL import Image, TiffImagePlugin
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LibTiffTestCase(PillowTestCase):
|
class LibTiffTestCase(PillowTestCase):
|
||||||
|
|
||||||
|
@ -231,7 +234,6 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
""" Are we generating the same interpretation
|
""" Are we generating the same interpretation
|
||||||
of the image as Imagemagick is? """
|
of the image as Imagemagick is? """
|
||||||
TiffImagePlugin.READ_LIBTIFF = True
|
TiffImagePlugin.READ_LIBTIFF = True
|
||||||
# Image.DEBUG = True
|
|
||||||
im = Image.open('Tests/images/12bit.cropped.tif')
|
im = Image.open('Tests/images/12bit.cropped.tif')
|
||||||
im.load()
|
im.load()
|
||||||
TiffImagePlugin.READ_LIBTIFF = False
|
TiffImagePlugin.READ_LIBTIFF = False
|
||||||
|
@ -243,14 +245,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
|
|
||||||
im2 = Image.open('Tests/images/12in16bit.tif')
|
im2 = Image.open('Tests/images/12in16bit.tif')
|
||||||
|
|
||||||
if Image.DEBUG:
|
logger.debug("%s", [img.getpixel((0, idx))
|
||||||
print(im.getpixel((0, 0)))
|
for img in [im, im2] for idx in range(3)])
|
||||||
print(im.getpixel((0, 1)))
|
|
||||||
print(im.getpixel((0, 2)))
|
|
||||||
|
|
||||||
print(im2.getpixel((0, 0)))
|
|
||||||
print(im2.getpixel((0, 1)))
|
|
||||||
print(im2.getpixel((0, 2)))
|
|
||||||
|
|
||||||
self.assert_image_equal(im, im2)
|
self.assert_image_equal(im, im2)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import logging
|
||||||
|
import struct
|
||||||
|
|
||||||
from helper import unittest, PillowTestCase, hopper, py3
|
from helper import unittest, PillowTestCase, hopper, py3
|
||||||
|
|
||||||
from PIL import Image, TiffImagePlugin
|
from PIL import Image, TiffImagePlugin
|
||||||
|
|
||||||
import struct
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TestFileTiff(PillowTestCase):
|
class TestFileTiff(PillowTestCase):
|
||||||
|
@ -118,7 +121,6 @@ class TestFileTiff(PillowTestCase):
|
||||||
""" Are we generating the same interpretation
|
""" Are we generating the same interpretation
|
||||||
of the image as Imagemagick is? """
|
of the image as Imagemagick is? """
|
||||||
|
|
||||||
# Image.DEBUG = True
|
|
||||||
im = Image.open('Tests/images/12bit.cropped.tif')
|
im = Image.open('Tests/images/12bit.cropped.tif')
|
||||||
|
|
||||||
# to make the target --
|
# to make the target --
|
||||||
|
@ -129,14 +131,8 @@ class TestFileTiff(PillowTestCase):
|
||||||
|
|
||||||
im2 = Image.open('Tests/images/12in16bit.tif')
|
im2 = Image.open('Tests/images/12in16bit.tif')
|
||||||
|
|
||||||
if Image.DEBUG:
|
logger.debug("%s", [img.getpixel((0, idx))
|
||||||
print(im.getpixel((0, 0)))
|
for img in [im, im2] for idx in range(3)])
|
||||||
print(im.getpixel((0, 1)))
|
|
||||||
print(im.getpixel((0, 2)))
|
|
||||||
|
|
||||||
print(im2.getpixel((0, 0)))
|
|
||||||
print(im2.getpixel((0, 1)))
|
|
||||||
print(im2.getpixel((0, 2)))
|
|
||||||
|
|
||||||
self.assert_image_equal(im, im2)
|
self.assert_image_equal(im, im2)
|
||||||
|
|
||||||
|
|
|
@ -23,14 +23,11 @@ class TestImageSequence(PillowTestCase):
|
||||||
self.assertEqual(index, 1)
|
self.assertEqual(index, 1)
|
||||||
|
|
||||||
def _test_multipage_tiff(self, dbg=False):
|
def _test_multipage_tiff(self, dbg=False):
|
||||||
# debug had side effect of calling fp.tell.
|
|
||||||
Image.DEBUG = dbg
|
|
||||||
im = Image.open('Tests/images/multipage.tiff')
|
im = Image.open('Tests/images/multipage.tiff')
|
||||||
for index, frame in enumerate(ImageSequence.Iterator(im)):
|
for index, frame in enumerate(ImageSequence.Iterator(im)):
|
||||||
frame.load()
|
frame.load()
|
||||||
self.assertEqual(index, im.tell())
|
self.assertEqual(index, im.tell())
|
||||||
frame.convert('RGB')
|
frame.convert('RGB')
|
||||||
Image.DEBUG = False
|
|
||||||
|
|
||||||
def test_tiff(self):
|
def test_tiff(self):
|
||||||
# self._test_multipage_tiff(True)
|
# self._test_multipage_tiff(True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user