/* * Gnome Set game - img.c * Copyright 2007 Kirill Gorelov * * 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 of the License, 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. */ #include "img.h" #include "debug.h" Img* img_new(void) { Img *image; DBG(IMG_DEBUG, "Creating new image...\n"); image = g_new(Img, 1); image->width = 0; image->height = 0; image->pixbuf = NULL; return image; } Img* img_new_from_file(const gchar *filename) { Img *image; GError *err = NULL; DBG(IMG_DEBUG, "Loading image from file %s\n", filename); if (filename == NULL) return NULL; image = img_new(); image->pixbuf = gdk_pixbuf_new_from_file(filename, &err); if (image->pixbuf == NULL) { printf("%s:: Error: %s\n", __func__, err->message); g_assert_not_reached(); } image->width = gdk_pixbuf_get_width(image->pixbuf); image->height = gdk_pixbuf_get_height(image->pixbuf); return image; } GdkPixbuf* img_render (Img *image, gint width, gint height) { GdkPixbuf *pixbuf; g_return_val_if_fail (width > 0 && height > 0, NULL); g_return_val_if_fail (image != NULL, NULL); pixbuf = gdk_pixbuf_scale_simple (image->pixbuf, width, height, GDK_INTERP_BILINEAR); return pixbuf; } void img_free(Img *image) { g_object_unref(image->pixbuf); g_free(image); }