mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-25 11:33:42 +03:00
Have to guard the ctypes.wintypes import
This commit is contained in:
parent
7a48d7658d
commit
eb80824f51
|
@ -1,17 +1,16 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
|
||||
from PIL import Image, ImageWin
|
||||
|
||||
import sys
|
||||
import ctypes
|
||||
import ctypes.wintypes
|
||||
from io import BytesIO
|
||||
|
||||
# see https://github.com/python-pillow/Pillow/pull/1431#issuecomment-144692652
|
||||
|
||||
if not sys.platform.startswith('win32'):
|
||||
unittest.skip("Win32 only test")
|
||||
if sys.platform.startswith('win32'):
|
||||
import ctypes.wintypes
|
||||
|
||||
class BITMAPFILEHEADER(ctypes.Structure):
|
||||
class BITMAPFILEHEADER(ctypes.Structure):
|
||||
_pack_ = 2
|
||||
_fields_ = [
|
||||
('bfType', ctypes.wintypes.WORD),
|
||||
|
@ -21,7 +20,7 @@ class BITMAPFILEHEADER(ctypes.Structure):
|
|||
('bfOffBits', ctypes.wintypes.DWORD),
|
||||
]
|
||||
|
||||
class BITMAPINFOHEADER(ctypes.Structure):
|
||||
class BITMAPINFOHEADER(ctypes.Structure):
|
||||
_pack_ = 2
|
||||
_fields_ = [
|
||||
('biSize', ctypes.wintypes.DWORD),
|
||||
|
@ -37,32 +36,32 @@ class BITMAPINFOHEADER(ctypes.Structure):
|
|||
('biClrImportant', ctypes.wintypes.DWORD),
|
||||
]
|
||||
|
||||
BI_RGB = 0
|
||||
DIB_RGB_COLORS = 0
|
||||
BI_RGB = 0
|
||||
DIB_RGB_COLORS = 0
|
||||
|
||||
memcpy = ctypes.cdll.msvcrt.memcpy
|
||||
memcpy.argtypes = [ ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t ]
|
||||
memcpy = ctypes.cdll.msvcrt.memcpy
|
||||
memcpy.argtypes = [ ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t ]
|
||||
|
||||
CreateCompatibleDC = ctypes.windll.gdi32.CreateCompatibleDC
|
||||
CreateCompatibleDC.argtypes = [ ctypes.wintypes.HDC ]
|
||||
CreateCompatibleDC.restype = ctypes.wintypes.HDC
|
||||
CreateCompatibleDC = ctypes.windll.gdi32.CreateCompatibleDC
|
||||
CreateCompatibleDC.argtypes = [ ctypes.wintypes.HDC ]
|
||||
CreateCompatibleDC.restype = ctypes.wintypes.HDC
|
||||
|
||||
DeleteDC = ctypes.windll.gdi32.DeleteDC
|
||||
DeleteDC.argtypes = [ ctypes.wintypes.HDC ]
|
||||
DeleteDC = ctypes.windll.gdi32.DeleteDC
|
||||
DeleteDC.argtypes = [ ctypes.wintypes.HDC ]
|
||||
|
||||
SelectObject = ctypes.windll.gdi32.SelectObject
|
||||
SelectObject.argtypes = [ ctypes.wintypes.HDC, ctypes.wintypes.HGDIOBJ ]
|
||||
SelectObject.restype = ctypes.wintypes.HGDIOBJ
|
||||
SelectObject = ctypes.windll.gdi32.SelectObject
|
||||
SelectObject.argtypes = [ ctypes.wintypes.HDC, ctypes.wintypes.HGDIOBJ ]
|
||||
SelectObject.restype = ctypes.wintypes.HGDIOBJ
|
||||
|
||||
DeleteObject = ctypes.windll.gdi32.DeleteObject
|
||||
DeleteObject.argtypes = [ ctypes.wintypes.HGDIOBJ ]
|
||||
DeleteObject = ctypes.windll.gdi32.DeleteObject
|
||||
DeleteObject.argtypes = [ ctypes.wintypes.HGDIOBJ ]
|
||||
|
||||
CreateDIBSection = ctypes.windll.gdi32.CreateDIBSection
|
||||
CreateDIBSection.argtypes = [ ctypes.wintypes.HDC, ctypes.c_void_p, ctypes.c_uint, ctypes.POINTER(ctypes.c_void_p), ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD ]
|
||||
CreateDIBSection.restype = ctypes.wintypes.HBITMAP
|
||||
CreateDIBSection = ctypes.windll.gdi32.CreateDIBSection
|
||||
CreateDIBSection.argtypes = [ ctypes.wintypes.HDC, ctypes.c_void_p, ctypes.c_uint, ctypes.POINTER(ctypes.c_void_p), ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD ]
|
||||
CreateDIBSection.restype = ctypes.wintypes.HBITMAP
|
||||
|
||||
|
||||
def serialize_dib(bi, pixels):
|
||||
def serialize_dib(bi, pixels):
|
||||
bf = BITMAPFILEHEADER()
|
||||
bf.bfType = 0x4d42
|
||||
bf.bfOffBits = ctypes.sizeof(bf) + bi.biSize
|
||||
|
@ -76,7 +75,7 @@ def serialize_dib(bi, pixels):
|
|||
memcpy(bp + bf.bfOffBits, pixels, bi.biSizeImage)
|
||||
return bytes(buf)
|
||||
|
||||
class TestImageWinPointers(PillowTestCase):
|
||||
class TestImageWinPointers(PillowTestCase):
|
||||
def test_pointer(self):
|
||||
im = hopper()
|
||||
(width, height) =im.size
|
||||
|
@ -110,4 +109,3 @@ class TestImageWinPointers(PillowTestCase):
|
|||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# End of file
|
||||
|
|
Loading…
Reference in New Issue
Block a user