2001-06-26 20:56:32 +00:00
|
|
|
/* Gdk-Pixbuf-CSource - GdkPixbuf based image CSource generator
|
|
|
|
* Copyright (C) 1999, 2001 Tim Janik
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2004-03-06 03:38:59 +00:00
|
|
|
#include <config.h>
|
2001-06-26 20:56:32 +00:00
|
|
|
|
2001-08-23 15:26:49 +00:00
|
|
|
#include "../gtk/gtkversion.h" /* versioning */
|
2001-06-26 20:56:32 +00:00
|
|
|
#include "gdk-pixbuf.h"
|
|
|
|
#include "gdk-pixdata.h"
|
2002-12-15 01:49:01 +00:00
|
|
|
#include <glib/gprintf.h>
|
2001-07-18 04:25:04 +00:00
|
|
|
#include <stdlib.h>
|
2001-06-26 20:56:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* --- defines --- */
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "Gdk-Pixbuf-CSource"
|
|
|
|
#define PRG_NAME "gdk-pixbuf-csource"
|
|
|
|
#define PKG_NAME "Gtk+"
|
|
|
|
#define PKG_HTTP_HOME "http://www.gtk.org"
|
|
|
|
|
|
|
|
|
|
|
|
/* --- prototypes --- */
|
|
|
|
static void parse_args (gint *argc_p,
|
|
|
|
gchar ***argv_p);
|
|
|
|
static void print_blurb (FILE *bout,
|
|
|
|
gboolean print_help);
|
|
|
|
|
|
|
|
|
|
|
|
/* --- variables --- */
|
|
|
|
static guint gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
|
|
|
|
static guint gen_ctype = GDK_PIXDATA_DUMP_GTYPES | GDK_PIXDATA_DUMP_STATIC | GDK_PIXDATA_DUMP_CONST;
|
|
|
|
static gboolean use_rle = TRUE;
|
|
|
|
static gboolean with_decoder = FALSE;
|
|
|
|
static gchar *image_name = "my_pixbuf";
|
|
|
|
static gboolean build_list = FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
/* --- functions --- */
|
|
|
|
static void
|
|
|
|
print_csource (FILE *f_out,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
GdkPixdata pixdata;
|
|
|
|
gpointer free_me;
|
|
|
|
GString *gstring;
|
|
|
|
|
|
|
|
free_me = gdk_pixdata_from_pixbuf (&pixdata, pixbuf, use_rle);
|
|
|
|
gstring = gdk_pixdata_to_csource (&pixdata, image_name,
|
|
|
|
gen_type | gen_ctype |
|
|
|
|
(with_decoder ? GDK_PIXDATA_DUMP_RLE_DECODER : 0));
|
|
|
|
|
2002-12-15 01:49:01 +00:00
|
|
|
g_fprintf (f_out, "%s\n", gstring->str);
|
2001-06-26 20:56:32 +00:00
|
|
|
|
|
|
|
g_free (free_me);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* initialize glib/GdkPixbuf */
|
2001-06-29 02:53:01 +00:00
|
|
|
g_type_init ();
|
2001-06-26 20:56:32 +00:00
|
|
|
|
|
|
|
/* parse args and do fast exits */
|
|
|
|
parse_args (&argc, &argv);
|
|
|
|
|
|
|
|
if (!build_list)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
print_blurb (stderr, TRUE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
|
|
|
|
if (!pixbuf)
|
|
|
|
{
|
2002-12-15 01:49:01 +00:00
|
|
|
g_fprintf (stderr, "failed to load \"%s\": %s\n",
|
2001-06-26 20:56:32 +00:00
|
|
|
argv[1],
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_csource (stdout, pixbuf);
|
Remove assorted G_OBJECT casts where unnecessary.
2001-12-13 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gdk-pixbuf-animation.c, gdk-pixbuf-loader.c, gdk-pixpuf.c,
io-gif-animation.c, io-gif.c, io-tiff.c, test-loaders.c: Remove
assorted G_OBJECT casts where unnecessary.
* gdk-pixbuf-loader.c: Call g_object_ref and g_object_unref
instead of gdk_pixbuf_animation_ref and gdk_pixbuf_animation_unref
resp.
* gdk-pixbuf-csource.c, io-bmp.c, io-gif-animation.c, io-ico.c,
io-jpeg.c, io-png.c, io-pnm.c, io-ras.c, io-tga.c, io-wbmp.c,
io-xbm.c, io-xpm.c, test-gdk-pixbuf.c: Dito for gdk_pixbuf_ref and
gdk_pixbuf_unref.
* Makefile.am, pixops/Makefile.am: Compile everything with
-DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED
* gdk-pixdata.c: Use g_ascii_strup() instead of g_strup().
* io-xpm.c: Use g_ascii_strcasecmp() instead of g_strcasecmp().
* demos/testpixbuf-drawable.c, demos/testpixbuf-save.c,
demos/testpixbuf-scale.c, demos/testpixbuf.c: Call g_object_ref
and g_object_unref instead of gdk_pixbuf_ref and gdk_pixbuf_unref
resp.
2001-12-13 21:22:12 +00:00
|
|
|
g_object_unref (pixbuf);
|
2001-06-26 20:56:32 +00:00
|
|
|
}
|
|
|
|
else /* parse name, file pairs */
|
|
|
|
{
|
|
|
|
gchar **p = argv + 1;
|
|
|
|
guint j = argc - 1;
|
|
|
|
gboolean toggle = FALSE;
|
|
|
|
|
|
|
|
while (j--)
|
|
|
|
{
|
|
|
|
if (!toggle)
|
|
|
|
image_name = *p++;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (*p, &error);
|
|
|
|
if (!pixbuf)
|
|
|
|
{
|
2002-12-15 01:49:01 +00:00
|
|
|
g_fprintf (stderr, "failed to load \"%s\": %s\n",
|
2001-06-26 20:56:32 +00:00
|
|
|
*p,
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
print_csource (stdout, pixbuf);
|
Remove assorted G_OBJECT casts where unnecessary.
2001-12-13 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gdk-pixbuf-animation.c, gdk-pixbuf-loader.c, gdk-pixpuf.c,
io-gif-animation.c, io-gif.c, io-tiff.c, test-loaders.c: Remove
assorted G_OBJECT casts where unnecessary.
* gdk-pixbuf-loader.c: Call g_object_ref and g_object_unref
instead of gdk_pixbuf_animation_ref and gdk_pixbuf_animation_unref
resp.
* gdk-pixbuf-csource.c, io-bmp.c, io-gif-animation.c, io-ico.c,
io-jpeg.c, io-png.c, io-pnm.c, io-ras.c, io-tga.c, io-wbmp.c,
io-xbm.c, io-xpm.c, test-gdk-pixbuf.c: Dito for gdk_pixbuf_ref and
gdk_pixbuf_unref.
* Makefile.am, pixops/Makefile.am: Compile everything with
-DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED
* gdk-pixdata.c: Use g_ascii_strup() instead of g_strup().
* io-xpm.c: Use g_ascii_strcasecmp() instead of g_strcasecmp().
* demos/testpixbuf-drawable.c, demos/testpixbuf-save.c,
demos/testpixbuf-scale.c, demos/testpixbuf.c: Call g_object_ref
and g_object_unref instead of gdk_pixbuf_ref and gdk_pixbuf_unref
resp.
2001-12-13 21:22:12 +00:00
|
|
|
g_object_unref (pixbuf);
|
2001-06-26 20:56:32 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
toggle = !toggle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_args (gint *argc_p,
|
|
|
|
gchar ***argv_p)
|
|
|
|
{
|
|
|
|
guint argc = *argc_p;
|
|
|
|
gchar **argv = *argv_p;
|
|
|
|
guint i, e;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (strcmp ("--macros", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
gen_type = GDK_PIXDATA_DUMP_MACROS;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--struct", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
gen_type = GDK_PIXDATA_DUMP_PIXDATA_STRUCT;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--stream", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--rle", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
use_rle = TRUE;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--raw", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
use_rle = FALSE;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--extern", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
gen_ctype &= ~GDK_PIXDATA_DUMP_STATIC;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--static", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
gen_ctype |= GDK_PIXDATA_DUMP_STATIC;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--decoder", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
with_decoder = TRUE;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if ((strcmp ("--name", argv[i]) == 0) ||
|
|
|
|
(strncmp ("--name=", argv[i], 7) == 0))
|
|
|
|
{
|
|
|
|
gchar *equal = argv[i] + 6;
|
|
|
|
|
|
|
|
if (*equal == '=')
|
|
|
|
image_name = g_strdup (equal + 1);
|
|
|
|
else if (i + 1 < argc)
|
|
|
|
{
|
|
|
|
image_name = g_strdup (argv[i + 1]);
|
|
|
|
argv[i] = NULL;
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("--build-list", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
build_list = TRUE;
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
else if (strcmp ("-h", argv[i]) == 0 ||
|
|
|
|
strcmp ("--help", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
print_blurb (stderr, TRUE);
|
|
|
|
argv[i] = NULL;
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else if (strcmp ("-v", argv[i]) == 0 ||
|
|
|
|
strcmp ("--version", argv[i]) == 0)
|
|
|
|
{
|
|
|
|
print_blurb (stderr, FALSE);
|
|
|
|
argv[i] = NULL;
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
|
|
|
|
{
|
|
|
|
GLogLevelFlags fatal_mask;
|
|
|
|
|
|
|
|
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
|
|
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
|
|
g_log_set_always_fatal (fatal_mask);
|
|
|
|
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
e = 0;
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
if (e)
|
|
|
|
{
|
|
|
|
if (argv[i])
|
|
|
|
{
|
|
|
|
argv[e++] = argv[i];
|
|
|
|
argv[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!argv[i])
|
|
|
|
e = i;
|
|
|
|
}
|
|
|
|
if (e)
|
|
|
|
*argc_p = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_blurb (FILE *bout,
|
|
|
|
gboolean print_help)
|
|
|
|
{
|
|
|
|
if (!print_help)
|
|
|
|
{
|
2002-12-15 01:49:01 +00:00
|
|
|
g_fprintf (bout, "%s version ", PRG_NAME);
|
|
|
|
g_fprintf (bout, "%u.%u.%u", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
|
|
|
|
g_fprintf (bout, "\n");
|
|
|
|
g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
|
|
|
|
g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
|
|
|
|
g_fprintf (bout, "the GNU Lesser General Public License which can be found in the\n");
|
|
|
|
g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
|
|
|
|
g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
|
2001-06-26 20:56:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-12-15 01:49:01 +00:00
|
|
|
g_fprintf (bout, "Usage: %s [options] [image]\n", PRG_NAME);
|
|
|
|
g_fprintf (bout, " %s [options] --build-list [[name image]...]\n", PRG_NAME);
|
|
|
|
g_fprintf (bout, " --stream generate pixbuf data stream\n");
|
|
|
|
g_fprintf (bout, " --struct generate GdkPixdata structure\n");
|
|
|
|
g_fprintf (bout, " --macros generate image size/pixel macros\n");
|
|
|
|
g_fprintf (bout, " --rle use one byte run-length-encoding\n");
|
|
|
|
g_fprintf (bout, " --raw provide raw image data copy\n");
|
|
|
|
g_fprintf (bout, " --extern generate extern symbols\n");
|
|
|
|
g_fprintf (bout, " --static generate static symbols\n");
|
|
|
|
g_fprintf (bout, " --decoder provide rle decoder\n");
|
|
|
|
g_fprintf (bout, " --name=identifier C macro/variable name\n");
|
|
|
|
g_fprintf (bout, " --build-list parse (name, image) pairs\n");
|
|
|
|
g_fprintf (bout, " -h, --help show this help message\n");
|
|
|
|
g_fprintf (bout, " -v, --version print version informations\n");
|
|
|
|
g_fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");
|
2001-06-26 20:56:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|