Skip to content

Instantly share code, notes, and snippets.

@davexunit
Last active December 18, 2015 23:48
Show Gist options
  • Save davexunit/5863630 to your computer and use it in GitHub Desktop.
Save davexunit/5863630 to your computer and use it in GitHub Desktop.
guile-sdl surface-pixels patch
--- src/sdlsurface.c 2013-05-24 18:03:03.156043808 -0400
+++ src/sdlsurface.c 2013-06-06 21:19:03.591137715 -0400
@@ -170,6 +170,33 @@
#undef FUNC_NAME
}
+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
+ }
/* utilities */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment