diff --git a/gdk-pixbuf/Makefile.am b/gdk-pixbuf/Makefile.am new file mode 100644 index 0000000000..54b3938877 --- /dev/null +++ b/gdk-pixbuf/Makefile.am @@ -0,0 +1,7 @@ + +_SOURCES = \ + gdk-pixbuf.c \ + gdk-pixbuf-io.c + +_HEADERS = \ + gdk-pixbuf.h diff --git a/gdk-pixbuf/gdk-pixbuf-cache.h b/gdk-pixbuf/gdk-pixbuf-cache.h new file mode 100644 index 0000000000..0afe745a4f --- /dev/null +++ b/gdk-pixbuf/gdk-pixbuf-cache.h @@ -0,0 +1,15 @@ +#ifndef _GDK_PIXBUF_CACHE_H_ +#define _GDK_PIXBUF_CACHE_H_ + +/* The optional cache interface */ +typedef struct { + int dummy; +} GdkPixBufCache; + +GdkPixBufCache *gdk_pixbuf_cache_new (long image_cache_limit, + long pixmap_bitmap_cache_limit); +void gdk_pixbuf_cache_destroy (GdkPixBufCache *cache); + +GdkPixBuf *gdk_pixbuf_cache_load_image (GdkPixBufCache *cache, + const char *file); +#endif diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c new file mode 100644 index 0000000000..61786ded23 --- /dev/null +++ b/gdk-pixbuf/gdk-pixbuf-io.c @@ -0,0 +1,69 @@ +/* + * gdk-pixbuf-io.c: Code to load images into GdkPixBufs + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include +#include "gdk-pixbuf.h" + +static struct { + char *module_name; + gboolean (*format_check)(char *buffer, int size); + GdkPixBuf *(*load)(char *filename); + int (*save)(char *filename, ...); +} loaders [] = { + { "png", pixbuf_check_png, NULL, NULL }, + { "jpeg", pixbuf_check_jpeg, NULL, NULL }, + { "tiff", pixbuf_check_tiff, NULL, NULL }, + { "gif", pixbuf_check_gif, NULL, NULL }, + { "xpm", pixbuf_check_xpm, pixbuf_xpm_load, pixbuf_xpm_save }, + { "bmp", pixbuf_check_bmp, NULL, NULL }, + { "ppm", pixbuf_check_ppm, NULL, NULL }, + { NULL, NULL, NULL, NULL }, +}; + +static int +image_file_format (const char *file) +{ + FILE *f = fopen (file); + + if (!f) + return -1; +} + +static void +image_loader_load (int idx) +{ +} + +GdkPixBuf * +gdk_pixbuf_load_image (const char *file) +{ + GdkPixBuf *pixbuf; + FormatLoader format_loader; + FILE *f; + char buffer [128]; + + f = fopen (file); + if (!f) + return NULL; + n = fread (&buffer, 1, sizeof (buffer), f); + fclose (f); + if (n == 0) + return NULL; + + for (i = 0; loaders [i].module_name; i++){ + if ((*loaders [i].format_check)(buffer, n)){ + if (!loaders [i].load) + image_loader_load (i); + + if (!loaders [i].load) + return NULL; + + return (*loaders [i].load)(file); + } + } + + return NULL; +} diff --git a/gdk-pixbuf/gdk-pixbuf.c b/gdk-pixbuf/gdk-pixbuf.c new file mode 100644 index 0000000000..052da78e41 --- /dev/null +++ b/gdk-pixbuf/gdk-pixbuf.c @@ -0,0 +1,36 @@ +/* + * gdk-pixbuf.c: Resource management. + * + * Author: + * Miguel de Icaza (miguel@gnu.org) + */ +#include +#include "gdk-pixbuf.h" + + +static void +gdk_pixbuf_destroy (GdkPixBuf *pixbuf) +{ + art_pixbuf_free (pixbuf->art_pixbuf); + g_free (pixbuf); +} + +void +gdk_pixbuf_ref (GdkPixBuf *pixbuf) +{ + g_return_if_fail (pixbuf != NULL); + + pixbuf->ref_count++; +} + +void +gdk_pixbuf_unref (GdkPixBuf *pixbuf) +{ + g_return_if_fail (pixbuf != NULL); + g_return_if_fail (pixbuf->ref_count == 0); + + pixbuf->ref_count--; + if (pixbuf->ref_count) + gdk_pixbuf_destroy (pixbuf); +} + diff --git a/gdk-pixbuf/gdk-pixbuf.h b/gdk-pixbuf/gdk-pixbuf.h new file mode 100644 index 0000000000..6c5e8f8fb6 --- /dev/null +++ b/gdk-pixbuf/gdk-pixbuf.h @@ -0,0 +1,18 @@ +#ifndef _GDK_PIXBUF_H_ +#define _GDK_PIXBUF_H_ + +#include + +typedef struct { + int ref_count; + ArtPixBuf *art_pixbuf; + void (*unref_func)(void *gdkpixbuf); +} GdkPixBuf; + +GdkPixBuf *gdk_pixbuf_load_image (const char *file); +void gdk_pixbuf_save_image (const char *format_id, const char *file, ...); +void gdk_pixbuf_ref (GdkPixBuf *pixbuf); +void gdk_pixbuf_unref (GdkPixBuf *pixbuf); +GdkPixBuf gdk_pixbuf_duplicate (GdkPixBuf *pixbuf); + +#endif /* _GDK_PIXBUF_H_ */ diff --git a/gdk-pixbuf/pixbuf.h b/gdk-pixbuf/pixbuf.h new file mode 100644 index 0000000000..181aa06642 --- /dev/null +++ b/gdk-pixbuf/pixbuf.h @@ -0,0 +1,18 @@ +#ifndef _GDK_PIXBUF_H_ +#define _GDK_PIXBUF_H_ + +#include + +typedef struct { + int ref_count; + ArtPixBuf *pixbuf; + void (*unref_func)(void *gdkpixbuf); +} GdkPixBuf; + +GdkPixBuf *gdk_pixbuf_load_image (const char *file); +void gdk_pixbuf_save_image (const char *format_id, const char *file, ...); +void gdk_pixbuf_ref (GdkPixBuf *pixbuf); +void gdk_pixbuf_unref (GdkPixBuf *pixbuf); +GdkPixBuf gdk_pixbuf_duplicate (GdkPixBuf *pixbuf); + +#endif /* _GDK_PIXBUF_H_ */