1 /* Program to convert an image file to inline C data
3 * Copyright (C) 2000 Red Hat, Inc.
5 * Developed by Havoc Pennington <hp@redhat.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include "gdk-pixbuf-private.h"
25 #include <glib/gprintf.h>
31 output_int (FILE *outfile, guint32 num, const char *comment)
35 /* Note, most significant bytes first */
41 g_fprintf (outfile, " /* %s (%u) */\n 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,\n",
43 bytes[0], bytes[1], bytes[2], bytes[3]);
47 output_bool (FILE *outfile, gboolean val, const char *comment)
49 g_fprintf (outfile, " /* %s (%s) */\n 0x%.2x,\n",
51 val ? "TRUE" : "FALSE",
56 output_pixbuf (FILE *outfile, gboolean ext_symbols,
70 g_fprintf (outfile, "%sconst guchar ", modifier);
71 fputs (varname, outfile);
72 fputs ("[] =\n", outfile);
73 fputs ("{\n", outfile);
75 p = gdk_pixbuf_get_pixels (pixbuf);
76 end = p + gdk_pixbuf_get_rowstride (pixbuf) * gdk_pixbuf_get_height (pixbuf);
77 has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
79 /* Sync the order of writing with the order of reading in
82 output_int (outfile, GDK_PIXBUF_INLINE_MAGIC_NUMBER, "File magic");
83 output_int (outfile, GDK_PIXBUF_INLINE_RAW, "Format of following stuff");
84 output_int (outfile, gdk_pixbuf_get_rowstride (pixbuf), "Rowstride");
85 output_int (outfile, gdk_pixbuf_get_width (pixbuf), "Width");
86 output_int (outfile, gdk_pixbuf_get_height (pixbuf), "Height");
88 output_bool (outfile, has_alpha, "Has an alpha channel");
90 output_int (outfile, gdk_pixbuf_get_colorspace (pixbuf), "Colorspace (0 == RGB, no other options implemented)");
92 output_int (outfile, gdk_pixbuf_get_n_channels (pixbuf), "Number of channels");
94 output_int (outfile, gdk_pixbuf_get_bits_per_sample (pixbuf), "Bits per sample");
96 fputs (" /* Image data */\n", outfile);
98 /* Copy the data in the pixbuf */
120 g_fprintf (outfile, " 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x", r, g, b, a);
122 g_fprintf (outfile, " 0x%.2x, 0x%.2x, 0x%.2x", r, g, b);
125 fputs (",", outfile);
127 fputs ("\n", outfile);
133 fputs ("\n", outfile);
138 fputs ("};\n\n", outfile);
144 g_fprintf (stderr, "Usage: make-inline-pixbuf [--extern-symbols] OUTFILE varname1 imagefile1 varname2 imagefile2 ...\n");
149 main (int argc, char **argv)
151 gboolean ext_symbols = FALSE;
163 if (strcmp (argv[i], "--extern-symbols") == 0)
171 outfile = fopen (argv[i], "w");
174 g_fprintf (stderr, "Failed to open output file `%s': %s\n",
175 argv[i], strerror (errno));
179 outfilename = argv[i];
182 fputs ("/* This file was automatically generated by the make-inline-pixbuf program.\n"
183 " * It contains inline RGB image data.\n"
186 /* Check for matched pairs of images/names */
187 if (((argc - i) % 2) != 0)
195 g_assert ((i + 1) < argc);
198 pixbuf = gdk_pixbuf_new_from_file (argv[i+1], &error);
202 g_fprintf (stderr, "%s\n", error->message);
204 remove (outfilename);
208 output_pixbuf (outfile, ext_symbols, argv[i], pixbuf);
210 gdk_pixbuf_unref (pixbuf);