mirror of
https://github.com/quantum5/win2xcur.git
synced 2025-08-02 11:58:13 -04:00
13 lines
355 B
Python
13 lines
355 B
Python
from typing import Any
|
|
|
|
import numpy as np
|
|
|
|
|
|
def premultiply_alpha(source: bytes) -> bytes:
|
|
buffer: np.ndarray[Any, np.dtype[np.double]] = np.frombuffer(source, dtype=np.uint8).astype(np.double)
|
|
alpha = buffer[3::4] / 255.0
|
|
buffer[0::4] *= alpha
|
|
buffer[1::4] *= alpha
|
|
buffer[2::4] *= alpha
|
|
return buffer.astype(np.uint8).tobytes()
|