Use standard function wand.image.Image.import_pixels

This commit is contained in:
Quantum 2020-10-04 02:31:27 -04:00
parent ec5eb36902
commit de7534243d
2 changed files with 5 additions and 22 deletions

View file

@ -2,9 +2,10 @@ import struct
from collections import defaultdict
from typing import Any, Dict, List, Tuple, cast
from wand.image import Image
from win2xcur.cursor import CursorFrame, CursorImage
from win2xcur.parser.base import BaseParser
from win2xcur.utils import image_from_pixels
class XCursorParser(BaseParser):
@ -77,8 +78,10 @@ class XCursorParser(BaseParser):
raise ValueError('Invalid image at %d: expected %d bytes, got %d bytes' %
(image_size, image_size, len(blob)))
image = Image(width=width, height=height)
image.import_pixels(channel_map='BGRA', data=blob)
images_by_size[nominal_size].append(
(CursorImage(image_from_pixels(blob, width, height, 'BGRA', 'char'), (x_offset, y_offset)), delay)
(CursorImage(image.sequence[0], (x_offset, y_offset)), delay)
)
if len(set(map(len, images_by_size.values()))) != 1:

View file

@ -1,20 +0,0 @@
import ctypes
from wand.api import library
from wand.image import Image
from wand.sequence import SingleImage
MagickImportImagePixels = library['MagickImportImagePixels']
MagickImportImagePixels.argtypes = (
ctypes.c_void_p, ctypes.c_ssize_t, ctypes.c_ssize_t, ctypes.c_size_t,
ctypes.c_size_t, ctypes.c_char_p, ctypes.c_int, ctypes.c_void_p
)
StorageType = ('undefined', 'char', 'double', 'float',
'integer', 'long', 'quantum', 'short')
def image_from_pixels(blob: bytes, width: int, height: int, pixel_format: str, pixel_size: str) -> SingleImage:
image = Image(width=width, height=height)
MagickImportImagePixels(image.wand, 0, 0, width, height, pixel_format.encode('ascii'),
StorageType.index(pixel_size), blob)
return image.sequence[0]