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 #include "../gtk/gtkversion.h" /* versioning */
22 #include "gdk-pixbuf.h"
23 #include "gdk-pixdata.h"
31 #define G_LOG_DOMAIN "Gdk-Pixbuf-CSource"
32 #define PRG_NAME "gdk-pixbuf-csource"
33 #define PKG_NAME "Gtk+"
34 #define PKG_HTTP_HOME "http://www.gtk.org"
37 /* --- prototypes --- */
38 static void parse_args (gint *argc_p,
40 static void print_blurb (FILE *bout,
44 /* --- variables --- */
45 static guint gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
46 static guint gen_ctype = GDK_PIXDATA_DUMP_GTYPES | GDK_PIXDATA_DUMP_STATIC | GDK_PIXDATA_DUMP_CONST;
47 static gboolean use_rle = TRUE;
48 static gboolean with_decoder = FALSE;
49 static gchar *image_name = "my_pixbuf";
50 static gboolean build_list = FALSE;
53 /* --- functions --- */
55 print_csource (FILE *f_out,
62 free_me = gdk_pixdata_from_pixbuf (&pixdata, pixbuf, use_rle);
63 gstring = gdk_pixdata_to_csource (&pixdata, image_name,
64 gen_type | gen_ctype |
65 (with_decoder ? GDK_PIXDATA_DUMP_RLE_DECODER : 0));
67 fprintf (f_out, "%s\n", gstring->str);
79 /* initialize glib/GdkPixbuf */
82 /* parse args and do fast exits */
83 parse_args (&argc, &argv);
89 print_blurb (stderr, TRUE);
93 pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
96 fprintf (stderr, "failed to load \"%s\": %s\n",
103 print_csource (stdout, pixbuf);
104 g_object_unref (pixbuf);
106 else /* parse name, file pairs */
108 gchar **p = argv + 1;
110 gboolean toggle = FALSE;
118 pixbuf = gdk_pixbuf_new_from_file (*p, &error);
121 fprintf (stderr, "failed to load \"%s\": %s\n",
124 g_error_free (error);
127 print_csource (stdout, pixbuf);
128 g_object_unref (pixbuf);
139 parse_args (gint *argc_p,
142 guint argc = *argc_p;
143 gchar **argv = *argv_p;
146 for (i = 1; i < argc; i++)
148 if (strcmp ("--macros", argv[i]) == 0)
150 gen_type = GDK_PIXDATA_DUMP_MACROS;
153 else if (strcmp ("--struct", argv[i]) == 0)
155 gen_type = GDK_PIXDATA_DUMP_PIXDATA_STRUCT;
158 else if (strcmp ("--stream", argv[i]) == 0)
160 gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
163 else if (strcmp ("--rle", argv[i]) == 0)
168 else if (strcmp ("--raw", argv[i]) == 0)
173 else if (strcmp ("--extern", argv[i]) == 0)
175 gen_ctype &= ~GDK_PIXDATA_DUMP_STATIC;
178 else if (strcmp ("--static", argv[i]) == 0)
180 gen_ctype |= GDK_PIXDATA_DUMP_STATIC;
183 else if (strcmp ("--decoder", argv[i]) == 0)
188 else if ((strcmp ("--name", argv[i]) == 0) ||
189 (strncmp ("--name=", argv[i], 7) == 0))
191 gchar *equal = argv[i] + 6;
194 image_name = g_strdup (equal + 1);
195 else if (i + 1 < argc)
197 image_name = g_strdup (argv[i + 1]);
203 else if (strcmp ("--build-list", argv[i]) == 0)
208 else if (strcmp ("-h", argv[i]) == 0 ||
209 strcmp ("--help", argv[i]) == 0)
211 print_blurb (stderr, TRUE);
215 else if (strcmp ("-v", argv[i]) == 0 ||
216 strcmp ("--version", argv[i]) == 0)
218 print_blurb (stderr, FALSE);
222 else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
224 GLogLevelFlags fatal_mask;
226 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
227 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
228 g_log_set_always_fatal (fatal_mask);
235 for (i = 1; i < argc; i++)
253 print_blurb (FILE *bout,
258 fprintf (bout, "%s version ", PRG_NAME);
259 fprintf (bout, "%u.%u.%u", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
260 fprintf (bout, "\n");
261 fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
262 fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
263 fprintf (bout, "the GNU Lesser General Public License which can be found in the\n");
264 fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
265 fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
269 fprintf (bout, "Usage: %s [options] [image]\n", PRG_NAME);
270 fprintf (bout, " %s [options] --build-list [[name image]...]\n", PRG_NAME);
271 fprintf (bout, " --stream generate pixbuf data stream\n");
272 fprintf (bout, " --struct generate GdkPixdata structure\n");
273 fprintf (bout, " --macros generate image size/pixel macros\n");
274 fprintf (bout, " --rle use one byte run-length-encoding\n");
275 fprintf (bout, " --raw provide raw image data copy\n");
276 fprintf (bout, " --extern generate extern symbols\n");
277 fprintf (bout, " --static generate static symbols\n");
278 fprintf (bout, " --decoder provide rle decoder\n");
279 fprintf (bout, " --name=identifier C macro/variable name\n");
280 fprintf (bout, " --build-list parse (name, image) pairs\n");
281 fprintf (bout, " -h, --help show this help message\n");
282 fprintf (bout, " -v, --version print version informations\n");
283 fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");