1from ctypes import CFUNCTYPE, Structure, POINTER, c_int, c_void_p 2from .dll import _bind 3from .stdinc import Uint8, Uint32, SDL_bool 4from .blendmode import SDL_BlendMode 5from .rect import SDL_Rect 6from .pixels import SDL_PixelFormat, SDL_Palette 7from .rwops import SDL_RWops, SDL_RWFromFile 8 9__all__ = [ 10 # Structs & Opaque Types 11 "SDL_BlitMap", "SDL_Surface", 12 13 # Defines 14 "SDL_SWSURFACE", "SDL_PREALLOC", "SDL_RLEACCEL", "SDL_DONTFREE", 15 "SDL_SIMD_ALIGNED", 16 17 # Macro Functions 18 "SDL_MUSTLOCK", 19 20 # Functions 21 "SDL_CreateRGBSurface", "SDL_CreateRGBSurfaceFrom", "SDL_FreeSurface", 22 "SDL_SetSurfacePalette", "SDL_LockSurface", "SDL_UnlockSurface", 23 "SDL_LoadBMP_RW", "SDL_LoadBMP", "SDL_SaveBMP_RW", "SDL_SaveBMP", 24 "SDL_SetSurfaceRLE", "SDL_HasSurfaceRLE", 25 "SDL_HasColorKey", "SDL_SetColorKey", "SDL_GetColorKey", 26 "SDL_SetSurfaceColorMod", "SDL_GetSurfaceColorMod", 27 "SDL_SetSurfaceAlphaMod", "SDL_GetSurfaceAlphaMod", 28 "SDL_SetSurfaceBlendMode", "SDL_GetSurfaceBlendMode", 29 "SDL_SetClipRect", "SDL_GetClipRect", "SDL_ConvertSurface", 30 "SDL_ConvertSurfaceFormat", "SDL_ConvertPixels", "SDL_FillRect", 31 "SDL_FillRects", "SDL_UpperBlit", "SDL_BlitSurface", "SDL_LowerBlit", 32 "SDL_SoftStretch", "SDL_SoftStretchLinear", 33 "SDL_UpperBlitScaled", "SDL_BlitScaled", 34 "SDL_LowerBlitScaled", "SDL_CreateRGBSurfaceWithFormat", 35 "SDL_CreateRGBSurfaceWithFormatFrom", "SDL_DuplicateSurface", 36 "SDL_SetYUVConversionMode", "SDL_GetYUVConversionMode", 37 "SDL_GetYUVConversionModeForResolution", 38 39 # Callback Functions 40 "SDL_Blit" 41] 42 43 44SDL_SWSURFACE = 0 45SDL_PREALLOC = 0x00000001 46SDL_RLEACCEL = 0x00000002 47SDL_DONTFREE = 0x00000004 48SDL_SIMD_ALIGNED = 0x00000008 49 50SDL_MUSTLOCK = lambda s: ((s.flags & SDL_RLEACCEL) != 0) 51 52SDL_YUV_CONVERSION_MODE = c_int 53SDL_YUV_CONVERSION_JPEG = 0 54SDL_YUV_CONVERSION_BT601 = 1 55SDL_YUV_CONVERSION_BT709 = 2 56SDL_YUV_CONVERSION_AUTOMATIC = 3 57 58class SDL_BlitMap(c_void_p): 59 pass 60 61class SDL_Surface(Structure): 62 _fields_ = [("flags", Uint32), 63 ("format", POINTER(SDL_PixelFormat)), 64 ("w", c_int), ("h", c_int), 65 ("pitch", c_int), 66 ("pixels", c_void_p), 67 ("userdata", c_void_p), 68 ("locked", c_int), 69 ("list_blitmap", c_void_p), 70 ("clip_rect", SDL_Rect), 71 ("map", POINTER(SDL_BlitMap)), 72 ("refcount", c_int) 73 ] 74 75SDL_Blit = CFUNCTYPE(c_int, POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)) 76 77SDL_CreateRGBSurface = _bind("SDL_CreateRGBSurface", [Uint32, c_int, c_int, c_int, Uint32, Uint32, Uint32, Uint32], POINTER(SDL_Surface)) 78SDL_CreateRGBSurfaceFrom = _bind("SDL_CreateRGBSurfaceFrom", [c_void_p, c_int, c_int, c_int, c_int, Uint32, Uint32, Uint32, Uint32], POINTER(SDL_Surface)) 79SDL_CreateRGBSurfaceWithFormat = _bind("SDL_CreateRGBSurfaceWithFormat", [Uint32, c_int, c_int, c_int, Uint32], POINTER(SDL_Surface)) 80SDL_CreateRGBSurfaceWithFormatFrom = _bind("SDL_CreateRGBSurfaceWithFormatFrom", [c_void_p, c_int, c_int, c_int, c_int, Uint32], POINTER(SDL_Surface)) 81SDL_FreeSurface = _bind("SDL_FreeSurface", [POINTER(SDL_Surface)]) 82SDL_SetSurfacePalette = _bind("SDL_SetSurfacePalette", [POINTER(SDL_Surface), POINTER(SDL_Palette)], c_int) 83SDL_LockSurface = _bind("SDL_LockSurface", [POINTER(SDL_Surface)], c_int) 84SDL_UnlockSurface = _bind("SDL_UnlockSurface", [POINTER(SDL_Surface)]) 85SDL_DuplicateSurface = _bind("SDL_DuplicateSurface", [POINTER(SDL_Surface)], POINTER(SDL_Surface), added='2.0.6') 86 87SDL_LoadBMP_RW = _bind("SDL_LoadBMP_RW", [POINTER(SDL_RWops), c_int], POINTER(SDL_Surface)) 88SDL_LoadBMP = lambda fname: SDL_LoadBMP_RW(SDL_RWFromFile(fname, b"rb"), 1) 89SDL_SaveBMP_RW = _bind("SDL_SaveBMP_RW", [POINTER(SDL_Surface), POINTER(SDL_RWops), c_int], c_int) 90SDL_SaveBMP = lambda surface, fname: SDL_SaveBMP_RW(surface, SDL_RWFromFile(fname, b"wb"), 1) 91 92SDL_SetSurfaceRLE = _bind("SDL_SetSurfaceRLE", [POINTER(SDL_Surface), c_int], c_int) 93SDL_HasSurfaceRLE = _bind("SDL_HasSurfaceRLE", [POINTER(SDL_Surface)], SDL_bool, added='2.0.14') 94SDL_HasColorKey = _bind("SDL_HasColorKey", [POINTER(SDL_Surface)], SDL_bool, added='2.0.9') 95SDL_SetColorKey = _bind("SDL_SetColorKey", [POINTER(SDL_Surface), c_int, Uint32], c_int) 96SDL_GetColorKey = _bind("SDL_GetColorKey", [POINTER(SDL_Surface), POINTER(Uint32)], c_int) 97SDL_SetSurfaceColorMod = _bind("SDL_SetSurfaceColorMod", [POINTER(SDL_Surface), Uint8, Uint8, Uint8], c_int) 98SDL_GetSurfaceColorMod = _bind("SDL_GetSurfaceColorMod", [POINTER(SDL_Surface), POINTER(Uint8), POINTER(Uint8), POINTER(Uint8)], c_int) 99SDL_SetSurfaceAlphaMod = _bind("SDL_SetSurfaceAlphaMod", [POINTER(SDL_Surface), Uint8], c_int) 100SDL_GetSurfaceAlphaMod = _bind("SDL_GetSurfaceAlphaMod", [POINTER(SDL_Surface), POINTER(Uint8)], c_int) 101SDL_SetSurfaceBlendMode = _bind("SDL_SetSurfaceBlendMode", [POINTER(SDL_Surface), SDL_BlendMode], c_int) 102SDL_GetSurfaceBlendMode = _bind("SDL_GetSurfaceBlendMode", [POINTER(SDL_Surface), POINTER(SDL_BlendMode)], c_int) 103SDL_SetClipRect = _bind("SDL_SetClipRect", [POINTER(SDL_Surface), POINTER(SDL_Rect)], SDL_bool) 104SDL_GetClipRect = _bind("SDL_GetClipRect", [POINTER(SDL_Surface), POINTER(SDL_Rect)]) 105SDL_ConvertSurface = _bind("SDL_ConvertSurface", [POINTER(SDL_Surface), POINTER(SDL_PixelFormat), Uint32], POINTER(SDL_Surface)) 106SDL_ConvertSurfaceFormat = _bind("SDL_ConvertSurfaceFormat", [POINTER(SDL_Surface), Uint32, Uint32], POINTER(SDL_Surface)) 107SDL_ConvertPixels = _bind("SDL_ConvertPixels", [c_int, c_int, Uint32, c_void_p, c_int, Uint32, c_void_p, c_int], c_int) 108SDL_FillRect = _bind("SDL_FillRect", [POINTER(SDL_Surface), POINTER(SDL_Rect), Uint32], c_int) 109SDL_FillRects = _bind("SDL_FillRects", [POINTER(SDL_Surface), POINTER(SDL_Rect), c_int, Uint32], c_int) 110 111SDL_UpperBlit = _bind("SDL_UpperBlit", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int) 112SDL_BlitSurface = SDL_UpperBlit 113SDL_LowerBlit = _bind("SDL_LowerBlit", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int) 114SDL_SoftStretch = _bind("SDL_SoftStretch", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int) 115SDL_SoftStretchLinear = _bind("SDL_SoftStretchLinear", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int, added='2.0.16') 116SDL_UpperBlitScaled = _bind("SDL_UpperBlitScaled", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int) 117SDL_BlitScaled = SDL_UpperBlitScaled 118SDL_LowerBlitScaled = _bind("SDL_LowerBlitScaled", [POINTER(SDL_Surface), POINTER(SDL_Rect), POINTER(SDL_Surface), POINTER(SDL_Rect)], c_int) 119 120SDL_SetYUVConversionMode = _bind("SDL_SetYUVConversionMode", [SDL_YUV_CONVERSION_MODE], None, added='2.0.8') 121SDL_GetYUVConversionMode = _bind("SDL_GetYUVConversionMode", None, SDL_YUV_CONVERSION_MODE, added='2.0.8') 122SDL_GetYUVConversionModeForResolution = _bind("SDL_GetYUVConversionModeForResolution", [c_int, c_int], SDL_YUV_CONVERSION_MODE, added='2.0.8') 123