diff options
Diffstat (limited to 'sdl2')
-rw-r--r-- | sdl2/bindings.scm | 45 | ||||
-rw-r--r-- | sdl2/surface.scm | 90 |
2 files changed, 134 insertions, 1 deletions
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm index 1672b0d..79fbf92 100644 --- a/sdl2/bindings.scm +++ b/sdl2/bindings.scm @@ -847,6 +847,48 @@ RETURN-TYPE and accept arguments of ARG-TYPES." ;;; +;;; Pixels +;;; + +(define-public SDL_PIXELFORMAT_UNKNOWN 0) +(define-public SDL_PIXELFORMAT_INDEX1LSB 286261504) +(define-public SDL_PIXELFORMAT_INDEX1MSB 287310080) +(define-public SDL_PIXELFORMAT_INDEX4LSB 303039488) +(define-public SDL_PIXELFORMAT_INDEX4MSB 304088064) +(define-public SDL_PIXELFORMAT_INDEX8 318769153) +(define-public SDL_PIXELFORMAT_RGB332 336660481) +(define-public SDL_PIXELFORMAT_RGB444 353504258) +(define-public SDL_PIXELFORMAT_RGB555 353570562) +(define-public SDL_PIXELFORMAT_BGR555 357764866) +(define-public SDL_PIXELFORMAT_ARGB4444 355602434) +(define-public SDL_PIXELFORMAT_RGBA4444 356651010) +(define-public SDL_PIXELFORMAT_ABGR4444 359796738) +(define-public SDL_PIXELFORMAT_BGRA4444 360845314) +(define-public SDL_PIXELFORMAT_ARGB1555 355667970) +(define-public SDL_PIXELFORMAT_RGBA5551 356782082) +(define-public SDL_PIXELFORMAT_ABGR1555 359862274) +(define-public SDL_PIXELFORMAT_BGRA5551 360976386) +(define-public SDL_PIXELFORMAT_RGB565 353701890) +(define-public SDL_PIXELFORMAT_BGR565 357896194) +(define-public SDL_PIXELFORMAT_RGB24 386930691) +(define-public SDL_PIXELFORMAT_BGR24 390076419) +(define-public SDL_PIXELFORMAT_RGB888 370546692) +(define-public SDL_PIXELFORMAT_RGBX8888 371595268) +(define-public SDL_PIXELFORMAT_BGR888 374740996) +(define-public SDL_PIXELFORMAT_BGRX8888 375789572) +(define-public SDL_PIXELFORMAT_ARGB8888 372645892) +(define-public SDL_PIXELFORMAT_RGBA8888 373694468) +(define-public SDL_PIXELFORMAT_ABGR8888 376840196) +(define-public SDL_PIXELFORMAT_BGRA8888 377888772) +(define-public SDL_PIXELFORMAT_ARGB2101010 372711428) +(define-public SDL_PIXELFORMAT_YV12 842094169) +(define-public SDL_PIXELFORMAT_IYUV 1448433993) +(define-public SDL_PIXELFORMAT_YUY2 844715353) +(define-public SDL_PIXELFORMAT_UYVY 1498831189) +(define-public SDL_PIXELFORMAT_YVYU 1431918169) + + +;;; ;;; Surface ;;; @@ -856,6 +898,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-foreign sdl-load-bmp-rw '* "SDL_LoadBMP_RW" (list '* int)) +(define-foreign sdl-convert-surface-format + '* "SDL_ConvertSurfaceFormat" (list '* uint32 uint32)) + ;;; ;;; Audio 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)))) |