From 270ef59a98d34fef418fb6cd27e46f3edc912948 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 28 Mar 2010 12:56:39 +0000 Subject: Merge jmb/new-cache; r=dsilvers,rs=vince svn path=/trunk/netsurf/; revision=10180 --- image/bmp.c | 13 ++++++++----- image/bmp.h | 4 ++-- image/gif.c | 37 +++++++++++++++++++------------------ image/gif.h | 4 ++-- image/ico.c | 49 ++++++++++++++++++++++++++++++------------------- image/ico.h | 8 +++++--- image/jpeg.c | 12 ++++++++---- image/mng.c | 31 +++++++++++++++++++------------ image/mng.h | 4 ++-- image/nssprite.c | 11 ++++++++--- image/png.c | 12 ++++++++---- image/png.h | 4 ++-- image/rsvg.c | 5 ++--- image/rsvg.h | 4 ++-- image/svg.c | 2 +- image/svg.h | 4 ++-- 16 files changed, 120 insertions(+), 84 deletions(-) (limited to 'image') diff --git a/image/bmp.c b/image/bmp.c index 2a27231ac..1774f945c 100644 --- a/image/bmp.c +++ b/image/bmp.c @@ -30,7 +30,7 @@ #include #include #include "utils/config.h" -#include "content/content.h" +#include "content/content_protected.h" #include "desktop/plotters.h" #include "image/bitmap.h" #include "image/bmp.h" @@ -49,8 +49,7 @@ bmp_bitmap_callback_vt bmp_bitmap_callbacks = { .bitmap_get_bpp = bitmap_get_bpp }; -bool nsbmp_create(struct content *c, struct content *parent, - const char *params[]) +bool nsbmp_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; @@ -71,12 +70,16 @@ bool nsbmp_convert(struct content *c, int iwidth, int iheight) bmp_image *bmp; union content_msg_data msg_data; uint32_t swidth; + const char *data; + unsigned long size; /* set the bmp data */ bmp = c->data.bmp.bmp; + data = content__get_source_data(c, &size); + /* analyse the BMP */ - res = bmp_analyse(bmp, c->source_size, (unsigned char *)c->source_data); + res = bmp_analyse(bmp, size, (unsigned char *) data); switch (res) { case BMP_OK: break; @@ -98,7 +101,7 @@ bool nsbmp_convert(struct content *c, int iwidth, int iheight) c->title = malloc(100); if (c->title) snprintf(c->title, 100, messages_get("BMPTitle"), c->width, - c->height, c->source_size); + c->height, size); swidth = bmp->bitmap_callbacks.bitmap_get_bpp(bmp->bitmap) * bmp->width; c->size += (swidth * bmp->height) + 16 + 44 + 100; diff --git a/image/bmp.h b/image/bmp.h index f7b974f03..7d70a952d 100644 --- a/image/bmp.h +++ b/image/bmp.h @@ -33,6 +33,7 @@ struct content; struct bitmap; +struct http_parameter; struct content_bmp_data { bmp_image *bmp; /** BMP image data */ @@ -40,8 +41,7 @@ struct content_bmp_data { extern bmp_bitmap_callback_vt bmp_bitmap_callbacks; /** Only to be used by ICO code. */ -bool nsbmp_create(struct content *c, struct content *parent, - const char *params[]); +bool nsbmp_create(struct content *c, const struct http_parameter *params); bool nsbmp_convert(struct content *c, int width, int height); void nsbmp_destroy(struct content *c); bool nsbmp_redraw(struct content *c, int x, int y, diff --git a/image/gif.c b/image/gif.c index 62d73f0b0..81da8bd5d 100644 --- a/image/gif.c +++ b/image/gif.c @@ -37,7 +37,7 @@ #include #include #include "utils/config.h" -#include "content/content.h" +#include "content/content_protected.h" #include "desktop/browser.h" #include "desktop/options.h" #include "desktop/plotters.h" @@ -64,8 +64,7 @@ gif_bitmap_callback_vt gif_bitmap_callbacks = { }; -bool nsgif_create(struct content *c, struct content *parent, - const char *params[]) +bool nsgif_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; /* Initialise our data structure */ @@ -85,26 +84,28 @@ bool nsgif_convert(struct content *c, int iwidth, int iheight) int res; struct gif_animation *gif; union content_msg_data msg_data; + const char *data; + unsigned long size; /* Get the animation */ gif = c->data.gif.gif; + data = content__get_source_data(c, &size); + /* Initialise the GIF */ do { - res = gif_initialise(gif, c->source_size, - (unsigned char *)c->source_data); - if (res != GIF_OK && res != GIF_WORKING && res != GIF_INSUFFICIENT_FRAME_DATA) { - switch (res) - { - case GIF_FRAME_DATA_ERROR: - case GIF_INSUFFICIENT_DATA: - case GIF_DATA_ERROR: - msg_data.error = messages_get("BadGIF"); - break; - case GIF_INSUFFICIENT_MEMORY: - msg_data.error = messages_get( - "NoMemory"); - break; + res = gif_initialise(gif, size, (unsigned char *) data); + if (res != GIF_OK && res != GIF_WORKING && + res != GIF_INSUFFICIENT_FRAME_DATA) { + switch (res) { + case GIF_FRAME_DATA_ERROR: + case GIF_INSUFFICIENT_DATA: + case GIF_DATA_ERROR: + msg_data.error = messages_get("BadGIF"); + break; + case GIF_INSUFFICIENT_MEMORY: + msg_data.error = messages_get("NoMemory"); + break; } content_broadcast(c, CONTENT_MSG_ERROR, msg_data); return false; @@ -125,7 +126,7 @@ bool nsgif_convert(struct content *c, int iwidth, int iheight) c->title = malloc(100); if (c->title) { snprintf(c->title, 100, messages_get("GIFTitle"), c->width, - c->height, c->source_size); + c->height, size); } c->size += (gif->width * gif->height * 4) + 16 + 44 + 100; diff --git a/image/gif.h b/image/gif.h index 0e3ef6605..87f647eba 100644 --- a/image/gif.h +++ b/image/gif.h @@ -31,14 +31,14 @@ #include struct content; +struct http_parameter; struct content_gif_data { struct gif_animation *gif; /**< GIF animation data */ int current_frame; /**< current frame to display [0...(max-1)] */ }; -bool nsgif_create(struct content *c, struct content *parent, - const char *params[]); +bool nsgif_create(struct content *c, const struct http_parameter *params); bool nsgif_convert(struct content *c, int width, int height); void nsgif_destroy(struct content *c); bool nsgif_redraw(struct content *c, int x, int y, diff --git a/image/ico.c b/image/ico.c index e2fce245a..df07d50ed 100644 --- a/image/ico.c +++ b/image/ico.c @@ -29,7 +29,8 @@ #include #include #include "utils/config.h" -#include "content/content.h" +#include "content/content_protected.h" +#include "content/hlcache.h" #include "desktop/plotters.h" #include "image/bitmap.h" #include "image/ico.h" @@ -37,8 +38,7 @@ #include "utils/messages.h" #include "utils/utils.h" -bool nsico_create(struct content *c, struct content *parent, - const char *params[]) +bool nsico_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; c->data.ico.ico = calloc(sizeof(ico_collection), 1); @@ -58,26 +58,29 @@ bool nsico_convert(struct content *c, int iwidth, int iheight) bmp_result res; ico_collection *ico; union content_msg_data msg_data; + const char *data; + unsigned long size; /* set the ico data */ ico = c->data.ico.ico; + data = content__get_source_data(c, &size); + /* analyse the ico */ - res = ico_analyse(ico, c->source_size, (unsigned char *) - c->source_data); + res = ico_analyse(ico, size, (unsigned char *) data); switch (res) { - case BMP_OK: - break; - case BMP_INSUFFICIENT_MEMORY: - msg_data.error = messages_get("NoMemory"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - return false; - case BMP_INSUFFICIENT_DATA: - case BMP_DATA_ERROR: - msg_data.error = messages_get("BadICO"); - content_broadcast(c, CONTENT_MSG_ERROR, msg_data); - return false; + case BMP_OK: + break; + case BMP_INSUFFICIENT_MEMORY: + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + case BMP_INSUFFICIENT_DATA: + case BMP_DATA_ERROR: + msg_data.error = messages_get("BadICO"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; } /* Store our content width and description */ @@ -86,7 +89,7 @@ bool nsico_convert(struct content *c, int iwidth, int iheight) c->title = malloc(100); if (c->title) snprintf(c->title, 100, messages_get("ICOTitle"), c->width, - c->height, c->source_size); + c->height, size); c->size += (ico->width * ico->height * 4) + 16 + 44 + 100; /* exit as a success */ @@ -117,14 +120,22 @@ bool nsico_redraw(struct content *c, int x, int y, /** sets the bitmap for an ico according to the dimensions */ -bool nsico_set_bitmap_from_size(struct content *c, int width, int height) +bool nsico_set_bitmap_from_size(hlcache_handle *h, int width, int height) { - struct bmp_image *bmp = ico_find(c->data.ico.ico, width, height); + struct content *c = hlcache_handle_get_content(h); + struct bmp_image *bmp; + + assert(c != NULL); + + bmp = ico_find(c->data.ico.ico, width, height); if (bmp == NULL) return false; + if ((bmp->decoded == false) && (bmp_decode(bmp) != BMP_OK)) return false; + c->bitmap = bmp->bitmap; + return true; } diff --git a/image/ico.h b/image/ico.h index f3686c0c5..e25da8361 100644 --- a/image/ico.h +++ b/image/ico.h @@ -30,13 +30,14 @@ #include struct content; +struct hlcache_handle; +struct http_parameter; struct content_ico_data { struct ico_collection *ico; /** ICO collection data */ }; -bool nsico_create(struct content *c, struct content *parent, - const char *params[]); +bool nsico_create(struct content *c, const struct http_parameter *params); bool nsico_convert(struct content *c, int width, int height); void nsico_destroy(struct content *c); bool nsico_redraw(struct content *c, int x, int y, @@ -48,7 +49,8 @@ bool nsico_redraw_tiled(struct content *c, int x, int y, int clip_x0, int clip_y0, int clip_x1, int clip_y1, float scale, colour background_colour, bool repeat_x, bool repeat_y); -bool nsico_set_bitmap_from_size(struct content *c, int width, int height); +bool nsico_set_bitmap_from_size(struct hlcache_handle *h, + int width, int height); #endif /* WITH_BMP */ diff --git a/image/jpeg.c b/image/jpeg.c index e96faaa67..1d66b05d3 100644 --- a/image/jpeg.c +++ b/image/jpeg.c @@ -27,7 +27,7 @@ #ifdef WITH_JPEG /* This must come first due to libpng issues */ -#include "content/content.h" +#include "content/content_protected.h" #include #include @@ -89,6 +89,10 @@ bool nsjpeg_convert(struct content *c, int w, int h) uint8_t * volatile pixels = NULL; size_t rowstride; union content_msg_data msg_data; + const char *data; + unsigned long size; + + data = content__get_source_data(c, &size); cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = nsjpeg_error_exit; @@ -102,8 +106,8 @@ bool nsjpeg_convert(struct content *c, int w, int h) return false; } jpeg_create_decompress(&cinfo); - source_mgr.next_input_byte = (unsigned char *) c->source_data; - source_mgr.bytes_in_buffer = c->source_size; + source_mgr.next_input_byte = (unsigned char *) data; + source_mgr.bytes_in_buffer = size; cinfo.src = &source_mgr; jpeg_read_header(&cinfo, TRUE); cinfo.out_color_space = JCS_RGB; @@ -161,7 +165,7 @@ bool nsjpeg_convert(struct content *c, int w, int h) c->title = malloc(100); if (c->title) snprintf(c->title, 100, messages_get("JPEGTitle"), - width, height, c->source_size); + width, height, size); c->size += height * rowstride + 100; c->status = CONTENT_STATUS_DONE; /* Done: update status bar */ diff --git a/image/mng.c b/image/mng.c index d21d9e879..e76125b9b 100644 --- a/image/mng.c +++ b/image/mng.c @@ -24,7 +24,7 @@ #ifdef WITH_MNG /* This must come first due to libpng issues */ -#include "content/content.h" +#include "content/content_protected.h" #include #include @@ -69,8 +69,7 @@ static void nsmng_free(mng_ptr p, mng_size_t n); #endif -bool nsmng_create(struct content *c, struct content *parent, - const char *params[]) +bool nsmng_create(struct content *c, const struct http_parameter *params) { mng_retcode code; union content_msg_data msg_data; @@ -179,6 +178,8 @@ mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer, mng_uint32 size, mng_uint32 *bytesread) { struct content *c; + const char *data; + unsigned long data_size; assert(mng != NULL); assert(buffer != NULL); @@ -186,17 +187,18 @@ mng_bool nsmng_readdata(mng_handle mng, mng_ptr buffer, mng_uint32 size, /* Get our content back */ - c = (struct content *)mng_get_userdata(mng); + c = (struct content *) mng_get_userdata(mng); assert(c != NULL); /* Copy any data we have (maximum of 'size') */ - *bytesread = ((c->source_size - c->data.mng.read_size) < size) ? - (c->source_size - c->data.mng.read_size) : size; + data = content__get_source_data(c, &data_size); + + *bytesread = ((data_size - c->data.mng.read_size) < size) ? + (data_size - c->data.mng.read_size) : size; if ((*bytesread) > 0) { - memcpy(buffer, c->source_data + c->data.mng.read_size, - *bytesread); + memcpy(buffer, data + c->data.mng.read_size, *bytesread); c->data.mng.read_size += *bytesread; } @@ -302,9 +304,13 @@ bool nsmng_convert(struct content *c, int width, int height) mng_retcode status; union content_msg_data msg_data; + const char *data; + unsigned long size; assert(c != NULL); + data = content__get_source_data(c, &size); + /* by this point, the png should have been parsed * and the bitmap created, so ensure that's the case */ @@ -322,13 +328,13 @@ bool nsmng_convert(struct content *c, int width, int height) if (c->type == CONTENT_MNG) { snprintf(c->title, 100, messages_get("MNGTitle"), - c->width, c->height, c->source_size); + c->width, c->height, size); } else if (c->type == CONTENT_PNG) { snprintf(c->title, 100, messages_get("PNGTitle"), - c->width, c->height, c->source_size); + c->width, c->height, size); } else { snprintf(c->title, 100, messages_get("JNGTitle"), - c->width, c->height, c->source_size); + c->width, c->height, size); } c->size += c->width * c->height * 4 + 100; @@ -658,7 +664,8 @@ mng_bool nsmng_errorproc(mng_handle mng, mng_int32 code, chunk[3] = (char)((chunktype ) & 0xFF); chunk[4] = '\0'; - LOG(("error playing '%s' chunk %s (%d):", c->url, chunk, chunkseq)); + LOG(("error playing '%s' chunk %s (%d):", + content__get_url(c), chunk, chunkseq)); LOG(("code %d severity %d extra1 %d extra2 %d text:'%s'", code, severity, extra1, extra2, text)); diff --git a/image/mng.h b/image/mng.h index 2ea85409c..553fff36f 100644 --- a/image/mng.h +++ b/image/mng.h @@ -29,6 +29,7 @@ #include struct content; +struct http_parameter; struct content_mng_data { bool opaque_test_pending; @@ -40,8 +41,7 @@ struct content_mng_data { void *handle; }; -bool nsmng_create(struct content *c, struct content *parent, - const char *params[]); +bool nsmng_create(struct content *c, const struct http_parameter *params); bool nsmng_process_data(struct content *c, char *data, unsigned int size); bool nsmng_convert(struct content *c, int width, int height); void nsmng_destroy(struct content *c); diff --git a/image/nssprite.c b/image/nssprite.c index d5db6b905..9f48ffccf 100644 --- a/image/nssprite.c +++ b/image/nssprite.c @@ -31,7 +31,7 @@ #include "utils/config.h" #include "desktop/plotters.h" #include "image/bitmap.h" -#include "content/content.h" +#include "content/content_protected.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" @@ -61,8 +61,13 @@ bool nssprite_convert(struct content *c, int width, int height) union content_msg_data msg_data; struct rosprite_mem_context* ctx; - ERRCHK(rosprite_create_mem_context((uint8_t *) c->source_data, - c->source_size, &ctx)); + + const char *data; + unsigned long size; + + data = content__get_source_data(c, &size); + + ERRCHK(rosprite_create_mem_context((uint8_t *) data, size, &ctx)); struct rosprite_area* sprite_area; ERRCHK(rosprite_load(rosprite_mem_reader, ctx, &sprite_area)); diff --git a/image/png.c b/image/png.c index e8bd55c59..dfb427230 100644 --- a/image/png.c +++ b/image/png.c @@ -30,7 +30,7 @@ #include "desktop/plotters.h" -#include "content/content.h" +#include "content/content_protected.h" #include "image/bitmap.h" @@ -62,8 +62,7 @@ static void row_callback(png_structp png, png_bytep new_row, static void end_callback(png_structp png, png_infop info); -bool nspng_create(struct content *c, struct content *parent, - const char *params[]) +bool nspng_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; @@ -264,16 +263,21 @@ void end_callback(png_structp png, png_infop info) bool nspng_convert(struct content *c, int width, int height) { + const char *data; + unsigned long size; + assert(c->data.png.png != NULL); assert(c->data.png.info != NULL); + data = content__get_source_data(c, &size); + png_destroy_read_struct(&c->data.png.png, &c->data.png.info, 0); c->title = malloc(NSPNG_TITLE_LEN); if (c->title != NULL) { snprintf(c->title, NSPNG_TITLE_LEN, messages_get("PNGTitle"), - c->width, c->height, c->source_size); + c->width, c->height, size); } c->size += (c->width * c->height * 4) + NSPNG_TITLE_LEN; diff --git a/image/png.h b/image/png.h index a5fa6dfae..b940434e7 100644 --- a/image/png.h +++ b/image/png.h @@ -31,6 +31,7 @@ struct content; struct bitmap; +struct http_parameter; struct content_png_data { png_structp png; @@ -41,8 +42,7 @@ struct content_png_data { size_t rowbytes; /**< Number of bytes per row */ }; -bool nspng_create(struct content *c, struct content *parent, - const char *params[]); +bool nspng_create(struct content *c, const struct http_parameter *params); bool nspng_process_data(struct content *c, char *data, unsigned int size); bool nspng_convert(struct content *c, int width, int height); void nspng_destroy(struct content *c); diff --git a/image/rsvg.c b/image/rsvg.c index 86e1d5b66..ea4b58b42 100644 --- a/image/rsvg.c +++ b/image/rsvg.c @@ -38,7 +38,7 @@ #include #include "image/rsvg.h" -#include "content/content.h" +#include "content/content_protected.h" #include "desktop/plotters.h" #include "image/bitmap.h" #include "utils/log.h" @@ -49,8 +49,7 @@ static inline void rsvg_argb_to_abgr(uint32_t pixels[], int width, int height, size_t rowstride); -bool rsvg_create(struct content *c, struct content *parent, - const char *params[]) +bool rsvg_create(struct content *c, const struct http_parameter *params) { struct content_rsvg_data *d = &c->data.rsvg; union content_msg_data msg_data; diff --git a/image/rsvg.h b/image/rsvg.h index b8c962787..ae28d3af1 100644 --- a/image/rsvg.h +++ b/image/rsvg.h @@ -33,6 +33,7 @@ #include "image/bitmap.h" struct content; +struct http_parameter; struct content_rsvg_data { RsvgHandle *rsvgh; /**< Context handle for RSVG renderer */ @@ -41,8 +42,7 @@ struct content_rsvg_data { struct bitmap *bitmap; /**< Created NetSurf bitmap */ }; -bool rsvg_create(struct content *c, struct content *parent, - const char *params[]); +bool rsvg_create(struct content *c, const struct http_parameter *params); bool rsvg_process_data(struct content *c, char *data, unsigned int size); bool rsvg_convert(struct content *c, int width, int height); void rsvg_destroy(struct content *c); diff --git a/image/svg.c b/image/svg.c index 4321a9fc3..99c4241eb 100644 --- a/image/svg.c +++ b/image/svg.c @@ -40,7 +40,7 @@ * Create a CONTENT_SVG. */ -bool svg_create(struct content *c, struct content *parent, const char *params[]) +bool svg_create(struct content *c, const struct http_parameter *params) { union content_msg_data msg_data; diff --git a/image/svg.h b/image/svg.h index b191c4cd6..fe9bea3d2 100644 --- a/image/svg.h +++ b/image/svg.h @@ -26,14 +26,14 @@ #include struct content; +struct http_parameter; struct svgtiny_diagram; struct content_svg_data { struct svgtiny_diagram *diagram; }; -bool svg_create(struct content *c, struct content *parent, - const char *params[]); +bool svg_create(struct content *c, const struct http_parameter *params); bool svg_convert(struct content *c, int width, int height); void svg_destroy(struct content *c); bool svg_redraw(struct content *c, int x, int y, -- cgit v1.2.3