All pastes #415915 Raw Edit

Something

public text v1 · immutable
#415915 ·published 2007-03-29 22:59 UTC
rendered paste body
#include <libgnome/libgnome.h>
#include <libgnomeui/libgnomeui.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-mime.h>

#include <stdio.h>
#include <glib/gprintf.h>

typedef struct
	{
		char *filename;
		gboolean has_alpha;
		int bits_per_sample;
		int width;
		int height;
		GdkColorspace colorspace;
	} info_pixbuf;

info_pixbuf info_pixbuf_new(void)
{
	info_pixbuf info;
	info.filename = NULL;
	info.has_alpha = TRUE;
	info.bits_per_sample = 8;
	info.width = 0;
	info.height = 0;
	info.colorspace = GDK_COLORSPACE_RGB;

	return info;
}


int
main (int argc, char **argv)
{

	GOptionContext *context = NULL;
	info_pixbuf fond;
	GdkPixbuf *pixbuf;

	fond = info_pixbuf_new();

	const GOptionEntry entries[]=
	{
		{"alpha", 'a', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_NONE, &fond.has_alpha, "fond transparent", NULL},
		{"width", 'w', 0, G_OPTION_ARG_INT, &fond.width, "width", NULL},
		{"height", 'h', 0, G_OPTION_ARG_INT, &fond.height, "height", NULL},
		{"nom de fichier", 	'f', G_OPTION_FLAG_FILENAME , G_OPTION_ARG_STRING, &fond.filename, "Nom de l'image de fond", NULL},
		{NULL, 0, 0, 0, NULL, NULL, NULL}
	};



	context = g_option_context_new("Pelemele");

	g_option_context_add_main_entries(context, entries, NULL);

	gnome_program_init("Pelemele", "0.0.1", LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_GOPTION_CONTEXT, context, GNOME_PARAM_NONE);



	if (fond.width <= 0)
	{
		g_printerr("width <= 0");
		g_option_context_free(context);
		exit(1);
	}

	if (fond.height <= 0)
	{
		g_printerr("height <= 0");
		g_option_context_free(context);
		exit(1);
	}

	pixbuf = gdk_pixbuf_new(fond.colorspace, fond.has_alpha, fond.bits_per_sample, fond.width, fond.height);
	//gdk_pixbuf_copy_area(src_pixbuf, src_x, src_y, width, height, pixbuf, dest_x, dest_y);

	if (fond.filename == NULL)
	{
		g_printerr("filename == NULL");
		g_option_context_free(context);
		gdk_pixbuf_unref(pixbuf);
		exit(1);
	}

	gdk_pixbuf_savev(pixbuf, fond.filename,  "png" , NULL, NULL, NULL);
	gdk_pixbuf_unref(pixbuf);
	g_free(fond.filename);

	g_option_context_free(context);


}