[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] pygame.image.frombuffer problems
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] pygame.image.frombuffer problems
- From: Norbert Sebok <seboknorbi@xxxxxxxxx>
- Date: Mon, 2 Jan 2006 06:42:18 +0100
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Mon, 02 Jan 2006 00:42:23 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=GDvi85VOUWILG8u/yYU59G/RRu39bfcUSHUXiU5PSOKWha9+NtHIIyeMdOZ978OuuB9vZutkg25ORJBmzaeCKnZkP2CcAmXmhQPI44IWdJaBhIVDXI2eeefhyzrbEiOoL/IqCAM+fPbmTdc13RoLc/edbYkowXmOcZjYjs+/jBQ=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
> I want a more effecient way of using pygame and pycairo together.
The solution is surprisingly easy and very fast: Cairo can draw
directly to an SDL surface.
I don't know if it's work on every platform, I use it only on Ubuntu
on x86 machines. But maybe it can work everywhere with the help of
SDL_PixelFormat's masks.
The main code in C:
cairo_surface_t *
create_for_sdl_data(SDL_Surface *sdl_surface)
{
int btpp = 4;
cairo_format_t format = CAIRO_FORMAT_RGB24;
unsigned char *data = sdl_surface->pixels;
int width = sdl_surface->w;
int height = sdl_surface->h;
int stride = width * btpp;
cairo_surface_t* s;
s = cairo_image_surface_create_for_data (data,format,width,height,stride);
return s;
}
and in Python it's as easy as:
screen = pygame.display.set_mode((width, height))
cairo_surface = create_for_sdl_data(screen)
ctx = cairo.Context(cairo_surface)
The full code is here: https://svn.synch.hu:8081/svn/hobby/cairo_sdl/
Be aware! This is my first C program.. Suggestions are welcome.
Norbert Sebok