mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 10:56:18 +03:00
Removed _to_int
This commit is contained in:
parent
90ece137b0
commit
8736a745f4
|
@ -28,6 +28,7 @@ enable_jpeg2k = features.check_codec("jpg_2000")
|
||||||
if enable_jpeg2k:
|
if enable_jpeg2k:
|
||||||
from PIL import Jpeg2KImagePlugin
|
from PIL import Jpeg2KImagePlugin
|
||||||
|
|
||||||
|
MAGIC = b"icns"
|
||||||
HEADERSIZE = 8
|
HEADERSIZE = 8
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ class IcnsFile:
|
||||||
self.dct = dct = {}
|
self.dct = dct = {}
|
||||||
self.fobj = fobj
|
self.fobj = fobj
|
||||||
sig, filesize = nextheader(fobj)
|
sig, filesize = nextheader(fobj)
|
||||||
if sig != b"icns":
|
if sig != MAGIC:
|
||||||
raise SyntaxError("not an icns file")
|
raise SyntaxError("not an icns file")
|
||||||
i = HEADERSIZE
|
i = HEADERSIZE
|
||||||
while i < filesize:
|
while i < filesize:
|
||||||
|
@ -301,14 +302,6 @@ class IcnsImageFile(ImageFile.ImageFile):
|
||||||
self.load_end()
|
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):
|
def _save(im, fp, filename):
|
||||||
"""
|
"""
|
||||||
Saves the image as a series of PNG files,
|
Saves the image as a series of PNG files,
|
||||||
|
@ -333,24 +326,22 @@ def _save(im, fp, filename):
|
||||||
entries = []
|
entries = []
|
||||||
for index, size in enumerate(sizes):
|
for index, size in enumerate(sizes):
|
||||||
stream = size_streams[size]
|
stream = size_streams[size]
|
||||||
entries.append(
|
entries.append({"type": size_str[index], "size": len(stream), "stream": stream})
|
||||||
{"type": _to_int(size_str[index]), "size": len(stream), "stream": stream}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Header
|
# Header
|
||||||
fp.write(struct.pack(">i", _to_int(MAGIC)))
|
fp.write(MAGIC)
|
||||||
fp.write(struct.pack(">i", sum(entry["size"] for entry in entries)))
|
fp.write(struct.pack(">i", sum(entry["size"] for entry in entries)))
|
||||||
|
|
||||||
# TOC
|
# TOC
|
||||||
fp.write(struct.pack(">i", _to_int(TOC)))
|
fp.write(b"TOC ")
|
||||||
fp.write(struct.pack(">i", HEADERSIZE + len(entries) * HEADERSIZE))
|
fp.write(struct.pack(">i", HEADERSIZE + len(entries) * HEADERSIZE))
|
||||||
for entry in entries:
|
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(struct.pack(">i", HEADERSIZE + entry["size"]))
|
||||||
|
|
||||||
# Data
|
# Data
|
||||||
for entry in entries:
|
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(struct.pack(">i", HEADERSIZE + entry["size"]))
|
||||||
fp.write(entry["stream"])
|
fp.write(entry["stream"])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user