New function for loading an image from a file either via module->load or
* gdk-pixbuf-io.c (generic_image_load): New function for loading an image from a file either via module->load or incrementally. (prepared_notify): ModulePreparedNotifyFunc for generic_image_load. (gdk_pixbuf_new_from_file): Use generic_image_load. * io-bmp.c, io-ico.c, io-ras.c, io-wbmp.c: Remove trivial implementations of module->load. (#71266)
This commit is contained in:
@ -1,5 +1,12 @@
|
|||||||
2002-07-07 Matthias Clasen <maclas@gmx.de>
|
2002-07-07 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gdk-pixbuf-io.c (generic_image_load): New function for loading
|
||||||
|
an image from a file either via module->load or incrementally.
|
||||||
|
(prepared_notify): ModulePreparedNotifyFunc for generic_image_load.
|
||||||
|
(gdk_pixbuf_new_from_file): Use generic_image_load.
|
||||||
|
* io-bmp.c, io-ico.c, io-ras.c, io-wbmp.c: Remove trivial
|
||||||
|
implementations of module->load. (#71266)
|
||||||
|
|
||||||
* io-ico.c (DecodeHeader): Correct computation of image height.
|
* io-ico.c (DecodeHeader): Correct computation of image height.
|
||||||
(OneLine): Correct update notification.
|
(OneLine): Correct update notification.
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
/* -*- mode: C; c-file-style: "linux" -*- */
|
||||||
/* GdkPixbuf library - Main loading interface.
|
/* GdkPixbuf library - Main loading interface.
|
||||||
*
|
*
|
||||||
* Copyright (C) 1999 The Free Software Foundation
|
* Copyright (C) 1999 The Free Software Foundation
|
||||||
@ -552,6 +553,55 @@ _gdk_pixbuf_get_module (guchar *buffer, guint size,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
prepared_notify (GdkPixbuf *pixbuf,
|
||||||
|
GdkPixbufAnimation *anim,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
if (pixbuf != NULL)
|
||||||
|
g_object_ref (pixbuf);
|
||||||
|
*((GdkPixbuf **)user_data) = pixbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GdkPixbuf *
|
||||||
|
generic_image_load (GdkPixbufModule *module,
|
||||||
|
FILE *f,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
guchar buffer[4096];
|
||||||
|
size_t length;
|
||||||
|
GdkPixbuf *pixbuf = NULL;
|
||||||
|
gpointer context;
|
||||||
|
|
||||||
|
if (module->load != NULL)
|
||||||
|
return (* module->load) (f, error);
|
||||||
|
|
||||||
|
context = module->begin_load (NULL, prepared_notify, NULL, &pixbuf, error);
|
||||||
|
|
||||||
|
if (!context)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while (!feof (f)) {
|
||||||
|
length = fread (buffer, 1, sizeof (buffer), f);
|
||||||
|
if (length > 0)
|
||||||
|
if (!module->load_increment (context, buffer, length, error)) {
|
||||||
|
module->stop_load (context, NULL);
|
||||||
|
if (pixbuf != NULL)
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!module->stop_load (context, error)) {
|
||||||
|
if (pixbuf != NULL)
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pixbuf;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdk_pixbuf_new_from_file:
|
* gdk_pixbuf_new_from_file:
|
||||||
* @filename: Name of file to load.
|
* @filename: Name of file to load.
|
||||||
@ -612,19 +662,8 @@ gdk_pixbuf_new_from_file (const char *filename,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image_module->load == NULL) {
|
|
||||||
g_set_error (error,
|
|
||||||
GDK_PIXBUF_ERROR,
|
|
||||||
GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION,
|
|
||||||
_("Don't know how to load the image in file '%s'"),
|
|
||||||
filename);
|
|
||||||
|
|
||||||
fclose (f);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
fseek (f, 0, SEEK_SET);
|
fseek (f, 0, SEEK_SET);
|
||||||
pixbuf = (* image_module->load) (f, error);
|
pixbuf = generic_image_load (image_module, f, error);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
|
||||||
if (pixbuf == NULL && error != NULL && *error == NULL) {
|
if (pixbuf == NULL && error != NULL && *error == NULL) {
|
||||||
|
|||||||
@ -194,45 +194,6 @@ static gboolean gdk_pixbuf__bmp_image_load_increment(gpointer data,
|
|||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Shared library entry point --> This should be removed when
|
|
||||||
generic_image_load enters gdk-pixbuf-io. */
|
|
||||||
static GdkPixbuf *gdk_pixbuf__bmp_image_load(FILE * f, GError **error)
|
|
||||||
{
|
|
||||||
guchar membuf[4096];
|
|
||||||
size_t length;
|
|
||||||
struct bmp_progressive_state *State;
|
|
||||||
|
|
||||||
GdkPixbuf *pb;
|
|
||||||
|
|
||||||
State =
|
|
||||||
gdk_pixbuf__bmp_image_begin_load(NULL, NULL, NULL, NULL,
|
|
||||||
error);
|
|
||||||
|
|
||||||
if (State == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
while (feof(f) == 0) {
|
|
||||||
length = fread(membuf, 1, sizeof (membuf), f);
|
|
||||||
if (length > 0)
|
|
||||||
if (!gdk_pixbuf__bmp_image_load_increment(State,
|
|
||||||
membuf,
|
|
||||||
length,
|
|
||||||
error)) {
|
|
||||||
gdk_pixbuf__bmp_image_stop_load (State, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (State->pixbuf != NULL)
|
|
||||||
g_object_ref(State->pixbuf);
|
|
||||||
|
|
||||||
pb = State->pixbuf;
|
|
||||||
|
|
||||||
gdk_pixbuf__bmp_image_stop_load(State, NULL);
|
|
||||||
return pb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Picks up a 32-bit little-endian integer starting at the specified location.
|
/* Picks up a 32-bit little-endian integer starting at the specified location.
|
||||||
* Does it by hand instead of dereferencing a simple (gint *) cast due to
|
* Does it by hand instead of dereferencing a simple (gint *) cast due to
|
||||||
* alignment constraints many platforms.
|
* alignment constraints many platforms.
|
||||||
@ -1083,7 +1044,6 @@ gdk_pixbuf__bmp_image_load_increment(gpointer data,
|
|||||||
void
|
void
|
||||||
gdk_pixbuf__bmp_fill_vtable (GdkPixbufModule *module)
|
gdk_pixbuf__bmp_fill_vtable (GdkPixbufModule *module)
|
||||||
{
|
{
|
||||||
module->load = gdk_pixbuf__bmp_image_load;
|
|
||||||
module->begin_load = gdk_pixbuf__bmp_image_begin_load;
|
module->begin_load = gdk_pixbuf__bmp_image_begin_load;
|
||||||
module->stop_load = gdk_pixbuf__bmp_image_stop_load;
|
module->stop_load = gdk_pixbuf__bmp_image_stop_load;
|
||||||
module->load_increment = gdk_pixbuf__bmp_image_load_increment;
|
module->load_increment = gdk_pixbuf__bmp_image_load_increment;
|
||||||
|
|||||||
@ -182,56 +182,6 @@ context_free (struct ico_progressive_state *context)
|
|||||||
|
|
||||||
g_free (context);
|
g_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shared library entry point --> Can go when generic_image_load
|
|
||||||
enters gdk-pixbuf-io */
|
|
||||||
static GdkPixbuf *
|
|
||||||
gdk_pixbuf__ico_image_load(FILE * f, GError **error)
|
|
||||||
{
|
|
||||||
guchar membuf [4096];
|
|
||||||
size_t length;
|
|
||||||
struct ico_progressive_state *State;
|
|
||||||
|
|
||||||
GdkPixbuf *pb;
|
|
||||||
|
|
||||||
State = gdk_pixbuf__ico_image_begin_load(NULL, NULL, NULL, NULL, error);
|
|
||||||
|
|
||||||
if (State == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
while (!feof(f)) {
|
|
||||||
length = fread(membuf, 1, 4096, f);
|
|
||||||
if (ferror (f)) {
|
|
||||||
g_set_error (error,
|
|
||||||
G_FILE_ERROR,
|
|
||||||
g_file_error_from_errno (errno),
|
|
||||||
_("Failure reading ICO: %s"), g_strerror (errno));
|
|
||||||
context_free (State);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (length > 0)
|
|
||||||
if (!gdk_pixbuf__ico_image_load_increment(State, membuf, length,
|
|
||||||
error)) {
|
|
||||||
context_free (State);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (State->pixbuf != NULL)
|
|
||||||
g_object_ref (State->pixbuf);
|
|
||||||
else {
|
|
||||||
g_set_error (error,
|
|
||||||
GDK_PIXBUF_ERROR,
|
|
||||||
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
||||||
_("ICO file was missing some data (perhaps it was truncated somehow?)"));
|
|
||||||
context_free (State);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pb = State->pixbuf;
|
|
||||||
|
|
||||||
gdk_pixbuf__ico_image_stop_load(State, NULL);
|
|
||||||
return pb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DecodeHeader(guchar *Data, gint Bytes,
|
static void DecodeHeader(guchar *Data, gint Bytes,
|
||||||
struct ico_progressive_state *State,
|
struct ico_progressive_state *State,
|
||||||
@ -878,7 +828,6 @@ gdk_pixbuf__ico_image_load_increment(gpointer data,
|
|||||||
void
|
void
|
||||||
gdk_pixbuf__ico_fill_vtable (GdkPixbufModule *module)
|
gdk_pixbuf__ico_fill_vtable (GdkPixbufModule *module)
|
||||||
{
|
{
|
||||||
module->load = gdk_pixbuf__ico_image_load;
|
|
||||||
module->begin_load = gdk_pixbuf__ico_image_begin_load;
|
module->begin_load = gdk_pixbuf__ico_image_begin_load;
|
||||||
module->stop_load = gdk_pixbuf__ico_image_stop_load;
|
module->stop_load = gdk_pixbuf__ico_image_stop_load;
|
||||||
module->load_increment = gdk_pixbuf__ico_image_load_increment;
|
module->load_increment = gdk_pixbuf__ico_image_load_increment;
|
||||||
|
|||||||
@ -104,41 +104,6 @@ static gboolean gdk_pixbuf__ras_image_load_increment(gpointer data,
|
|||||||
const guchar * buf, guint size,
|
const guchar * buf, guint size,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Shared library entry point */
|
|
||||||
static GdkPixbuf *gdk_pixbuf__ras_image_load(FILE * f, GError **error)
|
|
||||||
{
|
|
||||||
guchar *membuf;
|
|
||||||
size_t length;
|
|
||||||
struct ras_progressive_state *State;
|
|
||||||
|
|
||||||
GdkPixbuf *pb;
|
|
||||||
|
|
||||||
State = gdk_pixbuf__ras_image_begin_load(NULL, NULL, NULL, NULL, error);
|
|
||||||
|
|
||||||
membuf = g_malloc(4096);
|
|
||||||
|
|
||||||
g_assert(membuf != NULL);
|
|
||||||
|
|
||||||
while (feof(f) == 0) {
|
|
||||||
length = fread(membuf, 1, 4096, f);
|
|
||||||
if (!gdk_pixbuf__ras_image_load_increment(State, membuf, length,
|
|
||||||
error)) {
|
|
||||||
gdk_pixbuf__ras_image_stop_load (State, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_free(membuf);
|
|
||||||
if (State->pixbuf != NULL)
|
|
||||||
g_object_ref(State->pixbuf);
|
|
||||||
|
|
||||||
pb = State->pixbuf;
|
|
||||||
|
|
||||||
gdk_pixbuf__ras_image_stop_load(State, NULL);
|
|
||||||
return pb;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean RAS2State(struct rasterfile *RAS,
|
static gboolean RAS2State(struct rasterfile *RAS,
|
||||||
struct ras_progressive_state *State,
|
struct ras_progressive_state *State,
|
||||||
GError **error)
|
GError **error)
|
||||||
@ -541,7 +506,6 @@ gdk_pixbuf__ras_image_load_increment(gpointer data,
|
|||||||
void
|
void
|
||||||
gdk_pixbuf__ras_fill_vtable (GdkPixbufModule *module)
|
gdk_pixbuf__ras_fill_vtable (GdkPixbufModule *module)
|
||||||
{
|
{
|
||||||
module->load = gdk_pixbuf__ras_image_load;
|
|
||||||
module->begin_load = gdk_pixbuf__ras_image_begin_load;
|
module->begin_load = gdk_pixbuf__ras_image_begin_load;
|
||||||
module->stop_load = gdk_pixbuf__ras_image_stop_load;
|
module->stop_load = gdk_pixbuf__ras_image_stop_load;
|
||||||
module->load_increment = gdk_pixbuf__ras_image_load_increment;
|
module->load_increment = gdk_pixbuf__ras_image_load_increment;
|
||||||
|
|||||||
@ -75,41 +75,6 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data,
|
|||||||
guint size,
|
guint size,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
||||||
/* Shared library entry point --> This should be removed when
|
|
||||||
generic_image_load enters gdk-pixbuf-io. */
|
|
||||||
static GdkPixbuf *gdk_pixbuf__wbmp_image_load(FILE * f, GError **error)
|
|
||||||
{
|
|
||||||
size_t length;
|
|
||||||
char membuf[4096];
|
|
||||||
struct wbmp_progressive_state *State;
|
|
||||||
|
|
||||||
GdkPixbuf *pb;
|
|
||||||
|
|
||||||
State = gdk_pixbuf__wbmp_image_begin_load(NULL, NULL, NULL, NULL,
|
|
||||||
error);
|
|
||||||
|
|
||||||
if (State == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
while (feof(f) == 0) {
|
|
||||||
length = fread(membuf, 1, 4096, f);
|
|
||||||
if (!gdk_pixbuf__wbmp_image_load_increment(State, membuf, length,
|
|
||||||
error)) {
|
|
||||||
gdk_pixbuf__wbmp_image_stop_load (State, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (State->pixbuf != NULL)
|
|
||||||
g_object_ref(State->pixbuf);
|
|
||||||
|
|
||||||
pb = State->pixbuf;
|
|
||||||
|
|
||||||
gdk_pixbuf__wbmp_image_stop_load(State, NULL);
|
|
||||||
return pb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* func - called when we have pixmap created (but no image data)
|
* func - called when we have pixmap created (but no image data)
|
||||||
* user_data - passed as arg 1 to func
|
* user_data - passed as arg 1 to func
|
||||||
@ -376,7 +341,6 @@ static gboolean gdk_pixbuf__wbmp_image_load_increment(gpointer data,
|
|||||||
void
|
void
|
||||||
gdk_pixbuf__wbmp_fill_vtable (GdkPixbufModule *module)
|
gdk_pixbuf__wbmp_fill_vtable (GdkPixbufModule *module)
|
||||||
{
|
{
|
||||||
module->load = gdk_pixbuf__wbmp_image_load;
|
|
||||||
module->begin_load = gdk_pixbuf__wbmp_image_begin_load;
|
module->begin_load = gdk_pixbuf__wbmp_image_begin_load;
|
||||||
module->stop_load = gdk_pixbuf__wbmp_image_stop_load;
|
module->stop_load = gdk_pixbuf__wbmp_image_stop_load;
|
||||||
module->load_increment = gdk_pixbuf__wbmp_image_load_increment;
|
module->load_increment = gdk_pixbuf__wbmp_image_load_increment;
|
||||||
|
|||||||
Reference in New Issue
Block a user