Skip to content

Commit

Permalink
Removed _to_int
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 29, 2021
1 parent 90ece13 commit 8736a74
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/PIL/IcnsImagePlugin.py
Expand Up @@ -28,6 +28,7 @@
if enable_jpeg2k:
from PIL import Jpeg2KImagePlugin

MAGIC = b"icns"
HEADERSIZE = 8


Expand Down Expand Up @@ -165,7 +166,7 @@ def __init__(self, fobj):
self.dct = dct = {}
self.fobj = fobj
sig, filesize = nextheader(fobj)
if sig != b"icns":
if sig != MAGIC:
raise SyntaxError("not an icns file")
i = HEADERSIZE
while i < filesize:
Expand Down Expand Up @@ -301,14 +302,6 @@ def load(self):
self.load_end()


def _to_int(b):
return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]


MAGIC = b"icns"
TOC = b"TOC "


def _save(im, fp, filename):
"""
Saves the image as a series of PNG files,
Expand All @@ -333,24 +326,22 @@ def _save(im, fp, filename):
entries = []
for index, size in enumerate(sizes):
stream = size_streams[size]
entries.append(
{"type": _to_int(size_str[index]), "size": len(stream), "stream": stream}
)
entries.append({"type": size_str[index], "size": len(stream), "stream": stream})

# Header
fp.write(struct.pack(">i", _to_int(MAGIC)))
fp.write(MAGIC)
fp.write(struct.pack(">i", sum(entry["size"] for entry in entries)))

# TOC
fp.write(struct.pack(">i", _to_int(TOC)))
fp.write(b"TOC ")
fp.write(struct.pack(">i", HEADERSIZE + len(entries) * HEADERSIZE))
for entry in entries:
fp.write(struct.pack(">i", entry["type"]))
fp.write(entry["type"])
fp.write(struct.pack(">i", HEADERSIZE + entry["size"]))

# Data
for entry in entries:
fp.write(struct.pack(">i", entry["type"]))
fp.write(entry["type"])
fp.write(struct.pack(">i", HEADERSIZE + entry["size"]))
fp.write(entry["stream"])

Expand Down

0 comments on commit 8736a74

Please sign in to comment.