mirror of
https://github.com/quantum5/win2xcur.git
synced 2025-04-24 10:11:57 -04:00
Add ability to scale cursor images
This commit is contained in:
parent
0898f35183
commit
8e71037f5f
|
@ -7,7 +7,7 @@ from multiprocessing.pool import ThreadPool
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
from win2xcur import shadow
|
from win2xcur import scale, shadow
|
||||||
from win2xcur.parser import open_blob
|
from win2xcur.parser import open_blob
|
||||||
from win2xcur.writer import to_x11
|
from win2xcur.writer import to_x11
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ def main() -> None:
|
||||||
help='y-offset of shadow (as fraction of height)')
|
help='y-offset of shadow (as fraction of height)')
|
||||||
parser.add_argument('-c', '--shadow-color', default='#000000',
|
parser.add_argument('-c', '--shadow-color', default='#000000',
|
||||||
help='color of the shadow')
|
help='color of the shadow')
|
||||||
|
parser.add_argument('--scale', default=None, type=float,
|
||||||
|
help='Scale the cursor by the specified factor.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print_lock = Lock()
|
print_lock = Lock()
|
||||||
|
@ -46,6 +48,8 @@ def main() -> None:
|
||||||
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
|
if args.scale:
|
||||||
|
scale.apply_to_frames(cursor.frames, scale=args.scale)
|
||||||
if args.shadow:
|
if args.shadow:
|
||||||
shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius,
|
shadow.apply_to_frames(cursor.frames, color=args.shadow_color, radius=args.shadow_radius,
|
||||||
sigma=args.shadow_sigma, xoffset=args.shadow_x, yoffset=args.shadow_y)
|
sigma=args.shadow_sigma, xoffset=args.shadow_x, yoffset=args.shadow_y)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from multiprocessing.pool import ThreadPool
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import BinaryIO
|
from typing import BinaryIO
|
||||||
|
|
||||||
|
from win2xcur import scale
|
||||||
from win2xcur.parser import open_blob
|
from win2xcur.parser import open_blob
|
||||||
from win2xcur.writer import to_smart
|
from win2xcur.writer import to_smart
|
||||||
|
|
||||||
|
@ -17,6 +18,8 @@ def main() -> None:
|
||||||
help='X11 cursor files to convert (no extension)')
|
help='X11 cursor files to convert (no extension)')
|
||||||
parser.add_argument('-o', '--output', '--output-dir', default=os.curdir,
|
parser.add_argument('-o', '--output', '--output-dir', default=os.curdir,
|
||||||
help='Directory to store converted cursor files.')
|
help='Directory to store converted cursor files.')
|
||||||
|
parser.add_argument('-S', '--scale', default=None, type=float,
|
||||||
|
help='Scale the cursor by the specified factor.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print_lock = Lock()
|
print_lock = Lock()
|
||||||
|
@ -31,6 +34,8 @@ def main() -> None:
|
||||||
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
print(f'Error occurred while processing {name}:', file=sys.stderr)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
else:
|
else:
|
||||||
|
if args.scale:
|
||||||
|
scale.apply_to_frames(cursor.frames, scale=args.scale)
|
||||||
ext, result = to_smart(cursor.frames)
|
ext, result = to_smart(cursor.frames)
|
||||||
output = os.path.join(args.output, os.path.basename(name) + ext)
|
output = os.path.join(args.output, os.path.basename(name) + ext)
|
||||||
with open(output, 'wb') as f:
|
with open(output, 'wb') as f:
|
||||||
|
|
12
win2xcur/scale.py
Normal file
12
win2xcur/scale.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from win2xcur.cursor import CursorFrame
|
||||||
|
|
||||||
|
|
||||||
|
def apply_to_frames(frames: List[CursorFrame], *, scale: float) -> None:
|
||||||
|
for frame in frames:
|
||||||
|
for cursor in frame:
|
||||||
|
cursor.image.scale(
|
||||||
|
int(round(cursor.image.width * scale)),
|
||||||
|
int(round(cursor.image.height) * scale),
|
||||||
|
)
|
Loading…
Reference in a new issue