1 /* -*- Mode: C; c-basic-offset: 2; -*- */
2 /* GdkPixbuf library - test loaders
4 * Copyright (C) 2004 Matthias Clasen <mclasen@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22 #include "gdk-pixbuf/gdk-pixbuf.h"
27 static gboolean verbose
= FALSE
;
30 load_image (gpointer data
,
33 gchar
*filename
= data
;
37 size_t bufsize
= 1024;
38 GdkPixbufLoader
*loader
;
42 self
= g_thread_self ();
43 loader
= gdk_pixbuf_loader_new ();
45 file
= fopen (filename
, "r");
48 if (verbose
) g_print ("%p start image %s\n", self
, filename
);
51 nbytes
= fread (buf
, 1, bufsize
, file
);
52 if (!gdk_pixbuf_loader_write (loader
, buf
, nbytes
, &error
))
54 g_warning ("Error writing %s to loader: %s", filename
, error
->message
);
59 if (verbose
) g_print ("%p read %d bytes\n", self
, nbytes
);
66 if (verbose
) g_print ("%p finish image %s\n", self
, filename
);
68 if (!gdk_pixbuf_loader_close (loader
, &error
))
70 g_warning ("Error closing loader for %s: %s", filename
, error
->message
);
74 g_object_unref (loader
);
80 g_print ("usage: pixbuf-threads [--verbose] <files>\n");
85 main (int argc
, char **argv
)
92 if (!g_thread_supported ())
95 g_log_set_always_fatal (G_LOG_LEVEL_WARNING
| G_LOG_LEVEL_ERROR
| G_LOG_LEVEL_CRITICAL
);
101 if (strcmp (argv
[1], "--verbose") == 0)
107 pool
= g_thread_pool_new (load_image
, NULL
, 20, FALSE
, NULL
);
114 g_thread_pool_push (pool
, argv
[i
], NULL
);