diff --git a/win2xcur/align.py b/win2xcur/align.py new file mode 100644 index 0000000..e776ec7 --- /dev/null +++ b/win2xcur/align.py @@ -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) + diff --git a/win2xcur/main/x2wincur.py b/win2xcur/main/x2wincur.py index fabc142..f3cfc6d 100644 --- a/win2xcur/main/x2wincur.py +++ b/win2xcur/main/x2wincur.py @@ -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 @@ -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() @@ -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: diff --git a/win2xcur/main/x2wincurtheme.py b/win2xcur/main/x2wincurtheme.py index 892da4b..6689f06 100644 --- a/win2xcur/main/x2wincurtheme.py +++ b/win2xcur/main/x2wincurtheme.py @@ -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 @@ -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() @@ -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)