1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2002, Owen Taylor
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 <gdk-pixbuf/gdk-pixbuf.h>
22 #include <glib/gprintf.h>
26 #define BYTES_PER_OUTPUT_LINE 15
29 output_byte (guchar byte,
32 if (online == BYTES_PER_OUTPUT_LINE)
42 g_printf ("0x%02x", byte);
47 do_part (GdkPixbuf *pixbuf,
51 const char *base_name,
52 const char *part_name)
54 const guchar *pixels = gdk_pixbuf_get_pixels (pixbuf);
58 gint rowstride = gdk_pixbuf_get_rowstride (pixbuf);
59 gint n_channels = gdk_pixbuf_get_n_channels (pixbuf);
60 gint width = gdk_pixbuf_get_width (pixbuf);
61 gint height = gdk_pixbuf_get_height (pixbuf);
64 color1 = pixels + part1_index * n_channels;
65 color2 = pixels + part2_index * n_channels;
66 color3 = pixels + part3_index * n_channels;
69 g_printf ("static const guchar %s_%s_bits[] = {\n", base_name, part_name);
76 const guchar *p = pixels;
81 if ((part1_index >= 0 && memcmp (p, color1, n_channels) == 0) ||
82 (part2_index >= 0 && memcmp (p, color2, n_channels) == 0) ||
83 (part3_index >= 0 && memcmp (p, color3, n_channels) == 0))
88 online = output_byte (byte, online);
98 if (width & 7) /* a leftover partial byte */
99 online = output_byte (byte, online);
118 static const char *part_names[PART_LAST] = {
128 int main (int argc, char **argv)
130 gchar *progname = g_path_get_basename (argv[0]);
132 GError *error = NULL;
137 g_fprintf (stderr, "%s: Usage: %s FILE BASE\n", progname, progname);
143 pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
146 g_fprintf (stderr, "%s: cannot open file '%s': %s\n", progname, argv[1], error->message);
150 if (gdk_pixbuf_get_width (pixbuf) < PART_LAST)
152 g_fprintf (stderr, "%s: source image must be at least %d pixels wide\n", progname, PART_LAST);
156 if (gdk_pixbuf_get_height (pixbuf) < 1)
158 g_fprintf (stderr, "%s: source image must be at least 1 pixel height\n", progname);
162 g_printf ("/*\n * Extracted from %s, width=%d, height=%d\n */\n", argv[1],
163 gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf) - 1);
165 for (i = 0; i < PART_LAST; i++)
167 /* As a bit of a hack, we want the base image to extend over the text
168 * and text_aa parts so that we can draw the image either with or without
172 do_part (pixbuf, PART_BASE, PART_TEXT_AA, PART_TEXT, argv[2], part_names[i]);
174 do_part (pixbuf, i, -1, -1, argv[2], part_names[i]);