Blame tests/pixbuf-save-ref.c

Packit a4058c
/* -*- Mode: C; c-basic-offset: 2; -*- */
Packit a4058c
/* GdkPixbuf library - test loaders
Packit a4058c
 *
Packit a4058c
 * Copyright (C) 2001 Søren Sandmann (sandmann@daimi.au.dk)
Packit a4058c
 *
Packit a4058c
 * This program is free software; you can redistribute it and/or modify
Packit a4058c
 * it under the terms of the GNU General Public License as published by
Packit a4058c
 * the Free Software Foundation; either version 2 of the License, or
Packit a4058c
 * (at your option) any later version.
Packit a4058c
 *
Packit a4058c
 * This program 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
Packit a4058c
 * GNU General Public License for more details.
Packit a4058c
 *
Packit a4058c
 * You should have received a copy of the GNU General Public License
Packit a4058c
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit a4058c
 */
Packit a4058c
Packit a4058c
#include "config.h"
Packit a4058c
#include "gdk-pixbuf/gdk-pixbuf.h"
Packit a4058c
#include <stdio.h>
Packit a4058c
#include <stdlib.h>
Packit a4058c
Packit a4058c
static gboolean
Packit a4058c
load_and_save (const char *filename, GError **error)
Packit a4058c
{
Packit a4058c
  GdkPixbuf *pixbuf = NULL;
Packit a4058c
  GdkPixbufLoader *loader;
Packit a4058c
  guchar *contents;
Packit a4058c
  char *new_filename = NULL;
Packit a4058c
  gsize size;
Packit a4058c
  gboolean ret = TRUE;
Packit a4058c
Packit a4058c
  if (!g_file_get_contents (filename, (char **) &contents, &size, error))
Packit a4058c
    return FALSE;
Packit a4058c
Packit a4058c
  loader = gdk_pixbuf_loader_new ();
Packit a4058c
  if (!gdk_pixbuf_loader_write (loader, contents, size, error))
Packit a4058c
    {
Packit a4058c
      ret = FALSE;
Packit a4058c
      goto out;
Packit a4058c
    }
Packit a4058c
Packit a4058c
  if (!gdk_pixbuf_loader_close (loader, error))
Packit a4058c
    {
Packit a4058c
      if (!g_error_matches (*error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION))
Packit a4058c
        {
Packit a4058c
          ret = FALSE;
Packit a4058c
          goto out;
Packit a4058c
        }
Packit a4058c
      g_clear_error (error);
Packit a4058c
    }
Packit a4058c
Packit a4058c
  pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
Packit a4058c
  g_assert (pixbuf);
Packit a4058c
  g_object_ref (pixbuf);
Packit a4058c
Packit a4058c
  g_object_unref (loader);
Packit a4058c
Packit a4058c
  new_filename = g_strdup_printf ("%s.ref.png", filename);
Packit a4058c
  ret = gdk_pixbuf_save (pixbuf, new_filename, "png", error, NULL);
Packit a4058c
Packit a4058c
out:
Packit a4058c
  g_free (contents);
Packit a4058c
  g_free (new_filename);
Packit a4058c
  g_clear_object (&pixbuf);
Packit a4058c
Packit a4058c
  return ret;
Packit a4058c
}
Packit a4058c
Packit a4058c
static void
Packit a4058c
usage (void)
Packit a4058c
{
Packit a4058c
  g_print ("usage: pixbuf-save-ref <files>\n");
Packit a4058c
  exit (EXIT_FAILURE);
Packit a4058c
}
Packit a4058c
Packit a4058c
int
Packit a4058c
main (int argc, char **argv)
Packit a4058c
{
Packit a4058c
  int i;
Packit a4058c
Packit a4058c
  g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
Packit a4058c
Packit a4058c
  if (argc == 1)
Packit a4058c
    usage();
Packit a4058c
Packit a4058c
  for (i = 1; i < argc; ++i)
Packit a4058c
    {
Packit a4058c
      GError *err = NULL;
Packit a4058c
Packit a4058c
      g_print ("%s\t\t", argv[i]);
Packit a4058c
      fflush (stdout);
Packit a4058c
      if (!load_and_save (argv[i], &err))
Packit a4058c
        {
Packit a4058c
          fprintf (stderr, "%s: error: %s\n", argv[i], err->message);
Packit a4058c
          g_clear_error (&err;;
Packit a4058c
        }
Packit a4058c
      else
Packit a4058c
        {
Packit a4058c
          g_print ("success\n");
Packit a4058c
        }
Packit a4058c
    }
Packit a4058c
Packit a4058c
  return 0;
Packit a4058c
}