Skip to content

Commit

Permalink
Format code with Black (#3733)
Browse files Browse the repository at this point in the history
Format code with Black
  • Loading branch information
hugovk committed Jun 11, 2019
2 parents 92dc8f4 + cab7231 commit a986fed
Show file tree
Hide file tree
Showing 91 changed files with 3,265 additions and 2,717 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -2,6 +2,7 @@
-e .
alabaster
Babel
black; python_version >= '3.6'
check-manifest
cov-core
coverage
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -2,4 +2,5 @@
test=pytest

[flake8]
extend-ignore = E203, W503
max-line-length = 88
20 changes: 8 additions & 12 deletions src/PIL/BdfFontFile.py
Expand Up @@ -32,14 +32,10 @@
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other"
"OT": "Other",
}

bdf_spacing = {
"P": "Proportional",
"M": "Monospaced",
"C": "Cell"
}
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}


def bdf_char(f):
Expand All @@ -50,7 +46,7 @@ def bdf_char(f):
return None
if s[:9] == b"STARTCHAR":
break
id = s[9:].strip().decode('ascii')
id = s[9:].strip().decode("ascii")

# load symbol properties
props = {}
Expand All @@ -59,7 +55,7 @@ def bdf_char(f):
if not s or s[:6] == b"BITMAP":
break
i = s.find(b" ")
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")

# load bitmap
bitmap = []
Expand All @@ -73,7 +69,7 @@ def bdf_char(f):
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]

bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)

try:
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
Expand All @@ -87,8 +83,8 @@ def bdf_char(f):
##
# Font file plugin for the X11 BDF format.

class BdfFontFile(FontFile.FontFile):

class BdfFontFile(FontFile.FontFile):
def __init__(self, fp):

FontFile.FontFile.__init__(self)
Expand All @@ -105,10 +101,10 @@ def __init__(self, fp):
if not s or s[:13] == b"ENDPROPERTIES":
break
i = s.find(b" ")
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
if s.find(b"LogicalFontDescription") < 0:
comments.append(s[i+1:-1].decode('ascii'))
comments.append(s[i + 1 : -1].decode("ascii"))

while True:
c = bdf_char(fp)
Expand Down
40 changes: 13 additions & 27 deletions src/PIL/BlpImagePlugin.py
Expand Up @@ -47,11 +47,7 @@


def unpack_565(i):
return (
((i >> 11) & 0x1f) << 3,
((i >> 5) & 0x3f) << 2,
(i & 0x1f) << 3
)
return (((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3)


def decode_dxt1(data, alpha=False):
Expand Down Expand Up @@ -119,7 +115,7 @@ def decode_dxt3(data):

for block in range(blocks):
idx = block * 16
block = data[idx:idx + 16]
block = data[idx : idx + 16]
# Decode next 16-byte block.
bits = struct.unpack_from("<8B", block)
color0, color1 = struct.unpack_from("<HH", block, 8)
Expand All @@ -139,7 +135,7 @@ def decode_dxt3(data):
a >>= 4
else:
high = True
a &= 0xf
a &= 0xF
a *= 17 # We get a value between 0 and 15

color_code = (code >> 2 * (4 * j + i)) & 0x03
Expand Down Expand Up @@ -172,14 +168,12 @@ def decode_dxt5(data):

for block in range(blocks):
idx = block * 16
block = data[idx:idx + 16]
block = data[idx : idx + 16]
# Decode next 16-byte block.
a0, a1 = struct.unpack_from("<BB", block)

bits = struct.unpack_from("<6B", block, 2)
alphacode1 = (
bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
)
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
alphacode2 = bits[0] | (bits[1] << 8)

color0, color1 = struct.unpack_from("<HH", block, 8)
Expand Down Expand Up @@ -242,6 +236,7 @@ class BlpImageFile(ImageFile.ImageFile):
"""
Blizzard Mipmap Format
"""

format = "BLP"
format_description = "Blizzard Mipmap Format"

Expand All @@ -258,9 +253,7 @@ def _open(self):
else:
raise BLPFormatError("Bad BLP magic %r" % (self.magic))

self.tile = [
(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))
]
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]

def _read_blp_header(self):
self._blp_compression, = struct.unpack("<i", self.fp.read(4))
Expand Down Expand Up @@ -324,7 +317,6 @@ def _read_blp_header(self):


class BLP1Decoder(_BLPBaseDecoder):

def _load(self):
if self._blp_compression == BLP_FORMAT_JPEG:
self._decode_jpeg_stream()
Expand Down Expand Up @@ -368,7 +360,6 @@ def _decode_jpeg_stream(self):


class BLP2Decoder(_BLPBaseDecoder):

def _load(self):
palette = self._read_palette()

Expand All @@ -393,8 +384,7 @@ def _load(self):
linesize = (self.size[0] + 3) // 4 * 8
for yb in range((self.size[1] + 3) // 4):
for d in decode_dxt1(
self.fd.read(linesize),
alpha=bool(self._blp_alpha_depth)
self.fd.read(linesize), alpha=bool(self._blp_alpha_depth)
):
data += d

Expand All @@ -410,18 +400,14 @@ def _load(self):
for d in decode_dxt5(self.fd.read(linesize)):
data += d
else:
raise BLPFormatError("Unsupported alpha encoding %r" % (
self._blp_alpha_encoding
))
raise BLPFormatError(
"Unsupported alpha encoding %r" % (self._blp_alpha_encoding)
)
else:
raise BLPFormatError(
"Unknown BLP encoding %r" % (self._blp_encoding)
)
raise BLPFormatError("Unknown BLP encoding %r" % (self._blp_encoding))

else:
raise BLPFormatError(
"Unknown BLP compression %r" % (self._blp_compression)
)
raise BLPFormatError("Unknown BLP compression %r" % (self._blp_compression))

self.set_as_raw(bytes(data))

Expand Down

0 comments on commit a986fed

Please sign in to comment.