summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/IO/mime.c12
-rw-r--r--src/IO/mime.h18
-rw-r--r--src/Makefile.am3
-rw-r--r--src/dgif.h19
-rw-r--r--src/dicache.c86
-rw-r--r--src/dicache.h6
-rw-r--r--src/djpeg.h19
-rw-r--r--src/dpng.h19
-rw-r--r--src/gif.c50
-rw-r--r--src/jpeg.c49
-rw-r--r--src/png.c54
11 files changed, 183 insertions, 152 deletions
diff --git a/src/IO/mime.c b/src/IO/mime.c
index 33ec3322..9bffd619 100644
--- a/src/IO/mime.c
+++ b/src/IO/mime.c
@@ -96,16 +96,16 @@ static Viewer_t Mime_major_type_fetch(const char *Key, uint_t Size)
void a_Mime_init()
{
#ifdef ENABLE_GIF
- Mime_add_minor_type("image/gif", a_Gif_image);
+ Mime_add_minor_type("image/gif", a_Dicache_gif_image);
#endif
#ifdef ENABLE_JPEG
- Mime_add_minor_type("image/jpeg", a_Jpeg_image);
- Mime_add_minor_type("image/pjpeg", a_Jpeg_image);
- Mime_add_minor_type("image/jpg", a_Jpeg_image);
+ Mime_add_minor_type("image/jpeg", a_Dicache_jpeg_image);
+ Mime_add_minor_type("image/pjpeg", a_Dicache_jpeg_image);
+ Mime_add_minor_type("image/jpg", a_Dicache_jpeg_image);
#endif
#ifdef ENABLE_PNG
- Mime_add_minor_type("image/png", a_Png_image);
- Mime_add_minor_type("image/x-png", a_Png_image); /* deprecated */
+ Mime_add_minor_type("image/png", a_Dicache_png_image);
+ Mime_add_minor_type("image/x-png", a_Dicache_png_image); /* deprecated */
#endif
Mime_add_minor_type("text/html", a_Html_text);
diff --git a/src/IO/mime.h b/src/IO/mime.h
index 0f51a1e2..b9109211 100644
--- a/src/IO/mime.h
+++ b/src/IO/mime.h
@@ -31,18 +31,12 @@ void *a_Html_text (const char *Type,void *web, CA_Callback_t *Call,
void **Data);
void *a_Plain_text(const char *Type,void *web, CA_Callback_t *Call,
void **Data);
-#ifdef ENABLE_JPEG
-void *a_Jpeg_image(const char *Type,void *web, CA_Callback_t *Call,
- void **Data);
-#endif
-#ifdef ENABLE_PNG
-void *a_Png_image (const char *Type,void *web, CA_Callback_t *Call,
- void **Data);
-#endif
-#ifdef ENABLE_GIF
-void *a_Gif_image (const char *Type,void *web, CA_Callback_t *Call,
- void **Data);
-#endif
+void *a_Dicache_png_image (const char *Type,void *web, CA_Callback_t *Call,
+ void **Data);
+void *a_Dicache_gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data);
+void *a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data);
/*
* Functions defined inside Mime module
diff --git a/src/Makefile.am b/src/Makefile.am
index e944fb98..ab1a539e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,8 +87,11 @@ dillo_SOURCES = \
dns.c \
dns.h \
gif.c \
+ gif.h \
jpeg.c \
+ djpeg.h \
png.c \
+ dpng.h \
imgbuf.cc \
imgbuf.hh \
image.cc \
diff --git a/src/dgif.h b/src/dgif.h
new file mode 100644
index 00000000..d4980e54
--- /dev/null
+++ b/src/dgif.h
@@ -0,0 +1,19 @@
+#ifndef __GIF_H__
+#define __GIF_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "url.h"
+#include "image.hh"
+
+
+void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version);
+void a_Gif_callback(int Op, CacheClient_t *Client);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* !__GIF_H__ */
diff --git a/src/dicache.c b/src/dicache.c
index 36d08369..6ec1c7d8 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -20,9 +20,18 @@
#include "web.hh"
#include "dicache.h"
#include "cache.h"
+#include "dpng.h"
+#include "dgif.h"
+#include "djpeg.h"
typedef struct _DICacheNode DICacheNode;
+enum {
+ DIC_Gif,
+ DIC_Png,
+ DIC_Jpeg
+};
+
struct _DICacheNode {
int valid; /* flag */
DilloUrl *url; /* primary "Key" for this dicache entry */
@@ -374,6 +383,83 @@ void a_Dicache_close(DilloUrl *url, int version, CacheClient_t *Client)
/* ------------------------------------------------------------------------- */
/*
+ * Generic MIME handler for GIF, JPEG and PNG.
+ * Sets a_Dicache_callback as the cache-client,
+ * and also sets the image decoder.
+ *
+ * Parameters:
+ * Type: MIME type
+ * Ptr: points to a Web structure
+ * Call: Dillo calls this with more data/eod
+ * Data: Decoding data structure
+ */
+static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
+ CA_Callback_t *Call, void **Data)
+{
+ DilloWeb *web = Ptr;
+ DICacheEntry *DicEntry;
+
+ dReturn_val_if_fail(MimeType && Ptr, NULL);
+
+ if (!web->Image)
+ web->Image = a_Image_new(0, 0, NULL, prefs.bg_color);
+
+ /* Add an extra reference to the Image (for dicache usage) */
+ a_Image_ref(web->Image);
+
+ DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
+ if (!DicEntry) {
+ /* Let's create an entry for this image... */
+ DicEntry = a_Dicache_add_entry(web->url);
+ DicEntry->DecoderData =
+ (ImgType == DIC_Png) ?
+ a_Png_new(web->Image, DicEntry->url, DicEntry->version) :
+ (ImgType == DIC_Gif) ?
+ a_Gif_new(web->Image, DicEntry->url, DicEntry->version) :
+ (ImgType == DIC_Jpeg) ?
+ a_Jpeg_new(web->Image, DicEntry->url, DicEntry->version) :
+ NULL;
+ } else {
+ /* Repeated image */
+ a_Dicache_ref(DicEntry->url, DicEntry->version);
+ }
+ DicEntry->Decoder = (ImgType == DIC_Png) ? a_Png_callback :
+ (ImgType == DIC_Gif) ? a_Gif_callback :
+ (ImgType == DIC_Jpeg) ? a_Jpeg_callback : NULL;
+ *Data = DicEntry->DecoderData;
+ *Call = (CA_Callback_t) a_Dicache_callback;
+
+ return (web->Image->dw);
+}
+
+/*
+ * PNG wrapper for Dicache_image()
+ */
+void *a_Dicache_png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data)
+{
+ return Dicache_image(DIC_Png, Type, Ptr, Call, Data);
+}
+
+/*
+ * GIF wrapper for Dicache_image()
+ */
+void *a_Dicache_gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data)
+{
+ return Dicache_image(DIC_Gif, Type, Ptr, Call, Data);
+}
+
+/*
+ * JPEG wrapper for Dicache_image()
+ */
+void *a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data)
+{
+ return Dicache_image(DIC_Jpeg, Type, Ptr, Call, Data);
+}
+
+/*
* This function is a cache client; (but feeds its clients from dicache)
*/
void a_Dicache_callback(int Op, CacheClient_t *Client)
diff --git a/src/dicache.h b/src/dicache.h
index 51d67de2..70e5d9de 100644
--- a/src/dicache.h
+++ b/src/dicache.h
@@ -54,6 +54,12 @@ void a_Dicache_init (void);
DICacheEntry *a_Dicache_get_entry(const DilloUrl *Url, int version);
DICacheEntry *a_Dicache_add_entry(const DilloUrl *Url);
+void *a_Dicache_png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data);
+void *a_Dicache_gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data);
+void *a_Dicache_jpeg_image(const char *Type, void *Ptr, CA_Callback_t *Call,
+ void **Data);
void a_Dicache_callback(int Op, CacheClient_t *Client);
void a_Dicache_callback2(int Op, CacheClient_t *Client);
diff --git a/src/djpeg.h b/src/djpeg.h
new file mode 100644
index 00000000..d88f5671
--- /dev/null
+++ b/src/djpeg.h
@@ -0,0 +1,19 @@
+#ifndef __JPEG_H__
+#define __JPEG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "url.h"
+#include "image.hh"
+
+
+void *a_Jpeg_new(DilloImage *Image, DilloUrl *url, int version);
+void a_Jpeg_callback(int Op, CacheClient_t *Client);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* !__JPEG_H__ */
diff --git a/src/dpng.h b/src/dpng.h
new file mode 100644
index 00000000..a9ee8820
--- /dev/null
+++ b/src/dpng.h
@@ -0,0 +1,19 @@
+#ifndef __PNG_H__
+#define __PNG_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include "url.h"
+#include "image.hh"
+
+
+void *a_Png_new(DilloImage *Image, DilloUrl *url, int version);
+void a_Png_callback(int Op, CacheClient_t *Client);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* !__PNG_H__ */
diff --git a/src/gif.c b/src/gif.c
index 2a35bf9b..d05e2639 100644
--- a/src/gif.c
+++ b/src/gif.c
@@ -147,53 +147,12 @@ static void Gif_write(DilloGif *gif, void *Buf, uint_t BufSize);
static void Gif_close(DilloGif *gif, CacheClient_t *Client);
static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *buf,
int bufsize, void *Buf);
-static DilloGif *Gif_new(DilloImage *Image, DilloUrl *url, int version);
-static void Gif_callback(int Op, CacheClient_t *Client);
-
-/* exported function */
-void *a_Gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
- void **Data);
/*
- * MIME handler for "image/gif" type
- * Sets a_Dicache_callback as the cache-client,
- * and Gif_callback as the image decoder.
- */
-void *a_Gif_image(const char *Type, void *Ptr, CA_Callback_t *Call,
- void **Data)
-{
- DilloWeb *web = Ptr;
- DICacheEntry *DicEntry;
-
- if (!web->Image)
- web->Image = a_Image_new(0, 0, NULL, prefs.bg_color);
- /* TODO: get the backgound color from the parent widget -- Livio. */
-
- /* Add an extra reference to the Image (for dicache usage) */
- a_Image_ref(web->Image);
-
- DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
- if (!DicEntry) {
- /* Let's create an entry for this image... */
- DicEntry = a_Dicache_add_entry(web->url);
- DicEntry->DecoderData =
- Gif_new(web->Image, DicEntry->url, DicEntry->version);
- } else {
- /* Repeated image */
- a_Dicache_ref(DicEntry->url, DicEntry->version);
- }
- DicEntry->Decoder = Gif_callback;
- *Data = DicEntry->DecoderData;
- *Call = (CA_Callback_t) a_Dicache_callback;
-
- return (web->Image->dw);
-}
-
-/*
* Create a new gif structure for decoding a gif into a RGB buffer
*/
-static DilloGif *Gif_new(DilloImage *Image, DilloUrl *url, int version)
+void *a_Gif_new(DilloImage *Image, DilloUrl *url, int version)
{
DilloGif *gif = dMalloc(sizeof(DilloGif));
@@ -220,7 +179,7 @@ static DilloGif *Gif_new(DilloImage *Image, DilloUrl *url, int version)
* This function is a cache client, it receives data from the cache
* and dispatches it to the appropriate gif-processing functions
*/
-static void Gif_callback(int Op, CacheClient_t *Client)
+void a_Gif_callback(int Op, CacheClient_t *Client)
{
if (Op)
Gif_close(Client->CbData, Client);
@@ -1046,4 +1005,9 @@ static size_t Gif_process_bytes(DilloGif *gif, const uchar_t *ibuf,
return bufsize - tmp_bufsize;
}
+#else /* ENABLE_GIF */
+
+void *a_Gif_new() { return 0; }
+void a_Gif_callback() { return; }
+
#endif /* ENABLE_GIF */
diff --git a/src/jpeg.c b/src/jpeg.c
index db30c13f..f27d886f 100644
--- a/src/jpeg.c
+++ b/src/jpeg.c
@@ -81,15 +81,9 @@ typedef struct DilloJpeg {
/*
* Forward declarations
*/
-static DilloJpeg *Jpeg_new(DilloImage *Image, DilloUrl *url, int version);
-static void Jpeg_callback(int Op, CacheClient_t *Client);
static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize);
METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo);
-/* exported function */
-void *a_Jpeg_image(const char *Type, void *P, CA_Callback_t *Call,
- void **Data);
-
/* this is the routine called by libjpeg when it detects an error. */
METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo)
@@ -101,40 +95,6 @@ METHODDEF(void) Jpeg_errorexit (j_common_ptr cinfo)
}
/*
- * MIME handler for "image/jpeg" type
- * Sets a_Dicache_callback as the cache-client,
- * and Jpeg_callback as the image decoder.
- */
-void *a_Jpeg_image(const char *Type, void *P, CA_Callback_t *Call,
- void **Data)
-{
- DilloWeb *web = P;
- DICacheEntry *DicEntry;
-
- if (!web->Image)
- web->Image = a_Image_new(0, 0, NULL, 0);
-
- /* Add an extra reference to the Image (for dicache usage) */
- a_Image_ref(web->Image);
-
- DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
- if (!DicEntry) {
- /* Let's create an entry for this image... */
- DicEntry = a_Dicache_add_entry(web->url);
- DicEntry->DecoderData =
- Jpeg_new(web->Image, DicEntry->url, DicEntry->version);
- } else {
- /* Repeated image */
- a_Dicache_ref(DicEntry->url, DicEntry->version);
- }
- DicEntry->Decoder = Jpeg_callback;
- *Data = DicEntry->DecoderData;
- *Call = (CA_Callback_t) a_Dicache_callback;
-
- return (web->Image->dw);
-}
-
-/*
* Finish the decoding process
*/
static void Jpeg_close(DilloJpeg *jpeg, CacheClient_t *Client)
@@ -201,7 +161,7 @@ static void term_source(j_decompress_ptr cinfo)
{
}
-static DilloJpeg *Jpeg_new(DilloImage *Image, DilloUrl *url, int version)
+void *a_Jpeg_new(DilloImage *Image, DilloUrl *url, int version)
{
my_source_mgr *src;
DilloJpeg *jpeg = dMalloc(sizeof(*jpeg));
@@ -237,7 +197,7 @@ static DilloJpeg *Jpeg_new(DilloImage *Image, DilloUrl *url, int version)
return jpeg;
}
-static void Jpeg_callback(int Op, CacheClient_t *Client)
+void a_Jpeg_callback(int Op, CacheClient_t *Client)
{
if (Op)
Jpeg_close(Client->CbData, Client);
@@ -399,4 +359,9 @@ static void Jpeg_write(DilloJpeg *jpeg, void *Buf, uint_t BufSize)
}
}
+#else /* ENABLE_JPEG */
+
+void *a_Jpeg_new() { return 0; }
+void a_Jpeg_callback() { return; }
+
#endif /* ENABLE_JPEG */
diff --git a/src/png.c b/src/png.c
index 8b641c66..535298ca 100644
--- a/src/png.c
+++ b/src/png.c
@@ -107,13 +107,6 @@ struct _DilloPng {
#define BLACK 0
#define WHITE 255
-/*
- * Forward declarations
- */
-/* exported function */
-void *a_Png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
- void **Data);
-
static
void Png_error_handling(png_structp png_ptr, png_const_charp msg)
@@ -326,8 +319,6 @@ static void Png_write(DilloPng *png, void *Buf, uint_t BufSize)
{
dReturn_if_fail ( Buf != NULL && BufSize > 0 );
- _MSG("Png_callback BufSize = %d\n", BufSize);
-
/* Keep local copies so we don't have to pass multiple args to
* a number of functions. */
png->ipbuf = Buf;
@@ -413,7 +404,7 @@ static void Png_write(DilloPng *png, void *Buf, uint_t BufSize)
* failure. This means that you can't just wait for all the data to be
* presented before starting conversion and display.
*/
-static void Png_callback(int Op, CacheClient_t *Client)
+void a_Png_callback(int Op, CacheClient_t *Client)
{
if (Op) { /* EOF */
Png_close(Client->CbData, Client);
@@ -425,7 +416,7 @@ static void Png_callback(int Op, CacheClient_t *Client)
/*
* Create the image state data that must be kept between calls
*/
-static DilloPng *Png_new(DilloImage *Image, DilloUrl *url, int version)
+void *a_Png_new(DilloImage *Image, DilloUrl *url, int version)
{
DilloPng *png = dNew0(DilloPng, 1);
@@ -445,44 +436,9 @@ static DilloPng *Png_new(DilloImage *Image, DilloUrl *url, int version)
return png;
}
-/*
- * MIME handler for "image/png" type.
- * Sets a_Dicache_callback as the cache-client,
- * and Png_callback as the image decoder.
- *
- * Parameters:
- * Type: MIME type
- * Ptr: points to a Web structure
- * Call: Dillo calls this with more data/eod
- * Data: Decoding data structure
- */
-void *a_Png_image(const char *Type, void *Ptr, CA_Callback_t *Call,
- void **Data)
-{
- DilloWeb *web = Ptr;
- DICacheEntry *DicEntry;
-
- if (!web->Image)
- web->Image = a_Image_new(0, 0, NULL, prefs.bg_color);
+#else /* ENABLE_PNG */
- /* Add an extra reference to the Image (for dicache usage) */
- a_Image_ref(web->Image);
-
- DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
- if (!DicEntry) {
- /* Let's create an entry for this image... */
- DicEntry = a_Dicache_add_entry(web->url);
- DicEntry->DecoderData =
- Png_new(web->Image, DicEntry->url, DicEntry->version);
- } else {
- /* Repeated image */
- a_Dicache_ref(DicEntry->url, DicEntry->version);
- }
- DicEntry->Decoder = Png_callback;
- *Data = DicEntry->DecoderData;
- *Call = (CA_Callback_t) a_Dicache_callback;
-
- return (web->Image->dw);
-}
+void *a_Png_new() { return 0; }
+void a_Png_callback() { return; }
#endif /* ENABLE_PNG */