mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-24 12:41:16 +00:00
more work on the incremental loading
This commit is contained in:
parent
c84756cf38
commit
e5dfd2f5da
@ -24,6 +24,8 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "gdk-pixbuf.h"
|
||||
#include "gdk-pixbuf-io.h"
|
||||
#include "gdk-pixbuf-loader.h"
|
||||
|
||||
#define DEFAULT_WIDTH 24
|
||||
#define DEFAULT_HEIGHT 24
|
||||
@ -407,6 +409,10 @@ main (int argc, char **argv)
|
||||
int found_valid = FALSE;
|
||||
|
||||
GdkPixbuf *pixbuf;
|
||||
GtkObject *pixbuf_loader;
|
||||
FILE *file;
|
||||
gint val;
|
||||
guchar buf;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
@ -448,6 +454,20 @@ main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
pixbuf_loader = gdk_pixbuf_loader_new ();
|
||||
file = fopen ("/usr/share/pixmaps/up2date.png", "r");
|
||||
g_assert (file != NULL);
|
||||
|
||||
while (TRUE) {
|
||||
val = fgetc (file);
|
||||
if (val == EOF)
|
||||
break;
|
||||
buf = (guint) val;
|
||||
if (gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (pixbuf_loader), &buf, 1) == FALSE)
|
||||
break;
|
||||
}
|
||||
fclose (file);
|
||||
|
||||
if (found_valid)
|
||||
gtk_main ();
|
||||
|
||||
|
@ -29,6 +29,8 @@ libexec_LTLIBRARIES = \
|
||||
$(TIFF_LIB)
|
||||
|
||||
noinst_PROGRAMS = testpixbuf
|
||||
|
||||
|
||||
DEPS = libgdk_pixbuf.la
|
||||
INCLUDES = $(GLIB_CFLAGS) $(LIBART_CFLAGS) $(GTK_CFLAGS)
|
||||
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(libexecdir)\""
|
||||
@ -54,6 +56,9 @@ libgdk_pixbufinclude_HEADERS = \
|
||||
gdk-pixbuf.h \
|
||||
gdk-pixbuf-loader.h
|
||||
|
||||
noinst_HEADERS = \
|
||||
gdk-pixbuf-io.h
|
||||
|
||||
#
|
||||
# The PNG plugin.
|
||||
#
|
||||
|
@ -22,10 +22,8 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <gmodule.h>
|
||||
#include "gdk-pixbuf.h"
|
||||
#include "gdk-pixbuf-io.h"
|
||||
|
||||
|
||||
|
||||
@ -105,6 +103,7 @@ pixbuf_check_xpm (guchar *buffer, int size)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static gboolean
|
||||
pixbuf_check_bmp (guchar *buffer, int size)
|
||||
{
|
||||
@ -134,14 +133,9 @@ pixbuf_check_ppm (guchar *buffer, int size)
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct {
|
||||
char *module_name;
|
||||
gboolean (* format_check) (guchar *buffer, int size);
|
||||
GModule *module;
|
||||
GdkPixbuf *(* load) (FILE *f);
|
||||
GdkPixbuf *(* load_xpm_data) (const gchar **data);
|
||||
} file_formats [] = {
|
||||
ModuleType file_formats [] = {
|
||||
{ "png", pixbuf_check_png, NULL, NULL, NULL },
|
||||
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
|
||||
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
|
||||
@ -156,16 +150,16 @@ static struct {
|
||||
};
|
||||
|
||||
static void
|
||||
image_handler_load (int idx)
|
||||
image_handler_load (ModuleType *image_module)
|
||||
{
|
||||
char *module_name;
|
||||
char *path;
|
||||
GModule *module;
|
||||
void *load_sym;
|
||||
|
||||
g_return_if_fail(file_formats[idx].module == NULL);
|
||||
|
||||
module_name = g_strconcat ("pixbuf-", file_formats [idx].module_name, NULL);
|
||||
g_return_if_fail(image_module->module == NULL);
|
||||
|
||||
module_name = g_strconcat ("pixbuf-", image_module->module_name, NULL);
|
||||
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
|
||||
g_free (module_name);
|
||||
|
||||
@ -176,59 +170,72 @@ image_handler_load (int idx)
|
||||
return;
|
||||
}
|
||||
|
||||
file_formats [idx].module = module;
|
||||
image_module->module = module;
|
||||
|
||||
if (g_module_symbol (module, "image_load", &load_sym))
|
||||
file_formats [idx].load = load_sym;
|
||||
image_module->load = load_sym;
|
||||
|
||||
if (g_module_symbol (module, "image_load_xpm_data", &load_sym))
|
||||
file_formats [idx].load_xpm_data = load_sym;
|
||||
image_module->load_xpm_data = load_sym;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ModuleType *
|
||||
gdk_pixbuf_get_module (gchar *buffer, gint size)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; file_formats [i].module_name; i++) {
|
||||
if ((* file_formats [i].format_check) (buffer, size))
|
||||
return &(file_formats[i]);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GdkPixbuf *
|
||||
gdk_pixbuf_new_from_file (const char *filename)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
gint n, i;
|
||||
gint size;
|
||||
FILE *f;
|
||||
char buffer [128];
|
||||
ModuleType *image_module;
|
||||
|
||||
f = fopen (filename, "r");
|
||||
if (!f)
|
||||
return NULL;
|
||||
|
||||
n = fread (&buffer, 1, sizeof (buffer), f);
|
||||
size = fread (&buffer, 1, sizeof (buffer), f);
|
||||
|
||||
if (n == 0) {
|
||||
if (size == 0) {
|
||||
fclose (f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; file_formats [i].module_name; i++) {
|
||||
if ((* file_formats [i].format_check) (buffer, n)) {
|
||||
if (!file_formats [i].load)
|
||||
image_handler_load (i);
|
||||
image_module = gdk_pixbuf_get_module (buffer, size);
|
||||
if (image_module){
|
||||
if (!image_module->load)
|
||||
image_handler_load (image_module);
|
||||
|
||||
if (!file_formats [i].load) {
|
||||
fclose (f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek (f, 0, SEEK_SET);
|
||||
pixbuf = (* file_formats [i].load) (f);
|
||||
if (!image_module->load) {
|
||||
fclose (f);
|
||||
|
||||
if (pixbuf)
|
||||
g_assert (pixbuf->ref_count != 0);
|
||||
|
||||
return pixbuf;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fseek (f, 0, SEEK_SET);
|
||||
pixbuf = (* image_module->load) (f);
|
||||
fclose (f);
|
||||
|
||||
if (pixbuf)
|
||||
g_assert (pixbuf->ref_count != 0);
|
||||
|
||||
return pixbuf;
|
||||
} else {
|
||||
g_warning ("Unable to find handler for file: %s", filename);
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
g_warning ("Unable to find handler for file: %s", filename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -237,9 +244,9 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data)
|
||||
{
|
||||
GdkPixbuf *(* load_xpm_data) (const gchar **data);
|
||||
GdkPixbuf *pixbuf;
|
||||
|
||||
|
||||
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
|
||||
image_handler_load(XPM_FILE_FORMAT_INDEX);
|
||||
image_handler_load(&file_formats[XPM_FILE_FORMAT_INDEX]);
|
||||
}
|
||||
|
||||
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
|
||||
@ -253,4 +260,4 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data)
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1 +1,39 @@
|
||||
/* Nothing here yet */
|
||||
/* GdkPixbuf library - Io handling
|
||||
*
|
||||
* Copyright (C) 1999 The Free Software Foundation
|
||||
*
|
||||
* Authors: Mark Crichton <crichton@gimp.org>
|
||||
* Miguel de Icaza <miguel@gnu.org>
|
||||
* Federico Mena-Quintero <federico@gimp.org>
|
||||
* Jonathan Blandford <jrb@redhat.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#include <gmodule.h>
|
||||
#include "gdk-pixbuf.h"
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct _ModuleType ModuleType;
|
||||
struct _ModuleType {
|
||||
char *module_name;
|
||||
gboolean (* format_check) (guchar *buffer, int size);
|
||||
GModule *module;
|
||||
GdkPixbuf *(* load) (FILE *f);
|
||||
GdkPixbuf *(* load_xpm_data) (const gchar **data);
|
||||
};
|
||||
|
||||
|
||||
ModuleType *gdk_pixbuf_get_module (gchar *buffer, gint size);
|
||||
|
@ -24,14 +24,15 @@
|
||||
*/
|
||||
|
||||
#include "gdk-pixbuf-loader.h"
|
||||
#include "gdk-pixbuf-io.h"
|
||||
|
||||
|
||||
static GtkObjectClass *parent_class;
|
||||
static GtkObjectClass *parent_class;
|
||||
|
||||
static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
|
||||
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_destroy (GtkObject *loader);
|
||||
static void gdk_pixbuf_loader_finalize (GtkObject *loader);
|
||||
|
||||
/* Internal data */
|
||||
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
||||
@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
gboolean closed;
|
||||
gchar buf[128];
|
||||
gint buf_offset;
|
||||
ModuleType *image_module;
|
||||
};
|
||||
|
||||
GtkType
|
||||
@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
|
||||
static void
|
||||
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
loader->private = g_new (GdkPixbufLoaderPrivate, 1);
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
|
||||
loader->pixbuf = NULL;
|
||||
loader->closed = FALSE;
|
||||
priv = g_new (GdkPixbufLoaderPrivate, 1);
|
||||
loader->private = priv;
|
||||
|
||||
priv->pixbuf = NULL;
|
||||
priv->closed = FALSE;
|
||||
priv->buf_offset = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader)
|
||||
gdk_pixbuf_loader_destroy (GtkObject *loader)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
GdkPixbufLoaderPrivate *priv = NULL;
|
||||
|
||||
priv = loader->private;
|
||||
priv = GDK_PIXBUF_LOADER (loader)->private;
|
||||
gdk_pixbuf_unref (priv->pixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader)
|
||||
gdk_pixbuf_loader_finalize (GtkObject *loader)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
GdkPixbufLoader *load;
|
||||
GdkPixbufLoaderPrivate *priv = NULL;
|
||||
|
||||
priv = loader->private;
|
||||
load = GTK_CHECK_CAST (loader, GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader);
|
||||
priv = GDK_PIXBUF_LOADER (loader)->private;
|
||||
g_free (priv);
|
||||
}
|
||||
|
||||
@ -117,41 +126,60 @@ gdk_pixbuf_loader_new (void)
|
||||
* @loader: A loader.
|
||||
* @buf: The image data.
|
||||
* @count: The length of @buf in bytes.
|
||||
*
|
||||
*
|
||||
* This will load the next @size bytes of the image. It will return TRUE if the
|
||||
* data was loaded successfully, and FALSE if an error occurred. In this case,
|
||||
* the loader will be closed, and will not accept further writes.
|
||||
*
|
||||
*
|
||||
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
|
||||
* cannot parse the buf.
|
||||
**/
|
||||
gboolean
|
||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
|
||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (loader != NULL, FALSE);
|
||||
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
|
||||
g_return_val_if_fail (buf != NULL, FALSE);
|
||||
g_return_val_if_fail (count >= 0, FALSE);
|
||||
|
||||
priv = loader->private;
|
||||
|
||||
/* we expect it's not to be closed */
|
||||
g_return_val_if_fail (priv->closed == FALSE, FALSE);
|
||||
|
||||
if (priv->image_module == NULL) {
|
||||
g_print ("buf_offset:%d:\n", priv->buf_offset);
|
||||
memcpy (priv->buf + priv->buf_offset,
|
||||
buf,
|
||||
(priv->buf_offset + count) > 128 ? 128 - priv->buf_offset : count);
|
||||
if ((priv->buf_offset + count) >= 128) {
|
||||
priv->image_module = gdk_pixbuf_get_module (priv->buf, 128);
|
||||
if (priv->image_module == NULL) {
|
||||
g_print ("no module loaded. bummer\n");
|
||||
return FALSE;
|
||||
} else {
|
||||
g_print ("module loaded: name is %s\n", priv->image_module->module_name);
|
||||
}
|
||||
} else {
|
||||
priv->buf_offset += count;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_pixbuf_loader_get_pixbuf:
|
||||
* @loader: A loader.
|
||||
*
|
||||
*
|
||||
* Gets the GdkPixbuf that the loader is currently loading. If the loader
|
||||
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
|
||||
* Any application using this function should check for this value when it is
|
||||
* used. The pixbuf returned will be the same in all future calls to the
|
||||
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
|
||||
* using it.
|
||||
*
|
||||
*
|
||||
* Return value: The GdkPixbuf that the loader is loading.
|
||||
**/
|
||||
GdkPixbuf *
|
||||
@ -169,7 +197,7 @@ gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
|
||||
/**
|
||||
* gdk_pixbuf_loader_close:
|
||||
* @loader: A loader.
|
||||
*
|
||||
*
|
||||
* Tells the loader to stop accepting writes
|
||||
*
|
||||
**/
|
||||
|
@ -32,16 +32,15 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#pragma }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
|
||||
#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
|
||||
#define GDK_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass))
|
||||
#define GDK_IS_PIXBUF_LOADER (obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX))
|
||||
#define GDK_IS_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX))
|
||||
#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
|
||||
#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader))
|
||||
#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass))
|
||||
#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER))
|
||||
#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
|
||||
|
||||
|
||||
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
||||
@ -50,7 +49,7 @@ struct _GdkPixbufLoader
|
||||
GtkObject object;
|
||||
|
||||
/* < Private > */
|
||||
gpointer data;
|
||||
gpointer private;
|
||||
};
|
||||
|
||||
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
||||
@ -66,8 +65,9 @@ struct _GdkPixbufLoaderClass {
|
||||
|
||||
|
||||
|
||||
GtkType gdk_pixbuf_loader_get_type (void);
|
||||
GtkObject *gdk_pixbuf_loader_new (void);
|
||||
gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count);
|
||||
gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count);
|
||||
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
|
||||
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
||||
|
||||
|
@ -62,7 +62,8 @@ GdkPixbuf *
|
||||
image_load (FILE *f)
|
||||
{
|
||||
int w, h, i, j;
|
||||
guchar *pixels = NULL, *dptr;
|
||||
guchar *pixels = NULL;
|
||||
guchar *dptr;
|
||||
guchar *lines[4]; /* Used to expand rows, via rec_outbuf_height, from the header file:
|
||||
* "* Usually rec_outbuf_height will be 1 or 2, at most 4."
|
||||
*/
|
||||
|
@ -135,8 +135,8 @@ image_load (FILE *f)
|
||||
free_buffer, NULL);
|
||||
}
|
||||
|
||||
GdkImage *
|
||||
gboolean
|
||||
image_load_by_data (void *data, size_t count)
|
||||
{
|
||||
return NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ GdkPixbuf *
|
||||
image_load (FILE *f)
|
||||
{
|
||||
TIFF *tiff;
|
||||
guchar *pixels, *tmppix;
|
||||
guchar *pixels = NULL;
|
||||
guchar *tmppix;
|
||||
gint w, h, x, y, num_pixs, fd;
|
||||
uint32 *rast, *tmp_rast;
|
||||
|
||||
|
@ -24,14 +24,15 @@
|
||||
*/
|
||||
|
||||
#include "gdk-pixbuf-loader.h"
|
||||
#include "gdk-pixbuf-io.h"
|
||||
|
||||
|
||||
static GtkObjectClass *parent_class;
|
||||
static GtkObjectClass *parent_class;
|
||||
|
||||
static void gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass);
|
||||
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
|
||||
static void gdk_pixbuf_loader_destroy (GtkObject *loader);
|
||||
static void gdk_pixbuf_loader_finalize (GtkObject *loader);
|
||||
|
||||
/* Internal data */
|
||||
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
||||
@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
gboolean closed;
|
||||
gchar buf[128];
|
||||
gint buf_offset;
|
||||
ModuleType *image_module;
|
||||
};
|
||||
|
||||
GtkType
|
||||
@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
|
||||
static void
|
||||
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
loader->private = g_new (GdkPixbufLoaderPrivate, 1);
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
|
||||
loader->pixbuf = NULL;
|
||||
loader->closed = FALSE;
|
||||
priv = g_new (GdkPixbufLoaderPrivate, 1);
|
||||
loader->private = priv;
|
||||
|
||||
priv->pixbuf = NULL;
|
||||
priv->closed = FALSE;
|
||||
priv->buf_offset = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader)
|
||||
gdk_pixbuf_loader_destroy (GtkObject *loader)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
GdkPixbufLoaderPrivate *priv = NULL;
|
||||
|
||||
priv = loader->private;
|
||||
priv = GDK_PIXBUF_LOADER (loader)->private;
|
||||
gdk_pixbuf_unref (priv->pixbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader)
|
||||
gdk_pixbuf_loader_finalize (GtkObject *loader)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
GdkPixbufLoader *load;
|
||||
GdkPixbufLoaderPrivate *priv = NULL;
|
||||
|
||||
priv = loader->private;
|
||||
load = GTK_CHECK_CAST (loader, GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader);
|
||||
priv = GDK_PIXBUF_LOADER (loader)->private;
|
||||
g_free (priv);
|
||||
}
|
||||
|
||||
@ -117,41 +126,60 @@ gdk_pixbuf_loader_new (void)
|
||||
* @loader: A loader.
|
||||
* @buf: The image data.
|
||||
* @count: The length of @buf in bytes.
|
||||
*
|
||||
*
|
||||
* This will load the next @size bytes of the image. It will return TRUE if the
|
||||
* data was loaded successfully, and FALSE if an error occurred. In this case,
|
||||
* the loader will be closed, and will not accept further writes.
|
||||
*
|
||||
*
|
||||
* Return value: Returns TRUE if the write was successful -- FALSE if the loader
|
||||
* cannot parse the buf.
|
||||
**/
|
||||
gboolean
|
||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
|
||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
|
||||
{
|
||||
GdkPixbufLoaderPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (loader != NULL, FALSE);
|
||||
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), FALSE);
|
||||
g_return_val_if_fail (buf != NULL, FALSE);
|
||||
g_return_val_if_fail (count >= 0, FALSE);
|
||||
|
||||
priv = loader->private;
|
||||
|
||||
/* we expect it's not to be closed */
|
||||
g_return_val_if_fail (priv->closed == FALSE, FALSE);
|
||||
|
||||
if (priv->image_module == NULL) {
|
||||
g_print ("buf_offset:%d:\n", priv->buf_offset);
|
||||
memcpy (priv->buf + priv->buf_offset,
|
||||
buf,
|
||||
(priv->buf_offset + count) > 128 ? 128 - priv->buf_offset : count);
|
||||
if ((priv->buf_offset + count) >= 128) {
|
||||
priv->image_module = gdk_pixbuf_get_module (priv->buf, 128);
|
||||
if (priv->image_module == NULL) {
|
||||
g_print ("no module loaded. bummer\n");
|
||||
return FALSE;
|
||||
} else {
|
||||
g_print ("module loaded: name is %s\n", priv->image_module->module_name);
|
||||
}
|
||||
} else {
|
||||
priv->buf_offset += count;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gdk_pixbuf_loader_get_pixbuf:
|
||||
* @loader: A loader.
|
||||
*
|
||||
*
|
||||
* Gets the GdkPixbuf that the loader is currently loading. If the loader
|
||||
* hasn't been enough data via gdk_pixbuf_loader_write, then NULL is returned.
|
||||
* Any application using this function should check for this value when it is
|
||||
* used. The pixbuf returned will be the same in all future calls to the
|
||||
* loader, so simply calling a gdk_pixbuf_ref() should be sufficient to continue
|
||||
* using it.
|
||||
*
|
||||
*
|
||||
* Return value: The GdkPixbuf that the loader is loading.
|
||||
**/
|
||||
GdkPixbuf *
|
||||
@ -169,7 +197,7 @@ gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader)
|
||||
/**
|
||||
* gdk_pixbuf_loader_close:
|
||||
* @loader: A loader.
|
||||
*
|
||||
*
|
||||
* Tells the loader to stop accepting writes
|
||||
*
|
||||
**/
|
||||
|
@ -32,16 +32,15 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#pragma }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
|
||||
#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
|
||||
#define GDK_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_HBOX, GtkHBoxClass))
|
||||
#define GDK_IS_PIXBUF_LOADER (obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_HBOX))
|
||||
#define GDK_IS_PIXBUF_LOADER_CLASS (klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_HBOX))
|
||||
#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
|
||||
#define GDK_PIXBUF_LOADER(obj) (GTK_CHECK_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader))
|
||||
#define GDK_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass))
|
||||
#define GDK_IS_PIXBUF_LOADER(obj) (GTK_CHECK_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER))
|
||||
#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
|
||||
|
||||
|
||||
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
||||
@ -50,7 +49,7 @@ struct _GdkPixbufLoader
|
||||
GtkObject object;
|
||||
|
||||
/* < Private > */
|
||||
gpointer data;
|
||||
gpointer private;
|
||||
};
|
||||
|
||||
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
||||
@ -66,8 +65,9 @@ struct _GdkPixbufLoaderClass {
|
||||
|
||||
|
||||
|
||||
GtkType gdk_pixbuf_loader_get_type (void);
|
||||
GtkObject *gdk_pixbuf_loader_new (void);
|
||||
gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count);
|
||||
gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count);
|
||||
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
|
||||
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user