Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions win2xcur/align.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from typing import List
import bisect

from wand.color import Color

from win2xcur.cursor import CursorFrame

def apply_to_frames(frames: List[CursorFrame]) -> None:
sizes = [32, 48, 64, 96, 128, 256]

for frame in frames:
for cursor in frame:
size_index = bisect.bisect_left(sizes, cursor.image.width)

if size_index < len(sizes):
next_size = sizes[size_index]
cursor.image.background_color = Color("transparent")
cursor.image.extent(width=next_size, height=next_size)

5 changes: 5 additions & 0 deletions win2xcur/main/x2wincur.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import BinaryIO

from win2xcur import scale
from win2xcur import align
from win2xcur.parser import open_blob
from win2xcur.writer import to_smart

Expand All @@ -20,6 +21,8 @@ def main() -> None:
help='Directory to store converted cursor files.')
parser.add_argument('-S', '--scale', default=None, type=float,
help='Scale the cursor by the specified factor.')
parser.add_argument('--align-sizes', action='store_true',
help='Align image sizes to Windows default cursor sizes.')

args = parser.parse_args()
print_lock = Lock()
Expand All @@ -36,6 +39,8 @@ def process(file: BinaryIO) -> None:
else:
if args.scale:
scale.apply_to_frames(cursor.frames, scale=args.scale)
if args.align_sizes:
align.apply_to_frames(cursor.frames)
ext, result = to_smart(cursor.frames)
output = os.path.join(args.output, os.path.basename(name) + ext)
with open(output, 'wb') as f:
Expand Down
12 changes: 10 additions & 2 deletions win2xcur/main/x2wincurtheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from multiprocessing.pool import ThreadPool
from pathlib import Path

from win2xcur import scale
from win2xcur import align, scale
from win2xcur.parser.xtheme import parse_xcursor_theme
from win2xcur.theme import ALL_CURSORS
from win2xcur.writer.inf import export_windows_theme
Expand All @@ -19,6 +19,8 @@ def main() -> None:
help='Directory to store converted cursor files and install.inf.')
parser.add_argument('-S', '--scale', default=None, type=float,
help='Scale the cursor by the specified factor.')
parser.add_argument('--align-sizes', action='store_true',
help='Align image sizes to Windows default cursor sizes.')

args = parser.parse_args()

Expand All @@ -32,8 +34,14 @@ def main() -> None:

def process(name: str) -> None:
cursor = getattr(theme, name)
if args.scale and cursor:

if not cursor:
return

if args.scale:
scale.apply_to_frames(cursor.frames, scale=args.scale)
if args.align_sizes:
align.apply_to_frames(cursor.frames)

with ThreadPool(cpu_count()) as pool:
pool.map(process, ALL_CURSORS)
Expand Down