summaryrefslogtreecommitdiff
path: root/sdl2/surface.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-12-22 09:00:20 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-12-22 09:00:20 -0500
commit8e8fe4275a0db47e31422324c144b2cebee5df63 (patch)
tree469fa30d4a5b3bbc5757641d658acdccda0de620 /sdl2/surface.scm
parent5db39e02c1714a7390cbb71220107289886f42e8 (diff)
surface: Add binding for SDL_ConvertSurfaceFormat.
* sdl2/bindings.scm: Add a ton of pixel format constants. * sdl2/surface.scm: (symbol->sdl-pixel-format, convert-surface-format): New procedures.
Diffstat (limited to 'sdl2/surface.scm')
-rw-r--r--sdl2/surface.scm90
1 files changed, 89 insertions, 1 deletions
diff --git a/sdl2/surface.scm b/sdl2/surface.scm
index 1537c58..98ddf70 100644
--- a/sdl2/surface.scm
+++ b/sdl2/surface.scm
@@ -37,7 +37,9 @@
surface-width
surface-height
surface-pitch
- surface-pixels))
+ surface-pixels
+
+ convert-surface-format))
(define-wrapped-pointer-type <surface>
surface?
@@ -108,3 +110,89 @@ PROC."
(native-endianness)
%pointer-size))))
(pointer->bytevector pixels (* height pitch))))
+
+(define (symbol->sdl-pixel-format sym)
+ (match sym
+ ('index1lsb ffi:SDL_PIXELFORMAT_INDEX1LSB)
+ ('index1msb ffi:SDL_PIXELFORMAT_INDEX1MSB)
+ ('index4lsb ffi:SDL_PIXELFORMAT_INDEX4LSB)
+ ('index4msb ffi:SDL_PIXELFORMAT_INDEX4MSB)
+ ('index8 ffi:SDL_PIXELFORMAT_INDEX8)
+ ('rgb332 ffi:SDL_PIXELFORMAT_RGB332)
+ ('rgb444 ffi:SDL_PIXELFORMAT_RGB444)
+ ('rgb555 ffi:SDL_PIXELFORMAT_RGB555)
+ ('bgr555 ffi:SDL_PIXELFORMAT_BGR555)
+ ('argb4444 ffi:SDL_PIXELFORMAT_ARGB4444)
+ ('rgba4444 ffi:SDL_PIXELFORMAT_RGBA4444)
+ ('abgr4444 ffi:SDL_PIXELFORMAT_ABGR4444)
+ ('bgra4444 ffi:SDL_PIXELFORMAT_BGRA4444)
+ ('argb1555 ffi:SDL_PIXELFORMAT_ARGB1555)
+ ('rgba5551 ffi:SDL_PIXELFORMAT_RGBA5551)
+ ('abgr1555 ffi:SDL_PIXELFORMAT_ABGR1555)
+ ('bgra5551 ffi:SDL_PIXELFORMAT_BGRA5551)
+ ('rgb565 ffi:SDL_PIXELFORMAT_RGB565)
+ ('bgr565 ffi:SDL_PIXELFORMAT_BGR565)
+ ('rgb24 ffi:SDL_PIXELFORMAT_RGB24)
+ ('bgr24 ffi:SDL_PIXELFORMAT_BGR24)
+ ('rgb888 ffi:SDL_PIXELFORMAT_RGB888)
+ ('rgbx8888 ffi:SDL_PIXELFORMAT_RGBX8888)
+ ('bgr888 ffi:SDL_PIXELFORMAT_BGR888)
+ ('bgrx8888 ffi:SDL_PIXELFORMAT_BGRX8888)
+ ('argb8888 ffi:SDL_PIXELFORMAT_ARGB8888)
+ ('rgba8888 ffi:SDL_PIXELFORMAT_RGBA8888)
+ ('abgr8888 ffi:SDL_PIXELFORMAT_ABGR8888)
+ ('bgra8888 ffi:SDL_PIXELFORMAT_BGRA8888)
+ ('argb2101010 ffi:SDL_PIXELFORMAT_ARGB2101010)
+ ('yv12 ffi:SDL_PIXELFORMAT_YV12)
+ ('iyuv ffi:SDL_PIXELFORMAT_IYUV)
+ ('yuy2 ffi:SDL_PIXELFORMAT_YUY2)
+ ('uyvy ffi:SDL_PIXELFORMAT_UYVY)
+ ('yvyu ffi:SDL_PIXELFORMAT_YVYU)))
+
+(define (convert-surface-format surface format)
+ "Convert the pixels in SURFACE to FORMAT, a symbol representing a
+specific pixel format, and return a new surface object.
+
+Valid format types are:
+
+- index1lsb
+- index1msb
+- index4lsb
+- index4msb
+- index8
+- rgb332
+- rgb444
+- rgb555
+- bgr555
+- argb4444
+- rgba4444
+- abgr4444
+- bgra4444
+- argb1555
+- rgba5551
+- abgr1555
+- bgra5551
+- rgb565
+- bgr565
+- rgb24
+- bgr24
+- rgb888
+- rgbx8888
+- bgr888
+- bgrx8888
+- argb8888
+- rgba8888
+- abgr8888
+- bgra8888
+- argb2101010
+- yv12
+- iyuv
+- yuy2
+- uyvy
+- yvyu"
+ (let ((ptr (ffi:sdl-convert-surface-format (unwrap-surface surface)
+ (symbol->sdl-pixel-format format)
+ 0)))
+ (if (null-pointer? ptr)
+ (sdl-error "convert-surface-format" "failed to convert surface format")
+ (wrap-surface surface))))