Skip to content

Commit 8736a74

Browse files
committed
Removed _to_int
1 parent 90ece13 commit 8736a74

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/PIL/IcnsImagePlugin.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if enable_jpeg2k:
2929
from PIL import Jpeg2KImagePlugin
3030

31+
MAGIC = b"icns"
3132
HEADERSIZE = 8
3233

3334

@@ -165,7 +166,7 @@ def __init__(self, fobj):
165166
self.dct = dct = {}
166167
self.fobj = fobj
167168
sig, filesize = nextheader(fobj)
168-
if sig != b"icns":
169+
if sig != MAGIC:
169170
raise SyntaxError("not an icns file")
170171
i = HEADERSIZE
171172
while i < filesize:
@@ -301,14 +302,6 @@ def load(self):
301302
self.load_end()
302303

303304

304-
def _to_int(b):
305-
return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3]
306-
307-
308-
MAGIC = b"icns"
309-
TOC = b"TOC "
310-
311-
312305
def _save(im, fp, filename):
313306
"""
314307
Saves the image as a series of PNG files,
@@ -333,24 +326,22 @@ def _save(im, fp, filename):
333326
entries = []
334327
for index, size in enumerate(sizes):
335328
stream = size_streams[size]
336-
entries.append(
337-
{"type": _to_int(size_str[index]), "size": len(stream), "stream": stream}
338-
)
329+
entries.append({"type": size_str[index], "size": len(stream), "stream": stream})
339330

340331
# Header
341-
fp.write(struct.pack(">i", _to_int(MAGIC)))
332+
fp.write(MAGIC)
342333
fp.write(struct.pack(">i", sum(entry["size"] for entry in entries)))
343334

344335
# TOC
345-
fp.write(struct.pack(">i", _to_int(TOC)))
336+
fp.write(b"TOC ")
346337
fp.write(struct.pack(">i", HEADERSIZE + len(entries) * HEADERSIZE))
347338
for entry in entries:
348-
fp.write(struct.pack(">i", entry["type"]))
339+
fp.write(entry["type"])
349340
fp.write(struct.pack(">i", HEADERSIZE + entry["size"]))
350341

351342
# Data
352343
for entry in entries:
353-
fp.write(struct.pack(">i", entry["type"]))
344+
fp.write(entry["type"])
354345
fp.write(struct.pack(">i", HEADERSIZE + entry["size"]))
355346
fp.write(entry["stream"])
356347

0 commit comments

Comments
 (0)