/* * Copyright (C) 2006 Benjamin Otte * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include void usage (const char *filename) { g_print ("usage: %s GAMENAME-OR-FILE PNG-FILENAME\n\n", filename); } int main (int argc, char** argv) { const char *game_name, *png_file; int width = 48, height = 48; GError *error = NULL; cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; GameGame *game; g_type_init (); if (argc != 3) { usage (argv[0]); return 1; } game_name = argv[1]; png_file = argv[2]; if (g_str_has_suffix (game_name, "." G_MODULE_SUFFIX)) { game = game_game_load_from_file (game_name, &error); } else { game = game_game_load (game_name, &error); } if (game == NULL) { g_print ("Could not load game '%s': %s\n", game_name, error->message); g_error_free (error); return 1; } if (game->icon == NULL) { g_print ("Game '%s' has no icon\n", game_name); return 1; } surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cr = cairo_create (surface); cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.0); cairo_paint (cr); cairo_scale (cr, width, height); game_graphic_draw (game->icon, cr); cairo_destroy (cr); status = cairo_surface_write_to_png (surface, png_file); cairo_surface_destroy (surface); if (status != CAIRO_STATUS_SUCCESS) { g_print ("Errror saving icon to '%s': %s\n", png_file, cairo_status_to_string (status)); return 1; } g_object_unref (game); return 0; }