Replaced absolute PIL imports with relative imports (#2349)

This commit is contained in:
Andrew Murray 2017-01-18 00:22:18 +11:00 committed by wiredfool
parent c1b510c72c
commit 58b5c9187d
73 changed files with 160 additions and 258 deletions

View File

@ -19,8 +19,7 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image from . import Image, FontFile
from PIL import FontFile
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -24,18 +24,13 @@
# #
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16le as i16, i32le as i32, \
o8, o16le as o16, o32le as o32
import math import math
__version__ = "0.7" __version__ = "0.7"
i8 = _binary.i8
i16 = _binary.i16le
i32 = _binary.i32le
o8 = _binary.o8
o16 = _binary.o16le
o32 = _binary.o32le
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Read BMP file # Read BMP file

View File

@ -9,7 +9,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile from . import Image, ImageFile
_handler = None _handler = None

View File

@ -18,17 +18,14 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image, BmpImagePlugin, _binary from . import Image, BmpImagePlugin
from ._binary import i8, i16le as i16, i32le as i32
__version__ = "0.1" __version__ = "0.1"
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
i8 = _binary.i8
i16 = _binary.i16le
i32 = _binary.i32le
def _accept(prefix): def _accept(prefix):
return prefix[:4] == b"\0\0\2\0" return prefix[:4] == b"\0\0\2\0"

View File

@ -21,15 +21,14 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, _binary from . import Image
from PIL.PcxImagePlugin import PcxImageFile from ._binary import i32le as i32
from .PcxImagePlugin import PcxImageFile
__version__ = "0.2" __version__ = "0.2"
MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then? MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then?
i32 = _binary.i32le
def _accept(prefix): def _accept(prefix):
return len(prefix) >= 4 and i32(prefix) == MAGIC return len(prefix) >= 4 and i32(prefix) == MAGIC

View File

@ -12,7 +12,7 @@ Full text of the CC0 license:
import struct import struct
from io import BytesIO from io import BytesIO
from PIL import Image, ImageFile from . import Image, ImageFile
# Magic ("DDS ") # Magic ("DDS ")

View File

@ -23,16 +23,14 @@
import re import re
import io import io
import sys import sys
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i32le as i32, o32le as o32
__version__ = "0.5" __version__ = "0.5"
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
i32 = _binary.i32le
o32 = _binary.o32le
split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$") split = re.compile(r"^%%([^:]*):[ \t]*(.*)[ \t]*$")
field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$") field = re.compile(r"^%[%!\w]([^:]*)[ \t]*$")

View File

@ -9,7 +9,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile from . import Image, ImageFile
_handler = None _handler = None

View File

@ -16,15 +16,11 @@
# #
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16le as i16, i32le as i32, o8
__version__ = "0.2" __version__ = "0.2"
i8 = _binary.i8
i16 = _binary.i16le
i32 = _binary.i32le
o8 = _binary.o8
# #
# decoder # decoder

View File

@ -17,7 +17,7 @@
from __future__ import print_function from __future__ import print_function
import os import os
from PIL import Image, _binary from . import Image, _binary
WIDTH = 800 WIDTH = 800

View File

@ -17,15 +17,13 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i32le as i32, i8
import olefile import olefile
__version__ = "0.1" __version__ = "0.1"
i32 = _binary.i32le
i8 = _binary.i8
# we map from colour field tuples to (mode, rawmode) descriptors # we map from colour field tuples to (mode, rawmode) descriptors
MODES = { MODES = {
# opacity # opacity

View File

@ -42,7 +42,7 @@ Note: All data is stored in little-Endian (Intel) byte order.
import struct import struct
from io import BytesIO from io import BytesIO
from PIL import Image, ImageFile from . import Image, ImageFile
MAGIC = b"FTEX" MAGIC = b"FTEX"

View File

@ -24,9 +24,8 @@
# Version 3 files have a format specifier of 18 for 16bit floats in # Version 3 files have a format specifier of 18 for 16bit floats in
# the color depth field. This is currently unsupported by Pillow. # the color depth field. This is currently unsupported by Pillow.
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i32be as i32
i32 = _binary.i32be
def _accept(prefix): def _accept(prefix):

View File

@ -23,8 +23,9 @@
# purposes only. # purposes only.
from PIL import ImageFile, ImagePalette, _binary from . import ImageFile, ImagePalette
from PIL._util import isPath from ._binary import i16be as i16
from ._util import isPath
__version__ = "0.1" __version__ = "0.1"
@ -34,8 +35,6 @@ except ImportError:
import __builtin__ import __builtin__
builtins = __builtin__ builtins = __builtin__
i16 = _binary.i16be
## ##
# Image plugin for the GD uncompressed format. Note that this format # Image plugin for the GD uncompressed format. Note that this format

View File

@ -24,8 +24,9 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile, ImagePalette, \ from . import Image, ImageFile, ImagePalette, \
ImageChops, ImageSequence, _binary ImageChops, ImageSequence
from ._binary import i8, i16le as i16, o8, o16le as o16
__version__ = "0.9" __version__ = "0.9"
@ -33,11 +34,6 @@ __version__ = "0.9"
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Helpers # Helpers
i8 = _binary.i8
i16 = _binary.i16le
o8 = _binary.o8
o16 = _binary.o16le
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Identify/read GIF files # Identify/read GIF files

View File

@ -14,7 +14,7 @@
# #
from math import pi, log, sin, sqrt from math import pi, log, sin, sqrt
from PIL._binary import o8 from ._binary import o8
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Stuff to translate curve segments to palette values (derived from # Stuff to translate curve segments to palette values (derived from

View File

@ -15,7 +15,7 @@
# #
import re import re
from PIL._binary import o8 from ._binary import o8
## ##

View File

@ -9,7 +9,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile from . import Image, ImageFile
_handler = None _handler = None

View File

@ -9,7 +9,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile from . import Image, ImageFile
_handler = None _handler = None

View File

@ -15,7 +15,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile, PngImagePlugin, _binary from PIL import Image, ImageFile, PngImagePlugin
from PIL._binary import i8
import io import io
import os import os
import shutil import shutil
@ -27,8 +28,6 @@ enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
if enable_jpeg2k: if enable_jpeg2k:
from PIL import Jpeg2KImagePlugin from PIL import Jpeg2KImagePlugin
i8 = _binary.i8
HEADERSIZE = 8 HEADERSIZE = 8

View File

@ -25,7 +25,8 @@
import struct import struct
from io import BytesIO from io import BytesIO
from PIL import Image, ImageFile, BmpImagePlugin, PngImagePlugin, _binary from . import Image, ImageFile, BmpImagePlugin, PngImagePlugin
from ._binary import i8, i16le as i16, i32le as i32
from math import log, ceil from math import log, ceil
__version__ = "0.1" __version__ = "0.1"
@ -33,10 +34,6 @@ __version__ = "0.1"
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
i8 = _binary.i8
i16 = _binary.i16le
i32 = _binary.i32le
_MAGIC = b"\0\0\1\0" _MAGIC = b"\0\0\1\0"

View File

@ -27,8 +27,8 @@
import re import re
from PIL import Image, ImageFile, ImagePalette from . import Image, ImageFile, ImagePalette
from PIL._binary import i8 from ._binary import i8
__version__ = "0.7" __version__ = "0.7"

View File

@ -26,7 +26,7 @@
from __future__ import print_function from __future__ import print_function
from PIL import VERSION, PILLOW_VERSION, _plugins from . import VERSION, PILLOW_VERSION, _plugins
import logging import logging
import warnings import warnings
@ -64,7 +64,7 @@ try:
# import Image and use the Image.core variable instead. # import Image and use the Image.core variable instead.
# Also note that Image.core is not a publicly documented interface, # Also note that Image.core is not a publicly documented interface,
# and should be considered private and subject to change. # and should be considered private and subject to change.
from PIL import _imaging as core from . import _imaging as core
if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None): if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
raise ImportError("The _imaging extension was built for another " raise ImportError("The _imaging extension was built for another "
"version of Pillow or PIL") "version of Pillow or PIL")
@ -109,11 +109,9 @@ except ImportError:
import __builtin__ import __builtin__
builtins = __builtin__ builtins = __builtin__
from PIL import ImageMode from . import ImageMode
from PIL._binary import i8 from ._binary import i8
from PIL._util import isPath from ._util import isPath, isStringType, deferred_error
from PIL._util import isStringType
from PIL._util import deferred_error
import os import os
import sys import sys
@ -355,23 +353,23 @@ def preinit():
return return
try: try:
from PIL import BmpImagePlugin from . import BmpImagePlugin
except ImportError: except ImportError:
pass pass
try: try:
from PIL import GifImagePlugin from . import GifImagePlugin
except ImportError: except ImportError:
pass pass
try: try:
from PIL import JpegImagePlugin from . import JpegImagePlugin
except ImportError: except ImportError:
pass pass
try: try:
from PIL import PpmImagePlugin from . import PpmImagePlugin
except ImportError: except ImportError:
pass pass
try: try:
from PIL import PngImagePlugin from . import PngImagePlugin
except ImportError: except ImportError:
pass pass
# try: # try:
@ -525,7 +523,7 @@ class Image(object):
if self.palette: if self.palette:
new.palette = self.palette.copy() new.palette = self.palette.copy()
if im.mode == "P" and not new.palette: if im.mode == "P" and not new.palette:
from PIL import ImagePalette from . import ImagePalette
new.palette = ImagePalette.ImagePalette() new.palette = ImagePalette.ImagePalette()
new.info = self.info.copy() new.info = self.info.copy()
return new return new
@ -775,7 +773,7 @@ class Image(object):
if HAS_CFFI and USE_CFFI_ACCESS: if HAS_CFFI and USE_CFFI_ACCESS:
if self.pyaccess: if self.pyaccess:
return self.pyaccess return self.pyaccess
from PIL import PyAccess from . import PyAccess
self.pyaccess = PyAccess.new(self, self.readonly) self.pyaccess = PyAccess.new(self, self.readonly)
if self.pyaccess: if self.pyaccess:
return self.pyaccess return self.pyaccess
@ -908,7 +906,7 @@ class Image(object):
if mode == "P" and palette == ADAPTIVE: if mode == "P" and palette == ADAPTIVE:
im = self.im.quantize(colors) im = self.im.quantize(colors)
new = self._new(im) new = self._new(im)
from PIL import ImagePalette from . import ImagePalette
new.palette = ImagePalette.raw("RGB", new.im.getpalette("RGB")) new.palette = ImagePalette.raw("RGB", new.im.getpalette("RGB"))
if delete_trns: if delete_trns:
# This could possibly happen if we requantize to fewer colors. # This could possibly happen if we requantize to fewer colors.
@ -1321,7 +1319,7 @@ class Image(object):
box += (box[0]+size[0], box[1]+size[1]) box += (box[0]+size[0], box[1]+size[1])
if isStringType(im): if isStringType(im):
from PIL import ImageColor from . import ImageColor
im = ImageColor.getcolor(im, self.mode) im = ImageColor.getcolor(im, self.mode)
elif isImageType(im): elif isImageType(im):
@ -1468,7 +1466,7 @@ class Image(object):
:param data: A palette sequence (either a list or a string). :param data: A palette sequence (either a list or a string).
""" """
from PIL import ImagePalette from . import ImagePalette
if self.mode not in ("L", "P"): if self.mode not in ("L", "P"):
raise ValueError("illegal image mode") raise ValueError("illegal image mode")
@ -1583,7 +1581,7 @@ class Image(object):
angle = angle % 360.0 angle = angle % 360.0
# Fast paths regardless of filter, as long as we're not # Fast paths regardless of filter, as long as we're not
# translating or changing the center. # translating or changing the center.
if not (center or translate): if not (center or translate):
if angle == 0: if angle == 0:
return self.copy() return self.copy()
@ -1977,14 +1975,14 @@ class Image(object):
def toqimage(self): def toqimage(self):
"""Returns a QImage copy of this image""" """Returns a QImage copy of this image"""
from PIL import ImageQt from . import ImageQt
if not ImageQt.qt_is_installed: if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed") raise ImportError("Qt bindings are not installed")
return ImageQt.toqimage(self) return ImageQt.toqimage(self)
def toqpixmap(self): def toqpixmap(self):
"""Returns a QPixmap copy of this image""" """Returns a QPixmap copy of this image"""
from PIL import ImageQt from . import ImageQt
if not ImageQt.qt_is_installed: if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed") raise ImportError("Qt bindings are not installed")
return ImageQt.toqpixmap(self) return ImageQt.toqpixmap(self)
@ -2057,7 +2055,7 @@ def new(mode, size, color=0):
if isStringType(color): if isStringType(color):
# css3-style specifier # css3-style specifier
from PIL import ImageColor from . import ImageColor
color = ImageColor.getcolor(color, mode) color = ImageColor.getcolor(color, mode)
return Image()._new(core.fill(mode, size, color)) return Image()._new(core.fill(mode, size, color))
@ -2219,7 +2217,7 @@ def fromarray(obj, mode=None):
def fromqimage(im): def fromqimage(im):
"""Creates an image instance from a QImage image""" """Creates an image instance from a QImage image"""
from PIL import ImageQt from . import ImageQt
if not ImageQt.qt_is_installed: if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed") raise ImportError("Qt bindings are not installed")
return ImageQt.fromqimage(im) return ImageQt.fromqimage(im)
@ -2227,7 +2225,7 @@ def fromqimage(im):
def fromqpixmap(im): def fromqpixmap(im):
"""Creates an image instance from a QPixmap image""" """Creates an image instance from a QPixmap image"""
from PIL import ImageQt from . import ImageQt
if not ImageQt.qt_is_installed: if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed") raise ImportError("Qt bindings are not installed")
return ImageQt.fromqpixmap(im) return ImageQt.fromqpixmap(im)
@ -2531,7 +2529,7 @@ def _show(image, **options):
def _showxv(image, title=None, **options): def _showxv(image, title=None, **options):
from PIL import ImageShow from . import ImageShow
ImageShow.show(image, title, **options) ImageShow.show(image, title, **options)

View File

@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
def constant(image, value): def constant(image, value):

View File

@ -17,7 +17,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
import re import re

View File

@ -33,8 +33,8 @@
import numbers import numbers
import warnings import warnings
from PIL import Image, ImageColor from . import Image, ImageColor
from PIL._util import isStringType from ._util import isStringType
""" """
A simple 2D drawing interface for PIL images. A simple 2D drawing interface for PIL images.
@ -105,7 +105,7 @@ class ImageDraw(object):
"""Get the current default font.""" """Get the current default font."""
if not self.font: if not self.font:
# FIXME: should add a font repository # FIXME: should add a font repository
from PIL import ImageFont from . import ImageFont
self.font = ImageFont.load_default() self.font = ImageFont.load_default()
return self.font return self.font
@ -319,11 +319,11 @@ def getdraw(im=None, hints=None):
handler = None handler = None
if not hints or "nicest" in hints: if not hints or "nicest" in hints:
try: try:
from PIL import _imagingagg as handler from . import _imagingagg as handler
except ImportError: except ImportError:
pass pass
if handler is None: if handler is None:
from PIL import ImageDraw2 as handler from . import ImageDraw2 as handler
if im: if im:
im = handler.Draw(im) im = handler.Draw(im)
return im, handler return im, handler

View File

@ -16,7 +16,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageColor, ImageDraw, ImageFont, ImagePath from . import Image, ImageColor, ImageDraw, ImageFont, ImagePath
class Pen(object): class Pen(object):

View File

@ -18,7 +18,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFilter, ImageStat from . import Image, ImageFilter, ImageStat
class _Enhance(object): class _Enhance(object):

View File

@ -27,8 +27,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
from PIL._util import isPath from ._util import isPath
import io import io
import os import os
import sys import sys

View File

@ -25,8 +25,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
from PIL._util import isDirectory, isPath from ._util import isDirectory, isPath
import os import os
import sys import sys
@ -37,7 +37,7 @@ class _imagingft_not_installed(object):
raise ImportError("The _imagingft C module is not installed") raise ImportError("The _imagingft C module is not installed")
try: try:
from PIL import _imagingft as core from . import _imagingft as core
except ImportError: except ImportError:
core = _imagingft_not_installed() core = _imagingft_not_installed()

View File

@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
import sys import sys
if sys.platform not in ["win32", "darwin"]: if sys.platform not in ["win32", "darwin"]:
@ -75,7 +75,7 @@ def grabclipboard():
debug = 0 # temporary interface debug = 0 # temporary interface
data = Image.core.grabclipboard(debug) data = Image.core.grabclipboard(debug)
if isinstance(data, bytes): if isinstance(data, bytes):
from PIL import BmpImagePlugin from . import BmpImagePlugin
import io import io
return BmpImagePlugin.DibImageFile(io.BytesIO(data)) return BmpImagePlugin.DibImageFile(io.BytesIO(data))
return data return data

View File

@ -15,8 +15,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image, _imagingmath
from PIL import _imagingmath
try: try:
import builtins import builtins

View File

@ -35,7 +35,8 @@ def getmode(mode):
global _modes global _modes
if not _modes: if not _modes:
# initialize mode cache # initialize mode cache
from PIL import Image
from . import Image
modes = {} modes = {}
# core modes # core modes
for m, (basemode, basetype, bands) in Image._MODEINFO.items(): for m, (basemode, basetype, bands) in Image._MODEINFO.items():

View File

@ -7,8 +7,7 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image from . import Image, _imagingmorph
from PIL import _imagingmorph
import re import re
LUT_SIZE = 1 << 9 LUT_SIZE = 1 << 9

View File

@ -17,8 +17,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
from PIL._util import isStringType from ._util import isStringType
import operator import operator
import functools import functools
@ -39,7 +39,7 @@ def _border(border):
def _color(color, mode): def _color(color, mode):
if isStringType(color): if isStringType(color):
from PIL import ImageColor from . import ImageColor
color = ImageColor.getcolor(color, mode) color = ImageColor.getcolor(color, mode)
return color return color

View File

@ -17,10 +17,7 @@
# #
import array import array
from PIL import ImageColor from . import ImageColor, GimpPaletteFile, GimpGradientFile, PaletteFile
from PIL import GimpPaletteFile
from PIL import GimpGradientFile
from PIL import PaletteFile
class ImagePalette(object): class ImagePalette(object):

View File

@ -14,7 +14,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
# the Python class below is overridden by the C implementation. # the Python class below is overridden by the C implementation.

View File

@ -16,8 +16,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
from PIL._util import isPath from ._util import isPath
from io import BytesIO from io import BytesIO
qt_is_installed = True qt_is_installed = True

View File

@ -32,7 +32,7 @@ except ImportError:
tkinter = Tkinter tkinter = Tkinter
del Tkinter del Tkinter
from PIL import Image from . import Image
from io import BytesIO from io import BytesIO
@ -182,7 +182,7 @@ class PhotoImage(object):
except tkinter.TclError: except tkinter.TclError:
# activate Tkinter hook # activate Tkinter hook
try: try:
from PIL import _imagingtk from . import _imagingtk
try: try:
_imagingtk.tkinit(tk.interpaddr(), 1) _imagingtk.tkinit(tk.interpaddr(), 1)
except AttributeError: except AttributeError:

View File

@ -13,7 +13,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
class Transform(Image.ImageTransformHandler): class Transform(Image.ImageTransformHandler):

View File

@ -17,7 +17,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image
class HDC(object): class HDC(object):

View File

@ -17,7 +17,7 @@
import re import re
from PIL import Image, ImageFile from . import Image, ImageFile
__version__ = "0.2" __version__ = "0.2"

View File

@ -17,17 +17,13 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i8, i16be as i16, i32be as i32, o8
import os import os
import tempfile import tempfile
__version__ = "0.3" __version__ = "0.3"
i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
o8 = _binary.o8
COMPRESSION = { COMPRESSION = {
1: "raw", 1: "raw",
5: "jpeg" 5: "jpeg"
@ -191,7 +187,7 @@ def getiptcinfo(im):
:returns: A dictionary containing IPTC information, or None if :returns: A dictionary containing IPTC information, or None if
no IPTC information block was found. no IPTC information block was found.
""" """
from PIL import TiffImagePlugin, JpegImagePlugin from . import TiffImagePlugin, JpegImagePlugin
import io import io
data = None data = None

View File

@ -12,7 +12,7 @@
# #
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile from . import Image, ImageFile
import struct import struct
import os import os
import io import io

View File

@ -38,14 +38,10 @@ import array
import struct import struct
import io import io
import warnings import warnings
from PIL import Image, ImageFile, TiffImagePlugin, _binary from . import Image, ImageFile, TiffImagePlugin
from PIL.JpegPresets import presets from ._binary import i8, o8, i16be as i16, i32be as i32
from PIL._util import isStringType from .JpegPresets import presets
from ._util import isStringType
i8 = _binary.i8
o8 = _binary.o8
i16 = _binary.i16be
i32 = _binary.i32be
__version__ = "0.6" __version__ = "0.6"

View File

@ -17,7 +17,7 @@
# #
import struct import struct
from PIL import Image, ImageFile from . import Image, ImageFile
__version__ = "0.2" __version__ = "0.2"

View File

@ -17,7 +17,7 @@
# #
from PIL import Image, TiffImagePlugin from . import Image, TiffImagePlugin
import olefile import olefile

View File

@ -14,8 +14,8 @@
# #
from PIL import Image, ImageFile from . import Image, ImageFile
from PIL._binary import i8 from ._binary import i8
__version__ = "0.1" __version__ = "0.1"

View File

@ -18,7 +18,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, JpegImagePlugin from . import Image, JpegImagePlugin
__version__ = "0.1" __version__ = "0.1"

View File

@ -17,7 +17,8 @@
# #
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i16le as i16, o16le as o16
__version__ = "0.1" __version__ = "0.1"
@ -25,8 +26,6 @@ __version__ = "0.1"
# #
# read MSP files # read MSP files
i16 = _binary.i16le
def _accept(prefix): def _accept(prefix):
return prefix[:4] in [b"DanM", b"LinS"] return prefix[:4] in [b"DanM", b"LinS"]
@ -66,8 +65,6 @@ class MspImageFile(ImageFile.ImageFile):
# #
# write MSP files (uncompressed only) # write MSP files (uncompressed only)
o16 = _binary.o16le
def _save(im, fp, filename): def _save(im, fp, filename):

View File

@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import EpsImagePlugin from . import EpsImagePlugin
import sys import sys
## ##

View File

@ -13,7 +13,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL._binary import o8 from ._binary import o8
## ##

View File

@ -7,7 +7,8 @@
# Image plugin for Palm pixmap images (output only). # Image plugin for Palm pixmap images (output only).
## ##
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import o8, o16be as o16b
__version__ = "1.0" __version__ = "1.0"
@ -108,9 +109,6 @@ _COMPRESSION_TYPES = {
"scanline": 0x00, "scanline": 0x00,
} }
o8 = _binary.o8
o16b = _binary.o16be
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -15,12 +15,11 @@
# #
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i8
__version__ = "0.1" __version__ = "0.1"
i8 = _binary.i8
## ##
# Image plugin for PhotoCD images. This plugin only reads the 768x512 # Image plugin for PhotoCD images. This plugin only reads the 768x512

View File

@ -16,9 +16,8 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image from . import Image, FontFile
from PIL import FontFile from ._binary import i8, i16le as l16, i32le as l32, i16be as b16, i32be as b32
from PIL import _binary
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# declarations # declarations
@ -42,12 +41,6 @@ BYTES_PER_ROW = [
lambda bits: ((bits+63) >> 3) & ~7, lambda bits: ((bits+63) >> 3) & ~7,
] ]
i8 = _binary.i8
l16 = _binary.i16le
l32 = _binary.i32le
b16 = _binary.i16be
b32 = _binary.i32be
def sz(s, o): def sz(s, o):
return s[o:s.index(b"\0", o)] return s[o:s.index(b"\0", o)]

View File

@ -28,14 +28,11 @@
from __future__ import print_function from __future__ import print_function
import logging import logging
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16le as i16, o8, o16le as o16
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
i8 = _binary.i8
i16 = _binary.i16le
o8 = _binary.o8
__version__ = "0.6" __version__ = "0.6"
@ -123,8 +120,6 @@ SAVE = {
"RGB": (5, 8, 3, "RGB;L"), "RGB": (5, 8, 3, "RGB;L"),
} }
o16 = _binary.o16le
def _save(im, fp, filename, check=0): def _save(im, fp, filename, check=0):

View File

@ -20,8 +20,8 @@
# Image plugin for PDF images (output only). # Image plugin for PDF images (output only).
## ##
from PIL import Image, ImageFile from . import Image, ImageFile
from PIL._binary import i8 from ._binary import i8
import io import io
__version__ = "0.4" __version__ = "0.4"

View File

@ -19,16 +19,14 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i16le as i16
__version__ = "0.1" __version__ = "0.1"
# #
# helpers # helpers
i16 = _binary.i16le
def _accept(prefix): def _accept(prefix):
return prefix[:4] == b"\200\350\000\000" return prefix[:4] == b"\200\350\000\000"

View File

@ -38,16 +38,13 @@ import re
import zlib import zlib
import struct import struct
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16be as i16, i32be as i32, o8, o16be as o16, o32be as o32
__version__ = "0.9" __version__ = "0.9"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
is_cid = re.compile(br"\w\w\w\w").match is_cid = re.compile(br"\w\w\w\w").match
@ -621,10 +618,6 @@ class PngImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# PNG writer # PNG writer
o8 = _binary.o8
o16 = _binary.o16be
o32 = _binary.o32be
_OUTMODES = { _OUTMODES = {
# supported PIL modes, and corresponding rawmodes/bits/color combinations # supported PIL modes, and corresponding rawmodes/bits/color combinations
"1": ("1", b'\x01\x00'), "1": ("1", b'\x01\x00'),

View File

@ -17,7 +17,7 @@
import string import string
from PIL import Image, ImageFile from . import Image, ImageFile
__version__ = "0.2" __version__ = "0.2"

View File

@ -18,7 +18,8 @@
__version__ = "0.4" __version__ = "0.4"
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16be as i16, i32be as i32
MODES = { MODES = {
# (photoshop mode, bits) -> (pil mode, required channels) # (photoshop mode, bits) -> (pil mode, required channels)
@ -33,13 +34,6 @@ MODES = {
(9, 8): ("LAB", 3) (9, 8): ("LAB", 3)
} }
#
# helpers
i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
# --------------------------------------------------------------------. # --------------------------------------------------------------------.
# read PSD images # read PSD images

View File

@ -21,16 +21,13 @@
# #
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i8, o8, i16be as i16
import struct import struct
import os import os
__version__ = "0.3" __version__ = "0.3"
i8 = _binary.i8
o8 = _binary.o8
i16 = _binary.i16be
def _accept(prefix): def _accept(prefix):
return len(prefix) >= 2 and i16(prefix) == 474 return len(prefix) >= 2 and i16(prefix) == 474
@ -134,7 +131,7 @@ def _save(im, fp, filename):
fp.write(struct.pack('404s', b'')) # dummy fp.write(struct.pack('404s', b'')) # dummy
#assert we've got the right number of bands. #assert we've got the right number of bands.
if len(im.getbands()) != z: if len(im.getbands()) != z:
raise ValueError("incorrect number of bands in SGI write: %s vs %s" % raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
(z, len(im.getbands()))) (z, len(im.getbands())))

View File

@ -17,12 +17,11 @@
# #
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i32be as i32
__version__ = "0.3" __version__ = "0.3"
i32 = _binary.i32be
def _accept(prefix): def _accept(prefix):
return len(prefix) >= 4 and i32(prefix) == 0x59a66a95 return len(prefix) >= 4 and i32(prefix) == 0x59a66a95
@ -63,11 +62,11 @@ class SunImageFile(ImageFile.ImageFile):
self.size = i32(s[4:8]), i32(s[8:12]) self.size = i32(s[4:8]), i32(s[8:12])
depth = i32(s[12:16]) depth = i32(s[12:16])
data_length = i32(s[16:20]) # unreliable, ignore. data_length = i32(s[16:20]) # unreliable, ignore.
file_type = i32(s[20:24]) file_type = i32(s[20:24])
palette_type = i32(s[24:28]) # 0: None, 1: RGB, 2: Raw/arbitrary palette_type = i32(s[24:28]) # 0: None, 1: RGB, 2: Raw/arbitrary
palette_length = i32(s[28:32]) palette_length = i32(s[28:32])
if depth == 1: if depth == 1:
self.mode, rawmode = "1", "1;I" self.mode, rawmode = "1", "1;I"
elif depth == 4: elif depth == 4:
@ -85,23 +84,23 @@ class SunImageFile(ImageFile.ImageFile):
else: else:
self.mode, rawmode = 'RGB', 'BGRX' self.mode, rawmode = 'RGB', 'BGRX'
else: else:
raise SyntaxError("Unsupported Mode/Bit Depth") raise SyntaxError("Unsupported Mode/Bit Depth")
if palette_length: if palette_length:
if palette_length > 1024: if palette_length > 1024:
raise SyntaxError("Unsupported Color Palette Length") raise SyntaxError("Unsupported Color Palette Length")
if palette_type != 1: if palette_type != 1:
raise SyntaxError("Unsupported Palette Type") raise SyntaxError("Unsupported Palette Type")
offset = offset + palette_length offset = offset + palette_length
self.palette = ImagePalette.raw("RGB;L", self.fp.read(palette_length)) self.palette = ImagePalette.raw("RGB;L", self.fp.read(palette_length))
if self.mode == "L": if self.mode == "L":
self.mode = "P" self.mode = "P"
rawmode = rawmode.replace('L', 'P') rawmode = rawmode.replace('L', 'P')
# 16 bit boundaries on stride # 16 bit boundaries on stride
stride = ((self.size[0] * depth + 15) // 16) * 2 stride = ((self.size[0] * depth + 15) // 16) * 2
# file type: Type is the version (or flavor) of the bitmap # file type: Type is the version (or flavor) of the bitmap
# file. The following values are typically found in the Type # file. The following values are typically found in the Type
@ -127,7 +126,7 @@ class SunImageFile(ImageFile.ImageFile):
self.tile = [("sun_rle", (0, 0)+self.size, offset, rawmode)] self.tile = [("sun_rle", (0, 0)+self.size, offset, rawmode)]
else: else:
raise SyntaxError('Unsupported Sun Raster file type') raise SyntaxError('Unsupported Sun Raster file type')
# #
# registry # registry

View File

@ -14,7 +14,7 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
from PIL import ContainerIO from . import ContainerIO
## ##

View File

@ -17,7 +17,8 @@
# #
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import i8, i16le as i16, o8, o16le as o16, o32le as o32
__version__ = "0.3" __version__ = "0.3"
@ -26,9 +27,6 @@ __version__ = "0.3"
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Read RGA file # Read RGA file
i8 = _binary.i8
i16 = _binary.i16le
MODES = { MODES = {
# map imagetype/depth to rawmode # map imagetype/depth to rawmode
@ -132,10 +130,6 @@ class TgaImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Write TGA file # Write TGA file
o8 = _binary.o8
o16 = _binary.o16le
o32 = _binary.o32le
SAVE = { SAVE = {
"1": ("1", 1, 0, 3), "1": ("1", 1, 0, 3),
"L": ("L", 8, 0, 3), "L": ("L", 8, 0, 3),

View File

@ -41,10 +41,8 @@
from __future__ import division, print_function from __future__ import division, print_function
from PIL import Image, ImageFile from . import Image, ImageFile, ImagePalette, TiffTags
from PIL import ImagePalette from ._binary import i8, o8
from PIL import _binary
from PIL import TiffTags
import collections import collections
from fractions import Fraction from fractions import Fraction
@ -71,9 +69,6 @@ IFD_LEGACY_API = True
II = b"II" # little-endian (Intel style) II = b"II" # little-endian (Intel style)
MM = b"MM" # big-endian (Motorola style) MM = b"MM" # big-endian (Motorola style)
i8 = _binary.i8
o8 = _binary.o8
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Read TIFF files # Read TIFF files
@ -569,7 +564,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
def _register_loader(idx, size): def _register_loader(idx, size):
def decorator(func): def decorator(func):
from PIL.TiffTags import TYPES from .TiffTags import TYPES
if func.__name__.startswith("load_"): if func.__name__.startswith("load_"):
TYPES[idx] = func.__name__[5:].replace("_", " ") TYPES[idx] = func.__name__[5:].replace("_", " ")
_load_dispatch[idx] = size, func _load_dispatch[idx] = size, func
@ -583,7 +578,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
return decorator return decorator
def _register_basic(idx_fmt_name): def _register_basic(idx_fmt_name):
from PIL.TiffTags import TYPES from .TiffTags import TYPES
idx, fmt, name = idx_fmt_name idx, fmt, name = idx_fmt_name
TYPES[idx] = name TYPES[idx] = name
size = struct.calcsize("=" + fmt) size = struct.calcsize("=" + fmt)

View File

@ -23,7 +23,8 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image, _binary from . import Image
from ._binary import i32le as i32
try: try:
import builtins import builtins
@ -31,8 +32,6 @@ except ImportError:
import __builtin__ import __builtin__
builtins = __builtin__ builtins = __builtin__
i32 = _binary.i32le
def open(filename): def open(filename):
""" """

View File

@ -1,7 +1,5 @@
from PIL import Image from . import Image, ImageFile, _webp
from PIL import ImageFile
from io import BytesIO from io import BytesIO
from PIL import _webp
_VALID_WEBP_MODES = { _VALID_WEBP_MODES = {
@ -43,7 +41,7 @@ class WebPImageFile(ImageFile.ImageFile):
self.tile = [("raw", (0, 0) + self.size, 0, self.mode)] self.tile = [("raw", (0, 0) + self.size, 0, self.mode)]
def _getexif(self): def _getexif(self):
from PIL.JpegImagePlugin import _getexif from .JpegImagePlugin import _getexif
return _getexif(self) return _getexif(self)

View File

@ -21,7 +21,10 @@
from __future__ import print_function from __future__ import print_function
from PIL import Image, ImageFile, _binary from . import Image, ImageFile
from ._binary import i16le as word, si16le as short, i32le as dword, si32le as _long
__version__ = "0.2" __version__ = "0.2"
@ -59,13 +62,6 @@ if hasattr(Image.core, "drawwmf"):
register_handler(WmfHandler()) register_handler(WmfHandler())
# --------------------------------------------------------------------
word = _binary.i16le
short = _binary.si16le
dword = _binary.i32le
_long = _binary.si32le
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Read WMF file # Read WMF file

View File

@ -17,12 +17,11 @@
# FIXME: make save work (this requires quantization support) # FIXME: make save work (this requires quantization support)
# #
from PIL import Image, ImageFile, ImagePalette, _binary from . import Image, ImageFile, ImagePalette
from ._binary import o8
__version__ = "0.1" __version__ = "0.1"
o8 = _binary.o8
_MAGIC = b"P7 332" _MAGIC = b"P7 332"
# standard color palette for thumbnails (RGB332) # standard color palette for thumbnails (RGB332)

View File

@ -20,7 +20,7 @@
# #
import re import re
from PIL import Image, ImageFile from . import Image, ImageFile
__version__ = "0.6" __version__ = "0.6"

View File

@ -16,8 +16,8 @@
import re import re
from PIL import Image, ImageFile, ImagePalette from . import Image, ImageFile, ImagePalette
from PIL._binary import i8, o8 from ._binary import i8, o8
__version__ = "0.2" __version__ = "0.2"

View File

@ -1,4 +1,4 @@
from PIL import Image from . import Image
modules = { modules = {
"pil": "PIL._imaging", "pil": "PIL._imaging",