|
Packit |
a4058c |
/* Gdk-Pixbuf-Pixdata - GdkPixbuf to GdkPixdata
|
|
Packit |
a4058c |
* Copyright (C) 1999, 2001 Tim Janik
|
|
Packit |
a4058c |
* Copyright (C) 2012 Red Hat, Inc
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a4058c |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License as published by the Free Software Foundation; either
|
|
Packit |
a4058c |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a4058c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4058c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a4058c |
* Lesser General Public License for more details.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include "gdk-pixbuf.h"
|
|
Packit |
a4058c |
#include "gdk-pixdata.h"
|
|
Packit |
a4058c |
#include <glib/gprintf.h>
|
|
Packit |
a4058c |
#include <stdlib.h>
|
|
Packit |
a4058c |
#include <string.h>
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* --- defines --- */
|
|
Packit |
a4058c |
#undef G_LOG_DOMAIN
|
|
Packit |
a4058c |
#define G_LOG_DOMAIN "Gdk-Pixbuf-Pixdata"
|
|
Packit |
a4058c |
#define PRG_NAME "gdk-pixbuf-pixdata-3.0"
|
|
Packit |
a4058c |
#define PKG_NAME "gdk-pixbuf"
|
|
Packit |
a4058c |
#define PKG_HTTP_HOME "http://www.gtk.org"
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean use_rle = FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* --- prototypes --- */
|
|
Packit |
a4058c |
static void parse_args (gint *argc_p,
|
|
Packit |
a4058c |
gchar ***argv_p);
|
|
Packit |
a4058c |
static void print_blurb (FILE *bout,
|
|
Packit |
a4058c |
gboolean print_help);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
int
|
|
Packit |
a4058c |
main (int argc,
|
|
Packit |
a4058c |
char *argv[])
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf;
|
|
Packit |
a4058c |
GError *error = NULL;
|
|
Packit |
a4058c |
gchar *infilename;
|
|
Packit |
a4058c |
gchar *outfilename;
|
|
Packit |
a4058c |
gpointer free_me;
|
|
Packit |
a4058c |
GdkPixdata pixdata;
|
|
Packit |
a4058c |
guint8 *data;
|
|
Packit |
a4058c |
guint data_len;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* parse args and do fast exits */
|
|
Packit |
a4058c |
parse_args (&argc, &argv);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (argc != 3)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
print_blurb (stderr, TRUE);
|
|
Packit |
a4058c |
return 1;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#ifdef G_OS_WIN32
|
|
Packit |
a4058c |
infilename = g_locale_to_utf8 (argv[1], -1, NULL, NULL, NULL);
|
|
Packit |
a4058c |
#else
|
|
Packit |
a4058c |
infilename = argv[1];
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#ifdef G_OS_WIN32
|
|
Packit |
a4058c |
outfilename = g_locale_to_utf8 (argv[2], -1, NULL, NULL, NULL);
|
|
Packit |
a4058c |
#else
|
|
Packit |
a4058c |
outfilename = argv[2];
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
pixbuf = gdk_pixbuf_new_from_file (infilename, &error);
|
|
Packit |
a4058c |
if (!pixbuf)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_printerr ("failed to load \"%s\": %s\n",
|
|
Packit |
a4058c |
argv[1],
|
|
Packit |
a4058c |
error->message);
|
|
Packit |
a4058c |
g_error_free (error);
|
|
Packit |
a4058c |
return 1;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
Packit |
a4058c |
free_me = gdk_pixdata_from_pixbuf (&pixdata, pixbuf, use_rle);
|
|
Packit |
a4058c |
data = gdk_pixdata_serialize (&pixdata, &data_len);
|
|
Packit |
a4058c |
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!g_file_set_contents (outfilename, (char *)data, data_len, &error))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_printerr ("failed to load \"%s\": %s\n",
|
|
Packit |
a4058c |
argv[1],
|
|
Packit |
a4058c |
error->message);
|
|
Packit |
a4058c |
g_error_free (error);
|
|
Packit |
a4058c |
return 1;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_free (data);
|
|
Packit |
a4058c |
g_free (free_me);
|
|
Packit |
a4058c |
g_object_unref (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return 0;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
parse_args (gint *argc_p,
|
|
Packit |
a4058c |
gchar ***argv_p)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
guint argc = *argc_p;
|
|
Packit |
a4058c |
gchar **argv = *argv_p;
|
|
Packit |
a4058c |
guint i, e;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (i = 1; i < argc; i++)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (strcmp ("-r", argv[i]) == 0 ||
|
|
Packit |
a4058c |
strcmp ("--rle", argv[i]) == 0)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
use_rle = TRUE;
|
|
Packit |
a4058c |
argv[i] = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else if (strcmp ("-h", argv[i]) == 0 ||
|
|
Packit |
a4058c |
strcmp ("--help", argv[i]) == 0)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
print_blurb (stderr, TRUE);
|
|
Packit |
a4058c |
argv[i] = NULL;
|
|
Packit |
a4058c |
exit (0);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else if (strcmp ("-v", argv[i]) == 0 ||
|
|
Packit |
a4058c |
strcmp ("--version", argv[i]) == 0)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
print_blurb (stderr, FALSE);
|
|
Packit |
a4058c |
argv[i] = NULL;
|
|
Packit |
a4058c |
exit (0);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
GLogLevelFlags fatal_mask;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
|
|
Packit |
a4058c |
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
|
|
Packit |
a4058c |
g_log_set_always_fatal (fatal_mask);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
argv[i] = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
e = 0;
|
|
Packit |
a4058c |
for (i = 1; i < argc; i++)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (e)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (argv[i])
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
argv[e++] = argv[i];
|
|
Packit |
a4058c |
argv[i] = NULL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else if (!argv[i])
|
|
Packit |
a4058c |
e = i;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
if (e)
|
|
Packit |
a4058c |
*argc_p = e;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
print_blurb (FILE *bout,
|
|
Packit |
a4058c |
gboolean print_help)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
if (!print_help)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_fprintf (bout, "%s version ", PRG_NAME);
|
|
Packit |
a4058c |
g_fprintf (bout, "%s", GDK_PIXBUF_VERSION);
|
|
Packit |
a4058c |
g_fprintf (bout, "\n");
|
|
Packit |
a4058c |
g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
|
|
Packit |
a4058c |
g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
|
|
Packit |
a4058c |
g_fprintf (bout, "the GNU Lesser General Public License which can be found in the\n");
|
|
Packit |
a4058c |
g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
|
|
Packit |
a4058c |
g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_fprintf (bout, "Usage: %s [options] [input-file] [output-file]\n", PRG_NAME);
|
|
Packit |
a4058c |
g_fprintf (bout, " -r, --rle compress the image data using RLE\n");
|
|
Packit |
a4058c |
g_fprintf (bout, " -h, --help show this help message\n");
|
|
Packit |
a4058c |
g_fprintf (bout, " -v, --version print version informations\n");
|
|
Packit |
a4058c |
g_fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|