1 /* Gdk-Pixbuf-CSource - GdkPixbuf based image CSource generator
2 * Copyright (C) 1999, 2001 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #define __GTK_H_INSIDE__
22 #include "../gtk/gtkversion.h" /* versioning */
23 #undef __GTK_H_INSIDE__
24 #include "gdk-pixbuf.h"
25 #include "gdk-pixdata.h"
26 #include <glib/gprintf.h>
33 #define G_LOG_DOMAIN "Gdk-Pixbuf-CSource"
34 #define PRG_NAME "gdk-pixbuf-csource"
35 #define PKG_NAME "Gtk+"
36 #define PKG_HTTP_HOME "http://www.gtk.org"
39 /* --- prototypes --- */
40 static void parse_args (gint *argc_p,
42 static void print_blurb (FILE *bout,
46 /* --- variables --- */
47 static guint gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
48 static guint gen_ctype = GDK_PIXDATA_DUMP_GTYPES | GDK_PIXDATA_DUMP_STATIC | GDK_PIXDATA_DUMP_CONST;
49 static gboolean use_rle = TRUE;
50 static gboolean with_decoder = FALSE;
51 static gchar *image_name = "my_pixbuf";
52 static gboolean build_list = FALSE;
55 /* --- functions --- */
57 print_csource (FILE *f_out,
64 free_me = gdk_pixdata_from_pixbuf (&pixdata, pixbuf, use_rle);
65 gstring = gdk_pixdata_to_csource (&pixdata, image_name,
66 gen_type | gen_ctype |
67 (with_decoder ? GDK_PIXDATA_DUMP_RLE_DECODER : 0));
69 g_fprintf (f_out, "%s\n", gstring->str);
82 /* initialize glib/GdkPixbuf */
85 /* parse args and do fast exits */
86 parse_args (&argc, &argv);
92 print_blurb (stderr, TRUE);
97 infilename = g_locale_to_utf8 (argv[1], -1, NULL, NULL, NULL);
102 pixbuf = gdk_pixbuf_new_from_file (infilename, &error);
105 g_fprintf (stderr, "failed to load \"%s\": %s\n",
108 g_error_free (error);
112 print_csource (stdout, pixbuf);
113 g_object_unref (pixbuf);
115 else /* parse name, file pairs */
117 gchar **p = argv + 1;
119 gboolean toggle = FALSE;
124 infilename = g_locale_to_utf8 (*p, -1, NULL, NULL, NULL);
131 image_name = infilename;
136 pixbuf = gdk_pixbuf_new_from_file (infilename, &error);
139 g_fprintf (stderr, "failed to load \"%s\": %s\n",
142 g_error_free (error);
145 print_csource (stdout, pixbuf);
146 g_object_unref (pixbuf);
157 parse_args (gint *argc_p,
160 guint argc = *argc_p;
161 gchar **argv = *argv_p;
164 for (i = 1; i < argc; i++)
166 if (strcmp ("--macros", argv[i]) == 0)
168 gen_type = GDK_PIXDATA_DUMP_MACROS;
171 else if (strcmp ("--struct", argv[i]) == 0)
173 gen_type = GDK_PIXDATA_DUMP_PIXDATA_STRUCT;
176 else if (strcmp ("--stream", argv[i]) == 0)
178 gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
181 else if (strcmp ("--rle", argv[i]) == 0)
186 else if (strcmp ("--raw", argv[i]) == 0)
191 else if (strcmp ("--extern", argv[i]) == 0)
193 gen_ctype &= ~GDK_PIXDATA_DUMP_STATIC;
196 else if (strcmp ("--static", argv[i]) == 0)
198 gen_ctype |= GDK_PIXDATA_DUMP_STATIC;
201 else if (strcmp ("--decoder", argv[i]) == 0)
206 else if ((strcmp ("--name", argv[i]) == 0) ||
207 (strncmp ("--name=", argv[i], 7) == 0))
209 gchar *equal = argv[i] + 6;
212 image_name = g_strdup (equal + 1);
213 else if (i + 1 < argc)
215 image_name = g_strdup (argv[i + 1]);
221 else if (strcmp ("--build-list", argv[i]) == 0)
226 else if (strcmp ("-h", argv[i]) == 0 ||
227 strcmp ("--help", argv[i]) == 0)
229 print_blurb (stderr, TRUE);
233 else if (strcmp ("-v", argv[i]) == 0 ||
234 strcmp ("--version", argv[i]) == 0)
236 print_blurb (stderr, FALSE);
240 else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
242 GLogLevelFlags fatal_mask;
244 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
245 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
246 g_log_set_always_fatal (fatal_mask);
253 for (i = 1; i < argc; i++)
271 print_blurb (FILE *bout,
276 g_fprintf (bout, "%s version ", PRG_NAME);
277 g_fprintf (bout, "%d.%d.%d", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
278 g_fprintf (bout, "\n");
279 g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
280 g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
281 g_fprintf (bout, "the GNU Lesser General Public License which can be found in the\n");
282 g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
283 g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
287 g_fprintf (bout, "Usage: %s [options] [image]\n", PRG_NAME);
288 g_fprintf (bout, " %s [options] --build-list [[name image]...]\n", PRG_NAME);
289 g_fprintf (bout, " --stream generate pixbuf data stream\n");
290 g_fprintf (bout, " --struct generate GdkPixdata structure\n");
291 g_fprintf (bout, " --macros generate image size/pixel macros\n");
292 g_fprintf (bout, " --rle use one byte run-length-encoding\n");
293 g_fprintf (bout, " --raw provide raw image data copy\n");
294 g_fprintf (bout, " --extern generate extern symbols\n");
295 g_fprintf (bout, " --static generate static symbols\n");
296 g_fprintf (bout, " --decoder provide rle decoder\n");
297 g_fprintf (bout, " --name=identifier C macro/variable name\n");
298 g_fprintf (bout, " --build-list parse (name, image) pairs\n");
299 g_fprintf (bout, " -h, --help show this help message\n");
300 g_fprintf (bout, " -v, --version print version informations\n");
301 g_fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");