2 * Copyright (C) 2008 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <SDL_image.h>
27 CairoFromSDL (SDL_Surface *surface)
29 return cairo_image_surface_create_for_data (surface->pixels,
31 surface->w, surface->h,
36 CairoToSDL (cairo_surface_t *surface)
38 return SDL_CreateRGBSurfaceFrom (cairo_image_surface_get_data (surface),
39 cairo_image_surface_get_width (surface),
40 cairo_image_surface_get_height (surface),
42 cairo_image_surface_get_stride (surface),
43 0x00ff0000, 0x0000ff00, 0x000000ff,
48 CairoTarget (SDL_Surface *image, double scale)
50 unsigned char *data = NULL;
51 cairo_surface_t *surface = NULL;
53 cairo_surface_t *source;
58 data = malloc (w * h * 4);
59 surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
61 ctx = cairo_create (surface);
62 cairo_scale (ctx, scale, scale);
63 source = CairoFromSDL (image);
64 cairo_set_source_surface (ctx, source, 0, 0);
66 cairo_surface_destroy (source);
67 dest = CairoToSDL (surface);
68 cairo_surface_destroy (surface);
74 CairoScale (SDL_Surface *image, double scale)
78 SDL_Surface *scaled_image;
79 newfmt = SDL_CreateRGBSurface (SDL_SWSURFACE, 1, 1,
85 slice = SDL_ConvertSurface (image, newfmt->format, SDL_SWSURFACE);
86 SDL_FreeSurface (newfmt);
87 scaled_image = CairoTarget (slice, scale);
88 SDL_FreeSurface (slice);