Skip to content

Commit 5b10f5d

Browse files
committed
fix: Disable auto-canvasing on manual canvasing
1 parent 30a8d5a commit 5b10f5d

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

src/clickgen/cursors.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ class CursorImage:
1010
image: Image
1111
hotspot: Tuple[int, int]
1212
nominal: int
13-
14-
def __init__(self, image: Image, hotspot: Tuple[int, int], nominal: int) -> None:
13+
re_canvas: bool
14+
15+
def __init__(
16+
self,
17+
image: Image,
18+
hotspot: Tuple[int, int],
19+
nominal: int,
20+
re_canvas: bool = False,
21+
) -> None:
1522
self.image = image
1623
self.hotspot = hotspot
1724
self.nominal = nominal
25+
self.re_canvas = re_canvas
1826

1927
def __repr__(self) -> str:
20-
return f"CursorImage(image={self.image!r}, hotspot={self.hotspot!r}, nominal={self.nominal!r})"
28+
return f"CursorImage(image={self.image!r}, hotspot={self.hotspot!r}, nominal={self.nominal!r}, re_canvas={self.re_canvas!r})"
2129

2230

2331
class CursorFrame:

src/clickgen/cursors.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class CursorImage:
55
image: Image
66
hotspot: tuple[int, int]
77
nominal: int
8-
def __init__(self, image: Image, hotspot: tuple[int, int], nominal: int) -> None: ...
8+
re_canvas: bool
9+
def __init__(self, image: Image, hotspot: tuple[int, int], nominal: int, re_canvas: bool = False) -> None: ...
910

1011
class CursorFrame:
1112
images: list[CursorImage]

src/clickgen/parser/png.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ def _parse(self) -> List[CursorFrame]:
8585
res_img = self._image.resize((size, size), 1)
8686

8787
if size != canvas_size:
88-
canvas = Image.new("RGBA", (size, size), (0, 0, 0, 0))
88+
canvas = Image.new("RGBA", (canvas_size, canvas_size), (0, 0, 0, 0))
8989
canvas.paste(res_img, (0, 0))
9090
res_img = canvas
9191

9292
res_hotspot = self._cal_hotspot(res_img)
9393
images.append(
94-
CursorImage(image=res_img, hotspot=res_hotspot, nominal=canvas_size)
94+
CursorImage(
95+
image=res_img,
96+
hotspot=res_hotspot,
97+
nominal=canvas_size,
98+
re_canvas=size != canvas_size,
99+
)
95100
)
96101

97102
return [CursorFrame(images, delay=self.delay)]
@@ -109,7 +114,7 @@ def __init__(
109114
self,
110115
blobs: List[bytes],
111116
hotspot: Tuple[int, int],
112-
sizes: Optional[List[int]] = None,
117+
sizes: Optional[List[Union[int, str]]] = None,
113118
delay: Optional[int] = None,
114119
) -> None:
115120
super().__init__(blobs[0])

src/clickgen/parser/png.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class MultiPNGParser(BaseParser):
1919
@classmethod
2020
def can_parse(cls, blobs: list[bytes]) -> bool: ...
2121
frames: Incomplete
22-
def __init__(self, blobs: list[bytes], hotspot: tuple[int, int], sizes: list[int] | None = None, delay: int | None = None) -> None: ...
22+
def __init__(self, blobs: list[bytes], hotspot: tuple[int, int], sizes: list[int | str] | None = None, delay: int | None = None) -> None: ...

src/clickgen/writer/windows.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@ def re_canvas(size: int, img: Image.Image):
4747
# | 256 | 170.666 → 171 | 204.8 → 205 | 256 |
4848

4949
blob = BytesIO()
50-
if width <= 32 or height <= 32:
51-
re_canvas(32, clone).save(blob, "PNG")
52-
elif width <= 48 or height <= 48:
53-
re_canvas(48, clone).save(blob, "PNG")
54-
elif width <= 64 or height <= 64:
55-
re_canvas(64, clone).save(blob, "PNG")
56-
elif width <= 96 or height <= 96:
57-
re_canvas(96, clone).save(blob, "PNG")
58-
elif width <= 128 or height <= 128:
59-
re_canvas(128, clone).save(blob, "PNG")
50+
if not image.re_canvas:
51+
if width <= 32 or height <= 32:
52+
re_canvas(32, clone).save(blob, "PNG")
53+
elif width <= 48 or height <= 48:
54+
re_canvas(48, clone).save(blob, "PNG")
55+
elif width <= 64 or height <= 64:
56+
re_canvas(64, clone).save(blob, "PNG")
57+
elif width <= 96 or height <= 96:
58+
re_canvas(96, clone).save(blob, "PNG")
59+
elif width <= 128 or height <= 128:
60+
re_canvas(128, clone).save(blob, "PNG")
61+
else:
62+
re_canvas(256, clone).save(blob, "PNG")
6063
else:
61-
re_canvas(256, clone).save(blob, "PNG")
64+
image.image.save(blob, "PNG")
6265

6366
blob.seek(0)
6467
image_data.append(blob.read())

0 commit comments

Comments
 (0)