mirror of
https://github.com/quantum5/win2xcur.git
synced 2025-08-04 00:58:53 -04:00
13 lines
337 B
Python
13 lines
337 B
Python
from typing import cast
|
|
|
|
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 cast(bytes, buffer.astype(numpy.uint8).tobytes())
|