This commit is contained in:
jlwoolf 2022-09-27 07:59:41 -06:00
parent da093b9fef
commit 084704d156
2 changed files with 7 additions and 8 deletions

View File

@ -2,7 +2,6 @@ import struct
from io import BytesIO from io import BytesIO
from PIL import BmpImagePlugin, CurImagePlugin, Image, ImageFile from PIL import BmpImagePlugin, CurImagePlugin, Image, ImageFile
from PIL._binary import i16le as i16
from PIL._binary import i32le as i32 from PIL._binary import i32le as i32
from PIL._binary import o8 from PIL._binary import o8
from PIL._binary import o16le as o16 from PIL._binary import o16le as o16
@ -22,7 +21,7 @@ def _save_frame(im: Image.Image, fp: BytesIO, filename: str, info: dict):
) )
h = im.encoderinfo.get("hotspots", [(0, 0) for i in range(len(s))]) h = im.encoderinfo.get("hotspots", [(0, 0) for i in range(len(s))])
if len(hotspots) != len(sizes): if len(h) != len(s):
raise ValueError("Number of hotspots must be equal to number of cursor sizes") raise ValueError("Number of hotspots must be equal to number of cursor sizes")
# sort and remove duplicate sizes # sort and remove duplicate sizes
@ -185,7 +184,6 @@ def _write_multiple_frames(im: Image.Image, fp: BytesIO, filename: str):
fp.seek(fram_end) fp.seek(fram_end)
bmp = im.encoderinfo.get("bitmap_format") == "bmp"
display_rate = im.encoderinfo.get("display_rate", 2) display_rate = im.encoderinfo.get("display_rate", 2)
n_frames = len(frames) n_frames = len(frames)
n_steps = len(seq) if seq else n_frames n_steps = len(seq) if seq else n_frames

View File

@ -39,7 +39,7 @@ def _save(im: Image.Image, fp: BytesIO, filename: str):
) )
h = im.encoderinfo.get("hotspots", [(0, 0) for i in range(len(s))]) h = im.encoderinfo.get("hotspots", [(0, 0) for i in range(len(s))])
if len(hotspots) != len(sizes): if len(h) != len(s):
raise ValueError("Number of hotspots must be equal to number of cursor sizes") raise ValueError("Number of hotspots must be equal to number of cursor sizes")
# sort and remove duplicate sizes # sort and remove duplicate sizes
@ -146,10 +146,11 @@ class CurFile(IcoImagePlugin.IcoFile):
icon_header["dim"] = (icon_header["width"], icon_header["height"]) icon_header["dim"] = (icon_header["width"], icon_header["height"])
icon_header["square"] = icon_header["width"] * icon_header["height"] icon_header["square"] = icon_header["width"] * icon_header["height"]
# TODO: This needs further investigation. Cursor files do not really specify their bpp # TODO: This needs further investigation. Cursor files do not really
# like ICO's as those bits are used for the y_hotspot. For now, bpp is calculated by # specify their bpp like ICO's as those bits are used for the y_hotspot.
# subtracting the AND mask (equal to number of pixels * 1bpp) and dividing by the number # For now, bpp is calculated by subtracting the AND mask (equal to number
# of pixels. This seems to work well so far. # of pixels * 1bpp) and dividing by the number of pixels. This seems
# to work well so far.
BITMAP_INFO_HEADER_SIZE = 40 BITMAP_INFO_HEADER_SIZE = 40
bpp_without_and = ( bpp_without_and = (
(icon_header["size"] - BITMAP_INFO_HEADER_SIZE) * 8 (icon_header["size"] - BITMAP_INFO_HEADER_SIZE) * 8