[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (Guile-SDL) Feature request - Access pixels of a surface
From: |
Thien-Thi Nguyen |
Subject: |
Re: (Guile-SDL) Feature request - Access pixels of a surface |
Date: |
Sat, 01 Jun 2013 17:29:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
() David Thompson <address@hidden>
() Fri, 31 May 2013 21:10:25 -0400
I think read only access would suffice. Returning a SRFI 4 u8vector
sounds good. Copying the pixel data would be the safest approach,
IMO.
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
--
Thien-Thi Nguyen
GPG key: 4C807502
pgpVytNIyfPSK.pgp
Description: PGP signature
- Re: (Guile-SDL) Feature request - Access pixels of a surface,
Thien-Thi Nguyen <=