Skip to content
Browse files

Assorted fixes -- these werent't tested at all

  • Loading branch information...
1 parent 3d15c46 commit cd01a21e7e249ed7abe0b8a97b9c175fd5c0ec58 gpolo committed Dec 30, 2008
View
10 PIL/ContainerIO.py
@@ -81,30 +81,30 @@ def read(self, n = 0):
else:
n = self.length - self.pos
if not n: # EOF
- return ""
+ return b""
self.pos = self.pos + n
return self.fh.read(n)
##
# Read a line of text.
#
- # @return An 8-bit string.
+ # @return A byte string.
def readline(self):
- s = ""
+ s = b""
while 1:
c = self.read(1)
if not c:
break
s = s + c
- if c == "\n":
+ if c == b"\n":
break
return s
##
# Read multiple lines of text.
#
- # @return A list of 8-bit strings.
+ # @return A list of byte strings.
def readlines(self):
l = []
View
6 PIL/FpxImagePlugin.py
@@ -83,7 +83,7 @@ def _open_index(self, index = 1):
size = max(self.size)
i = 1
while size > 64:
- size = size / 2
+ size = size // 2
i = i + 1
self.maxid = i - 1
@@ -170,8 +170,8 @@ def _open_subimage(self, index = 1, subimage = 0):
elif compression == 2:
- internal_color_conversion = ord(s[14])
- jpeg_tables = ord(s[15])
+ internal_color_conversion = s[14]
+ jpeg_tables = s[15]
rawmode = self.rawmode
if internal_color_conversion:
View
5 PIL/GdImageFile.py
@@ -25,11 +25,10 @@
__version__ = "0.1"
-import string
-from . import Image, ImageFile, ImagePalette
+import Image, ImageFile, ImagePalette
def i16(c):
- return ord(c[1]) + (ord(c[0])<<8)
+ return c[1] + (c[0] << 8)
##
# Image plugin for the GD uncompressed format. Note that this format
View
28 PIL/GimpGradientFile.py
@@ -29,20 +29,20 @@ def linear(middle, pos):
if middle < EPSILON:
return 0.0
else:
- return 0.5 * pos / middle
+ return 0.5 * pos // middle
else:
pos = pos - middle
middle = 1.0 - middle
if middle < EPSILON:
return 1.0
else:
- return 0.5 + 0.5 * pos / middle
+ return 0.5 + 0.5 * pos // middle
def curved(middle, pos):
- return pos ** (log(0.5) / log(max(middle, EPSILON)))
+ return pos ** (log(0.5) // log(max(middle, EPSILON)))
def sine(middle, pos):
- return (sin((-pi / 2.0) + pi * linear(middle, pos)) + 1.0) / 2.0
+ return (sin((-pi // 2.0) + pi * linear(middle, pos)) + 1.0) // 2.0
def sphere_increasing(middle, pos):
return sqrt(1.0 - (linear(middle, pos) - 1.0) ** 2)
@@ -65,7 +65,7 @@ def getpalette(self, entries = 256):
for i in range(entries):
- x = i / float(entries-1)
+ x = i // float(entries-1)
while x1 < x:
ix = ix + 1
@@ -76,18 +76,18 @@ def getpalette(self, entries = 256):
if w < EPSILON:
scale = segment(0.5, 0.5)
else:
- scale = segment((xm - x0) / w, (x - x0) / w)
+ scale = segment((xm - x0) // w, (x - x0) // w)
# expand to RGBA
- r = chr(int(255 * ((rgb1[0] - rgb0[0]) * scale + rgb0[0]) + 0.5))
- g = chr(int(255 * ((rgb1[1] - rgb0[1]) * scale + rgb0[1]) + 0.5))
- b = chr(int(255 * ((rgb1[2] - rgb0[2]) * scale + rgb0[2]) + 0.5))
- a = chr(int(255 * ((rgb1[3] - rgb0[3]) * scale + rgb0[3]) + 0.5))
+ r = int(255 * ((rgb1[0] - rgb0[0]) * scale + rgb0[0]) + 0.5)
+ g = int(255 * ((rgb1[1] - rgb0[1]) * scale + rgb0[1]) + 0.5)
+ b = int(255 * ((rgb1[2] - rgb0[2]) * scale + rgb0[2]) + 0.5)
+ a = int(255 * ((rgb1[3] - rgb0[3]) * scale + rgb0[3]) + 0.5)
# add to palette
- palette.append(r + g + b + a)
+ palette.append(bytes((r, g, b, a)))
- return string.join(palette, ""), "RGBA"
+ return b"".join(palette), "RGBA"
##
# File handler for GIMP's gradient format.
@@ -96,7 +96,7 @@ class GimpGradientFile(GradientFile):
def __init__(self, fp):
- if fp.readline()[:13] != "GIMP Gradient":
+ if fp.readline()[:13] != b"GIMP Gradient":
raise SyntaxError("not a GIMP gradient file")
count = int(fp.readline())
@@ -105,7 +105,7 @@ def __init__(self, fp):
for i in range(count):
- s = string.split(fp.readline())
+ s = fp.readline().split()
w = list(map(float, s[:11]))
x0, x1 = w[0], w[2]
View
10 PIL/GimpPaletteFile.py
@@ -14,7 +14,7 @@
# See the README file for information on usage and redistribution.
#
-import re, string
+import re
##
# File handler for GIMP's palette format.
@@ -27,7 +27,7 @@ def __init__(self, fp):
self.palette = [chr(i)*3 for i in list(range(256))]
- if fp.readline()[:12] != "GIMP Palette":
+ if fp.readline()[:12] != b"GIMP Palette":
raise SyntaxError("not a GIMP palette file")
i = 0
@@ -39,12 +39,12 @@ def __init__(self, fp):
if not s:
break
# skip fields and comment lines
- if re.match("\w+:|#", s):
+ if re.match(b"\w+:|#", s):
continue
if len(s) > 100:
raise SyntaxError("bad palette file")
- v = tuple(map(int, string.split(s)[:3]))
+ v = tuple(map(int, s.split()[:3]))
if len(v) != 3:
raise ValueError("bad palette entry")
@@ -53,7 +53,7 @@ def __init__(self, fp):
i = i + 1
- self.palette = string.join(self.palette, "")
+ self.palette = b"".join(self.palette)
def getpalette(self):
View
2 PIL/ImageDraw2.py
@@ -16,7 +16,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image, ImageColor, ImageDraw, ImageFont, ImagePath
+import Image, ImageColor, ImageDraw, ImageFont, ImagePath
class Pen:
def __init__(self, color, width=1, opacity=255):
View
2 PIL/ImageFileIO.py
@@ -40,7 +40,7 @@ def __init__(self, fp):
if __name__ == "__main__":
- from . import Image
+ import Image
fp = open("/images/clenna.im", "rb")
im = Image.open(ImageFileIO(fp))
im.load() # make sure we can read the raster data
View
32 PIL/ImageFont.py
@@ -25,8 +25,8 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
-import os, string, sys
+import Image
+import os, sys
# FIXME: add support for pilfont2 format (see FontFile.py)
@@ -85,12 +85,12 @@ def _load_pilfont(self, filename):
def _load_pilfont_data(self, file, image):
# read PILfont header
- if file.readline() != "PILfont\n":
+ if file.readline() != b"PILfont\n":
raise SyntaxError("Not a PILfont file")
- d = string.split(file.readline(), ";")
+ d = file.readline().split(b";")
self.info = [] # FIXME: should be a dictionary
s = file.readline()
- while s and s != "DATA\n":
+ while s and s != b"DATA\n":
self.info.append(s)
# read PILfont metrics
@@ -245,7 +245,7 @@ def load_default():
f = ImageFont()
f._load_pilfont_data(
# courB08
- StringIO(base64.decodestring('''
+ StringIO(base64.decodestring(b'''
UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@@ -337,7 +337,7 @@ def load_default():
pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
+QAGAAIAzgAKANUAEw==
-''')), Image.open(StringIO(base64.decodestring('''
+''')), Image.open(StringIO(base64.decodestring(b'''
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
@@ -367,11 +367,13 @@ def load_default():
if __name__ == "__main__":
# create font data chunk for embedding
import base64, os, sys
- font = "../Images/courB08"
- print(" f._load_pilfont_data(")
- print(" # %s" % os.path.basename(font))
- print(" StringIO(base64.decodestring('''")
- base64.encode(open(font + ".pil", "rb"), sys.stdout)
- print("''')), Image.open(StringIO(base64.decodestring('''")
- base64.encode(open(font + ".pbm", "rb"), sys.stdout)
- print("'''))))")
+ output = open(sys.argv[1], "wb")
+ font = b"../Images/courB08"
+ output.write(b" f._load_pilfont_data(\n")
+ output.write(b" # " + os.path.basename(font) + b"\n")
+ output.write(b" StringIO(base64.decodestring(b'''\n")
+ base64.encode(open(font + b".pil", "rb"), output)
+ output.write(b"''')), Image.open(StringIO(base64.decodestring(b'''\n")
+ base64.encode(open(font + b".pbm", "rb"), output)
+ output.write(b"'''))))")
+ output.close()
View
2 PIL/ImageGrab.py
@@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
##
# (New in 1.1.3) The <b>ImageGrab</b> module can be used to copy
View
8 PIL/ImageOps.py
@@ -17,7 +17,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
import operator
from functools import reduce
@@ -95,7 +95,7 @@ def autocontrast(image, cutoff=0, ignore=None):
for ix in range(256):
n = n + h[ix]
# remove cutoff% pixels from the low end
- cut = n * cutoff / 100
+ cut = n * cutoff // 100
for lo in range(256):
if cut > h[lo]:
cut = cut - h[lo]
@@ -106,7 +106,7 @@ def autocontrast(image, cutoff=0, ignore=None):
if cut <= 0:
break
# remove cutoff% samples from the hi end
- cut = n * cutoff / 100
+ cut = n * cutoff // 100
for hi in range(255, -1, -1):
if cut > h[hi]:
cut = cut - h[hi]
@@ -127,7 +127,7 @@ def autocontrast(image, cutoff=0, ignore=None):
# don't bother
lut.extend(list(range(256)))
else:
- scale = 255.0 / (hi - lo)
+ scale = 255 / (hi - lo)
offset = -lo * scale
for ix in range(256):
ix = int(ix * scale + offset)
View
2 PIL/ImagePath.py
@@ -14,7 +14,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
##
# Path wrapper.
View
2 PIL/ImageQt.py
@@ -15,7 +15,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
from PyQt4.QtGui import QImage, qRgb
View
8 PIL/ImageStat.py
@@ -21,7 +21,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
import operator, math
from functools import reduce
@@ -55,7 +55,7 @@ def __init__(self, image_or_list, mask = None):
self.h = image_or_list # assume it to be a histogram list
if type(self.h) != type([]):
raise TypeError("first argument must be image or list")
- self.bands = list(list(range(len(self.h) / 256)))
+ self.bands = list(list(range(len(self.h) // 256)))
def __getattr__(self, id):
"Calculate missing attribute"
@@ -127,7 +127,7 @@ def _getmedian(self):
v = []
for i in self.bands:
s = 0
- l = self.count[i]/2
+ l = self.count[i]//2
b = i * 256
for j in range(256):
s = s + self.h[b+j]
@@ -141,7 +141,7 @@ def _getrms(self):
v = []
for i in self.bands:
- v.append(math.sqrt(self.sum2[i] / self.count[i]))
+ v.append(math.sqrt(self.sum2[i] // self.count[i]))
return v
View
2 PIL/ImageWin.py
@@ -17,7 +17,7 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
##
# The <b>ImageWin</b> module contains support to create and display
View
8 PIL/MpegImagePlugin.py
@@ -28,12 +28,12 @@ def __init__(self, fp):
self.bits = 0
self.bitbuffer = 0
- def __next__(self):
- return ord(self.fp.read(1))
+ def next(self):
+ return self.fp.read(1)
def peek(self, bits):
while self.bits < bits:
- c = next(self)
+ c = self.next()
if c < 0:
self.bits = 0
continue
@@ -43,7 +43,7 @@ def peek(self, bits):
def skip(self, bits):
while self.bits < bits:
- self.bitbuffer = (self.bitbuffer << 8) + ord(self.fp.read(1))
+ self.bitbuffer = (self.bitbuffer << 8) + self.fp.read(1)
self.bits = self.bits + 8
self.bits = self.bits - bits
View
12 PIL/MspImagePlugin.py
@@ -26,10 +26,10 @@
# read MSP files
def i16(c):
- return ord(c[0]) + (ord(c[1])<<8)
+ return c[0] + (c[1] << 8)
def _accept(prefix):
- return prefix[:4] in ["DanM", "LinS"]
+ return prefix[:4] in [b"DanM", b"LinS"]
##
# Image plugin for Windows MSP images. This plugin supports both
@@ -44,7 +44,7 @@ def _open(self):
# Header
s = self.fp.read(32)
- if s[:4] not in ["DanM", "LinS"]:
+ if s[:4] not in [b"DanM", b"LinS"]:
raise SyntaxError("not an MSP file")
# Header checksum
@@ -57,7 +57,7 @@ def _open(self):
self.mode = "1"
self.size = i16(s[4:]), i16(s[6:])
- if s[:4] == "DanM":
+ if s[:4] == b"DanM":
self.tile = [("raw", (0,0)+self.size, 32, ("1", 0, 1))]
else:
self.tile = [("msp", (0,0)+self.size, 32+2*self.size[1], None)]
@@ -66,7 +66,7 @@ def _open(self):
# write MSP files (uncompressed only)
def o16(i):
- return chr(i&255) + chr(i>>8&255)
+ return bytes((i&255, i>>8&255))
def _save(im, fp, filename):
@@ -76,7 +76,7 @@ def _save(im, fp, filename):
# create MSP header
header = [0] * 16
- header[0], header[1] = i16("Da"), i16("nM") # version 1
+ header[0], header[1] = i16(b"Da"), i16(b"nM") # version 1
header[2], header[3] = im.size
header[4], header[5] = 1, 1
header[6], header[7] = 1, 1
View
18 PIL/OleFileIO.py
@@ -36,17 +36,17 @@
# See the README file for information on usage and redistribution.
#
-import string, io
+import io
def i16(c, o = 0):
- return ord(c[o])+(ord(c[o+1])<<8)
+ return c[o] + (c[o+1] << 8)
def i32(c, o = 0):
- return ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24)
+ return c[o] + (c[o+1] << 8) + (c[o+2] << 16) + (c[o+3] << 24)
-MAGIC = '\320\317\021\340\241\261\032\341'
+MAGIC = b'\320\317\021\340\241\261\032\341'
#
# --------------------------------------------------------------------
@@ -105,7 +105,7 @@ def __init__(self, fp, sect, size, offset, sectorsize, fat):
data.append(fp.read(sectorsize))
sect = fat[sect]
- data = string.join(data, "")
+ data = b"".join(data)
# print len(data), size
@@ -344,7 +344,7 @@ def loaddirectory(self, sect):
entry = fp.read(128)
if not entry:
break
- type = ord(entry[66])
+ type = entry[66]
name = self._unicode(entry[0:0+i16(entry, 64)])
ptrs = i32(entry, 68), i32(entry, 72), i32(entry, 76)
sect, size = i32(entry, 116), i32(entry, 120)
@@ -446,7 +446,7 @@ def getproperties(self, filename):
fp.seek(i32(s, 16))
# get section
- s = "****" + fp.read(i32(fp.read(4))-4)
+ s = b"****" + fp.read(i32(fp.read(4))-4)
for i in range(i32(s, 4)):
@@ -480,9 +480,9 @@ def getproperties(self, filename):
value = int(i32(s, offset+4)) + (int(i32(s, offset+8))<<32)
# FIXME: this is a 64-bit int: "number of 100ns periods
# since Jan 1,1601". Should map this to Python time
- value = value / 10000000 # seconds
+ value = value // 10000000 # seconds
elif type == VT_UI1:
- value = ord(s[offset+4])
+ value = s[offset+4]
elif type == VT_CLSID:
value = self._clsid(s[offset+4:offset+20])
elif type == VT_CF:
View
6 PIL/PcfFontFile.py
@@ -16,11 +16,9 @@
# See the README file for information on usage and redistribution.
#
-from . import Image
+import Image
from . import FontFile
-import string
-
# --------------------------------------------------------------------
# declarations
@@ -55,7 +53,7 @@ def b32(c):
return c[3] + (c[2] << 8) + (c[1] << 16) + (c[0] << 24)
def sz(s, o):
- return s[o:string.index(s, "\0", o)]
+ return s[o:s.index(b"\0", o)]
##
# Font file plugin for the X11 PCF format.
View
6 PIL/SpiderImagePlugin.py
@@ -165,7 +165,7 @@ def convert2byte(self, depth=255):
(min, max) = self.getextrema()
m = 1
if max != min:
- m = depth / (max-min)
+ m = depth // (max-min)
b = -m * min
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
@@ -204,11 +204,11 @@ def loadImageSeries(filelist=None):
def makeSpiderHeader(im):
nsam,nrow = im.size
lenbyt = nsam * 4 # There are labrec records in the header
- labrec = 1024 / lenbyt
+ labrec = 1024 // lenbyt
if 1024%lenbyt != 0: labrec += 1
labbyt = labrec * lenbyt
hdr = []
- nvalues = labbyt / 4
+ nvalues = labbyt // 4
for i in range(nvalues):
hdr.append(0.0)
View
5 PIL/TarIO.py
@@ -15,7 +15,6 @@
#
from . import ContainerIO
-import string
##
# A file object that provides read access to a given member of a TAR
@@ -40,13 +39,13 @@ def __init__(self, tarfile, file):
raise IOError("unexpected end of tar file")
name = s[:100]
- i = string.find(name, chr(0))
+ i = name.find(b'\x00')
if i == 0:
raise IOError("cannot find subfile")
if i > 0:
name = name[:i]
- size = string.atoi(s[124:136], 8)
+ size = int(s[124:136], 8)
if file == name:
break
View
103 PIL/WalImageFile.py
@@ -1,3 +1,4 @@
+# -*- encoding: utf-8 -*-
#
# The Python Imaging Library.
# $Id: WalImageFile.py 2134 2004-10-06 08:55:20Z fredrik $
@@ -23,7 +24,7 @@
import Image
def i32(c, o=0):
- return ord(c[o])+(ord(c[o+1])<<8)+(ord(c[o+2])<<16)+(ord(c[o+3])<<24)
+ return c[o] + (c[o+1] << 8) + (c[o+2] << 16) + (c[o+3] << 24)
##
# Load texture from a Quake2 WAL texture file.
@@ -59,8 +60,8 @@ def open(filename):
im.format_description = "Quake2 Texture"
# strings are null-terminated
- im.info["name"] = header[:32].split("\0", 1)[0]
- next_name = header[56:56+32].split("\0", 1)[0]
+ im.info["name"] = header[:32].split(b"\0", 1)[0]
+ next_name = header[56:56+32].split(b"\0", 1)[0]
if next_name:
im.info["next_name"] = next_name
@@ -69,54 +70,54 @@ def open(filename):
quake2palette = (
# default palette taken from piffo 0.93 by Hans Häggström
- "\x01\x01\x01\x0b\x0b\x0b\x12\x12\x12\x17\x17\x17\x1b\x1b\x1b\x1e"
- "\x1e\x1e\x22\x22\x22\x26\x26\x26\x29\x29\x29\x2c\x2c\x2c\x2f\x2f"
- "\x2f\x32\x32\x32\x35\x35\x35\x37\x37\x37\x3a\x3a\x3a\x3c\x3c\x3c"
- "\x24\x1e\x13\x22\x1c\x12\x20\x1b\x12\x1f\x1a\x10\x1d\x19\x10\x1b"
- "\x17\x0f\x1a\x16\x0f\x18\x14\x0d\x17\x13\x0d\x16\x12\x0d\x14\x10"
- "\x0b\x13\x0f\x0b\x10\x0d\x0a\x0f\x0b\x0a\x0d\x0b\x07\x0b\x0a\x07"
- "\x23\x23\x26\x22\x22\x25\x22\x20\x23\x21\x1f\x22\x20\x1e\x20\x1f"
- "\x1d\x1e\x1d\x1b\x1c\x1b\x1a\x1a\x1a\x19\x19\x18\x17\x17\x17\x16"
- "\x16\x14\x14\x14\x13\x13\x13\x10\x10\x10\x0f\x0f\x0f\x0d\x0d\x0d"
- "\x2d\x28\x20\x29\x24\x1c\x27\x22\x1a\x25\x1f\x17\x38\x2e\x1e\x31"
- "\x29\x1a\x2c\x25\x17\x26\x20\x14\x3c\x30\x14\x37\x2c\x13\x33\x28"
- "\x12\x2d\x24\x10\x28\x1f\x0f\x22\x1a\x0b\x1b\x14\x0a\x13\x0f\x07"
- "\x31\x1a\x16\x30\x17\x13\x2e\x16\x10\x2c\x14\x0d\x2a\x12\x0b\x27"
- "\x0f\x0a\x25\x0f\x07\x21\x0d\x01\x1e\x0b\x01\x1c\x0b\x01\x1a\x0b"
- "\x01\x18\x0a\x01\x16\x0a\x01\x13\x0a\x01\x10\x07\x01\x0d\x07\x01"
- "\x29\x23\x1e\x27\x21\x1c\x26\x20\x1b\x25\x1f\x1a\x23\x1d\x19\x21"
- "\x1c\x18\x20\x1b\x17\x1e\x19\x16\x1c\x18\x14\x1b\x17\x13\x19\x14"
- "\x10\x17\x13\x0f\x14\x10\x0d\x12\x0f\x0b\x0f\x0b\x0a\x0b\x0a\x07"
- "\x26\x1a\x0f\x23\x19\x0f\x20\x17\x0f\x1c\x16\x0f\x19\x13\x0d\x14"
- "\x10\x0b\x10\x0d\x0a\x0b\x0a\x07\x33\x22\x1f\x35\x29\x26\x37\x2f"
- "\x2d\x39\x35\x34\x37\x39\x3a\x33\x37\x39\x30\x34\x36\x2b\x31\x34"
- "\x27\x2e\x31\x22\x2b\x2f\x1d\x28\x2c\x17\x25\x2a\x0f\x20\x26\x0d"
- "\x1e\x25\x0b\x1c\x22\x0a\x1b\x20\x07\x19\x1e\x07\x17\x1b\x07\x14"
- "\x18\x01\x12\x16\x01\x0f\x12\x01\x0b\x0d\x01\x07\x0a\x01\x01\x01"
- "\x2c\x21\x21\x2a\x1f\x1f\x29\x1d\x1d\x27\x1c\x1c\x26\x1a\x1a\x24"
- "\x18\x18\x22\x17\x17\x21\x16\x16\x1e\x13\x13\x1b\x12\x12\x18\x10"
- "\x10\x16\x0d\x0d\x12\x0b\x0b\x0d\x0a\x0a\x0a\x07\x07\x01\x01\x01"
- "\x2e\x30\x29\x2d\x2e\x27\x2b\x2c\x26\x2a\x2a\x24\x28\x29\x23\x27"
- "\x27\x21\x26\x26\x1f\x24\x24\x1d\x22\x22\x1c\x1f\x1f\x1a\x1c\x1c"
- "\x18\x19\x19\x16\x17\x17\x13\x13\x13\x10\x0f\x0f\x0d\x0b\x0b\x0a"
- "\x30\x1e\x1b\x2d\x1c\x19\x2c\x1a\x17\x2a\x19\x14\x28\x17\x13\x26"
- "\x16\x10\x24\x13\x0f\x21\x12\x0d\x1f\x10\x0b\x1c\x0f\x0a\x19\x0d"
- "\x0a\x16\x0b\x07\x12\x0a\x07\x0f\x07\x01\x0a\x01\x01\x01\x01\x01"
- "\x28\x29\x38\x26\x27\x36\x25\x26\x34\x24\x24\x31\x22\x22\x2f\x20"
- "\x21\x2d\x1e\x1f\x2a\x1d\x1d\x27\x1b\x1b\x25\x19\x19\x21\x17\x17"
- "\x1e\x14\x14\x1b\x13\x12\x17\x10\x0f\x13\x0d\x0b\x0f\x0a\x07\x07"
- "\x2f\x32\x29\x2d\x30\x26\x2b\x2e\x24\x29\x2c\x21\x27\x2a\x1e\x25"
- "\x28\x1c\x23\x26\x1a\x21\x25\x18\x1e\x22\x14\x1b\x1f\x10\x19\x1c"
- "\x0d\x17\x1a\x0a\x13\x17\x07\x10\x13\x01\x0d\x0f\x01\x0a\x0b\x01"
- "\x01\x3f\x01\x13\x3c\x0b\x1b\x39\x10\x20\x35\x14\x23\x31\x17\x23"
- "\x2d\x18\x23\x29\x18\x3f\x3f\x3f\x3f\x3f\x39\x3f\x3f\x31\x3f\x3f"
- "\x2a\x3f\x3f\x20\x3f\x3f\x14\x3f\x3c\x12\x3f\x39\x0f\x3f\x35\x0b"
- "\x3f\x32\x07\x3f\x2d\x01\x3d\x2a\x01\x3b\x26\x01\x39\x21\x01\x37"
- "\x1d\x01\x34\x1a\x01\x32\x16\x01\x2f\x12\x01\x2d\x0f\x01\x2a\x0b"
- "\x01\x27\x07\x01\x23\x01\x01\x1d\x01\x01\x17\x01\x01\x10\x01\x01"
- "\x3d\x01\x01\x19\x19\x3f\x3f\x01\x01\x01\x01\x3f\x16\x16\x13\x10"
- "\x10\x0f\x0d\x0d\x0b\x3c\x2e\x2a\x36\x27\x20\x30\x21\x18\x29\x1b"
- "\x10\x3c\x39\x37\x37\x32\x2f\x31\x2c\x28\x2b\x26\x21\x30\x22\x20"
+ b"\x01\x01\x01\x0b\x0b\x0b\x12\x12\x12\x17\x17\x17\x1b\x1b\x1b\x1e"
+ b"\x1e\x1e\x22\x22\x22\x26\x26\x26\x29\x29\x29\x2c\x2c\x2c\x2f\x2f"
+ b"\x2f\x32\x32\x32\x35\x35\x35\x37\x37\x37\x3a\x3a\x3a\x3c\x3c\x3c"
+ b"\x24\x1e\x13\x22\x1c\x12\x20\x1b\x12\x1f\x1a\x10\x1d\x19\x10\x1b"
+ b"\x17\x0f\x1a\x16\x0f\x18\x14\x0d\x17\x13\x0d\x16\x12\x0d\x14\x10"
+ b"\x0b\x13\x0f\x0b\x10\x0d\x0a\x0f\x0b\x0a\x0d\x0b\x07\x0b\x0a\x07"
+ b"\x23\x23\x26\x22\x22\x25\x22\x20\x23\x21\x1f\x22\x20\x1e\x20\x1f"
+ b"\x1d\x1e\x1d\x1b\x1c\x1b\x1a\x1a\x1a\x19\x19\x18\x17\x17\x17\x16"
+ b"\x16\x14\x14\x14\x13\x13\x13\x10\x10\x10\x0f\x0f\x0f\x0d\x0d\x0d"
+ b"\x2d\x28\x20\x29\x24\x1c\x27\x22\x1a\x25\x1f\x17\x38\x2e\x1e\x31"
+ b"\x29\x1a\x2c\x25\x17\x26\x20\x14\x3c\x30\x14\x37\x2c\x13\x33\x28"
+ b"\x12\x2d\x24\x10\x28\x1f\x0f\x22\x1a\x0b\x1b\x14\x0a\x13\x0f\x07"
+ b"\x31\x1a\x16\x30\x17\x13\x2e\x16\x10\x2c\x14\x0d\x2a\x12\x0b\x27"
+ b"\x0f\x0a\x25\x0f\x07\x21\x0d\x01\x1e\x0b\x01\x1c\x0b\x01\x1a\x0b"
+ b"\x01\x18\x0a\x01\x16\x0a\x01\x13\x0a\x01\x10\x07\x01\x0d\x07\x01"
+ b"\x29\x23\x1e\x27\x21\x1c\x26\x20\x1b\x25\x1f\x1a\x23\x1d\x19\x21"
+ b"\x1c\x18\x20\x1b\x17\x1e\x19\x16\x1c\x18\x14\x1b\x17\x13\x19\x14"
+ b"\x10\x17\x13\x0f\x14\x10\x0d\x12\x0f\x0b\x0f\x0b\x0a\x0b\x0a\x07"
+ b"\x26\x1a\x0f\x23\x19\x0f\x20\x17\x0f\x1c\x16\x0f\x19\x13\x0d\x14"
+ b"\x10\x0b\x10\x0d\x0a\x0b\x0a\x07\x33\x22\x1f\x35\x29\x26\x37\x2f"
+ b"\x2d\x39\x35\x34\x37\x39\x3a\x33\x37\x39\x30\x34\x36\x2b\x31\x34"
+ b"\x27\x2e\x31\x22\x2b\x2f\x1d\x28\x2c\x17\x25\x2a\x0f\x20\x26\x0d"
+ b"\x1e\x25\x0b\x1c\x22\x0a\x1b\x20\x07\x19\x1e\x07\x17\x1b\x07\x14"
+ b"\x18\x01\x12\x16\x01\x0f\x12\x01\x0b\x0d\x01\x07\x0a\x01\x01\x01"
+ b"\x2c\x21\x21\x2a\x1f\x1f\x29\x1d\x1d\x27\x1c\x1c\x26\x1a\x1a\x24"
+ b"\x18\x18\x22\x17\x17\x21\x16\x16\x1e\x13\x13\x1b\x12\x12\x18\x10"
+ b"\x10\x16\x0d\x0d\x12\x0b\x0b\x0d\x0a\x0a\x0a\x07\x07\x01\x01\x01"
+ b"\x2e\x30\x29\x2d\x2e\x27\x2b\x2c\x26\x2a\x2a\x24\x28\x29\x23\x27"
+ b"\x27\x21\x26\x26\x1f\x24\x24\x1d\x22\x22\x1c\x1f\x1f\x1a\x1c\x1c"
+ b"\x18\x19\x19\x16\x17\x17\x13\x13\x13\x10\x0f\x0f\x0d\x0b\x0b\x0a"
+ b"\x30\x1e\x1b\x2d\x1c\x19\x2c\x1a\x17\x2a\x19\x14\x28\x17\x13\x26"
+ b"\x16\x10\x24\x13\x0f\x21\x12\x0d\x1f\x10\x0b\x1c\x0f\x0a\x19\x0d"
+ b"\x0a\x16\x0b\x07\x12\x0a\x07\x0f\x07\x01\x0a\x01\x01\x01\x01\x01"
+ b"\x28\x29\x38\x26\x27\x36\x25\x26\x34\x24\x24\x31\x22\x22\x2f\x20"
+ b"\x21\x2d\x1e\x1f\x2a\x1d\x1d\x27\x1b\x1b\x25\x19\x19\x21\x17\x17"
+ b"\x1e\x14\x14\x1b\x13\x12\x17\x10\x0f\x13\x0d\x0b\x0f\x0a\x07\x07"
+ b"\x2f\x32\x29\x2d\x30\x26\x2b\x2e\x24\x29\x2c\x21\x27\x2a\x1e\x25"
+ b"\x28\x1c\x23\x26\x1a\x21\x25\x18\x1e\x22\x14\x1b\x1f\x10\x19\x1c"
+ b"\x0d\x17\x1a\x0a\x13\x17\x07\x10\x13\x01\x0d\x0f\x01\x0a\x0b\x01"
+ b"\x01\x3f\x01\x13\x3c\x0b\x1b\x39\x10\x20\x35\x14\x23\x31\x17\x23"
+ b"\x2d\x18\x23\x29\x18\x3f\x3f\x3f\x3f\x3f\x39\x3f\x3f\x31\x3f\x3f"
+ b"\x2a\x3f\x3f\x20\x3f\x3f\x14\x3f\x3c\x12\x3f\x39\x0f\x3f\x35\x0b"
+ b"\x3f\x32\x07\x3f\x2d\x01\x3d\x2a\x01\x3b\x26\x01\x39\x21\x01\x37"
+ b"\x1d\x01\x34\x1a\x01\x32\x16\x01\x2f\x12\x01\x2d\x0f\x01\x2a\x0b"
+ b"\x01\x27\x07\x01\x23\x01\x01\x1d\x01\x01\x17\x01\x01\x10\x01\x01"
+ b"\x3d\x01\x01\x19\x19\x3f\x3f\x01\x01\x01\x01\x3f\x16\x16\x13\x10"
+ b"\x10\x0f\x0d\x0d\x0b\x3c\x2e\x2a\x36\x27\x20\x30\x21\x18\x29\x1b"
+ b"\x10\x3c\x39\x37\x37\x32\x2f\x31\x2c\x28\x2b\x26\x21\x30\x22\x20"
)
if __name__ == "__main__":
View
22 PIL/WmfImagePlugin.py
@@ -33,16 +33,16 @@ def register_handler(handler):
# --------------------------------------------------------------------
def word(c, o=0):
- return ord(c[o]) + (ord(c[o+1])<<8)
+ return c[o] + (c[o+1] << 8)
def short(c, o=0):
- v = ord(c[o]) + (ord(c[o+1])<<8)
+ v = c[o] + (c[o+1] <<8)
if v >= 32768:
v = v - 65536
return v
def dword(c, o=0):
- return ord(c[o]) + (ord(c[o+1])<<8) + (ord(c[o+2])<<16) + (ord(c[o+3])<<24)
+ return c[o] + (c[o+1] << 8) + (c[o+2] << 16) + (c[o+3] << 24)
def int(c, o=0):
return dword(c, o)
@@ -53,8 +53,8 @@ def int(c, o=0):
def _accept(prefix):
return (
- prefix[:6] == "\xd7\xcd\xc6\x9a\x00\x00" or
- prefix[:4] == "\x01\x00\x00\x00"
+ prefix[:6] == b"\xd7\xcd\xc6\x9a\x00\x00" or
+ prefix[:4] == b"\x01\x00\x00\x00"
)
##
@@ -70,7 +70,7 @@ def _open(self):
# check placable header
s = self.fp.read(80)
- if s[:6] == "\xd7\xcd\xc6\x9a\x00\x00":
+ if s[:6] == b"\xd7\xcd\xc6\x9a\x00\x00":
# placeable windows metafile
@@ -82,7 +82,7 @@ def _open(self):
x1 = short(s, 10); y1 = short(s, 12)
# normalize size to 72 dots per inch
- size = (x1 - x0) * 72 / inch, (y1 - y0) * 72 / inch
+ size = (x1 - x0) * 72 // inch, (y1 - y0) * 72 // inch
self.info["wmf_bbox"] = x0, y0, x1, y1
@@ -91,10 +91,10 @@ def _open(self):
# print self.mode, self.size, self.info
# sanity check (standard metafile header)
- if s[22:26] != "\x01\x00\t\x00":
+ if s[22:26] != b"\x01\x00\t\x00":
raise SyntaxError("Unsupported WMF file format")
- elif int(s) == 1 and s[40:44] == " EMF":
+ elif int(s) == 1 and s[40:44] == b" EMF":
# enhanced metafile
# get bounding box
@@ -108,8 +108,8 @@ def _open(self):
size = x1 - x0, y1 - y0
# calculate dots per inch from bbox and frame
- xdpi = 2540 * (x1 - y0) / (frame[2] - frame[0])
- ydpi = 2540 * (y1 - y0) / (frame[3] - frame[1])
+ xdpi = 2540 * (x1 - y0) // (frame[2] - frame[0])
+ ydpi = 2540 * (y1 - y0) // (frame[3] - frame[1])
self.info["wmf_bbox"] = x0, y0, x1, y1
View
12 PIL/XVThumbImagePlugin.py
@@ -22,12 +22,14 @@
import Image, ImageFile, ImagePalette
# standard color palette for thumbnails (RGB332)
-PALETTE = ""
+PALETTE = b""
for r in range(8):
for g in range(8):
for b in range(4):
- PALETTE = PALETTE + (chr((r * 255) // 7) +
- chr((g * 255) // 7) + chr((b * 255) // 3))
+ PALETTE += bytes((
+ (r * 255) // 7,
+ (g * 255) // 7,
+ (b * 255) // 3))
##
# Image plugin for XV thumbnail images.
@@ -41,13 +43,13 @@ def _open(self):
# check magic
s = self.fp.read(6)
- if s != "P7 332":
+ if s != b"P7 332":
raise SyntaxError("not an XV thumbnail file")
# skip info comments
while 1:
s = self.fp.readline().strip()
- if s == "#END_OF_COMMENTS":
+ if s == b"#END_OF_COMMENTS":
break
# read header line

0 comments on commit cd01a21

Please sign in to comment.
Something went wrong with that request. Please try again.