mirror of
https://github.com/quantum5/win2xcur.git
synced 2025-04-24 02:01:57 -04:00
Premultiply alpha when converting to Xcursor
This commit is contained in:
parent
b383486d67
commit
b4fc7812e4
|
@ -1 +1,2 @@
|
|||
numpy
|
||||
Wand
|
||||
|
|
2
setup.py
2
setup.py
|
@ -9,7 +9,7 @@ setup(
|
|||
name='win2xcur',
|
||||
version='0.0.3',
|
||||
packages=find_packages(),
|
||||
install_requires=['Wand'],
|
||||
install_requires=['numpy', 'Wand'],
|
||||
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
|
|
10
win2xcur/utils.py
Normal file
10
win2xcur/utils.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
import numpy
|
||||
|
||||
|
||||
def premultiply_alpha(source: bytes) -> bytes:
|
||||
buffer = numpy.frombuffer(source, dtype=numpy.uint8).astype(numpy.double)
|
||||
alpha = buffer[3::4] / 255.0
|
||||
buffer[0::4] *= alpha
|
||||
buffer[1::4] *= alpha
|
||||
buffer[2::4] *= alpha
|
||||
return buffer.astype(numpy.uint8).tobytes()
|
|
@ -4,6 +4,7 @@ from typing import List
|
|||
|
||||
from win2xcur.cursor import CursorFrame
|
||||
from win2xcur.parser import XCursorParser
|
||||
from win2xcur.utils import premultiply_alpha
|
||||
|
||||
|
||||
def to_x11(frames: List[CursorFrame]) -> bytes:
|
||||
|
@ -15,7 +16,7 @@ def to_x11(frames: List[CursorFrame]) -> bytes:
|
|||
header = XCursorParser.IMAGE_HEADER.pack(
|
||||
XCursorParser.IMAGE_HEADER.size,
|
||||
XCursorParser.CHUNK_IMAGE,
|
||||
cursor.image.width,
|
||||
cursor.nominal,
|
||||
1,
|
||||
cursor.image.width,
|
||||
cursor.image.height,
|
||||
|
@ -25,8 +26,8 @@ def to_x11(frames: List[CursorFrame]) -> bytes:
|
|||
)
|
||||
chunks.append((
|
||||
XCursorParser.CHUNK_IMAGE,
|
||||
cursor.image.width,
|
||||
header + bytes(cursor.image.export_pixels(channel_map='BGRA'))
|
||||
cursor.nominal,
|
||||
header + premultiply_alpha(bytes(cursor.image.export_pixels(channel_map='BGRA')))
|
||||
))
|
||||
|
||||
header = XCursorParser.FILE_HEADER.pack(
|
||||
|
|
Loading…
Reference in a new issue