OK, sounds like a good way to start. Here is a sketch that you can copy
into src/sdlsurface.c somewhere:
PRIMPROC
(surface_pixels, "surface-pixels", 1, 0, 0,
(SCM surface),
doc: /***********
Return the pixel data of @var{surface} as a new SRFI 4 u8vector.
If there are problems, return @code{#f}. */)
{
#define FUNC_NAME s_surface_pixels
SDL_Surface *src;
size_t len;
void *pixels;
ASSERT_SURFACE (surface, 1);
src = UNPACK_SURFACE (surface);
len = src->w * src->h * src->format->BytesPerPixel;
if (! (pixels = malloc (len)))
RETURN_FALSE;
if (! memcpy (pixels, src->pixels, len))
{
/* Should never get here, since ‘memcpy’ returns ‘pixels’,
but who knows? */
free (pixels);
RETURN_FALSE;
}
return scm_take_u8vector (pixels, len);
#undef FUNC_NAME
}
You can modify test/image.scm to test it like so:
(let* ((gnu-head (SDL:load-image (datafile "gnu-goatee.jpg")))
(v (SDL:surface-pixels gnu-head)))
(fso "gnu-head => ~S (pixels: ~A)~%"
gnu-head
(if (u8vector? v)
(fs "u8vector length ~A" (u8vector-length v))
'unavailable))
(SDL:blit-surface gnu-head gnu-rect (SDL:get-video-surface) gnu-rect))
If it works for you, i'll include it in the next release. On the other
hand, if there are problems, please let me know soon so that we can fix
those first, and THEN i'll include it in the next release. :-D