Commit 0da5c74f authored by Jonathan Blandford's avatar Jonathan Blandford Committed by Jonathan Blandford

started work on the tiff non-incremental loader.


1999-10-28  Jonathan Blandford  <jrb@redhat.com>

	* src/io-tiff.c (image_load_increment): started work on the tiff
	non-incremental loader.

	* src/io-gif.c (image_load_increment): started work on the gif
	incremental loader.

	* src/gdk-pixbuf-io.h: Changed ModuleType to GdkPixbufModule.
parent 29a640d1
......@@ -135,7 +135,7 @@ pixbuf_check_ppm (guchar *buffer, int size)
}
#endif
ModuleType file_formats [] = {
GdkPixbufModule file_formats [] = {
{ "png", pixbuf_check_png, NULL, NULL, NULL, NULL, NULL, NULL },
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL, NULL, NULL, NULL },
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL, NULL, NULL, NULL },
......@@ -150,7 +150,7 @@ ModuleType file_formats [] = {
};
static void
image_handler_load (ModuleType *image_module)
image_handler_load (GdkPixbufModule *image_module)
{
char *module_name;
char *path;
......@@ -205,7 +205,7 @@ image_handler_load (ModuleType *image_module)
ModuleType *
GdkPixbufModule *
gdk_pixbuf_get_module (gchar *buffer, gint size)
{
gint i;
......@@ -224,7 +224,7 @@ gdk_pixbuf_new_from_file (const char *filename)
gint size;
FILE *f;
char buffer [128];
ModuleType *image_module;
GdkPixbufModule *image_module;
f = fopen (filename, "r");
if (!f)
......
......@@ -30,8 +30,8 @@
typedef void (* ModulePreparedNotifyFunc) (GdkPixbuf *pixbuf, gpointer user_data);
typedef struct _ModuleType ModuleType;
struct _ModuleType {
typedef struct _GdkPixbufModule GdkPixbufModule;
struct _GdkPixbufModule {
char *module_name;
gboolean (* format_check) (guchar *buffer, int size);
GModule *module;
......@@ -45,5 +45,5 @@ struct _ModuleType {
};
ModuleType *gdk_pixbuf_get_module (gchar *buffer, gint size);
GdkPixbufModule *gdk_pixbuf_get_module (gchar *buffer, gint size);
......@@ -53,7 +53,7 @@ typedef struct {
gboolean closed;
gchar buf[128];
gint buf_offset;
ModuleType *image_module;
GdkPixbufModule *image_module;
gpointer context;
} GdkPixbufLoaderPrivate;
......
......@@ -27,7 +27,7 @@
#include <glib.h>
#include <gif_lib.h>
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-io.h"
/* Destroy notification function for the libart pixbuf */
......@@ -44,10 +44,10 @@ image_load (FILE *f)
gint fn, is_trans = FALSE;
gint done = 0;
gint t_color = -1;
gint w, h, i, j;
gint w = 0, h = 0, i, j;
guchar *pixels, *tmpptr;
GifFileType *gif;
GifRowType *rows;
GifRowType *rows = NULL;
GifRecordType rec;
ColorMapObject *cmap;
int intoffset[] = { 0, 4, 2, 1 };
......@@ -183,3 +183,71 @@ image_load (FILE *f)
w, h, is_trans ? (w * 4) : (w * 3),
free_buffer, NULL);
}
/* Progressive loader */
typedef struct _GifData GifData;
struct _GifData
{
ModulePreparedNotifyFunc *func;
gpointer user_data;
GifFileType *gif_handle;
guchar *buf;
guint ptr;
gint size;
};
gpointer
image_begin_load (ModulePreparedNotifyFunc *func, gpointer user_data)
{
GifData *context;
context = g_new (GifData, 1);
context->func = func;
context->user_data = user_data;
context->buf = NULL;
context->gif_handle = NULL;
return context;
}
int
myInputFunc (GifFileType *type, GifByteType *byte, int length)
{
GifData *context;
context = (GifData *) type->UserData;
g_print ("in myInputFunc\nSize requested is %d\n", length);
if (length > context->size - context->ptr) {
memcpy (byte, context->buf + context->ptr, context->size - context->ptr);
return context->size - context->ptr;
}
memcpy (byte, context->buf + context->ptr, length);
return length;
}
void
image_stop_load (gpointer context)
{
g_free ((GifData *) context);
}
gboolean
image_load_increment (gpointer data, guchar *buf, guint size)
{
GifData *context = (GifData *) data;
g_print ("in load_increment: %d\n", size);
context->buf = g_realloc (context->buf, size);
context->ptr = 0;
context->size = size;
memcpy (context->buf, buf, size);
if ((context->gif_handle == NULL) && (context->size > 20))
context->gif_handle = DGifOpen (context, myInputFunc);
g_print ("width = %d, height = %d\n", context->gif_handle->SWidth, context->gif_handle->SHeight);
return FALSE;
}
......@@ -25,9 +25,11 @@
/* Following code (almost) blatantly ripped from Imlib */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tiffio.h>
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-io.h"
......@@ -99,3 +101,60 @@ image_load (FILE *f)
w, h, w * 4,
free_buffer, NULL);
}
/* Progressive loader */
/*
* Tiff loading progressively cannot be done. We write it to a file, then load
* the file when it's done.
*/
typedef struct _TiffData TiffData;
struct _TiffData
{
ModulePreparedNotifyFunc *func;
gpointer user_data;
FILE *file;
};
gpointer
image_begin_load (ModulePreparedNotifyFunc *func, gpointer user_data)
{
TiffData *context;
gint fd;
char template[21];
context = g_new (TiffData, 1);
context->func = func;
context->user_data = user_data;
strncpy (template, "/tmp/temp-tiffXXXXXX", strlen ("/tmp/temp-tiffXXXXXX"));
fd = mkstemp (template);
g_print ("fd=%d\n", fd);
context->file = fdopen (fd, "w");
if (context->file == NULL)
g_print ("it's null\n");
else
g_print ("it's not null\n");
return context;
}
void
image_stop_load (gpointer data)
{
TiffData *context = (TiffData*) data;
fclose (context->file);
/* unlink (context->file);*/
g_free ((TiffData *) context);
}
gboolean
image_load_increment (gpointer data, guchar *buf, guint size)
{
TiffData *context = (TiffData *) data;
g_assert (context->file != NULL);
fwrite (buf, sizeof (guchar), size, context->file);
return TRUE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment