1/*  Part of the SDL3 pack for SWI-Prolog.
    2
    3    SDL_surface.h — surface creation and management.
    4
    5    @see https://wiki.libsdl.org/SDL3/SDL_surface
    6*/
    7
    8:- module(sdl_surface, [
    9    sdl_destroysurface/1,
   10    sdl_createsurfacefrom/6
   11]).   12
   13:- use_module(library(sdl/foreign), [
   14    sdl_createsurfacefrom_/6,
   15    sdl_destroysurface/1,
   16    sdl_surface_blob_portray/2
   17]).   18:- reexport(library(sdl/foreign), [sdl_destroysurface/1]).   19:- use_module(library(sdl/pixels), [sdl_pixel_format/2]).   20:- use_module(library(ptr)).   21
   22:- multifile error:has_type/2.   23error:has_type(sdl_surface_blob,  X) :- blob(X, sdl_surface_blob).
   24
   25:- multifile prolog:error_message//1.   26prolog:error_message(type_error(sdl_surface_blob, Culprit)) -->
   27   [ 'sdl_surface_blob, found ~q'-[Culprit] ].
   28
   29user:portray(Surface) :-
   30   blob(Surface, sdl_surface_blob), !,
   31   sdl_surface_blob_portray(current_output, Surface).
 sdl_destroysurface(+Surface:blob) is det
Destroy a previously created surface blob.
See also
- https://wiki.libsdl.org/SDL3/SDL_DestroySurface
 sdl_createsurfacefrom(-Surface:blob, +Width:positive_integer, +Height:positive_integer, +Format:sdl_pixel_format, +Pixels:ptr_blob, +Pitch:integer) is det
Wrap existing pixel data in an SDL surface without copying. Pixels is a PtrBlob (e.g. from cairo_image_surface_get_data) whose pointed-to buffer is borrowed by the surface; the surface keeps a reference to the buffer so it stays valid for the surface's lifetime. Format is one of the atoms enumerated by sdl_pixel_format/2, and Pitch is the byte stride of a row.
See also
- https://wiki.libsdl.org/SDL3/SDL_CreateSurfaceFrom
   50sdl_createsurfacefrom(Surface, Width, Height, Format, Pixels, Pitch) :-
   51   must_be(var, Surface),
   52   must_be(positive_integer, Width),
   53   must_be(positive_integer, Height),
   54   must_be(sdl_pixel_format, Format),
   55   must_be(ptr_blob, Pixels),
   56   must_be(integer, Pitch),
   57   sdl_pixel_format(Format, IntFormat),
   58   sdl_createsurfacefrom_(Surface, Width, Height, IntFormat, Pixels, Pitch)