2002-07-07 20:29:48 +00:00
|
|
|
|
/* -*- mode: C; c-file-style: "linux" -*- */
|
1999-10-20 21:20:49 +00:00
|
|
|
|
/* GdkPixbuf library - Main loading interface.
|
1999-01-04 23:53:12 +00:00
|
|
|
|
*
|
1999-10-20 21:20:49 +00:00
|
|
|
|
* Copyright (C) 1999 The Free Software Foundation
|
|
|
|
|
*
|
|
|
|
|
* Authors: Miguel de Icaza <miguel@gnu.org>
|
|
|
|
|
* Federico Mena-Quintero <federico@gimp.org>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-10-20 21:20:49 +00:00
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1999-10-20 21:20:49 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-10-20 21:20:49 +00:00
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
* Boston, MA 02111-1307, USA.
|
1999-01-04 23:53:12 +00:00
|
|
|
|
*/
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
2004-03-06 03:38:59 +00:00
|
|
|
|
#include <config.h>
|
2004-01-09 20:00:14 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
1999-08-09 06:09:24 +00:00
|
|
|
|
#include <string.h>
|
1999-11-22 20:43:58 +00:00
|
|
|
|
#include <glib.h>
|
2000-10-06 18:19:18 +00:00
|
|
|
|
#include <errno.h>
|
2004-01-09 20:00:14 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
|
#include "gdk-pixbuf-private.h"
|
1999-11-23 01:25:28 +00:00
|
|
|
|
#include "gdk-pixbuf-io.h"
|
2005-03-14 19:37:00 +00:00
|
|
|
|
#include "gdk-pixbuf-alias.h"
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
|
2001-10-29 06:48:04 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
#define STRICT
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#undef STRICT
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static gint
|
|
|
|
|
format_check (GdkPixbufModule *module, guchar *buffer, int size)
|
1999-01-05 04:31:03 +00:00
|
|
|
|
{
|
2005-07-22 04:37:27 +00:00
|
|
|
|
int i, j;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
gchar m;
|
|
|
|
|
GdkPixbufModulePattern *pattern;
|
2005-07-22 15:34:32 +00:00
|
|
|
|
gboolean anchored;
|
2005-08-30 16:55:49 +00:00
|
|
|
|
guchar *prefix;
|
|
|
|
|
gchar *mask;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
for (pattern = module->info->signature; pattern->prefix; pattern++) {
|
2005-07-22 04:37:27 +00:00
|
|
|
|
if (pattern->mask && pattern->mask[0] == '*') {
|
2005-08-30 16:55:49 +00:00
|
|
|
|
prefix = (guchar *)pattern->prefix + 1;
|
2005-07-22 04:37:27 +00:00
|
|
|
|
mask = pattern->mask + 1;
|
2005-07-22 15:34:32 +00:00
|
|
|
|
anchored = FALSE;
|
2005-07-22 04:37:27 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2005-08-30 16:55:49 +00:00
|
|
|
|
prefix = (guchar *)pattern->prefix;
|
2005-07-22 04:37:27 +00:00
|
|
|
|
mask = pattern->mask;
|
2005-07-22 15:34:32 +00:00
|
|
|
|
anchored = TRUE;
|
2005-07-22 04:37:27 +00:00
|
|
|
|
}
|
2005-07-22 15:34:32 +00:00
|
|
|
|
for (i = 0; i < size; i++) {
|
2005-07-22 04:37:27 +00:00
|
|
|
|
for (j = 0; i + j < size && prefix[j] != 0; j++) {
|
|
|
|
|
m = mask ? mask[j] : ' ';
|
|
|
|
|
if (m == ' ') {
|
|
|
|
|
if (buffer[i + j] != prefix[j])
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (m == '!') {
|
|
|
|
|
if (buffer[i + j] == prefix[j])
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (m == 'z') {
|
|
|
|
|
if (buffer[i + j] != 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (m == 'n') {
|
|
|
|
|
if (buffer[i + j] == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-22 15:34:32 +00:00
|
|
|
|
|
2005-07-22 04:37:27 +00:00
|
|
|
|
if (prefix[j] == 0)
|
|
|
|
|
return pattern->relevance;
|
2005-07-22 15:34:32 +00:00
|
|
|
|
|
|
|
|
|
if (anchored)
|
|
|
|
|
break;
|
2005-07-22 04:37:27 +00:00
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
1999-01-05 04:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
G_LOCK_DEFINE_STATIC (init_lock);
|
|
|
|
|
G_LOCK_DEFINE_STATIC (threadunsafe_loader_lock);
|
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
_gdk_pixbuf_lock (GdkPixbufModule *image_module)
|
|
|
|
|
{
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (g_threads_got_initialized &&
|
|
|
|
|
!(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
G_LOCK (threadunsafe_loader_lock);
|
2004-11-16 02:51:19 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
}
|
2004-11-16 02:51:19 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gdk_pixbuf_unlock (GdkPixbufModule *image_module)
|
|
|
|
|
{
|
|
|
|
|
if (!(image_module->info->flags & GDK_PIXBUF_FORMAT_THREADSAFE)) {
|
|
|
|
|
G_UNLOCK (threadunsafe_loader_lock);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static GSList *file_formats = NULL;
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static void gdk_pixbuf_io_init ();
|
1999-01-05 04:31:03 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static GSList *
|
2004-10-28 15:00:05 +00:00
|
|
|
|
get_file_formats (void)
|
1999-01-05 04:31:03 +00:00
|
|
|
|
{
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
G_LOCK (init_lock);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (file_formats == NULL)
|
|
|
|
|
gdk_pixbuf_io_init ();
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
G_UNLOCK (init_lock);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
return file_formats;
|
1999-01-05 04:31:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-08-09 06:09:24 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
#ifdef USE_GMODULE
|
1999-01-05 04:31:03 +00:00
|
|
|
|
|
|
|
|
|
static gboolean
|
2002-10-03 22:39:51 +00:00
|
|
|
|
scan_string (const char **pos, GString *out)
|
1999-01-05 04:31:03 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
const char *p = *pos, *q = *pos;
|
|
|
|
|
char *tmp, *tmp2;
|
|
|
|
|
gboolean quoted;
|
|
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*p))
|
|
|
|
|
p++;
|
|
|
|
|
|
|
|
|
|
if (!*p)
|
1999-01-05 04:31:03 +00:00
|
|
|
|
return FALSE;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (*p == '"') {
|
|
|
|
|
p++;
|
|
|
|
|
quoted = FALSE;
|
|
|
|
|
for (q = p; (*q != '"') || quoted; q++) {
|
|
|
|
|
if (!*q)
|
|
|
|
|
return FALSE;
|
|
|
|
|
quoted = (*q == '\\') && !quoted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tmp = g_strndup (p, q - p);
|
|
|
|
|
tmp2 = g_strcompress (tmp);
|
|
|
|
|
g_string_truncate (out, 0);
|
|
|
|
|
g_string_append (out, tmp2);
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
g_free (tmp2);
|
1999-01-05 04:31:03 +00:00
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
q++;
|
|
|
|
|
*pos = q;
|
|
|
|
|
|
1999-11-05 21:29:33 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-29 16:49:39 +00:00
|
|
|
|
static gboolean
|
2002-10-03 22:39:51 +00:00
|
|
|
|
scan_int (const char **pos, int *out)
|
1999-11-29 16:49:39 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
int i = 0;
|
|
|
|
|
char buf[32];
|
|
|
|
|
const char *p = *pos;
|
|
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*p))
|
|
|
|
|
p++;
|
|
|
|
|
|
|
|
|
|
if (*p < '0' || *p > '9')
|
1999-11-29 16:49:39 +00:00
|
|
|
|
return FALSE;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
while ((*p >= '0') && (*p <= '9') && i < sizeof (buf)) {
|
|
|
|
|
buf[i] = *p;
|
|
|
|
|
i++;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i == sizeof (buf))
|
|
|
|
|
return FALSE;
|
|
|
|
|
else
|
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
|
|
|
|
|
*out = atoi (buf);
|
|
|
|
|
|
|
|
|
|
*pos = p;
|
1999-11-29 16:49:39 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-06 21:14:15 +00:00
|
|
|
|
static gboolean
|
2002-10-03 22:39:51 +00:00
|
|
|
|
skip_space (const char **pos)
|
1999-11-05 00:16:10 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
const char *p = *pos;
|
|
|
|
|
|
|
|
|
|
while (g_ascii_isspace (*p))
|
|
|
|
|
p++;
|
|
|
|
|
|
|
|
|
|
*pos = p;
|
|
|
|
|
|
|
|
|
|
return !(*p == '\0');
|
1999-11-05 00:16:10 +00:00
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
2004-03-15 13:07:04 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
/* DllMain function needed to tuck away the gdk-pixbuf DLL name */
|
|
|
|
|
G_WIN32_DLLMAIN_FOR_DLL_NAME (static, dll_name)
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_toplevel (void)
|
|
|
|
|
{
|
|
|
|
|
static char *toplevel = NULL;
|
|
|
|
|
|
|
|
|
|
if (toplevel == NULL)
|
|
|
|
|
toplevel = g_win32_get_package_installation_subdirectory
|
|
|
|
|
(GETTEXT_PACKAGE, dll_name, "");
|
|
|
|
|
|
|
|
|
|
return toplevel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_sysconfdir (void)
|
|
|
|
|
{
|
|
|
|
|
static char *sysconfdir = NULL;
|
|
|
|
|
|
|
|
|
|
if (sysconfdir == NULL)
|
|
|
|
|
sysconfdir = g_win32_get_package_installation_subdirectory
|
|
|
|
|
(GETTEXT_PACKAGE, dll_name, "etc");
|
|
|
|
|
|
|
|
|
|
return sysconfdir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef GTK_SYSCONFDIR
|
|
|
|
|
#define GTK_SYSCONFDIR get_sysconfdir()
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
correct_prefix (gchar **path)
|
|
|
|
|
{
|
|
|
|
|
if (strncmp (*path, GTK_PREFIX "/", strlen (GTK_PREFIX "/")) == 0 ||
|
|
|
|
|
strncmp (*path, GTK_PREFIX "\\", strlen (GTK_PREFIX "\\")) == 0)
|
|
|
|
|
{
|
|
|
|
|
/* This is an entry put there by gdk-pixbuf-query-loaders on the
|
|
|
|
|
* packager's system. On Windows a prebuilt GTK+ package can be
|
|
|
|
|
* installed in a random location. The gdk-pixbuf.loaders file
|
|
|
|
|
* distributed in such a package contains paths from the package
|
|
|
|
|
* builder's machine. Replace the build-time prefix with the
|
|
|
|
|
* installation prefix on this machine.
|
|
|
|
|
*/
|
|
|
|
|
gchar *tem = *path;
|
|
|
|
|
*path = g_strconcat (get_toplevel (), tem + strlen (GTK_PREFIX), NULL);
|
|
|
|
|
g_free (tem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-12 20:43:08 +00:00
|
|
|
|
#endif /* G_OS_WIN32 */
|
2004-03-15 13:07:04 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static gchar *
|
|
|
|
|
gdk_pixbuf_get_module_file (void)
|
2000-07-28 00:09:36 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
gchar *result = g_strdup (g_getenv ("GDK_PIXBUF_MODULE_FILE"));
|
2000-07-28 00:09:36 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (!result)
|
|
|
|
|
result = g_build_filename (GTK_SYSCONFDIR, "gtk-2.0", "gdk-pixbuf.loaders", NULL);
|
2000-07-28 00:09:36 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
return result;
|
2000-07-28 00:09:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static void
|
2004-10-28 15:00:05 +00:00
|
|
|
|
gdk_pixbuf_io_init (void)
|
2001-01-22 02:08:53 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
GIOChannel *channel;
|
|
|
|
|
gchar *line_buf;
|
|
|
|
|
gsize term;
|
|
|
|
|
GString *tmp_buf = g_string_new (NULL);
|
|
|
|
|
gboolean have_error = FALSE;
|
|
|
|
|
GdkPixbufModule *module = NULL;
|
|
|
|
|
gchar *filename = gdk_pixbuf_get_module_file ();
|
|
|
|
|
int flags;
|
|
|
|
|
int n_patterns = 0;
|
|
|
|
|
GdkPixbufModulePattern *pattern;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
channel = g_io_channel_new_file (filename, "r", &error);
|
|
|
|
|
if (!channel) {
|
2004-07-15 23:24:51 +00:00
|
|
|
|
g_warning ("Cannot open pixbuf loader module file '%s': %s",
|
2002-10-03 22:39:51 +00:00
|
|
|
|
filename, error->message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (!have_error && g_io_channel_read_line (channel, &line_buf, NULL, &term, NULL) == G_IO_STATUS_NORMAL) {
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
p = line_buf;
|
2001-01-22 02:08:53 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
line_buf[term] = 0;
|
2001-08-21 08:51:06 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (!skip_space (&p)) {
|
|
|
|
|
/* Blank line marking the end of a module
|
|
|
|
|
*/
|
|
|
|
|
if (module && *p != '#') {
|
2004-03-15 13:07:04 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
correct_prefix (&module->module_path);
|
|
|
|
|
#endif
|
2002-10-03 22:39:51 +00:00
|
|
|
|
file_formats = g_slist_prepend (file_formats, module);
|
|
|
|
|
module = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto next_line;
|
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (*p == '#')
|
|
|
|
|
goto next_line;
|
|
|
|
|
|
|
|
|
|
if (!module) {
|
|
|
|
|
/* Read a module location
|
|
|
|
|
*/
|
|
|
|
|
module = g_new0 (GdkPixbufModule, 1);
|
|
|
|
|
n_patterns = 0;
|
|
|
|
|
|
|
|
|
|
if (!scan_string (&p, tmp_buf)) {
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
module->module_path = g_strdup (tmp_buf->str);
|
|
|
|
|
}
|
|
|
|
|
else if (!module->module_name) {
|
|
|
|
|
module->info = g_new0 (GdkPixbufFormat, 1);
|
|
|
|
|
if (!scan_string (&p, tmp_buf)) {
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
module->info->name = g_strdup (tmp_buf->str);
|
|
|
|
|
module->module_name = module->info->name;
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (!scan_int (&p, &flags)) {
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
module->info->flags = flags;
|
|
|
|
|
|
|
|
|
|
if (!scan_string (&p, tmp_buf)) {
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
if (tmp_buf->str[0] != 0)
|
|
|
|
|
module->info->domain = g_strdup (tmp_buf->str);
|
|
|
|
|
|
|
|
|
|
if (!scan_string (&p, tmp_buf)) {
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
module->info->description = g_strdup (tmp_buf->str);
|
|
|
|
|
}
|
|
|
|
|
else if (!module->info->mime_types) {
|
|
|
|
|
int n = 1;
|
|
|
|
|
module->info->mime_types = g_new0 (gchar*, 1);
|
|
|
|
|
while (scan_string (&p, tmp_buf)) {
|
|
|
|
|
if (tmp_buf->str[0] != 0) {
|
|
|
|
|
module->info->mime_types =
|
|
|
|
|
g_realloc (module->info->mime_types, (n + 1) * sizeof (gchar*));
|
|
|
|
|
module->info->mime_types[n - 1] = g_strdup (tmp_buf->str);
|
2004-10-28 15:00:05 +00:00
|
|
|
|
module->info->mime_types[n] = NULL;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!module->info->extensions) {
|
|
|
|
|
int n = 1;
|
|
|
|
|
module->info->extensions = g_new0 (gchar*, 1);
|
|
|
|
|
while (scan_string (&p, tmp_buf)) {
|
|
|
|
|
if (tmp_buf->str[0] != 0) {
|
|
|
|
|
module->info->extensions =
|
|
|
|
|
g_realloc (module->info->extensions, (n + 1) * sizeof (gchar*));
|
|
|
|
|
module->info->extensions[n - 1] = g_strdup (tmp_buf->str);
|
2004-10-28 15:00:05 +00:00
|
|
|
|
module->info->extensions[n] = NULL;
|
2002-10-03 22:39:51 +00:00
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
n_patterns++;
|
|
|
|
|
module->info->signature = (GdkPixbufModulePattern *)
|
|
|
|
|
g_realloc (module->info->signature, (n_patterns + 1) * sizeof (GdkPixbufModulePattern));
|
|
|
|
|
pattern = module->info->signature + n_patterns;
|
|
|
|
|
pattern->prefix = NULL;
|
|
|
|
|
pattern->mask = NULL;
|
|
|
|
|
pattern->relevance = 0;
|
|
|
|
|
pattern--;
|
|
|
|
|
if (!scan_string (&p, tmp_buf))
|
|
|
|
|
goto context_error;
|
|
|
|
|
pattern->prefix = g_strdup (tmp_buf->str);
|
|
|
|
|
|
|
|
|
|
if (!scan_string (&p, tmp_buf))
|
|
|
|
|
goto context_error;
|
|
|
|
|
if (*tmp_buf->str)
|
|
|
|
|
pattern->mask = g_strdup (tmp_buf->str);
|
|
|
|
|
else
|
|
|
|
|
pattern->mask = NULL;
|
|
|
|
|
|
|
|
|
|
if (!scan_int (&p, &pattern->relevance))
|
|
|
|
|
goto context_error;
|
|
|
|
|
|
|
|
|
|
goto next_line;
|
|
|
|
|
|
|
|
|
|
context_error:
|
|
|
|
|
g_free (pattern->prefix);
|
|
|
|
|
g_free (pattern->mask);
|
|
|
|
|
g_free (pattern);
|
|
|
|
|
g_warning ("Error parsing loader info in '%s'\n %s",
|
|
|
|
|
filename, line_buf);
|
|
|
|
|
have_error = TRUE;
|
|
|
|
|
}
|
|
|
|
|
next_line:
|
|
|
|
|
g_free (line_buf);
|
|
|
|
|
}
|
|
|
|
|
g_string_free (tmp_buf, TRUE);
|
|
|
|
|
g_io_channel_unref (channel);
|
|
|
|
|
g_free (filename);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
1999-10-29 19:27:51 +00:00
|
|
|
|
|
|
|
|
|
/* actually load the image handler - gdk_pixbuf_get_module only get a */
|
|
|
|
|
/* reference to the module to load, it doesn't actually load it */
|
|
|
|
|
/* perhaps these actions should be combined in one function */
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
_gdk_pixbuf_load_module_unlocked (GdkPixbufModule *image_module,
|
|
|
|
|
GError **error)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
1999-01-05 04:31:03 +00:00
|
|
|
|
char *path;
|
|
|
|
|
GModule *module;
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
gpointer sym;
|
2004-11-12 20:43:08 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
g_return_val_if_fail (image_module->module == NULL, FALSE);
|
1999-10-26 20:43:39 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
path = image_module->module_path;
|
2005-12-16 19:06:09 +00:00
|
|
|
|
module = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
|
|
|
|
|
if (!module) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_FAILED,
|
|
|
|
|
_("Unable to load image-loading module: %s: %s"),
|
|
|
|
|
path, g_module_error ());
|
|
|
|
|
return FALSE;
|
1999-10-27 18:55:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
image_module->module = module;
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (g_module_symbol (module, "fill_vtable", &sym)) {
|
|
|
|
|
GdkPixbufModuleFillVtableFunc func = (GdkPixbufModuleFillVtableFunc) sym;
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
(* func) (image_module);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
return TRUE;
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_FAILED,
|
|
|
|
|
_("Image-loading module %s does not export the proper interface; perhaps it's from a different GTK version?"),
|
|
|
|
|
path);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
return FALSE;
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
}
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
_gdk_pixbuf_load_module (GdkPixbufModule *image_module,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gboolean ret;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean locked = FALSE;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
/* be extra careful, maybe the module initializes
|
|
|
|
|
* the thread system
|
|
|
|
|
*/
|
|
|
|
|
if (g_threads_got_initialized)
|
|
|
|
|
{
|
|
|
|
|
G_LOCK (init_lock);
|
|
|
|
|
locked = TRUE;
|
|
|
|
|
}
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (locked)
|
|
|
|
|
G_UNLOCK (init_lock);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2004-11-12 20:43:08 +00:00
|
|
|
|
|
|
|
|
|
#else /* !USE_GMODULE */
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
#define module(type) \
|
|
|
|
|
extern void MODULE_ENTRY (type, fill_info) (GdkPixbufFormat *info); \
|
|
|
|
|
extern void MODULE_ENTRY (type, fill_vtable) (GdkPixbufModule *module)
|
|
|
|
|
|
|
|
|
|
module (png);
|
|
|
|
|
module (bmp);
|
|
|
|
|
module (wbmp);
|
|
|
|
|
module (gif);
|
|
|
|
|
module (ico);
|
|
|
|
|
module (ani);
|
|
|
|
|
module (jpeg);
|
|
|
|
|
module (pnm);
|
|
|
|
|
module (ras);
|
|
|
|
|
module (tiff);
|
|
|
|
|
module (xpm);
|
|
|
|
|
module (xbm);
|
|
|
|
|
module (tga);
|
2003-05-21 20:20:07 +00:00
|
|
|
|
module (pcx);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
gboolean
|
2001-02-20 02:59:30 +00:00
|
|
|
|
_gdk_pixbuf_load_module (GdkPixbufModule *image_module,
|
|
|
|
|
GError **error)
|
2000-02-22 00:29:00 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
GdkPixbufModuleFillInfoFunc fill_info = NULL;
|
|
|
|
|
GdkPixbufModuleFillVtableFunc fill_vtable = NULL;
|
|
|
|
|
|
2000-02-22 00:29:00 +00:00
|
|
|
|
image_module->module = (void *) 1;
|
2001-01-09 09:53:28 +00:00
|
|
|
|
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
if (FALSE) {
|
|
|
|
|
/* Ugly hack so we can use else if unconditionally below ;-) */
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_png
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "png") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (png, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (png, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_bmp
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "bmp") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (bmp, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (bmp, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_wbmp
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "wbmp") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (wbmp, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (wbmp, fill_vtable);
|
2000-07-28 00:09:36 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-07-28 00:09:36 +00:00
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_gif
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "gif") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (gif, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (gif, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_ico
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "ico") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (ico, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (ico, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2002-09-06 21:14:15 +00:00
|
|
|
|
#ifdef INCLUDE_ani
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "ani") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (ani, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (ani, fill_vtable);
|
2002-09-06 21:14:15 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#ifdef INCLUDE_jpeg
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "jpeg") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (jpeg, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (jpeg, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef INCLUDE_pnm
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "pnm") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (pnm, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (pnm, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef INCLUDE_ras
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "ras") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (ras, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (ras, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef INCLUDE_tiff
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "tiff") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (tiff, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (tiff, fill_vtable);
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
2001-01-09 09:53:28 +00:00
|
|
|
|
#endif
|
2000-10-18 18:42:54 +00:00
|
|
|
|
|
2001-01-22 02:08:53 +00:00
|
|
|
|
#ifdef INCLUDE_xpm
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "xpm") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (xpm, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (xpm, fill_vtable);
|
2001-01-22 02:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
#ifdef INCLUDE_xbm
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "xbm") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (xbm, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (xbm, fill_vtable);
|
2001-01-22 02:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-08-21 08:51:06 +00:00
|
|
|
|
#ifdef INCLUDE_tga
|
2002-10-03 22:39:51 +00:00
|
|
|
|
else if (strcmp (image_module->module_name, "tga") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (tga, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (tga, fill_vtable);
|
2001-08-21 08:51:06 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
|
2003-05-21 20:20:07 +00:00
|
|
|
|
#ifdef INCLUDE_pcx
|
|
|
|
|
else if (strcmp (image_module->module_name, "pcx") == 0) {
|
|
|
|
|
fill_info = MODULE_ENTRY (pcx, fill_info);
|
|
|
|
|
fill_vtable = MODULE_ENTRY (pcx, fill_vtable);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
if (fill_vtable) {
|
|
|
|
|
(* fill_vtable) (image_module);
|
2002-10-03 22:39:51 +00:00
|
|
|
|
image_module->info = g_new0 (GdkPixbufFormat, 1);
|
|
|
|
|
(* fill_info) (image_module->info);
|
|
|
|
|
|
Add built marshaller files to support GdkPixbufLoader signals
2001-01-22 Havoc Pennington <hp@redhat.com>
* Makefile.am: Add built marshaller files to support
GdkPixbufLoader signals
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): have
GDK_PIXBUF_MODULEDIR unconditionally replace the compiled-in
module location, rather than acting as a fallback, because we are
using GDK_PIXBUF_MODULEDIR to use gdk-pixbuf before installing it.
* gdk-pixbuf.h: include gdk-pixbuf-loader.h
* gdk-pixbuf-loader.h, gdk-pixbuf-loader.c: Move back over here
from gtk, and add error to close(), because stop_load may do
parsing of the image.
* pixops/have_mmx.S (_pixops_have_mmx): add newline at end of file
* io-*.c: make individual operations static, and add fill_vtable
functions which are exported. Fix the collection of type warnings
that surfaced, including a number of functions that didn't
properly take a GError and some that weren't
const-correct. Involved adding error handling for a few loaders.
* gdk-pixbuf-io.h: Add error reporting to stop_load function
* gdk-pixbuf-io.c (gdk_pixbuf_load_module): change to just look up
a function that fills in the GdkPixbufModule vtable, instead of
looking up all the image functions individually; this means we
can get type safety within modules for the loader functions.
Also it means you don't have to keep the statically compiled and
GModule versions in sync.
* test-gdk-pixbuf.c (main): remove gdk_pixbuf_init()
* make-inline-pixbuf.c (main): remove call to gdk_pixbuf_init()
* gdk-pixbuf.h: nuke gdk_pixbuf_init()
* gdk-pixbuf-animation.c (gdk_pixbuf_frame_get_type): g_type_init
() here
* gdk-pixbuf.c (gdk_pixbuf_get_type): g_type_init () here
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_get_type):
g_type_init() here
2001-01-22 Havoc Pennington <hp@redhat.com>
* demos/testanimation.c: fix to reflect gdk-pixbuf changes
* demos/testpixbuf.c: fix to reflect gdk-pixbuf changes
* gtk/gdk-pixbuf-loader.c, gtk/gdk-pixbuf-loader.h:
Remove, move back to gdk-pixbuf
* gtk/gtktextiter.c, gtk/gtktextiter.h: add sentence equivalents
to all the word functions
* gtk/gtktextview.c (gtk_text_view_start_cursor_blink): return
before doing anything on NULL layout or if we don't have the focus
* gtk/testtext.c (fill_example_buffer): "justification"
* gtk/gtktexttag.h, gtk/gtktexttag.c: change the tag attribute
to be called "justification" not "justify"
* demos/gtk-demo/textview.c (create_tags): "justification"
* gtk/gtktextlayout.c (set_para_values): Handle char-wise wrapping
2001-01-22 23:09:48 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
|
|
|
|
|
_("Image type '%s' is not supported"),
|
|
|
|
|
image_module->module_name);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2000-02-22 00:29:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
static void
|
|
|
|
|
gdk_pixbuf_io_init ()
|
|
|
|
|
{
|
|
|
|
|
gchar *included_formats[] = {
|
|
|
|
|
"ani", "png", "bmp", "wbmp", "gif",
|
|
|
|
|
"ico", "jpeg", "pnm", "ras", "tiff",
|
2003-05-21 20:20:07 +00:00
|
|
|
|
"xpm", "xbm", "tga", "pcx",
|
2002-10-03 22:39:51 +00:00
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
gchar **name;
|
|
|
|
|
GdkPixbufModule *module = NULL;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
for (name = included_formats; *name; name++) {
|
|
|
|
|
module = g_new0 (GdkPixbufModule, 1);
|
|
|
|
|
module->module_name = *name;
|
2004-11-12 20:43:08 +00:00
|
|
|
|
if (_gdk_pixbuf_load_module (module, NULL))
|
2002-10-03 22:39:51 +00:00
|
|
|
|
file_formats = g_slist_prepend (file_formats, module);
|
|
|
|
|
else
|
|
|
|
|
g_free (module);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-02-22 00:29:00 +00:00
|
|
|
|
|
2004-11-12 20:43:08 +00:00
|
|
|
|
#endif /* !USE_GMODULE */
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
|
|
|
|
|
2000-07-28 00:09:36 +00:00
|
|
|
|
GdkPixbufModule *
|
2001-02-20 02:59:30 +00:00
|
|
|
|
_gdk_pixbuf_get_named_module (const char *name,
|
|
|
|
|
GError **error)
|
2000-07-28 00:09:36 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
GSList *modules;
|
2000-07-28 00:09:36 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
|
|
|
|
|
GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
|
2004-07-08 03:56:36 +00:00
|
|
|
|
|
|
|
|
|
if (module->info->disabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (!strcmp (name, module->module_name))
|
|
|
|
|
return module;
|
2000-07-28 00:09:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
|
|
|
|
|
_("Image type '%s' is not supported"),
|
|
|
|
|
name);
|
|
|
|
|
|
2000-07-28 00:09:36 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-28 14:46:46 +00:00
|
|
|
|
GdkPixbufModule *
|
2001-02-20 02:59:30 +00:00
|
|
|
|
_gdk_pixbuf_get_module (guchar *buffer, guint size,
|
|
|
|
|
const gchar *filename,
|
|
|
|
|
GError **error)
|
1999-10-26 20:43:39 +00:00
|
|
|
|
{
|
2002-10-03 22:39:51 +00:00
|
|
|
|
GSList *modules;
|
|
|
|
|
|
|
|
|
|
gint score, best = 0;
|
|
|
|
|
GdkPixbufModule *selected = NULL;
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name = NULL;
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
|
|
|
|
|
GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
|
2004-07-08 03:56:36 +00:00
|
|
|
|
|
|
|
|
|
if (module->info->disabled)
|
|
|
|
|
continue;
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
score = format_check (module, buffer, size);
|
|
|
|
|
if (score > best) {
|
|
|
|
|
best = score;
|
|
|
|
|
selected = module;
|
|
|
|
|
}
|
|
|
|
|
if (score >= 100)
|
|
|
|
|
break;
|
1999-10-26 20:43:39 +00:00
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (selected != NULL)
|
|
|
|
|
return selected;
|
2000-01-02 03:59:22 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
if (filename)
|
2004-11-11 03:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
display_name = g_filename_display_name (filename);
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
|
|
|
|
|
_("Couldn't recognize the image file format for file '%s'"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name);
|
|
|
|
|
g_free (display_name);
|
2004-06-05 05:16:18 +00:00
|
|
|
|
}
|
2000-10-18 18:42:54 +00:00
|
|
|
|
else
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
|
|
|
|
|
_("Unrecognized image file format"));
|
|
|
|
|
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
1999-10-26 20:43:39 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-07 20:29:48 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
prepared_notify (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixbufAnimation *anim,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
if (pixbuf != NULL)
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
*((GdkPixbuf **)user_data) = pixbuf;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-22 21:32:06 +00:00
|
|
|
|
GdkPixbuf *
|
|
|
|
|
_gdk_pixbuf_generic_image_load (GdkPixbufModule *module,
|
|
|
|
|
FILE *f,
|
|
|
|
|
GError **error)
|
2002-07-07 20:29:48 +00:00
|
|
|
|
{
|
|
|
|
|
guchar buffer[4096];
|
|
|
|
|
size_t length;
|
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
2003-11-09 22:08:33 +00:00
|
|
|
|
GdkPixbufAnimation *animation = NULL;
|
2002-07-07 20:29:48 +00:00
|
|
|
|
gpointer context;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean locked;
|
2002-07-07 20:29:48 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
locked = _gdk_pixbuf_lock (module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
|
|
|
|
if (module->load != NULL) {
|
|
|
|
|
pixbuf = (* module->load) (f, error);
|
|
|
|
|
} else if (module->begin_load != NULL) {
|
2003-11-09 22:08:33 +00:00
|
|
|
|
|
|
|
|
|
context = module->begin_load (NULL, prepared_notify, NULL, &pixbuf, error);
|
2002-07-07 20:29:48 +00:00
|
|
|
|
|
2003-11-09 22:08:33 +00:00
|
|
|
|
if (!context)
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
goto out;
|
2003-11-09 22:08:33 +00:00
|
|
|
|
|
2004-04-13 14:57:03 +00:00
|
|
|
|
while (!feof (f) && !ferror (f)) {
|
2003-11-09 22:08:33 +00:00
|
|
|
|
length = fread (buffer, 1, sizeof (buffer), f);
|
|
|
|
|
if (length > 0)
|
|
|
|
|
if (!module->load_increment (context, buffer, length, error)) {
|
|
|
|
|
module->stop_load (context, NULL);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (pixbuf != NULL) {
|
2003-11-09 22:08:33 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
pixbuf = NULL;
|
|
|
|
|
}
|
|
|
|
|
goto out;
|
2003-11-09 22:08:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!module->stop_load (context, error)) {
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (pixbuf != NULL) {
|
2003-11-09 22:08:33 +00:00
|
|
|
|
g_object_unref (pixbuf);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
pixbuf = NULL;
|
|
|
|
|
}
|
2003-11-09 22:08:33 +00:00
|
|
|
|
}
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
} else if (module->load_animation != NULL) {
|
2003-11-09 22:08:33 +00:00
|
|
|
|
animation = (* module->load_animation) (f, error);
|
|
|
|
|
if (animation != NULL) {
|
|
|
|
|
pixbuf = gdk_pixbuf_animation_get_static_image (animation);
|
2002-07-07 20:29:48 +00:00
|
|
|
|
|
2003-11-09 22:08:33 +00:00
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
g_object_unref (animation);
|
|
|
|
|
}
|
2002-07-07 20:29:48 +00:00
|
|
|
|
}
|
2003-11-09 22:08:33 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
out:
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (locked)
|
|
|
|
|
_gdk_pixbuf_unlock (module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
return pixbuf;
|
2002-07-07 20:29:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 08:14:32 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new_from_file:
|
2004-12-05 12:43:47 +00:00
|
|
|
|
* @filename: Name of file to load, in the GLib file name encoding
|
2000-10-18 18:42:54 +00:00
|
|
|
|
* @error: Return location for an error
|
1999-11-10 06:40:12 +00:00
|
|
|
|
*
|
1999-11-04 08:14:32 +00:00
|
|
|
|
* Creates a new pixbuf by loading an image from a file. The file format is
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* detected automatically. If %NULL is returned, then @error will be set.
|
2000-10-18 18:42:54 +00:00
|
|
|
|
* Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
|
1999-11-10 06:40:12 +00:00
|
|
|
|
*
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
|
1999-11-10 06:40:12 +00:00
|
|
|
|
* any of several error conditions occurred: the file could not be opened,
|
|
|
|
|
* there was no loader for the file's format, there was not enough memory to
|
|
|
|
|
* allocate the image buffer, or the image file contained invalid data.
|
1999-11-04 08:14:32 +00:00
|
|
|
|
**/
|
1999-10-18 19:29:45 +00:00
|
|
|
|
GdkPixbuf *
|
2000-10-18 18:42:54 +00:00
|
|
|
|
gdk_pixbuf_new_from_file (const char *filename,
|
|
|
|
|
GError **error)
|
1999-01-04 23:53:12 +00:00
|
|
|
|
{
|
1999-10-18 19:29:45 +00:00
|
|
|
|
GdkPixbuf *pixbuf;
|
2000-01-02 03:59:22 +00:00
|
|
|
|
int size;
|
1999-01-04 23:53:12 +00:00
|
|
|
|
FILE *f;
|
2005-10-03 15:07:35 +00:00
|
|
|
|
guchar buffer[1024];
|
1999-10-28 14:46:46 +00:00
|
|
|
|
GdkPixbufModule *image_module;
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name;
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2000-01-02 03:59:22 +00:00
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
2003-04-24 18:51:07 +00:00
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2004-11-11 03:12:25 +00:00
|
|
|
|
|
|
|
|
|
display_name = g_filename_display_name (filename);
|
2000-01-02 03:59:22 +00:00
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
f = g_fopen (filename, "rb");
|
2000-10-18 18:42:54 +00:00
|
|
|
|
if (!f) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
|
_("Failed to open file '%s': %s"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name,
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_strerror (errno));
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
1999-01-04 23:53:12 +00:00
|
|
|
|
return NULL;
|
2000-10-18 18:42:54 +00:00
|
|
|
|
}
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
1999-10-26 20:43:39 +00:00
|
|
|
|
size = fread (&buffer, 1, sizeof (buffer), f);
|
|
|
|
|
if (size == 0) {
|
2000-10-18 18:42:54 +00:00
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
|
|
|
_("Image file '%s' contains no data"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name);
|
|
|
|
|
g_free (display_name);
|
1999-08-09 06:09:24 +00:00
|
|
|
|
fclose (f);
|
1999-01-04 23:53:12 +00:00
|
|
|
|
return NULL;
|
1999-01-05 04:31:03 +00:00
|
|
|
|
}
|
1999-01-04 23:53:12 +00:00
|
|
|
|
|
2001-02-20 02:59:30 +00:00
|
|
|
|
image_module = _gdk_pixbuf_get_module (buffer, size, filename, error);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
if (image_module == NULL) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
fclose (f);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-10-20 21:20:49 +00:00
|
|
|
|
|
2000-01-02 03:59:22 +00:00
|
|
|
|
if (image_module->module == NULL)
|
2001-02-20 02:59:30 +00:00
|
|
|
|
if (!_gdk_pixbuf_load_module (image_module, error)) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
fclose (f);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-10-26 20:43:39 +00:00
|
|
|
|
|
2000-01-02 03:59:22 +00:00
|
|
|
|
fseek (f, 0, SEEK_SET);
|
2002-08-22 21:32:06 +00:00
|
|
|
|
pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
|
1999-01-05 04:31:03 +00:00
|
|
|
|
fclose (f);
|
2000-01-02 03:59:22 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
if (pixbuf == NULL && error != NULL && *error == NULL) {
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
/* I don't trust these crufty longjmp()'ing image libs
|
|
|
|
|
* to maintain proper error invariants, and I don't
|
|
|
|
|
* want user code to segfault as a result. We need to maintain
|
2004-06-05 05:16:18 +00:00
|
|
|
|
* the invariant that error gets set if NULL is returned.
|
2000-10-18 18:42:54 +00:00
|
|
|
|
*/
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
g_warning ("Bug! gdk-pixbuf loader '%s' didn't set an error on failure.", image_module->module_name);
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_FAILED,
|
|
|
|
|
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
} else if (error != NULL && *error != NULL) {
|
|
|
|
|
|
|
|
|
|
/* Add the filename to the error message */
|
|
|
|
|
GError *e = *error;
|
2004-06-05 05:16:18 +00:00
|
|
|
|
gchar *old;
|
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
|
old = e->message;
|
|
|
|
|
e->message = g_strdup_printf (_("Failed to load image '%s': %s"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name,
|
2004-06-05 05:16:18 +00:00
|
|
|
|
old);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
g_free (old);
|
|
|
|
|
}
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2000-01-02 03:59:22 +00:00
|
|
|
|
return pixbuf;
|
1999-01-04 23:53:12 +00:00
|
|
|
|
}
|
1999-10-22 21:05:16 +00:00
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
#undef gdk_pixbuf_new_from_file
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
gdk_pixbuf_new_from_file (const char *filename,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gchar *utf8_filename =
|
|
|
|
|
g_locale_to_utf8 (filename, -1, NULL, NULL, error);
|
|
|
|
|
GdkPixbuf *retval;
|
|
|
|
|
|
|
|
|
|
if (utf8_filename == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
retval = gdk_pixbuf_new_from_file_utf8 (utf8_filename, error);
|
|
|
|
|
|
|
|
|
|
g_free (utf8_filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-23 22:55:34 +00:00
|
|
|
|
static void
|
|
|
|
|
size_prepared_cb (GdkPixbufLoader *loader,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
struct {
|
2004-08-26 05:33:13 +00:00
|
|
|
|
gint width;
|
|
|
|
|
gint height;
|
|
|
|
|
gboolean preserve_aspect_ratio;
|
2003-07-23 22:55:34 +00:00
|
|
|
|
} *info = data;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (width > 0 && height > 0);
|
|
|
|
|
|
2005-07-01 16:52:33 +00:00
|
|
|
|
if (info->preserve_aspect_ratio &&
|
|
|
|
|
(info->width > 0 || info->height > 0)) {
|
|
|
|
|
if (info->width < 0)
|
|
|
|
|
{
|
|
|
|
|
width = width * (double)info->height/(double)height;
|
|
|
|
|
height = info->height;
|
|
|
|
|
}
|
|
|
|
|
else if (info->height < 0)
|
|
|
|
|
{
|
|
|
|
|
height = height * (double)info->width/(double)width;
|
|
|
|
|
width = info->width;
|
|
|
|
|
}
|
|
|
|
|
else if ((double)height * (double)info->width >
|
|
|
|
|
(double)width * (double)info->height) {
|
2004-08-26 05:33:13 +00:00
|
|
|
|
width = 0.5 + (double)width * (double)info->height / (double)height;
|
|
|
|
|
height = info->height;
|
|
|
|
|
} else {
|
|
|
|
|
height = 0.5 + (double)height * (double)info->width / (double)width;
|
|
|
|
|
width = info->width;
|
|
|
|
|
}
|
2003-07-23 22:55:34 +00:00
|
|
|
|
} else {
|
2005-07-01 16:52:33 +00:00
|
|
|
|
if (info->width > 0)
|
|
|
|
|
width = info->width;
|
|
|
|
|
if (info->height > 0)
|
|
|
|
|
height = info->height;
|
2003-07-23 22:55:34 +00:00
|
|
|
|
}
|
2004-08-26 05:33:13 +00:00
|
|
|
|
|
2003-07-23 22:55:34 +00:00
|
|
|
|
gdk_pixbuf_loader_set_size (loader, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new_from_file_at_size:
|
|
|
|
|
* @filename: Name of file to load, in the GLib file name encoding
|
2005-07-01 16:52:33 +00:00
|
|
|
|
* @width: The width the image should have or -1 to not constrain the width
|
|
|
|
|
* @height: The height the image should have or -1 to not constrain the height
|
2004-12-05 12:43:47 +00:00
|
|
|
|
* @error: Return location for an error
|
|
|
|
|
*
|
|
|
|
|
* Creates a new pixbuf by loading an image from a file. The file format is
|
|
|
|
|
* detected automatically. If %NULL is returned, then @error will be set.
|
|
|
|
|
* Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
|
|
|
|
|
* The image will be scaled to fit in the requested size, preserving
|
|
|
|
|
* the image's aspect ratio.
|
|
|
|
|
*
|
|
|
|
|
* Return value: A newly-created pixbuf with a reference count of 1, or
|
|
|
|
|
* %NULL if any of several error conditions occurred: the file could not
|
|
|
|
|
* be opened, there was no loader for the file's format, there was not
|
|
|
|
|
* enough memory to allocate the image buffer, or the image file contained
|
|
|
|
|
* invalid data.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
gdk_pixbuf_new_from_file_at_size (const char *filename,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
return gdk_pixbuf_new_from_file_at_scale (filename,
|
|
|
|
|
width, height,
|
|
|
|
|
TRUE, error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
#undef gdk_pixbuf_new_from_file_at_size
|
|
|
|
|
|
|
|
|
|
GdkPixbuf *
|
|
|
|
|
gdk_pixbuf_new_from_file_at_size (const char *filename,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gchar *utf8_filename =
|
|
|
|
|
g_locale_to_utf8 (filename, -1, NULL, NULL, error);
|
|
|
|
|
GdkPixbuf *retval;
|
|
|
|
|
|
|
|
|
|
if (utf8_filename == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
retval = gdk_pixbuf_new_from_file_at_size_utf8 (utf8_filename,
|
|
|
|
|
width, height,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_free (utf8_filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-07-13 19:43:09 +00:00
|
|
|
|
/**
|
2004-08-26 05:33:13 +00:00
|
|
|
|
* gdk_pixbuf_new_from_file_at_scale:
|
2004-12-05 12:43:47 +00:00
|
|
|
|
* @filename: Name of file to load, in the GLib file name encoding
|
2005-07-01 16:52:33 +00:00
|
|
|
|
* @width: The width the image should have or -1 to not constrain the width
|
|
|
|
|
* @height: The height the image should have or -1 to not constrain the height
|
2004-08-26 05:33:13 +00:00
|
|
|
|
* @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
|
2003-07-13 19:43:09 +00:00
|
|
|
|
* @error: Return location for an error
|
|
|
|
|
*
|
|
|
|
|
* Creates a new pixbuf by loading an image from a file. The file format is
|
|
|
|
|
* detected automatically. If %NULL is returned, then @error will be set.
|
|
|
|
|
* Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
|
2004-08-26 05:33:13 +00:00
|
|
|
|
* The image will be scaled to fit in the requested size, optionally preserving
|
2005-07-01 16:52:33 +00:00
|
|
|
|
* the image's aspect ratio.
|
|
|
|
|
*
|
|
|
|
|
* When preserving the aspect ratio, a @width of -1 will cause the image
|
|
|
|
|
* to be scaled to the exact given height, and a @height of -1 will cause
|
|
|
|
|
* the image to be scaled to the exact given width. When not preserving
|
|
|
|
|
* aspect ratio, a @width or @height of -1 means to not scale the image
|
|
|
|
|
* at all in that dimension. Negative values for @width and @height are
|
|
|
|
|
* allowed since 2.8.
|
2003-07-13 19:43:09 +00:00
|
|
|
|
*
|
2004-08-26 05:33:13 +00:00
|
|
|
|
* Return value: A newly-created pixbuf with a reference count of 1, or %NULL
|
|
|
|
|
* if any of several error conditions occurred: the file could not be opened,
|
2003-07-13 19:43:09 +00:00
|
|
|
|
* there was no loader for the file's format, there was not enough memory to
|
|
|
|
|
* allocate the image buffer, or the image file contained invalid data.
|
|
|
|
|
*
|
2004-08-26 05:33:13 +00:00
|
|
|
|
* Since: 2.6
|
2003-07-13 19:43:09 +00:00
|
|
|
|
**/
|
|
|
|
|
GdkPixbuf *
|
2004-08-26 05:33:13 +00:00
|
|
|
|
gdk_pixbuf_new_from_file_at_scale (const char *filename,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
gboolean preserve_aspect_ratio,
|
|
|
|
|
GError **error)
|
2003-07-13 19:43:09 +00:00
|
|
|
|
{
|
2004-08-26 05:33:13 +00:00
|
|
|
|
|
2003-07-13 19:43:09 +00:00
|
|
|
|
GdkPixbufLoader *loader;
|
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
|
|
guchar buffer [4096];
|
|
|
|
|
int length;
|
|
|
|
|
FILE *f;
|
2003-07-23 22:55:34 +00:00
|
|
|
|
struct {
|
|
|
|
|
gint width;
|
|
|
|
|
gint height;
|
2004-08-26 05:33:13 +00:00
|
|
|
|
gboolean preserve_aspect_ratio;
|
2003-07-23 22:55:34 +00:00
|
|
|
|
} info;
|
2003-07-13 19:43:09 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
2005-07-01 16:52:33 +00:00
|
|
|
|
g_return_val_if_fail (width > 0 || width == -1, NULL);
|
|
|
|
|
g_return_val_if_fail (height > 0 || height == -1, NULL);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
f = g_fopen (filename, "rb");
|
2003-07-13 19:43:09 +00:00
|
|
|
|
if (!f) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name = g_filename_display_name (filename);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
g_set_error (error,
|
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
|
_("Failed to open file '%s': %s"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name,
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_strerror (errno));
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loader = gdk_pixbuf_loader_new ();
|
2003-07-23 22:55:34 +00:00
|
|
|
|
|
|
|
|
|
info.width = width;
|
|
|
|
|
info.height = height;
|
2004-08-26 05:33:13 +00:00
|
|
|
|
info.preserve_aspect_ratio = preserve_aspect_ratio;
|
2004-06-05 05:16:18 +00:00
|
|
|
|
|
2003-07-23 22:55:34 +00:00
|
|
|
|
g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
|
2004-04-13 14:57:03 +00:00
|
|
|
|
while (!feof (f) && !ferror (f)) {
|
2003-07-13 19:43:09 +00:00
|
|
|
|
length = fread (buffer, 1, sizeof (buffer), f);
|
|
|
|
|
if (length > 0)
|
|
|
|
|
if (!gdk_pixbuf_loader_write (loader, buffer, length, error)) {
|
2003-07-23 21:39:11 +00:00
|
|
|
|
gdk_pixbuf_loader_close (loader, NULL);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
fclose (f);
|
2004-02-08 09:13:18 +00:00
|
|
|
|
g_object_unref (loader);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose (f);
|
|
|
|
|
|
|
|
|
|
if (!gdk_pixbuf_loader_close (loader, error)) {
|
2004-02-08 09:13:18 +00:00
|
|
|
|
g_object_unref (loader);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
|
|
|
|
|
|
|
|
|
|
if (!pixbuf) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name = g_filename_display_name (filename);
|
2004-02-08 09:13:18 +00:00
|
|
|
|
g_object_unref (loader);
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_set_error (error,
|
2003-07-13 19:43:09 +00:00
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_FAILED,
|
|
|
|
|
_("Failed to load image '%s': reason not known, probably a corrupt image file"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name);
|
|
|
|
|
g_free (display_name);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_ref (pixbuf);
|
|
|
|
|
|
2004-02-08 09:13:18 +00:00
|
|
|
|
g_object_unref (loader);
|
2003-07-13 19:43:09 +00:00
|
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
|
}
|
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
#undef gdk_pixbuf_new_from_file_at_scale
|
|
|
|
|
|
2004-08-26 05:33:13 +00:00
|
|
|
|
GdkPixbuf *
|
2004-12-05 12:43:47 +00:00
|
|
|
|
gdk_pixbuf_new_from_file_at_scale (const char *filename,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
gboolean preserve_aspect_ratio,
|
|
|
|
|
GError **error)
|
2004-08-26 05:33:13 +00:00
|
|
|
|
{
|
2004-12-05 12:43:47 +00:00
|
|
|
|
gchar *utf8_filename =
|
|
|
|
|
g_locale_to_utf8 (filename, -1, NULL, NULL, error);
|
|
|
|
|
GdkPixbuf *retval;
|
|
|
|
|
|
|
|
|
|
if (utf8_filename == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
retval = gdk_pixbuf_new_from_file_at_scale_utf8 (utf8_filename,
|
|
|
|
|
width, height,
|
|
|
|
|
preserve_aspect_ratio,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_free (utf8_filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
2004-08-26 05:33:13 +00:00
|
|
|
|
}
|
2004-12-05 12:43:47 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2004-08-26 05:33:13 +00:00
|
|
|
|
|
2004-01-07 00:26:58 +00:00
|
|
|
|
static void
|
|
|
|
|
info_cb (GdkPixbufLoader *loader,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
struct {
|
|
|
|
|
GdkPixbufFormat *format;
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
} *info = data;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (width > 0 && height > 0);
|
|
|
|
|
|
|
|
|
|
info->format = gdk_pixbuf_loader_get_format (loader);
|
|
|
|
|
info->width = width;
|
|
|
|
|
info->height = height;
|
|
|
|
|
|
|
|
|
|
gdk_pixbuf_loader_set_size (loader, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_file_info:
|
|
|
|
|
* @filename: The name of the file to identify.
|
|
|
|
|
* @width: Return location for the width of the image, or %NULL
|
|
|
|
|
* @height: Return location for the height of the image, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Parses an image file far enough to determine its format and size.
|
|
|
|
|
*
|
|
|
|
|
* Returns: A #GdkPixbufFormat describing the image format of the file
|
|
|
|
|
* or %NULL if the image format wasn't recognized. The return value
|
|
|
|
|
* is owned by GdkPixbuf and should not be freed.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
GdkPixbufFormat *
|
|
|
|
|
gdk_pixbuf_get_file_info (const gchar *filename,
|
|
|
|
|
gint *width,
|
|
|
|
|
gint *height)
|
|
|
|
|
{
|
|
|
|
|
GdkPixbufLoader *loader;
|
|
|
|
|
guchar buffer [4096];
|
|
|
|
|
int length;
|
|
|
|
|
FILE *f;
|
|
|
|
|
struct {
|
|
|
|
|
GdkPixbufFormat *format;
|
|
|
|
|
gint width;
|
|
|
|
|
gint height;
|
|
|
|
|
} info;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
f = g_fopen (filename, "rb");
|
2004-01-07 00:26:58 +00:00
|
|
|
|
if (!f)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
loader = gdk_pixbuf_loader_new ();
|
|
|
|
|
|
|
|
|
|
info.format = NULL;
|
|
|
|
|
info.width = -1;
|
|
|
|
|
info.height = -1;
|
|
|
|
|
|
|
|
|
|
g_signal_connect (loader, "size-prepared", G_CALLBACK (info_cb), &info);
|
|
|
|
|
|
2004-04-13 14:57:03 +00:00
|
|
|
|
while (!feof (f) && !ferror (f)) {
|
2004-01-07 00:26:58 +00:00
|
|
|
|
length = fread (buffer, 1, sizeof (buffer), f);
|
|
|
|
|
if (length > 0) {
|
|
|
|
|
if (!gdk_pixbuf_loader_write (loader, buffer, length, NULL))
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (info.format != NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose (f);
|
|
|
|
|
gdk_pixbuf_loader_close (loader, NULL);
|
2004-02-08 09:13:18 +00:00
|
|
|
|
g_object_unref (loader);
|
2004-01-07 00:26:58 +00:00
|
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
|
*width = info.width;
|
|
|
|
|
if (height)
|
|
|
|
|
*height = info.height;
|
|
|
|
|
|
|
|
|
|
return info.format;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-10 06:40:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_new_from_xpm_data:
|
1999-11-10 22:48:46 +00:00
|
|
|
|
* @data: Pointer to inline XPM data.
|
1999-12-17 21:42:47 +00:00
|
|
|
|
*
|
1999-11-10 06:40:12 +00:00
|
|
|
|
* Creates a new pixbuf by parsing XPM data in memory. This data is commonly
|
|
|
|
|
* the result of including an XPM file into a program's C source.
|
1999-12-17 21:42:47 +00:00
|
|
|
|
*
|
1999-11-10 06:40:12 +00:00
|
|
|
|
* Return value: A newly-created pixbuf with a reference count of 1.
|
|
|
|
|
**/
|
1999-10-22 21:05:16 +00:00
|
|
|
|
GdkPixbuf *
|
2000-01-02 03:59:22 +00:00
|
|
|
|
gdk_pixbuf_new_from_xpm_data (const char **data)
|
1999-10-22 21:05:16 +00:00
|
|
|
|
{
|
2000-01-02 03:59:22 +00:00
|
|
|
|
GdkPixbuf *(* load_xpm_data) (const char **data);
|
|
|
|
|
GdkPixbuf *pixbuf;
|
2001-01-26 18:50:58 +00:00
|
|
|
|
GError *error = NULL;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
GdkPixbufModule *xpm_module;
|
|
|
|
|
gboolean locked;
|
|
|
|
|
|
|
|
|
|
xpm_module = _gdk_pixbuf_get_named_module ("xpm", &error);
|
2003-01-02 23:13:11 +00:00
|
|
|
|
if (xpm_module == NULL) {
|
|
|
|
|
g_warning ("Error loading XPM image loader: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-12-17 21:42:47 +00:00
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
if (xpm_module->module == NULL) {
|
|
|
|
|
if (!_gdk_pixbuf_load_module (xpm_module, &error)) {
|
2001-01-26 18:50:58 +00:00
|
|
|
|
g_warning ("Error loading XPM image loader: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
2003-01-02 23:13:11 +00:00
|
|
|
|
return NULL;
|
2001-01-26 18:50:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
locked = _gdk_pixbuf_lock (xpm_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2003-01-02 23:13:11 +00:00
|
|
|
|
if (xpm_module->load_xpm_data == NULL) {
|
2000-01-02 03:59:22 +00:00
|
|
|
|
g_warning ("gdk-pixbuf XPM module lacks XPM data capability");
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
pixbuf = NULL;
|
|
|
|
|
} else {
|
2002-10-03 22:39:51 +00:00
|
|
|
|
load_xpm_data = xpm_module->load_xpm_data;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
pixbuf = (* load_xpm_data) (data);
|
|
|
|
|
}
|
2004-11-16 02:51:19 +00:00
|
|
|
|
|
|
|
|
|
if (locked)
|
|
|
|
|
_gdk_pixbuf_unlock (xpm_module);
|
2000-01-02 03:59:22 +00:00
|
|
|
|
return pixbuf;
|
1999-12-17 21:42:47 +00:00
|
|
|
|
}
|
2000-10-06 18:19:18 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
collect_save_options (va_list opts,
|
|
|
|
|
gchar ***keys,
|
|
|
|
|
gchar ***vals)
|
|
|
|
|
{
|
|
|
|
|
gchar *key;
|
|
|
|
|
gchar *val;
|
|
|
|
|
gchar *next;
|
|
|
|
|
gint count;
|
|
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
*keys = NULL;
|
|
|
|
|
*vals = NULL;
|
|
|
|
|
|
|
|
|
|
next = va_arg (opts, gchar*);
|
|
|
|
|
while (next)
|
|
|
|
|
{
|
|
|
|
|
key = next;
|
|
|
|
|
val = va_arg (opts, gchar*);
|
|
|
|
|
|
|
|
|
|
++count;
|
|
|
|
|
|
|
|
|
|
/* woo, slow */
|
|
|
|
|
*keys = g_realloc (*keys, sizeof(gchar*) * (count + 1));
|
|
|
|
|
*vals = g_realloc (*vals, sizeof(gchar*) * (count + 1));
|
|
|
|
|
|
|
|
|
|
(*keys)[count-1] = g_strdup (key);
|
|
|
|
|
(*vals)[count-1] = g_strdup (val);
|
|
|
|
|
|
|
|
|
|
(*keys)[count] = NULL;
|
|
|
|
|
(*vals)[count] = NULL;
|
|
|
|
|
|
|
|
|
|
next = va_arg (opts, gchar*);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-07 01:57:42 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
save_to_file_callback (const gchar *buf,
|
|
|
|
|
gsize count,
|
|
|
|
|
GError **error,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
FILE *filehandle = data;
|
|
|
|
|
gsize n;
|
|
|
|
|
|
|
|
|
|
n = fwrite (buf, 1, count, filehandle);
|
|
|
|
|
if (n != count) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
|
_("Error writing to image file: %s"),
|
|
|
|
|
g_strerror (errno));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-06 18:19:18 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_pixbuf_real_save (GdkPixbuf *pixbuf,
|
|
|
|
|
FILE *filehandle,
|
2000-10-06 18:26:23 +00:00
|
|
|
|
const char *type,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
gchar **keys,
|
|
|
|
|
gchar **values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
gboolean ret;
|
|
|
|
|
GdkPixbufModule *image_module = NULL;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean locked;
|
2000-10-18 18:42:54 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
image_module = _gdk_pixbuf_get_named_module (type, error);
|
2000-10-18 18:42:54 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (image_module == NULL)
|
|
|
|
|
return FALSE;
|
2000-10-06 18:19:18 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (image_module->module == NULL)
|
|
|
|
|
if (!_gdk_pixbuf_load_module (image_module, error))
|
|
|
|
|
return FALSE;
|
2000-10-18 18:42:54 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
locked = _gdk_pixbuf_lock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
|
|
|
|
if (image_module->save) {
|
|
|
|
|
/* save normally */
|
|
|
|
|
ret = (* image_module->save) (filehandle, pixbuf,
|
2004-01-07 01:57:42 +00:00
|
|
|
|
keys, values,
|
|
|
|
|
error);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
} else if (image_module->save_to_callback) {
|
|
|
|
|
/* save with simple callback */
|
|
|
|
|
ret = (* image_module->save_to_callback) (save_to_file_callback,
|
2004-01-07 01:57:42 +00:00
|
|
|
|
filehandle, pixbuf,
|
|
|
|
|
keys, values,
|
|
|
|
|
error);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* can't save */
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
|
|
|
|
|
_("This build of gdk-pixbuf does not support saving the image format: %s"),
|
|
|
|
|
type);
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (locked)
|
|
|
|
|
_gdk_pixbuf_unlock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
return ret;
|
2004-01-07 01:57:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define TMP_FILE_BUF_SIZE 4096
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
save_to_callback_with_tmp_file (GdkPixbufModule *image_module,
|
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixbufSaveFunc save_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
gchar **keys,
|
|
|
|
|
gchar **values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
FILE *f = NULL;
|
|
|
|
|
gboolean retval = FALSE;
|
|
|
|
|
gchar *buf = NULL;
|
|
|
|
|
gsize n;
|
|
|
|
|
gchar *filename = NULL;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean locked;
|
2004-01-07 01:57:42 +00:00
|
|
|
|
|
|
|
|
|
buf = g_try_malloc (TMP_FILE_BUF_SIZE);
|
|
|
|
|
if (buf == NULL) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
|
|
|
_("Insufficient memory to save image to callback"));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd = g_file_open_tmp ("gdkpixbuf-save-tmp.XXXXXX", &filename, error);
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
goto end;
|
|
|
|
|
f = fdopen (fd, "wb+");
|
|
|
|
|
if (f == NULL) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
|
_("Failed to open temporary file"));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
locked = _gdk_pixbuf_lock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
retval = (image_module->save) (f, pixbuf, keys, values, error);
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (locked)
|
|
|
|
|
_gdk_pixbuf_unlock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (!retval)
|
2004-01-07 01:57:42 +00:00
|
|
|
|
goto end;
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
2004-01-07 01:57:42 +00:00
|
|
|
|
rewind (f);
|
|
|
|
|
for (;;) {
|
|
|
|
|
n = fread (buf, 1, TMP_FILE_BUF_SIZE, f);
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
if (!save_func (buf, n, error, user_data))
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
if (n != TMP_FILE_BUF_SIZE)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ferror (f)) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
|
|
|
|
_("Failed to read from temporary file"));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
/* cleanup and return retval */
|
|
|
|
|
if (f)
|
|
|
|
|
fclose (f);
|
|
|
|
|
if (filename) {
|
2004-12-05 12:43:47 +00:00
|
|
|
|
g_unlink (filename);
|
2004-01-07 01:57:42 +00:00
|
|
|
|
g_free (filename);
|
|
|
|
|
}
|
|
|
|
|
g_free (buf);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gdk_pixbuf_real_save_to_callback (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixbufSaveFunc save_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
const char *type,
|
|
|
|
|
gchar **keys,
|
|
|
|
|
gchar **values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
gboolean ret;
|
|
|
|
|
GdkPixbufModule *image_module = NULL;
|
2004-11-16 02:51:19 +00:00
|
|
|
|
gboolean locked;
|
2004-01-07 01:57:42 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
image_module = _gdk_pixbuf_get_named_module (type, error);
|
2004-01-07 01:57:42 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (image_module == NULL)
|
|
|
|
|
return FALSE;
|
2004-01-07 01:57:42 +00:00
|
|
|
|
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
if (image_module->module == NULL)
|
|
|
|
|
if (!_gdk_pixbuf_load_module (image_module, error))
|
|
|
|
|
return FALSE;
|
2004-01-07 01:57:42 +00:00
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
locked = _gdk_pixbuf_lock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
|
|
|
|
|
if (image_module->save_to_callback) {
|
|
|
|
|
/* save normally */
|
|
|
|
|
ret = (* image_module->save_to_callback) (save_func, user_data,
|
2004-01-07 01:57:42 +00:00
|
|
|
|
pixbuf, keys, values,
|
|
|
|
|
error);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
} else if (image_module->save) {
|
|
|
|
|
/* use a temporary file */
|
|
|
|
|
ret = save_to_callback_with_tmp_file (image_module, pixbuf,
|
2004-01-07 01:57:42 +00:00
|
|
|
|
save_func, user_data,
|
|
|
|
|
keys, values,
|
|
|
|
|
error);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* can't save */
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
|
|
|
|
|
_("This build of gdk-pixbuf does not support saving the image format: %s"),
|
|
|
|
|
type);
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-16 02:51:19 +00:00
|
|
|
|
if (locked)
|
|
|
|
|
_gdk_pixbuf_unlock (image_module);
|
Changes to make gdk-pixbuf threadsafe (#157310, #157306, Colin Walters):
2004-11-12 Matthias Clasen <mclasen@redhat.com>
Changes to make gdk-pixbuf threadsafe (#157310, #157306,
Colin Walters):
* gdk-pixbuf-io.h (enum GdkPixbufFormatFlags): Add
GDK_PIXBUF_FORMAT_THREADSAFE to indicate that an image loader
is threadsafe.
* gdk-pixbuf-io.c (get_file_formats, _gdk_pixbuf_load_module):
Use a lock to make initialization of global data structures
threadsafe.
* gdk-pixbuf-private.h:
* gdk-pixbuf-io.c (_gdk_pixbuf_lock, _gdk_pixbuf_unlock):
Auxiliary functions which use another lock to protect
threadunsafe image loaders.
* gdk-pixbuf-io.c (gdk_pixbuf_real_save):
(save_to_callback_with_tmp_file):
(gdk_pixbuf_real_save_to_callback):
(gdk_pixbuf_new_from_xpm_data):
(_gdk_pixbuf_generic_image_load):
* gdk-pixbuf-animation.c (gdk_pixbuf_animation_new_from_file):
* gdk-pixbuf-loader.c (gdk_pixbuf_loader_load_module):
(gdk_pixbuf_loader_close):
(gdk_pixbuf_loader_finalize):
Use _gdk_pixbuf_lock() and _gdk_pixbuf_unlock().
* io-ani.c, io-bmp.c, io-gif.c, io-ico.c:
* io-jpeg.c, io-pcx.c, io-png.c, io-pnm.c:
* io-ras.c, io-tga.c, io-wbmp.c, io-xbm.c:
* io-xpm.c: Mark as threadsafe.
* io-tiff.c: Remove pointless locking, mark as
threadunsafe.
2004-11-12 05:34:31 +00:00
|
|
|
|
return ret;
|
2000-10-06 18:19:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_save:
|
More precise documentation about underscores and mnemonics. (#66380)
* gtk/gtklabel.c (gtk_label_new_with_mnemonic),
gtk/gtkbutton.c (gtk_button_new_with_mnemonic): More precise
documentation about underscores and mnemonics. (#66380)
* gtk/gtktextiter.c (gtk_text_iter_backward_word_starts): Fix
cyclic reference in docs.
* gtk/gtklabel.c (gtk_label_set_justify): Correct documentation
of default value. (#65402)
* gtk/gtkmain.c (gtk_set_locale, gtk_disable_set_locale):
Markup fixes.
* gdk-pixbuf-io.c, gdk-pixbuf-animation.c, gdk-pixbuf-data.c,
gdk-pixbuf-loader.c, gdk-pixbuf-scale.c, gdk-pixbuf-util.c,
gdk-pixdata.c: Markup fixes.
* gtk/text_widget.sgml: More precise wording. (#63388)
* gtk/tmpl/gtksignal.sgml (GTK_SIGNAL_OFFSET): Add docs.
* gtk/resources.sgml: Fix markup of mail URLs.
* gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkobject.sgml: Markup fixes.
* gtk/tmpl/gtktoolbar.sgml (gtk_toolbar_{prepend,append}_element):
Expand documentation. (#60471)
* gtk/tmpl/gtkmain.sgml: Remove misleading information about
gtk_set_locale(). (#65758)
2001-12-20 23:09:29 +00:00
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @filename: name of file to save.
|
2000-10-06 18:26:23 +00:00
|
|
|
|
* @type: name of file format.
|
More precise documentation about underscores and mnemonics. (#66380)
* gtk/gtklabel.c (gtk_label_new_with_mnemonic),
gtk/gtkbutton.c (gtk_button_new_with_mnemonic): More precise
documentation about underscores and mnemonics. (#66380)
* gtk/gtktextiter.c (gtk_text_iter_backward_word_starts): Fix
cyclic reference in docs.
* gtk/gtklabel.c (gtk_label_set_justify): Correct documentation
of default value. (#65402)
* gtk/gtkmain.c (gtk_set_locale, gtk_disable_set_locale):
Markup fixes.
* gdk-pixbuf-io.c, gdk-pixbuf-animation.c, gdk-pixbuf-data.c,
gdk-pixbuf-loader.c, gdk-pixbuf-scale.c, gdk-pixbuf-util.c,
gdk-pixdata.c: Markup fixes.
* gtk/text_widget.sgml: More precise wording. (#63388)
* gtk/tmpl/gtksignal.sgml (GTK_SIGNAL_OFFSET): Add docs.
* gtk/resources.sgml: Fix markup of mail URLs.
* gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkobject.sgml: Markup fixes.
* gtk/tmpl/gtktoolbar.sgml (gtk_toolbar_{prepend,append}_element):
Expand documentation. (#60471)
* gtk/tmpl/gtkmain.sgml: Remove misleading information about
gtk_set_locale(). (#65758)
2001-12-20 23:09:29 +00:00
|
|
|
|
* @error: return location for error, or %NULL
|
2000-10-06 18:19:18 +00:00
|
|
|
|
* @Varargs: list of key-value save options
|
|
|
|
|
*
|
2005-02-24 04:41:35 +00:00
|
|
|
|
* Saves pixbuf to a file in format @type. By default, "jpeg", "png", "ico"
|
|
|
|
|
* and "bmp" are possible file formats to save in, but more formats may be
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* installed. The list of all writable formats can be determined in the
|
|
|
|
|
* following way:
|
|
|
|
|
*
|
|
|
|
|
* <informalexample><programlisting>
|
|
|
|
|
* void add_if_writable (GdkPixbufFormat *data, GSList **list)
|
|
|
|
|
* {
|
|
|
|
|
* if (gdk_pixbuf_format_is_writable (data))
|
|
|
|
|
* *list = g_slist_prepend (*list, data);
|
|
|
|
|
* }
|
2004-01-07 03:31:21 +00:00
|
|
|
|
* <!-- -->
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* GSList *formats = gdk_pixbuf_get_formats (<!-- -->);
|
|
|
|
|
* GSList *writable_formats = NULL;
|
2004-01-07 03:31:21 +00:00
|
|
|
|
* g_slist_foreach (formats, add_if_writable, &writable_formats);
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* g_slist_free (formats);
|
|
|
|
|
* </programlisting></informalexample>
|
|
|
|
|
*
|
|
|
|
|
* If @error is set, %FALSE will be returned. Possible errors include
|
2001-10-05 18:51:47 +00:00
|
|
|
|
* those in the #GDK_PIXBUF_ERROR domain and those in the #G_FILE_ERROR domain.
|
2000-10-06 18:19:18 +00:00
|
|
|
|
*
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* The variable argument list should be %NULL-terminated; if not empty,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
* it should contain pairs of strings that modify the save
|
|
|
|
|
* parameters. For example:
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* <informalexample><programlisting>
|
More precise documentation about underscores and mnemonics. (#66380)
* gtk/gtklabel.c (gtk_label_new_with_mnemonic),
gtk/gtkbutton.c (gtk_button_new_with_mnemonic): More precise
documentation about underscores and mnemonics. (#66380)
* gtk/gtktextiter.c (gtk_text_iter_backward_word_starts): Fix
cyclic reference in docs.
* gtk/gtklabel.c (gtk_label_set_justify): Correct documentation
of default value. (#65402)
* gtk/gtkmain.c (gtk_set_locale, gtk_disable_set_locale):
Markup fixes.
* gdk-pixbuf-io.c, gdk-pixbuf-animation.c, gdk-pixbuf-data.c,
gdk-pixbuf-loader.c, gdk-pixbuf-scale.c, gdk-pixbuf-util.c,
gdk-pixdata.c: Markup fixes.
* gtk/text_widget.sgml: More precise wording. (#63388)
* gtk/tmpl/gtksignal.sgml (GTK_SIGNAL_OFFSET): Add docs.
* gtk/resources.sgml: Fix markup of mail URLs.
* gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkobject.sgml: Markup fixes.
* gtk/tmpl/gtktoolbar.sgml (gtk_toolbar_{prepend,append}_element):
Expand documentation. (#60471)
* gtk/tmpl/gtkmain.sgml: Remove misleading information about
gtk_set_locale(). (#65758)
2001-12-20 23:09:29 +00:00
|
|
|
|
* gdk_pixbuf_save (pixbuf, handle, "jpeg", &error,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
* "quality", "100", NULL);
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* </programlisting></informalexample>
|
2000-10-06 18:19:18 +00:00
|
|
|
|
*
|
2005-05-24 17:09:56 +00:00
|
|
|
|
* Currently only few parameters exist. JPEG images can be saved with a
|
|
|
|
|
* "quality" parameter; its value should be in the range [0,100].
|
|
|
|
|
*
|
2001-10-05 18:51:47 +00:00
|
|
|
|
* Text chunks can be attached to PNG images by specifying parameters of
|
|
|
|
|
* the form "tEXt::key", where key is an ASCII string of length 1-79.
|
2005-05-24 17:09:56 +00:00
|
|
|
|
* The values are UTF-8 encoded strings. The PNG compression level can
|
|
|
|
|
* be specified using the "compression" parameter; it's value is in an
|
|
|
|
|
* integer in the range of [0,9].
|
|
|
|
|
*
|
2003-07-03 23:37:34 +00:00
|
|
|
|
* ICO images can be saved in depth 16, 24, or 32, by using the "depth"
|
|
|
|
|
* parameter. When the ICO saver is given "x_hot" and "y_hot" parameters,
|
|
|
|
|
* it produces a CUR instead of an ICO.
|
2000-10-06 18:19:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save (GdkPixbuf *pixbuf,
|
|
|
|
|
const char *filename,
|
2000-10-06 18:26:23 +00:00
|
|
|
|
const char *type,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
GError **error,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
gchar **keys = NULL;
|
|
|
|
|
gchar **values = NULL;
|
|
|
|
|
va_list args;
|
|
|
|
|
gboolean result;
|
2003-04-24 18:51:07 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
|
|
|
|
|
va_start (args, error);
|
|
|
|
|
|
|
|
|
|
collect_save_options (args, &keys, &values);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
2000-10-06 18:26:23 +00:00
|
|
|
|
result = gdk_pixbuf_savev (pixbuf, filename, type,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
keys, values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
g_strfreev (values);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-10 19:13:19 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
#undef gdk_pixbuf_save
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save (GdkPixbuf *pixbuf,
|
|
|
|
|
const char *filename,
|
|
|
|
|
const char *type,
|
|
|
|
|
GError **error,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
char *utf8_filename;
|
|
|
|
|
gchar **keys = NULL;
|
|
|
|
|
gchar **values = NULL;
|
|
|
|
|
va_list args;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
|
|
|
|
|
|
|
|
|
|
if (utf8_filename == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
va_start (args, error);
|
|
|
|
|
|
|
|
|
|
collect_save_options (args, &keys, &values);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
result = gdk_pixbuf_savev_utf8 (pixbuf, utf8_filename, type,
|
|
|
|
|
keys, values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_free (utf8_filename);
|
|
|
|
|
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
g_strfreev (values);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-10-06 18:19:18 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_savev:
|
More precise documentation about underscores and mnemonics. (#66380)
* gtk/gtklabel.c (gtk_label_new_with_mnemonic),
gtk/gtkbutton.c (gtk_button_new_with_mnemonic): More precise
documentation about underscores and mnemonics. (#66380)
* gtk/gtktextiter.c (gtk_text_iter_backward_word_starts): Fix
cyclic reference in docs.
* gtk/gtklabel.c (gtk_label_set_justify): Correct documentation
of default value. (#65402)
* gtk/gtkmain.c (gtk_set_locale, gtk_disable_set_locale):
Markup fixes.
* gdk-pixbuf-io.c, gdk-pixbuf-animation.c, gdk-pixbuf-data.c,
gdk-pixbuf-loader.c, gdk-pixbuf-scale.c, gdk-pixbuf-util.c,
gdk-pixdata.c: Markup fixes.
* gtk/text_widget.sgml: More precise wording. (#63388)
* gtk/tmpl/gtksignal.sgml (GTK_SIGNAL_OFFSET): Add docs.
* gtk/resources.sgml: Fix markup of mail URLs.
* gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkobject.sgml: Markup fixes.
* gtk/tmpl/gtktoolbar.sgml (gtk_toolbar_{prepend,append}_element):
Expand documentation. (#60471)
* gtk/tmpl/gtkmain.sgml: Remove misleading information about
gtk_set_locale(). (#65758)
2001-12-20 23:09:29 +00:00
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @filename: name of file to save.
|
2000-10-06 18:26:23 +00:00
|
|
|
|
* @type: name of file format.
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* @option_keys: name of options to set, %NULL-terminated
|
2000-10-06 18:19:18 +00:00
|
|
|
|
* @option_values: values for named options
|
Markup fixes.
* gtk/gtkdialog.c, gtk/gtkrc.c, gtk/gtkwidget.c: Markup fixes.
* gdk-pixbuf-io.c: Markup fixes.
* gdk-pixbuf/tmpl/scaling.sgml, gdk/tmpl/fonts.sgml,
gdk/tmpl/general.sgml, gdk/tmpl/rgb.sgml, gdk/tmpl/visuals.sgml,
gdk/tmpl/windows.sgml, gtk/gtk-docs.sgml, gtk/tmpl/gtkaccellabel.sgml,
gtk/tmpl/gtkcombo.sgml, gtk/tmpl/gtkdialog.sgml,
gtk/tmpl/gtkdrawingarea.sgml, gtk/tmpl/gtkeditable.sgml,
gtk/tmpl/gtkfilesel.sgml, gtk/tmpl/gtkfontseldlg.sgml,
gtk/tmpl/gtkimage.sgml, gtk/tmpl/gtkmain.sgml, gtk/tmpl/gtkmenu.sgml,
gtk/tmpl/gtkmessagedialog.sgml, gtk/tmpl/gtkobject.sgml,
gtk/tmpl/gtkpaned.sgml, gtk/tmpl/gtkradiobutton.sgml,
gtk/tmpl/gtkrc.sgml, gtk/tmpl/gtkscale.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtksocket.sgml, gtk/tmpl/gtkspinbutton.sgml,
gtk/tmpl/gtktogglebutton.sgml, gtk/tmpl/gtksignal.sgml,
gtk/tmpl/gtktooltips.sgml, gtk/tmpl/gtkwindow.sgml,
gdk/tmpl/regions.sgml, gtk/tmpl/gtkfontsel.sgml,
gtk/tmpl/gtkpixmap.sgml, gtk/tmpl/gtkprogress.sgml,
gtk/tmpl/gtkselection.sgml, gtk/tmpl/gtktable.sgml,
gtk/tmpl/gtktipsquery.sgml: Markup fixes (mainly examples).
2001-12-13 19:51:24 +00:00
|
|
|
|
* @error: return location for error, or %NULL
|
2000-10-06 18:19:18 +00:00
|
|
|
|
*
|
2006-02-28 09:48:49 +00:00
|
|
|
|
* Saves pixbuf to a file in @type, which is currently "jpeg", "png", "tiff", "ico" or "bmp".
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* If @error is set, %FALSE will be returned.
|
|
|
|
|
* See gdk_pixbuf_save () for more details.
|
2000-10-06 18:19:18 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_savev (GdkPixbuf *pixbuf,
|
|
|
|
|
const char *filename,
|
2000-10-06 18:26:23 +00:00
|
|
|
|
const char *type,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
char **option_keys,
|
|
|
|
|
char **option_values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
FILE *f = NULL;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
2000-10-06 18:26:23 +00:00
|
|
|
|
g_return_val_if_fail (type != NULL, FALSE);
|
2003-04-24 18:51:07 +00:00
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
|
2004-12-05 12:43:47 +00:00
|
|
|
|
f = g_fopen (filename, "wb");
|
2000-10-06 18:19:18 +00:00
|
|
|
|
|
|
|
|
|
if (f == NULL) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name = g_filename_display_name (filename);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
g_set_error (error,
|
2000-10-18 18:42:54 +00:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
2000-10-06 18:19:18 +00:00
|
|
|
|
_("Failed to open '%s' for writing: %s"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name,
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_strerror (errno));
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-06 18:26:23 +00:00
|
|
|
|
result = gdk_pixbuf_real_save (pixbuf, f, type,
|
2000-10-06 18:19:18 +00:00
|
|
|
|
option_keys, option_values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error != NULL, FALSE);
|
|
|
|
|
fclose (f);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fclose (f) < 0) {
|
2004-11-11 03:12:25 +00:00
|
|
|
|
gchar *display_name = g_filename_display_name (filename);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
g_set_error (error,
|
2000-10-18 18:42:54 +00:00
|
|
|
|
G_FILE_ERROR,
|
|
|
|
|
g_file_error_from_errno (errno),
|
2000-10-06 18:19:18 +00:00
|
|
|
|
_("Failed to close '%s' while writing image, all data may not have been saved: %s"),
|
2004-11-11 03:12:25 +00:00
|
|
|
|
display_name,
|
2004-06-05 05:16:18 +00:00
|
|
|
|
g_strerror (errno));
|
2004-11-11 03:12:25 +00:00
|
|
|
|
g_free (display_name);
|
2000-10-06 18:19:18 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
2005-03-10 19:13:19 +00:00
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
|
|
|
|
|
#undef gdk_pixbuf_savev
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_savev (GdkPixbuf *pixbuf,
|
|
|
|
|
const char *filename,
|
|
|
|
|
const char *type,
|
|
|
|
|
char **option_keys,
|
|
|
|
|
char **option_values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
char *utf8_filename;
|
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
utf8_filename = g_locale_to_utf8 (filename, -1, NULL, NULL, error);
|
|
|
|
|
|
|
|
|
|
if (utf8_filename == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
retval = gdk_pixbuf_savev_utf8 (pixbuf, utf8_filename, type,
|
|
|
|
|
option_keys, option_values, error);
|
|
|
|
|
|
|
|
|
|
g_free (utf8_filename);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-01-07 01:57:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_save_to_callback:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @save_func: a function that is called to save each block of data that
|
|
|
|
|
* the save routine generates.
|
|
|
|
|
* @user_data: user data to pass to the save function.
|
|
|
|
|
* @type: name of file format.
|
|
|
|
|
* @error: return location for error, or %NULL
|
|
|
|
|
* @Varargs: list of key-value save options
|
|
|
|
|
*
|
|
|
|
|
* Saves pixbuf in format @type by feeding the produced data to a
|
|
|
|
|
* callback. Can be used when you want to store the image to something
|
|
|
|
|
* other than a file, such as an in-memory buffer or a socket.
|
|
|
|
|
* If @error is set, %FALSE will be returned. Possible errors
|
|
|
|
|
* include those in the #GDK_PIXBUF_ERROR domain and whatever the save
|
|
|
|
|
* function generates.
|
|
|
|
|
*
|
|
|
|
|
* See gdk_pixbuf_save() for more details.
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save_to_callback (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixbufSaveFunc save_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
const char *type,
|
|
|
|
|
GError **error,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
gchar **keys = NULL;
|
|
|
|
|
gchar **values = NULL;
|
|
|
|
|
va_list args;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
va_start (args, error);
|
|
|
|
|
|
|
|
|
|
collect_save_options (args, &keys, &values);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
result = gdk_pixbuf_save_to_callbackv (pixbuf, save_func, user_data,
|
|
|
|
|
type, keys, values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
g_strfreev (values);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_save_to_callbackv:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @save_func: a function that is called to save each block of data that
|
|
|
|
|
* the save routine generates.
|
|
|
|
|
* @user_data: user data to pass to the save function.
|
|
|
|
|
* @type: name of file format.
|
|
|
|
|
* @option_keys: name of options to set, %NULL-terminated
|
|
|
|
|
* @option_values: values for named options
|
|
|
|
|
* @error: return location for error, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Saves pixbuf to a callback in format @type, which is currently "jpeg",
|
2006-02-28 09:48:49 +00:00
|
|
|
|
* "png", "tiff", "ico" or "bmp". If @error is set, %FALSE will be returned. See
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* gdk_pixbuf_save_to_callback () for more details.
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf,
|
|
|
|
|
GdkPixbufSaveFunc save_func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
const char *type,
|
|
|
|
|
char **option_keys,
|
|
|
|
|
char **option_values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (save_func != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (type != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
result = gdk_pixbuf_real_save_to_callback (pixbuf,
|
|
|
|
|
save_func, user_data, type,
|
|
|
|
|
option_keys, option_values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error != NULL, FALSE);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_save_to_buffer:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @buffer: location to receive a pointer to the new buffer.
|
|
|
|
|
* @buffer_size: location to receive the size of the new buffer.
|
|
|
|
|
* @type: name of file format.
|
|
|
|
|
* @error: return location for error, or %NULL
|
|
|
|
|
* @Varargs: list of key-value save options
|
|
|
|
|
*
|
|
|
|
|
* Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
|
2006-02-28 09:48:49 +00:00
|
|
|
|
* "png", "tiff", "ico" or "bmp". This is a convenience function that uses
|
2004-01-07 01:57:42 +00:00
|
|
|
|
* gdk_pixbuf_save_to_callback() to do the real work. Note that the buffer
|
|
|
|
|
* is not nul-terminated and may contain embedded nuls.
|
|
|
|
|
* If @error is set, %FALSE will be returned and @string will be set to
|
|
|
|
|
* %NULL. Possible errors include those in the #GDK_PIXBUF_ERROR
|
|
|
|
|
* domain.
|
|
|
|
|
*
|
|
|
|
|
* See gdk_pixbuf_save() for more details.
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save_to_buffer (GdkPixbuf *pixbuf,
|
|
|
|
|
gchar **buffer,
|
|
|
|
|
gsize *buffer_size,
|
|
|
|
|
const char *type,
|
|
|
|
|
GError **error,
|
|
|
|
|
...)
|
|
|
|
|
{
|
|
|
|
|
gchar **keys = NULL;
|
|
|
|
|
gchar **values = NULL;
|
|
|
|
|
va_list args;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
va_start (args, error);
|
|
|
|
|
|
|
|
|
|
collect_save_options (args, &keys, &values);
|
|
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
|
|
result = gdk_pixbuf_save_to_bufferv (pixbuf, buffer, buffer_size,
|
|
|
|
|
type, keys, values,
|
|
|
|
|
error);
|
|
|
|
|
|
|
|
|
|
g_strfreev (keys);
|
|
|
|
|
g_strfreev (values);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct SaveToBufferData {
|
|
|
|
|
gchar *buffer;
|
|
|
|
|
gsize len, max;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
save_to_buffer_callback (const gchar *data,
|
|
|
|
|
gsize count,
|
|
|
|
|
GError **error,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
struct SaveToBufferData *sdata = user_data;
|
|
|
|
|
gchar *new_buffer;
|
|
|
|
|
gsize new_max;
|
|
|
|
|
|
|
|
|
|
if (sdata->len + count > sdata->max) {
|
|
|
|
|
new_max = MAX (sdata->max*2, sdata->len + count);
|
|
|
|
|
new_buffer = g_try_realloc (sdata->buffer, new_max);
|
|
|
|
|
if (!new_buffer) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
|
|
|
_("Insufficient memory to save image into a buffer"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
sdata->buffer = new_buffer;
|
|
|
|
|
sdata->max = new_max;
|
|
|
|
|
}
|
|
|
|
|
memcpy (sdata->buffer + sdata->len, data, count);
|
|
|
|
|
sdata->len += count;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_save_to_bufferv:
|
|
|
|
|
* @pixbuf: a #GdkPixbuf.
|
|
|
|
|
* @buffer: location to receive a pointer to the new buffer.
|
|
|
|
|
* @buffer_size: location to receive the size of the new buffer.
|
|
|
|
|
* @type: name of file format.
|
|
|
|
|
* @option_keys: name of options to set, %NULL-terminated
|
|
|
|
|
* @option_values: values for named options
|
|
|
|
|
* @error: return location for error, or %NULL
|
|
|
|
|
*
|
|
|
|
|
* Saves pixbuf to a new buffer in format @type, which is currently "jpeg",
|
2006-02-28 09:48:49 +00:00
|
|
|
|
* "tiff", "png", "ico" or "bmp". See gdk_pixbuf_save_to_buffer() for more details.
|
2004-01-07 01:57:42 +00:00
|
|
|
|
*
|
|
|
|
|
* Return value: whether an error was set
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_save_to_bufferv (GdkPixbuf *pixbuf,
|
|
|
|
|
gchar **buffer,
|
|
|
|
|
gsize *buffer_size,
|
|
|
|
|
const char *type,
|
|
|
|
|
char **option_keys,
|
|
|
|
|
char **option_values,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
static const gint initial_max = 1024;
|
|
|
|
|
struct SaveToBufferData sdata;
|
|
|
|
|
|
|
|
|
|
*buffer = NULL;
|
|
|
|
|
*buffer_size = 0;
|
|
|
|
|
|
|
|
|
|
sdata.buffer = g_try_malloc (initial_max);
|
|
|
|
|
sdata.max = initial_max;
|
|
|
|
|
sdata.len = 0;
|
|
|
|
|
if (!sdata.buffer) {
|
|
|
|
|
g_set_error (error,
|
|
|
|
|
GDK_PIXBUF_ERROR,
|
|
|
|
|
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
|
|
|
_("Insufficient memory to save image into a buffer"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!gdk_pixbuf_save_to_callbackv (pixbuf,
|
|
|
|
|
save_to_buffer_callback, &sdata,
|
|
|
|
|
type, option_keys, option_values,
|
|
|
|
|
error)) {
|
|
|
|
|
g_free (sdata.buffer);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*buffer = sdata.buffer;
|
|
|
|
|
*buffer_size = sdata.len;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_get_name:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns the name of the format.
|
|
|
|
|
*
|
|
|
|
|
* Return value: the name of the format.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
gchar *
|
|
|
|
|
gdk_pixbuf_format_get_name (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_strdup (format->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_get_description:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns a description of the format.
|
|
|
|
|
*
|
2003-07-11 20:36:25 +00:00
|
|
|
|
* Return value: a description of the format.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
gchar *
|
|
|
|
|
gdk_pixbuf_format_get_description (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
gchar *domain;
|
|
|
|
|
gchar *description;
|
|
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (format->domain != NULL)
|
|
|
|
|
domain = format->domain;
|
|
|
|
|
else
|
|
|
|
|
domain = GETTEXT_PACKAGE;
|
|
|
|
|
description = dgettext (domain, format->description);
|
|
|
|
|
|
|
|
|
|
return g_strdup (description);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_get_mime_types:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns the mime types supported by the format.
|
|
|
|
|
*
|
2003-07-11 20:36:25 +00:00
|
|
|
|
* Return value: a %NULL-terminated array of mime types which must be freed with
|
|
|
|
|
* g_strfreev() when it is no longer needed.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
gchar **
|
|
|
|
|
gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_strdupv (format->mime_types);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_get_extensions:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
2002-11-28 00:33:17 +00:00
|
|
|
|
* Returns the filename extensions typically used for files in the
|
|
|
|
|
* given format.
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*
|
2003-07-11 20:36:25 +00:00
|
|
|
|
* Return value: a %NULL-terminated array of filename extensions which must be
|
|
|
|
|
* freed with g_strfreev() when it is no longer needed.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
gchar **
|
|
|
|
|
gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return g_strdupv (format->extensions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_is_writable:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns whether pixbufs can be saved in the given format.
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether pixbufs can be saved in the given format.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_format_is_writable (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
return (format->flags & GDK_PIXBUF_FORMAT_WRITABLE) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-06 03:14:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_is_scalable:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns whether this image format is scalable. If a file is in a
|
|
|
|
|
* scalable format, it is preferable to load it at the desired size,
|
|
|
|
|
* rather than loading it at the default size and scaling the
|
|
|
|
|
* resulting pixbuf to the desired size.
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether this image format is scalable.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.6
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_format_is_scalable (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
return (format->flags & GDK_PIXBUF_FORMAT_SCALABLE) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-08 03:56:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_is_disabled:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
|
|
|
|
* Returns whether this image format is disabled. See
|
|
|
|
|
* gdk_pixbuf_format_set_disabled().
|
|
|
|
|
*
|
|
|
|
|
* Return value: whether this image format is disabled.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.6
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gdk_pixbuf_format_is_disabled (GdkPixbufFormat *format)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
return format->disabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_set_disabled:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
* @disabled: %TRUE to disable the format @format
|
|
|
|
|
*
|
|
|
|
|
* Disables or enables an image format. If a format is disabled,
|
|
|
|
|
* gdk-pixbuf won't use the image loader for this format to load
|
|
|
|
|
* images. Applications can use this to avoid using image loaders
|
|
|
|
|
* with an inappropriate license, see gdk_pixbuf_format_get_license().
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.6
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gdk_pixbuf_format_set_disabled (GdkPixbufFormat *format,
|
|
|
|
|
gboolean disabled)
|
|
|
|
|
{
|
2004-07-09 22:40:37 +00:00
|
|
|
|
g_return_if_fail (format != NULL);
|
2004-07-08 03:56:36 +00:00
|
|
|
|
|
|
|
|
|
format->disabled = disabled != FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_format_get_license:
|
|
|
|
|
* @format: a #GdkPixbufFormat
|
|
|
|
|
*
|
2005-12-30 06:02:04 +00:00
|
|
|
|
* Returns information about the license of the image loader for the format. The
|
|
|
|
|
* returned string should be a shorthand for a wellknown license, e.g. "LGPL",
|
|
|
|
|
* "GPL", "QPL", "GPL/QPL", or "other" to indicate some other license. This
|
|
|
|
|
* string should be freed with g_free() when it's no longer needed.
|
2004-07-08 03:56:36 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: a string describing the license of @format.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.6
|
|
|
|
|
*/
|
|
|
|
|
gchar*
|
|
|
|
|
gdk_pixbuf_format_get_license (GdkPixbufFormat *format)
|
|
|
|
|
{
|
2004-10-28 15:00:05 +00:00
|
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
2004-07-08 03:56:36 +00:00
|
|
|
|
|
|
|
|
|
return g_strdup (format->license);
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
GdkPixbufFormat *
|
|
|
|
|
_gdk_pixbuf_get_format (GdkPixbufModule *module)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (module != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
return module->info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gdk_pixbuf_get_formats:
|
|
|
|
|
*
|
|
|
|
|
* Obtains the available information about the image formats supported
|
|
|
|
|
* by GdkPixbuf.
|
|
|
|
|
*
|
|
|
|
|
* Returns: A list of #GdkPixbufFormat<!-- -->s describing the supported
|
|
|
|
|
* image formats. The list should be freed when it is no longer needed,
|
|
|
|
|
* but the structures themselves are owned by #GdkPixbuf and should not be
|
|
|
|
|
* freed.
|
2002-11-28 00:33:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.2
|
2002-10-03 22:39:51 +00:00
|
|
|
|
*/
|
|
|
|
|
GSList *
|
|
|
|
|
gdk_pixbuf_get_formats (void)
|
|
|
|
|
{
|
|
|
|
|
GSList *result = NULL;
|
|
|
|
|
GSList *modules;
|
|
|
|
|
|
|
|
|
|
for (modules = get_file_formats (); modules; modules = g_slist_next (modules)) {
|
|
|
|
|
GdkPixbufModule *module = (GdkPixbufModule *)modules->data;
|
|
|
|
|
GdkPixbufFormat *info = _gdk_pixbuf_get_format (module);
|
|
|
|
|
result = g_slist_prepend (result, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-03-14 19:37:00 +00:00
|
|
|
|
#define __GDK_PIXBUF_IO_C__
|
|
|
|
|
#include "gdk-pixbuf-aliasdef.c"
|
|
|
|
|
|
2002-10-03 22:39:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|