summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-05-08 19:54:35 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-05-08 19:54:35 +0000
commit8be1e85e919d5b6c12979dca0d57f7cd67d2cb79 (patch)
treec0887e7c26229de5f543b03eb9bdb8d5561e9787 /image
parent8f6c343309dd32c3193622961df5e2f785915665 (diff)
downloadnetsurf-8be1e85e919d5b6c12979dca0d57f7cd67d2cb79.tar.gz
netsurf-8be1e85e919d5b6c12979dca0d57f7cd67d2cb79.tar.bz2
consolidate content redraw
more cleanups ready for image content refactor svn path=/trunk/netsurf/; revision=12317
Diffstat (limited to 'image')
-rw-r--r--image/bmp.c227
-rw-r--r--image/gif.c448
-rw-r--r--image/ico.c173
-rw-r--r--image/jpeg.c15
-rw-r--r--image/png.c15
-rw-r--r--image/rsvg.c184
6 files changed, 468 insertions, 594 deletions
diff --git a/image/bmp.c b/image/bmp.c
index dbb4d9796..9e1326e62 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -46,54 +46,8 @@ typedef struct nsbmp_content {
bmp_image *bmp; /** BMP image data */
} nsbmp_content;
-static nserror nsbmp_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static nserror nsbmp_create_bmp_data(nsbmp_content *bmp);
-static bool nsbmp_convert(struct content *c);
-static void nsbmp_destroy(struct content *c);
-static bool nsbmp_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-static bool nsbmp_redraw_tiled(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour,
- bool repeat_x, bool repeat_y);
-static nserror nsbmp_clone(const struct content *old, struct content **newc);
-static content_type nsbmp_content_type(lwc_string *mime_type);
-static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state);
-/* The Bitmap callbacks function table;
- * necessary for interaction with nsbmplib.
- */
-bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
- .bitmap_create = nsbmp_bitmap_create,
- .bitmap_destroy = bitmap_destroy,
- .bitmap_set_suspendable = bitmap_set_suspendable,
- .bitmap_get_buffer = bitmap_get_buffer,
- .bitmap_get_bpp = bitmap_get_bpp
-};
-
-static const content_handler nsbmp_content_handler = {
- nsbmp_create,
- NULL,
- nsbmp_convert,
- NULL,
- nsbmp_destroy,
- NULL,
- NULL,
- NULL,
- nsbmp_redraw,
- nsbmp_redraw_tiled,
- NULL,
- NULL,
- nsbmp_clone,
- NULL,
- nsbmp_content_type,
- false
-};
static const char *nsbmp_types[] = {
"application/bmp",
@@ -112,46 +66,24 @@ static const char *nsbmp_types[] = {
static lwc_string *nsbmp_mime_types[NOF_ELEMENTS(nsbmp_types)];
-nserror nsbmp_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
- lerror = lwc_intern_string(nsbmp_types[i],
- strlen(nsbmp_types[i]),
- &nsbmp_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
+static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
+{
+ union content_msg_data msg_data;
- error = content_factory_register_handler(nsbmp_mime_types[i],
- &nsbmp_content_handler);
- if (error != NSERROR_OK)
- goto error;
+ bmp->bmp = calloc(sizeof(struct bmp_image), 1);
+ if (bmp->bmp == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
}
- return NSERROR_OK;
-
-error:
- nsbmp_fini();
+ bmp_create(bmp->bmp, &bmp_bitmap_callbacks);
- return error;
+ return NSERROR_OK;
}
-void nsbmp_fini(void)
-{
- uint32_t i;
- for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
- if (nsbmp_mime_types[i] != NULL)
- lwc_string_unref(nsbmp_mime_types[i]);
- }
-}
-
-nserror nsbmp_create(const content_handler *handler,
+static nserror nsbmp_create(const content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -181,23 +113,39 @@ nserror nsbmp_create(const content_handler *handler,
return NSERROR_OK;
}
-nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
-{
- union content_msg_data msg_data;
-
- bmp->bmp = calloc(sizeof(struct bmp_image), 1);
- if (bmp->bmp == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&bmp->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
- }
+/**
+ * Callback for libnsbmp; forwards the call to bitmap_create()
+ *
+ * \param width width of image in pixels
+ * \param height width of image in pixels
+ * \param state a flag word indicating the initial state
+ * \return an opaque struct bitmap, or NULL on memory exhaustion
+ */
+static void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
+{
+ unsigned int bitmap_state = BITMAP_NEW;
- bmp_create(bmp->bmp, &bmp_bitmap_callbacks);
+ /* set bitmap state based on bmp state */
+ bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0;
+ bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ?
+ BITMAP_CLEAR_MEMORY : 0;
- return NSERROR_OK;
+ /* return the created bitmap */
+ return bitmap_create(width, height, bitmap_state);
}
-bool nsbmp_convert(struct content *c)
+/* The Bitmap callbacks function table;
+ * necessary for interaction with nsbmplib.
+ */
+bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
+ .bitmap_create = nsbmp_bitmap_create,
+ .bitmap_destroy = bitmap_destroy,
+ .bitmap_set_suspendable = bitmap_set_suspendable,
+ .bitmap_get_buffer = bitmap_get_buffer,
+ .bitmap_get_bpp = bitmap_get_bpp
+};
+
+static bool nsbmp_convert(struct content *c)
{
nsbmp_content *bmp = (nsbmp_content *) c;
bmp_result res;
@@ -249,25 +197,7 @@ bool nsbmp_convert(struct content *c)
return true;
}
-
-bool nsbmp_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
-{
- nsbmp_content *bmp = (nsbmp_content *) c;
-
- if (bmp->bmp->decoded == false)
- if (bmp_decode(bmp->bmp) != BMP_OK)
- return false;
-
- c->bitmap = bmp->bmp->bitmap;
-
- return plot.bitmap(x, y, width, height, c->bitmap,
- background_colour, BITMAPF_NONE);
-}
-
-
-bool nsbmp_redraw_tiled(struct content *c, int x, int y,
+static bool nsbmp_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
@@ -291,7 +221,7 @@ bool nsbmp_redraw_tiled(struct content *c, int x, int y,
}
-void nsbmp_destroy(struct content *c)
+static void nsbmp_destroy(struct content *c)
{
nsbmp_content *bmp = (nsbmp_content *) c;
@@ -300,7 +230,7 @@ void nsbmp_destroy(struct content *c)
}
-nserror nsbmp_clone(const struct content *old, struct content **newc)
+static nserror nsbmp_clone(const struct content *old, struct content **newc)
{
nsbmp_content *new_bmp;
nserror error;
@@ -335,30 +265,67 @@ nserror nsbmp_clone(const struct content *old, struct content **newc)
return NSERROR_OK;
}
-content_type nsbmp_content_type(lwc_string *mime_type)
+static content_type nsbmp_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
-/**
- * Callback for libnsbmp; forwards the call to bitmap_create()
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \param state a flag word indicating the initial state
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-void *nsbmp_bitmap_create(int width, int height, unsigned int bmp_state)
+
+static const content_handler nsbmp_content_handler = {
+ nsbmp_create,
+ NULL,
+ nsbmp_convert,
+ NULL,
+ nsbmp_destroy,
+ NULL,
+ NULL,
+ NULL,
+ nsbmp_redraw,
+ NULL,
+ NULL,
+ nsbmp_clone,
+ NULL,
+ nsbmp_content_type,
+ false
+};
+
+nserror nsbmp_init(void)
{
- unsigned int bitmap_state = BITMAP_NEW;
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
- /* set bitmap state based on bmp state */
- bitmap_state |= (bmp_state & BMP_OPAQUE) ? BITMAP_OPAQUE : 0;
- bitmap_state |= (bmp_state & BMP_CLEAR_MEMORY) ?
- BITMAP_CLEAR_MEMORY : 0;
+ for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
+ lerror = lwc_intern_string(nsbmp_types[i],
+ strlen(nsbmp_types[i]),
+ &nsbmp_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
- /* return the created bitmap */
- return bitmap_create(width, height, bitmap_state);
+ error = content_factory_register_handler(nsbmp_mime_types[i],
+ &nsbmp_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ nsbmp_fini();
+
+ return error;
+}
+
+void nsbmp_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(nsbmp_mime_types); i++) {
+ if (nsbmp_mime_types[i] != NULL)
+ lwc_string_unref(nsbmp_mime_types[i]);
+ }
}
#endif
diff --git a/image/gif.c b/image/gif.c
index 20a67424e..798097bf5 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -56,32 +56,28 @@ typedef struct nsgif_content {
int current_frame; /**< current frame to display [0...(max-1)] */
} nsgif_content;
-static nserror nsgif_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static nserror nsgif_create_gif_data(nsgif_content *c);
-static bool nsgif_convert(struct content *c);
-static void nsgif_destroy(struct content *c);
-static bool nsgif_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-static bool nsgif_redraw_tiled(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour,
- bool repeat_x, bool repeat_y);
-static nserror nsgif_clone(const struct content *old, struct content **newc);
-static content_type nsgif_content_type(lwc_string *mime_type);
+static const char *nsgif_types[] = {
+ "image/gif"
+};
-static void *nsgif_bitmap_create(int width, int height);
-static void nsgif_invalidate(void *bitmap, void *private_word);
-static void nsgif_animate(void *p);
-static gif_result nsgif_get_frame(struct content *c);
+static lwc_string *nsgif_mime_types[NOF_ELEMENTS(nsgif_types)];
+
+/**
+ * Callback for libnsgif; forwards the call to bitmap_create()
+ *
+ * \param width width of image in pixels
+ * \param height width of image in pixels
+ * \return an opaque struct bitmap, or NULL on memory exhaustion
+ */
+static void *nsgif_bitmap_create(int width, int height)
+{
+ return bitmap_create(width, height, BITMAP_NEW);
+}
/* The Bitmap callbacks function table;
* necessary for interaction with nsgiflib.
*/
-gif_bitmap_callback_vt gif_bitmap_callbacks = {
+static gif_bitmap_callback_vt gif_bitmap_callbacks = {
.bitmap_create = nsgif_bitmap_create,
.bitmap_destroy = bitmap_destroy,
.bitmap_get_buffer = bitmap_get_buffer,
@@ -90,71 +86,24 @@ gif_bitmap_callback_vt gif_bitmap_callbacks = {
.bitmap_modified = bitmap_modified
};
-static const content_handler nsgif_content_handler = {
- nsgif_create,
- NULL,
- nsgif_convert,
- NULL,
- nsgif_destroy,
- NULL,
- NULL,
- NULL,
- nsgif_redraw,
- nsgif_redraw_tiled,
- NULL,
- NULL,
- nsgif_clone,
- NULL,
- nsgif_content_type,
- false
-};
-
-static const char *nsgif_types[] = {
- "image/gif"
-};
-
-static lwc_string *nsgif_mime_types[NOF_ELEMENTS(nsgif_types)];
-
-nserror nsgif_init(void)
+static nserror nsgif_create_gif_data(nsgif_content *c)
{
- uint32_t i;
- lwc_error lerror;
- nserror error;
-
- for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
- lerror = lwc_intern_string(nsgif_types[i],
- strlen(nsgif_types[i]),
- &nsgif_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
+ union content_msg_data msg_data;
- error = content_factory_register_handler(nsgif_mime_types[i],
- &nsgif_content_handler);
- if (error != NSERROR_OK)
- goto error;
+ /* Initialise our data structure */
+ c->gif = calloc(sizeof(gif_animation), 1);
+ if (c->gif == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
}
-
+ gif_create(c->gif, &gif_bitmap_callbacks);
return NSERROR_OK;
-
-error:
- nsgif_fini();
-
- return error;
}
-void nsgif_fini(void)
-{
- uint32_t i;
- for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
- if (nsgif_mime_types[i] != NULL)
- lwc_string_unref(nsgif_mime_types[i]);
- }
-}
-nserror nsgif_create(const content_handler *handler,
+static nserror nsgif_create(const content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -184,23 +133,122 @@ nserror nsgif_create(const content_handler *handler,
return NSERROR_OK;
}
-nserror nsgif_create_gif_data(nsgif_content *c)
+/**
+ * Performs any necessary animation.
+ *
+ * \param p The content to animate
+*/
+static void nsgif_animate(void *p)
{
- union content_msg_data msg_data;
+ nsgif_content *gif = p;
+ union content_msg_data data;
+ int delay;
+ int f;
- /* Initialise our data structure */
- c->gif = calloc(sizeof(gif_animation), 1);
- if (c->gif == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
+ /* Advance by a frame, updating the loop count accordingly */
+ gif->current_frame++;
+ if (gif->current_frame == (int)gif->gif->frame_count_partial) {
+ gif->current_frame = 0;
+
+ /* A loop count of 0 has a special meaning of infinite */
+ if (gif->gif->loop_count != 0) {
+ gif->gif->loop_count--;
+ if (gif->gif->loop_count == 0) {
+ gif->current_frame =
+ gif->gif->frame_count_partial - 1;
+ gif->gif->loop_count = -1;
+ }
+ }
}
- gif_create(c->gif, &gif_bitmap_callbacks);
- return NSERROR_OK;
+
+ /* Continue animating if we should */
+ if (gif->gif->loop_count >= 0) {
+ delay = gif->gif->frames[gif->current_frame].frame_delay;
+ if (delay < option_minimum_gif_delay)
+ delay = option_minimum_gif_delay;
+ schedule(delay, nsgif_animate, gif);
+ }
+
+ if ((!option_animate_images) ||
+ (!gif->gif->frames[gif->current_frame].display))
+ return;
+
+ /* area within gif to redraw */
+ f = gif->current_frame;
+ data.redraw.x = gif->gif->frames[f].redraw_x;
+ data.redraw.y = gif->gif->frames[f].redraw_y;
+ data.redraw.width = gif->gif->frames[f].redraw_width;
+ data.redraw.height = gif->gif->frames[f].redraw_height;
+
+ /* redraw background (true) or plot on top (false) */
+ if (gif->current_frame > 0) {
+ data.redraw.full_redraw =
+ gif->gif->frames[f - 1].redraw_required;
+ /* previous frame needed clearing: expand the redraw area to
+ * cover it */
+ if (data.redraw.full_redraw) {
+ if (data.redraw.x >
+ (int)(gif->gif->frames[f - 1].redraw_x)) {
+ data.redraw.width += data.redraw.x -
+ gif->gif->frames[f - 1].redraw_x;
+ data.redraw.x =
+ gif->gif->frames[f - 1].redraw_x;
+ }
+ if (data.redraw.y >
+ (int)(gif->gif->frames[f - 1].redraw_y)) {
+ data.redraw.height += (data.redraw.y -
+ gif->gif->frames[f - 1].redraw_y);
+ data.redraw.y =
+ gif->gif->frames[f - 1].redraw_y;
+ }
+ if ((int)(gif->gif->frames[f - 1].redraw_x +
+ gif->gif->frames[f - 1].redraw_width) >
+ (data.redraw.x + data.redraw.width))
+ data.redraw.width =
+ gif->gif->frames[f - 1].redraw_x -
+ data.redraw.x +
+ gif->gif->frames[f - 1].redraw_width;
+ if ((int)(gif->gif->frames[f - 1].redraw_y +
+ gif->gif->frames[f - 1].redraw_height) >
+ (data.redraw.y + data.redraw.height))
+ data.redraw.height =
+ gif->gif->frames[f - 1].redraw_y -
+ data.redraw.y +
+ gif->gif->frames[f - 1].redraw_height;
+ }
+ } else {
+ /* do advanced check */
+ if ((data.redraw.x == 0) && (data.redraw.y == 0) &&
+ (data.redraw.width == (int)(gif->gif->width)) &&
+ (data.redraw.height == (int)(gif->gif->height))) {
+ data.redraw.full_redraw = !gif->gif->frames[f].opaque;
+ } else {
+ data.redraw.full_redraw = true;
+ data.redraw.x = 0;
+ data.redraw.y = 0;
+ data.redraw.width = gif->gif->width;
+ data.redraw.height = gif->gif->height;
+ }
+ }
+
+ /* other data */
+ data.redraw.object = (struct content *) gif;
+ data.redraw.object_x = 0;
+ data.redraw.object_y = 0;
+ data.redraw.object_width = gif->base.width;
+ data.redraw.object_height = gif->base.height;
+
+ content_broadcast(&gif->base, CONTENT_MSG_REDRAW, data);
}
+static void nsgif_invalidate(void *bitmap, void *private_word)
+{
+ struct gif_animation *gif = (struct gif_animation *)private_word;
+
+ gif->decoded_frame = -1;
+}
-bool nsgif_convert(struct content *c)
+static bool nsgif_convert(struct content *c)
{
nsgif_content *gif = (nsgif_content *) c;
int res;
@@ -265,31 +313,32 @@ bool nsgif_convert(struct content *c)
return true;
}
-void nsgif_invalidate(void *bitmap, void *private_word)
-{
- struct gif_animation *gif = (struct gif_animation *)private_word;
-
- gif->decoded_frame = -1;
-}
-bool nsgif_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
+/**
+ * Updates the GIF bitmap to display the current frame
+ *
+ * \param c the content to update
+ */
+static gif_result nsgif_get_frame(struct content *c)
{
nsgif_content *gif = (nsgif_content *) c;
+ int previous_frame, current_frame, frame;
+ gif_result res = GIF_OK;
- if (gif->current_frame != gif->gif->decoded_frame)
- if (nsgif_get_frame(c) != GIF_OK)
- return false;
- c->bitmap = gif->gif->frame_image;
- if ((width == -1) && (height == -1))
- return true;
- return plot.bitmap(x, y, width, height, c->bitmap,
- background_colour, BITMAPF_NONE);
-}
+ current_frame = gif->current_frame;
+ if (!option_animate_images)
+ current_frame = 0;
+ if (current_frame < gif->gif->decoded_frame)
+ previous_frame = 0;
+ else
+ previous_frame = gif->gif->decoded_frame + 1;
+ for (frame = previous_frame; frame <= current_frame; frame++)
+ res = gif_decode_frame(gif->gif, frame);
+ return res;
+}
-bool nsgif_redraw_tiled(struct content *c, int x, int y,
+static bool nsgif_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
@@ -302,6 +351,9 @@ bool nsgif_redraw_tiled(struct content *c, int x, int y,
return false;
c->bitmap = gif->gif->frame_image;
+
+ if ((width == -1) && (height == -1))
+ return true;
if (repeat_x)
flags |= BITMAPF_REPEAT_X;
@@ -312,7 +364,7 @@ bool nsgif_redraw_tiled(struct content *c, int x, int y,
}
-void nsgif_destroy(struct content *c)
+static void nsgif_destroy(struct content *c)
{
nsgif_content *gif = (nsgif_content *) c;
@@ -323,7 +375,7 @@ void nsgif_destroy(struct content *c)
}
-nserror nsgif_clone(const struct content *old, struct content **newc)
+static nserror nsgif_clone(const struct content *old, struct content **newc)
{
nsgif_content *gif;
nserror error;
@@ -358,155 +410,67 @@ nserror nsgif_clone(const struct content *old, struct content **newc)
return NSERROR_OK;
}
-content_type nsgif_content_type(lwc_string *mime_type)
+static content_type nsgif_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
-/**
- * Updates the GIF bitmap to display the current frame
- *
- * \param c the content to update
- */
-gif_result nsgif_get_frame(struct content *c)
-{
- nsgif_content *gif = (nsgif_content *) c;
- int previous_frame, current_frame, frame;
- gif_result res = GIF_OK;
-
- current_frame = gif->current_frame;
- if (!option_animate_images)
- current_frame = 0;
- if (current_frame < gif->gif->decoded_frame)
- previous_frame = 0;
- else
- previous_frame = gif->gif->decoded_frame + 1;
- for (frame = previous_frame; frame <= current_frame; frame++)
- res = gif_decode_frame(gif->gif, frame);
-
- return res;
-}
+static const content_handler nsgif_content_handler = {
+ nsgif_create,
+ NULL,
+ nsgif_convert,
+ NULL,
+ nsgif_destroy,
+ NULL,
+ NULL,
+ NULL,
+ nsgif_redraw,
+ NULL,
+ NULL,
+ nsgif_clone,
+ NULL,
+ nsgif_content_type,
+ false
+};
-/**
- * Performs any necessary animation.
- *
- * \param p The content to animate
-*/
-void nsgif_animate(void *p)
+nserror nsgif_init(void)
{
- nsgif_content *gif = p;
- union content_msg_data data;
- int delay;
- int f;
-
- /* Advance by a frame, updating the loop count accordingly */
- gif->current_frame++;
- if (gif->current_frame == (int)gif->gif->frame_count_partial) {
- gif->current_frame = 0;
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
- /* A loop count of 0 has a special meaning of infinite */
- if (gif->gif->loop_count != 0) {
- gif->gif->loop_count--;
- if (gif->gif->loop_count == 0) {
- gif->current_frame =
- gif->gif->frame_count_partial - 1;
- gif->gif->loop_count = -1;
- }
+ for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
+ lerror = lwc_intern_string(nsgif_types[i],
+ strlen(nsgif_types[i]),
+ &nsgif_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
}
- }
- /* Continue animating if we should */
- if (gif->gif->loop_count >= 0) {
- delay = gif->gif->frames[gif->current_frame].frame_delay;
- if (delay < option_minimum_gif_delay)
- delay = option_minimum_gif_delay;
- schedule(delay, nsgif_animate, gif);
+ error = content_factory_register_handler(nsgif_mime_types[i],
+ &nsgif_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
}
- if ((!option_animate_images) ||
- (!gif->gif->frames[gif->current_frame].display))
- return;
-
- /* area within gif to redraw */
- f = gif->current_frame;
- data.redraw.x = gif->gif->frames[f].redraw_x;
- data.redraw.y = gif->gif->frames[f].redraw_y;
- data.redraw.width = gif->gif->frames[f].redraw_width;
- data.redraw.height = gif->gif->frames[f].redraw_height;
-
- /* redraw background (true) or plot on top (false) */
- if (gif->current_frame > 0) {
- data.redraw.full_redraw =
- gif->gif->frames[f - 1].redraw_required;
- /* previous frame needed clearing: expand the redraw area to
- * cover it */
- if (data.redraw.full_redraw) {
- if (data.redraw.x >
- (int)(gif->gif->frames[f - 1].redraw_x)) {
- data.redraw.width += data.redraw.x -
- gif->gif->frames[f - 1].redraw_x;
- data.redraw.x =
- gif->gif->frames[f - 1].redraw_x;
- }
- if (data.redraw.y >
- (int)(gif->gif->frames[f - 1].redraw_y)) {
- data.redraw.height += (data.redraw.y -
- gif->gif->frames[f - 1].redraw_y);
- data.redraw.y =
- gif->gif->frames[f - 1].redraw_y;
- }
- if ((int)(gif->gif->frames[f - 1].redraw_x +
- gif->gif->frames[f - 1].redraw_width) >
- (data.redraw.x + data.redraw.width))
- data.redraw.width =
- gif->gif->frames[f - 1].redraw_x -
- data.redraw.x +
- gif->gif->frames[f - 1].redraw_width;
- if ((int)(gif->gif->frames[f - 1].redraw_y +
- gif->gif->frames[f - 1].redraw_height) >
- (data.redraw.y + data.redraw.height))
- data.redraw.height =
- gif->gif->frames[f - 1].redraw_y -
- data.redraw.y +
- gif->gif->frames[f - 1].redraw_height;
- }
- } else {
- /* do advanced check */
- if ((data.redraw.x == 0) && (data.redraw.y == 0) &&
- (data.redraw.width == (int)(gif->gif->width)) &&
- (data.redraw.height == (int)(gif->gif->height))) {
- data.redraw.full_redraw = !gif->gif->frames[f].opaque;
- } else {
- data.redraw.full_redraw = true;
- data.redraw.x = 0;
- data.redraw.y = 0;
- data.redraw.width = gif->gif->width;
- data.redraw.height = gif->gif->height;
- }
- }
+ return NSERROR_OK;
- /* other data */
- data.redraw.object = (struct content *) gif;
- data.redraw.object_x = 0;
- data.redraw.object_y = 0;
- data.redraw.object_width = gif->base.width;
- data.redraw.object_height = gif->base.height;
+error:
+ nsgif_fini();
- content_broadcast(&gif->base, CONTENT_MSG_REDRAW, data);
+ return error;
}
-
-/**
- * Callback for libnsgif; forwards the call to bitmap_create()
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-void *nsgif_bitmap_create(int width, int height)
+void nsgif_fini(void)
{
- return bitmap_create(width, height, BITMAP_NEW);
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(nsgif_mime_types); i++) {
+ if (nsgif_mime_types[i] != NULL)
+ lwc_string_unref(nsgif_mime_types[i]);
+ }
}
#endif
diff --git a/image/ico.c b/image/ico.c
index 0397c5c7f..2f546b6e8 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -46,42 +46,6 @@ typedef struct nsico_content {
struct ico_collection *ico; /** ICO collection data */
} nsico_content;
-static nserror nsico_create(const content_handler *handler,
- lwc_string *imime_type, const struct http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static nserror nsico_create_ico_data(nsico_content *c);
-static bool nsico_convert(struct content *c);
-static void nsico_destroy(struct content *c);
-static bool nsico_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-static bool nsico_redraw_tiled(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour,
- bool repeat_x, bool repeat_y);
-static nserror nsico_clone(const struct content *old, struct content **newc);
-static content_type nsico_content_type(lwc_string *mime_type);
-
-static const content_handler nsico_content_handler = {
- nsico_create,
- NULL,
- nsico_convert,
- NULL,
- nsico_destroy,
- NULL,
- NULL,
- NULL,
- nsico_redraw,
- nsico_redraw_tiled,
- NULL,
- NULL,
- nsico_clone,
- NULL,
- nsico_content_type,
- false
-};
-
static const char *nsico_types[] = {
"application/ico",
"application/x-ico",
@@ -92,46 +56,23 @@ static const char *nsico_types[] = {
static lwc_string *nsico_mime_types[NOF_ELEMENTS(nsico_types)];
-nserror nsico_init(void)
-{
- uint32_t i;
- lwc_error lerror;
- nserror error;
- for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
- lerror = lwc_intern_string(nsico_types[i],
- strlen(nsico_types[i]),
- &nsico_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
+static nserror nsico_create_ico_data(nsico_content *c)
+{
+ union content_msg_data msg_data;
- error = content_factory_register_handler(nsico_mime_types[i],
- &nsico_content_handler);
- if (error != NSERROR_OK)
- goto error;
+ c->ico = calloc(sizeof(ico_collection), 1);
+ if (c->ico == NULL) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
}
-
+ ico_collection_create(c->ico, &bmp_bitmap_callbacks);
return NSERROR_OK;
-
-error:
- nsico_fini();
-
- return error;
}
-void nsico_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
- if (nsico_mime_types[i] != NULL)
- lwc_string_unref(nsico_mime_types[i]);
- }
-}
-nserror nsico_create(const content_handler *handler,
+static nserror nsico_create(const content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -161,22 +102,9 @@ nserror nsico_create(const content_handler *handler,
return NSERROR_OK;
}
-nserror nsico_create_ico_data(nsico_content *c)
-{
- union content_msg_data msg_data;
-
- c->ico = calloc(sizeof(ico_collection), 1);
- if (c->ico == NULL) {
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
- }
- ico_collection_create(c->ico, &bmp_bitmap_callbacks);
- return NSERROR_OK;
-}
-bool nsico_convert(struct content *c)
+static bool nsico_convert(struct content *c)
{
nsico_content *ico = (nsico_content *) c;
struct bmp_image *bmp;
@@ -228,21 +156,8 @@ bool nsico_convert(struct content *c)
return true;
}
-bool nsico_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
-{
- nsico_content *ico = (nsico_content *) c;
- struct bmp_image *bmp = ico_find(ico->ico, width, height);
- if (!bmp->decoded)
- if (bmp_decode(bmp) != BMP_OK)
- return false;
- c->bitmap = bmp->bitmap;
- return plot.bitmap(x, y, width, height, c->bitmap,
- background_colour, BITMAPF_NONE);
-}
-bool nsico_redraw_tiled(struct content *c, int x, int y,
+static bool nsico_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
@@ -266,7 +181,7 @@ bool nsico_redraw_tiled(struct content *c, int x, int y,
}
-void nsico_destroy(struct content *c)
+static void nsico_destroy(struct content *c)
{
nsico_content *ico = (nsico_content *) c;
@@ -274,7 +189,7 @@ void nsico_destroy(struct content *c)
free(ico->ico);
}
-nserror nsico_clone(const struct content *old, struct content **newc)
+static nserror nsico_clone(const struct content *old, struct content **newc)
{
nsico_content *ico;
nserror error;
@@ -309,9 +224,67 @@ nserror nsico_clone(const struct content *old, struct content **newc)
return NSERROR_OK;
}
-content_type nsico_content_type(lwc_string *mime_type)
+static content_type nsico_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
+static const content_handler nsico_content_handler = {
+ nsico_create,
+ NULL,
+ nsico_convert,
+ NULL,
+ nsico_destroy,
+ NULL,
+ NULL,
+ NULL,
+ nsico_redraw,
+ NULL,
+ NULL,
+ nsico_clone,
+ NULL,
+ nsico_content_type,
+ false
+};
+
+
+nserror nsico_init(void)
+{
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
+
+ for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
+ lerror = lwc_intern_string(nsico_types[i],
+ strlen(nsico_types[i]),
+ &nsico_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
+ error = content_factory_register_handler(nsico_mime_types[i],
+ &nsico_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ nsico_fini();
+
+ return error;
+}
+
+void nsico_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(nsico_mime_types); i++) {
+ if (nsico_mime_types[i] != NULL)
+ lwc_string_unref(nsico_mime_types[i]);
+ }
+}
+
#endif
diff --git a/image/jpeg.c b/image/jpeg.c
index 9709bc0f7..1d0e16edd 100644
--- a/image/jpeg.c
+++ b/image/jpeg.c
@@ -275,21 +275,9 @@ static void nsjpeg_destroy(struct content *c)
/**
- * Redraw a CONTENT_JPEG.
- */
-static bool nsjpeg_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
-{
- return plot.bitmap(x, y, width, height,
- c->bitmap, background_colour, BITMAPF_NONE);
-}
-
-
-/**
* Redraw a CONTENT_JPEG with appropriate tiling.
*/
-static bool nsjpeg_redraw_tiled(struct content *c, int x, int y,
+static bool nsjpeg_redraw(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
@@ -356,7 +344,6 @@ static const content_handler nsjpeg_content_handler = {
NULL,
NULL,
nsjpeg_redraw,
- nsjpeg_redraw_tiled,
NULL,
NULL,
nsjpeg_clone,
diff --git a/image/png.c b/image/png.c
index 69ea92312..f3fbf35ea 100644
--- a/image/png.c
+++ b/image/png.c
@@ -344,24 +344,12 @@ static void nspng_destroy(struct content *c)
static bool nspng_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
-{
- nspng_content *png_c = (nspng_content *) c;
-
- assert(png_c->bitmap != NULL);
-
- return plot.bitmap(x, y, width, height, png_c->bitmap,
- background_colour, BITMAPF_NONE);
-}
-
-static bool nspng_redraw_tiled(struct content *c, int x, int y,
int width, int height, const struct rect *clip,
float scale, colour background_colour,
bool repeat_x, bool repeat_y)
{
nspng_content *png_c = (nspng_content *) c;
- bitmap_flags_t flags = 0;
+ bitmap_flags_t flags = BITMAPF_NONE;
assert(png_c->bitmap != NULL);
@@ -434,7 +422,6 @@ static const content_handler nspng_content_handler = {
NULL,
NULL,
nspng_redraw,
- nspng_redraw_tiled,
NULL,
NULL,
nspng_clone,
diff --git a/image/rsvg.c b/image/rsvg.c
index 26370de57..80c5368a4 100644
--- a/image/rsvg.c
+++ b/image/rsvg.c
@@ -56,42 +56,7 @@ typedef struct rsvg_content {
struct bitmap *bitmap; /**< Created NetSurf bitmap */
} rsvg_content;
-static nserror rsvg_create(const content_handler *handler,
- lwc_string *imime_type, const http_parameter *params,
- llcache_handle *llcache, const char *fallback_charset,
- bool quirks, struct content **c);
-static nserror rsvg_create_svg_data(rsvg_content *c);
-static bool rsvg_process_data(struct content *c, const char *data,
- unsigned int size);
-static bool rsvg_convert(struct content *c);
-static void rsvg_destroy(struct content *c);
-static bool rsvg_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour);
-static nserror rsvg_clone(const struct content *old, struct content **newc);
-static content_type rsvg_content_type(lwc_string *mime_type);
-static inline void rsvg_argb_to_abgr(uint8_t *pixels,
- int width, int height, size_t rowstride);
-
-static const content_handler rsvg_content_handler = {
- rsvg_create,
- rsvg_process_data,
- rsvg_convert,
- NULL,
- rsvg_destroy,
- NULL,
- NULL,
- NULL,
- rsvg_redraw,
- NULL,
- NULL,
- NULL,
- rsvg_clone,
- NULL,
- rsvg_content_type,
- false
-};
static const char *rsvg_types[] = {
"image/svg",
@@ -100,46 +65,28 @@ static const char *rsvg_types[] = {
static lwc_string *rsvg_mime_types[NOF_ELEMENTS(rsvg_types)];
-nserror nsrsvg_init(void)
+
+static nserror rsvg_create_svg_data(rsvg_content *c)
{
- uint32_t i;
- lwc_error lerror;
- nserror error;
+ union content_msg_data msg_data;
- for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
- lerror = lwc_intern_string(rsvg_types[i],
- strlen(rsvg_types[i]),
- &rsvg_mime_types[i]);
- if (lerror != lwc_error_ok) {
- error = NSERROR_NOMEM;
- goto error;
- }
+ c->rsvgh = NULL;
+ c->cs = NULL;
+ c->ct = NULL;
+ c->bitmap = NULL;
- error = content_factory_register_handler(rsvg_mime_types[i],
- &rsvg_content_handler);
- if (error != NSERROR_OK)
- goto error;
+ if ((c->rsvgh = rsvg_handle_new()) == NULL) {
+ LOG(("rsvg_handle_new() returned NULL."));
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return NSERROR_NOMEM;
}
return NSERROR_OK;
-
-error:
- nsrsvg_fini();
-
- return error;
}
-void nsrsvg_fini(void)
-{
- uint32_t i;
-
- for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
- if (rsvg_mime_types[i] != NULL)
- lwc_string_unref(rsvg_mime_types[i]);
- }
-}
-nserror rsvg_create(const content_handler *handler,
+static nserror rsvg_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
bool quirks, struct content **c)
@@ -169,26 +116,8 @@ nserror rsvg_create(const content_handler *handler,
return NSERROR_OK;
}
-nserror rsvg_create_svg_data(rsvg_content *c)
-{
- union content_msg_data msg_data;
-
- c->rsvgh = NULL;
- c->cs = NULL;
- c->ct = NULL;
- c->bitmap = NULL;
- if ((c->rsvgh = rsvg_handle_new()) == NULL) {
- LOG(("rsvg_handle_new() returned NULL."));
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return NSERROR_NOMEM;
- }
-
- return NSERROR_OK;
-}
-
-bool rsvg_process_data(struct content *c, const char *data,
+static bool rsvg_process_data(struct content *c, const char *data,
unsigned int size)
{
rsvg_content *d = (rsvg_content *) c;
@@ -235,7 +164,7 @@ static inline void rsvg_argb_to_abgr(uint8_t *pixels,
}
}
-bool rsvg_convert(struct content *c)
+static bool rsvg_convert(struct content *c)
{
rsvg_content *d = (rsvg_content *) c;
union content_msg_data msg_data;
@@ -300,15 +229,25 @@ bool rsvg_convert(struct content *c)
return true;
}
-bool rsvg_redraw(struct content *c, int x, int y,
- int width, int height, const struct rect *clip,
- float scale, colour background_colour)
+static bool rsvg_redraw(struct content *c, int x, int y,
+ int width, int height, const struct rect *clip,
+ float scale, colour background_colour,
+ bool repeat_x, bool repeat_y)
{
- plot.bitmap(x, y, width, height, c->bitmap, background_colour, BITMAPF_NONE);
- return true;
+ bitmap_flags_t flags = BITMAPF_NONE;
+
+ assert(c->bitmap != NULL);
+
+ if (repeat_x)
+ flags |= BITMAPF_REPEAT_X;
+ if (repeat_y)
+ flags |= BITMAPF_REPEAT_Y;
+
+ return plot.bitmap(x, y, width, height,
+ c->bitmap, background_colour, flags);
}
-void rsvg_destroy(struct content *c)
+static void rsvg_destroy(struct content *c)
{
rsvg_content *d = (rsvg_content *) c;
@@ -320,7 +259,7 @@ void rsvg_destroy(struct content *c)
return;
}
-nserror rsvg_clone(const struct content *old, struct content **newc)
+static nserror rsvg_clone(const struct content *old, struct content **newc)
{
rsvg_content *svg;
nserror error;
@@ -365,9 +304,66 @@ nserror rsvg_clone(const struct content *old, struct content **newc)
return NSERROR_OK;
}
-content_type rsvg_content_type(lwc_string *mime_type)
+static content_type rsvg_content_type(lwc_string *mime_type)
{
return CONTENT_IMAGE;
}
+static const content_handler rsvg_content_handler = {
+ rsvg_create,
+ rsvg_process_data,
+ rsvg_convert,
+ NULL,
+ rsvg_destroy,
+ NULL,
+ NULL,
+ NULL,
+ rsvg_redraw,
+ NULL,
+ NULL,
+ rsvg_clone,
+ NULL,
+ rsvg_content_type,
+ false
+};
+
+nserror nsrsvg_init(void)
+{
+ uint32_t i;
+ lwc_error lerror;
+ nserror error;
+
+ for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
+ lerror = lwc_intern_string(rsvg_types[i],
+ strlen(rsvg_types[i]),
+ &rsvg_mime_types[i]);
+ if (lerror != lwc_error_ok) {
+ error = NSERROR_NOMEM;
+ goto error;
+ }
+
+ error = content_factory_register_handler(rsvg_mime_types[i],
+ &rsvg_content_handler);
+ if (error != NSERROR_OK)
+ goto error;
+ }
+
+ return NSERROR_OK;
+
+error:
+ nsrsvg_fini();
+
+ return error;
+}
+
+void nsrsvg_fini(void)
+{
+ uint32_t i;
+
+ for (i = 0; i < NOF_ELEMENTS(rsvg_mime_types); i++) {
+ if (rsvg_mime_types[i] != NULL)
+ lwc_string_unref(rsvg_mime_types[i]);
+ }
+}
+
#endif /* WITH_RSVG */