more work on the incremental loading
This commit is contained in:
parent
c84756cf38
commit
e5dfd2f5da
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include "gdk-pixbuf.h"
|
#include "gdk-pixbuf.h"
|
||||||
|
#include "gdk-pixbuf-io.h"
|
||||||
|
#include "gdk-pixbuf-loader.h"
|
||||||
|
|
||||||
#define DEFAULT_WIDTH 24
|
#define DEFAULT_WIDTH 24
|
||||||
#define DEFAULT_HEIGHT 24
|
#define DEFAULT_HEIGHT 24
|
||||||
@ -407,6 +409,10 @@ main (int argc, char **argv)
|
|||||||
int found_valid = FALSE;
|
int found_valid = FALSE;
|
||||||
|
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
GtkObject *pixbuf_loader;
|
||||||
|
FILE *file;
|
||||||
|
gint val;
|
||||||
|
guchar buf;
|
||||||
|
|
||||||
gtk_init (&argc, &argv);
|
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)
|
if (found_valid)
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ libexec_LTLIBRARIES = \
|
|||||||
$(TIFF_LIB)
|
$(TIFF_LIB)
|
||||||
|
|
||||||
noinst_PROGRAMS = testpixbuf
|
noinst_PROGRAMS = testpixbuf
|
||||||
|
|
||||||
|
|
||||||
DEPS = libgdk_pixbuf.la
|
DEPS = libgdk_pixbuf.la
|
||||||
INCLUDES = $(GLIB_CFLAGS) $(LIBART_CFLAGS) $(GTK_CFLAGS)
|
INCLUDES = $(GLIB_CFLAGS) $(LIBART_CFLAGS) $(GTK_CFLAGS)
|
||||||
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(libexecdir)\""
|
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(libexecdir)\""
|
||||||
@ -54,6 +56,9 @@ libgdk_pixbufinclude_HEADERS = \
|
|||||||
gdk-pixbuf.h \
|
gdk-pixbuf.h \
|
||||||
gdk-pixbuf-loader.h
|
gdk-pixbuf-loader.h
|
||||||
|
|
||||||
|
noinst_HEADERS = \
|
||||||
|
gdk-pixbuf-io.h
|
||||||
|
|
||||||
#
|
#
|
||||||
# The PNG plugin.
|
# The PNG plugin.
|
||||||
#
|
#
|
||||||
|
@ -22,10 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gmodule.h>
|
#include "gdk-pixbuf-io.h"
|
||||||
#include "gdk-pixbuf.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -105,6 +103,7 @@ pixbuf_check_xpm (guchar *buffer, int size)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
static gboolean
|
static gboolean
|
||||||
pixbuf_check_bmp (guchar *buffer, int size)
|
pixbuf_check_bmp (guchar *buffer, int size)
|
||||||
{
|
{
|
||||||
@ -134,14 +133,9 @@ pixbuf_check_ppm (guchar *buffer, int size)
|
|||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static struct {
|
ModuleType file_formats [] = {
|
||||||
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 [] = {
|
|
||||||
{ "png", pixbuf_check_png, NULL, NULL, NULL },
|
{ "png", pixbuf_check_png, NULL, NULL, NULL },
|
||||||
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
|
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
|
||||||
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
|
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
|
||||||
@ -156,16 +150,16 @@ static struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
image_handler_load (int idx)
|
image_handler_load (ModuleType *image_module)
|
||||||
{
|
{
|
||||||
char *module_name;
|
char *module_name;
|
||||||
char *path;
|
char *path;
|
||||||
GModule *module;
|
GModule *module;
|
||||||
void *load_sym;
|
void *load_sym;
|
||||||
|
|
||||||
g_return_if_fail(file_formats[idx].module == NULL);
|
g_return_if_fail(image_module->module == NULL);
|
||||||
|
|
||||||
module_name = g_strconcat ("pixbuf-", file_formats [idx].module_name, NULL);
|
module_name = g_strconcat ("pixbuf-", image_module->module_name, NULL);
|
||||||
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
|
path = g_module_build_path (PIXBUF_LIBDIR, module_name);
|
||||||
g_free (module_name);
|
g_free (module_name);
|
||||||
|
|
||||||
@ -176,59 +170,72 @@ image_handler_load (int idx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_formats [idx].module = module;
|
image_module->module = module;
|
||||||
|
|
||||||
if (g_module_symbol (module, "image_load", &load_sym))
|
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))
|
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 *
|
GdkPixbuf *
|
||||||
gdk_pixbuf_new_from_file (const char *filename)
|
gdk_pixbuf_new_from_file (const char *filename)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
gint n, i;
|
gint size;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char buffer [128];
|
char buffer [128];
|
||||||
|
ModuleType *image_module;
|
||||||
|
|
||||||
f = fopen (filename, "r");
|
f = fopen (filename, "r");
|
||||||
if (!f)
|
if (!f)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
n = fread (&buffer, 1, sizeof (buffer), f);
|
size = fread (&buffer, 1, sizeof (buffer), f);
|
||||||
|
|
||||||
if (n == 0) {
|
if (size == 0) {
|
||||||
fclose (f);
|
fclose (f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; file_formats [i].module_name; i++) {
|
image_module = gdk_pixbuf_get_module (buffer, size);
|
||||||
if ((* file_formats [i].format_check) (buffer, n)) {
|
if (image_module){
|
||||||
if (!file_formats [i].load)
|
if (!image_module->load)
|
||||||
image_handler_load (i);
|
image_handler_load (image_module);
|
||||||
|
|
||||||
if (!file_formats [i].load) {
|
if (!image_module->load) {
|
||||||
fclose (f);
|
fclose (f);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek (f, 0, SEEK_SET);
|
fseek (f, 0, SEEK_SET);
|
||||||
pixbuf = (* file_formats [i].load) (f);
|
pixbuf = (* image_module->load) (f);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
|
||||||
if (pixbuf)
|
if (pixbuf)
|
||||||
g_assert (pixbuf->ref_count != 0);
|
g_assert (pixbuf->ref_count != 0);
|
||||||
|
|
||||||
return pixbuf;
|
return pixbuf;
|
||||||
}
|
} else {
|
||||||
|
g_warning ("Unable to find handler for file: %s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose (f);
|
fclose (f);
|
||||||
g_warning ("Unable to find handler for file: %s", filename);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,7 +246,7 @@ gdk_pixbuf_new_from_xpm_data (const gchar **data)
|
|||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
|
|
||||||
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
|
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) {
|
if (file_formats[XPM_FILE_FORMAT_INDEX].load_xpm_data == NULL) {
|
||||||
|
@ -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-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_class_init (GdkPixbufLoaderClass *klass);
|
||||||
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
||||||
static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_destroy (GtkObject *loader);
|
||||||
static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_finalize (GtkObject *loader);
|
||||||
|
|
||||||
/* Internal data */
|
/* Internal data */
|
||||||
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
||||||
@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
|
|||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
gboolean closed;
|
gboolean closed;
|
||||||
|
gchar buf[128];
|
||||||
|
gint buf_offset;
|
||||||
|
ModuleType *image_module;
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkType
|
GtkType
|
||||||
@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
|
|||||||
static void
|
static void
|
||||||
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbufLoaderPrivate *priv;
|
||||||
loader->private = g_new (GdkPixbufLoaderPrivate, 1);
|
|
||||||
|
|
||||||
loader->pixbuf = NULL;
|
priv = g_new (GdkPixbufLoaderPrivate, 1);
|
||||||
loader->closed = FALSE;
|
loader->private = priv;
|
||||||
|
|
||||||
|
priv->pixbuf = NULL;
|
||||||
|
priv->closed = FALSE;
|
||||||
|
priv->buf_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
gdk_pixbuf_unref (priv->pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
g_free (priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,18 +135,37 @@ gdk_pixbuf_loader_new (void)
|
|||||||
* cannot parse the buf.
|
* cannot parse the buf.
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
|
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
|
||||||
{
|
{
|
||||||
GdkPixbufLoaderPrivate *priv;
|
GdkPixbufLoaderPrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (loader != NULL, FALSE);
|
g_return_val_if_fail (loader != NULL, FALSE);
|
||||||
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), 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;
|
priv = loader->private;
|
||||||
|
|
||||||
/* we expect it's not to be closed */
|
/* we expect it's not to be closed */
|
||||||
g_return_val_if_fail (priv->closed == FALSE, FALSE);
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,16 +32,15 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
|
#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
|
||||||
#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
|
#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), GTK_TYPE_HBOX, GtkHBoxClass))
|
#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), GTK_TYPE_HBOX))
|
#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), GTK_TYPE_HBOX))
|
#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
||||||
@ -50,7 +49,7 @@ struct _GdkPixbufLoader
|
|||||||
GtkObject object;
|
GtkObject object;
|
||||||
|
|
||||||
/* < Private > */
|
/* < Private > */
|
||||||
gpointer data;
|
gpointer private;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
||||||
@ -66,8 +65,9 @@ struct _GdkPixbufLoaderClass {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GtkType gdk_pixbuf_loader_get_type (void);
|
||||||
GtkObject *gdk_pixbuf_loader_new (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);
|
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
|
||||||
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
||||||
|
|
||||||
|
@ -62,7 +62,8 @@ GdkPixbuf *
|
|||||||
image_load (FILE *f)
|
image_load (FILE *f)
|
||||||
{
|
{
|
||||||
int w, h, i, j;
|
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:
|
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."
|
* "* Usually rec_outbuf_height will be 1 or 2, at most 4."
|
||||||
*/
|
*/
|
||||||
|
@ -135,8 +135,8 @@ image_load (FILE *f)
|
|||||||
free_buffer, NULL);
|
free_buffer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkImage *
|
gboolean
|
||||||
image_load_by_data (void *data, size_t count)
|
image_load_by_data (void *data, size_t count)
|
||||||
{
|
{
|
||||||
return NULL;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ GdkPixbuf *
|
|||||||
image_load (FILE *f)
|
image_load (FILE *f)
|
||||||
{
|
{
|
||||||
TIFF *tiff;
|
TIFF *tiff;
|
||||||
guchar *pixels, *tmppix;
|
guchar *pixels = NULL;
|
||||||
|
guchar *tmppix;
|
||||||
gint w, h, x, y, num_pixs, fd;
|
gint w, h, x, y, num_pixs, fd;
|
||||||
uint32 *rast, *tmp_rast;
|
uint32 *rast, *tmp_rast;
|
||||||
|
|
||||||
|
@ -24,14 +24,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gdk-pixbuf-loader.h"
|
#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_class_init (GdkPixbufLoaderClass *klass);
|
||||||
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_init (GdkPixbufLoader *loader);
|
||||||
static void gdk_pixbuf_loader_destroy (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_destroy (GtkObject *loader);
|
||||||
static void gdk_pixbuf_loader_finalize (GdkPixbufLoader *loader);
|
static void gdk_pixbuf_loader_finalize (GtkObject *loader);
|
||||||
|
|
||||||
/* Internal data */
|
/* Internal data */
|
||||||
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
typedef struct _GdkPixbufLoaderPrivate GdkPixbufLoaderPrivate;
|
||||||
@ -39,6 +40,9 @@ struct _GdkPixbufLoaderPrivate
|
|||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
gboolean closed;
|
gboolean closed;
|
||||||
|
gchar buf[128];
|
||||||
|
gint buf_offset;
|
||||||
|
ModuleType *image_module;
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkType
|
GtkType
|
||||||
@ -76,28 +80,33 @@ gdk_pixbuf_loader_class_init (GdkPixbufLoaderClass *klass)
|
|||||||
static void
|
static void
|
||||||
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
gdk_pixbuf_loader_init (GdkPixbufLoader *loader)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbufLoaderPrivate *priv;
|
||||||
loader->private = g_new (GdkPixbufLoaderPrivate, 1);
|
|
||||||
|
|
||||||
loader->pixbuf = NULL;
|
priv = g_new (GdkPixbufLoaderPrivate, 1);
|
||||||
loader->closed = FALSE;
|
loader->private = priv;
|
||||||
|
|
||||||
|
priv->pixbuf = NULL;
|
||||||
|
priv->closed = FALSE;
|
||||||
|
priv->buf_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
gdk_pixbuf_unref (priv->pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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);
|
g_free (priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,18 +135,37 @@ gdk_pixbuf_loader_new (void)
|
|||||||
* cannot parse the buf.
|
* cannot parse the buf.
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, size_t count)
|
gdk_pixbuf_loader_write (GdkPixbufLoader *loader, gchar *buf, gint count)
|
||||||
{
|
{
|
||||||
GdkPixbufLoaderPrivate *priv;
|
GdkPixbufLoaderPrivate *priv;
|
||||||
|
|
||||||
g_return_val_if_fail (loader != NULL, FALSE);
|
g_return_val_if_fail (loader != NULL, FALSE);
|
||||||
g_return_val_if_fail (GDK_IS_PIXBUF_LOADER (loader), 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;
|
priv = loader->private;
|
||||||
|
|
||||||
/* we expect it's not to be closed */
|
/* we expect it's not to be closed */
|
||||||
g_return_val_if_fail (priv->closed == FALSE, FALSE);
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,16 +32,15 @@
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define GDK_TYPE_PIXBUF_LOADER (gtk_pixbuf_get_type ())
|
#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ())
|
||||||
#define GDK_PIXBUF_LOADER (obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_HBOX, GtkHBox))
|
#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), GTK_TYPE_HBOX, GtkHBoxClass))
|
#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), GTK_TYPE_HBOX))
|
#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), GTK_TYPE_HBOX))
|
#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER))
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
typedef struct _GdkPixbufLoader GdkPixbufLoader;
|
||||||
@ -50,7 +49,7 @@ struct _GdkPixbufLoader
|
|||||||
GtkObject object;
|
GtkObject object;
|
||||||
|
|
||||||
/* < Private > */
|
/* < Private > */
|
||||||
gpointer data;
|
gpointer private;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass;
|
||||||
@ -66,8 +65,9 @@ struct _GdkPixbufLoaderClass {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
GtkType gdk_pixbuf_loader_get_type (void);
|
||||||
GtkObject *gdk_pixbuf_loader_new (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);
|
GdkPixbuf *gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader);
|
||||||
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
void gdk_pixbuf_loader_close (GdkPixbufLoader *loader);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user