summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
Diffstat (limited to 'image')
-rw-r--r--image/bitmap.h77
-rw-r--r--image/bmp.c75
-rw-r--r--image/gif.c26
-rw-r--r--image/ico.c46
-rw-r--r--image/image.c32
-rw-r--r--image/image_cache.c4
-rw-r--r--image/jpeg.c26
-rw-r--r--image/png.c39
8 files changed, 179 insertions, 146 deletions
diff --git a/image/bitmap.h b/image/bitmap.h
index 193249259..459a50a73 100644
--- a/image/bitmap.h
+++ b/image/bitmap.h
@@ -53,31 +53,72 @@
#ifndef _NETSURF_IMAGE_BITMAP_H_
#define _NETSURF_IMAGE_BITMAP_H_
-#include <stdbool.h>
-#include <stdlib.h>
-
#define BITMAP_NEW 0
#define BITMAP_OPAQUE (1 << 0) /** image is opaque */
#define BITMAP_MODIFIED (1 << 1) /** buffer has been modified */
#define BITMAP_CLEAR_MEMORY (1 << 2) /** memory should be wiped */
struct content;
-
-/** An opaque image. */
struct bitmap;
-void *bitmap_create(int width, int height, unsigned int state);
-void bitmap_set_opaque(void *bitmap, bool opaque);
-bool bitmap_test_opaque(void *bitmap);
-bool bitmap_get_opaque(void *bitmap);
-unsigned char *bitmap_get_buffer(void *bitmap);
-size_t bitmap_get_rowstride(void *bitmap);
-size_t bitmap_get_bpp(void *bitmap);
-void bitmap_destroy(void *bitmap);
-bool bitmap_save(void *bitmap, const char *path, unsigned flags);
-void bitmap_modified(void *bitmap);
-
-int bitmap_get_width(void *bitmap);
-int bitmap_get_height(void *bitmap);
+/**
+ * Bitmap operations.
+ */
+struct gui_bitmap_table {
+ /* Mandantory entries */
+
+ /**
+ * Create a new bitmap
+ */
+ void *(*create)(int width, int height, unsigned int state);
+
+ /**
+ * Destroy a bitmap
+ */
+ void (*destroy)(void *bitmap);
+
+ /**
+ * Set the opacity of a bitmap
+ */
+ void (*set_opaque)(void *bitmap, bool opaque);
+
+ /**
+ * Get the opacity of a bitmap
+ */
+ bool (*get_opaque)(void *bitmap);
+
+ /**
+ */
+ bool (*test_opaque)(void *bitmap);
+
+ /**
+ */
+ unsigned char *(*get_buffer)(void *bitmap);
+
+ /**
+ */
+ size_t (*get_rowstride)(void *bitmap);
+
+ /**
+ */
+ int (*get_width)(void *bitmap);
+
+ /**
+ */
+ int (*get_height)(void *bitmap);
+
+ /**
+ */
+ size_t (*get_bpp)(void *bitmap);
+
+ /**
+ */
+ bool (*save)(void *bitmap, const char *path, unsigned flags);
+
+ /**
+ * Marks a bitmap as modified.
+ */
+ void (*modified)(void *bitmap);
+};
#endif
diff --git a/image/bmp.c b/image/bmp.c
index 946bca83b..dfa573fee 100644
--- a/image/bmp.c
+++ b/image/bmp.c
@@ -17,23 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Content for image/bmp (implementation)
+/**
+ * \file
+ * implementation of content handler for BMP images.
*/
-#include <assert.h>
-#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libnsbmp.h>
-#include "utils/config.h"
+#include "utils/messages.h"
#include "content/content_protected.h"
-#include "content/hlcache.h"
+#include "desktop/gui_internal.h"
#include "desktop/plotters.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
#include "image/bitmap.h"
#include "image/bmp.h"
@@ -46,9 +42,36 @@ typedef struct nsbmp_content {
struct bitmap *bitmap; /**< Created NetSurf bitmap */
} nsbmp_content;
+/**
+ * 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;
+
+ /* 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 the created bitmap */
+ return guit->bitmap->create(width, height, bitmap_state);
+}
+
static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
{
union content_msg_data msg_data;
+ bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
+ .bitmap_create = nsbmp_bitmap_create,
+ .bitmap_destroy = guit->bitmap->destroy,
+ .bitmap_get_buffer = guit->bitmap->get_buffer,
+ .bitmap_get_bpp = guit->bitmap->get_bpp
+ };
bmp->bmp = calloc(sizeof(struct bmp_image), 1);
if (bmp->bmp == NULL) {
@@ -62,7 +85,6 @@ static nserror nsbmp_create_bmp_data(nsbmp_content *bmp)
return NSERROR_OK;
}
-
static nserror nsbmp_create(const content_handler *handler,
lwc_string *imime_type, const struct http_parameter *params,
llcache_handle *llcache, const char *fallback_charset,
@@ -93,37 +115,6 @@ static nserror nsbmp_create(const content_handler *handler,
return NSERROR_OK;
}
-/**
- * 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;
-
- /* 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 the created bitmap */
- return bitmap_create(width, height, bitmap_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_get_buffer = bitmap_get_buffer,
- .bitmap_get_bpp = bitmap_get_bpp
-};
-
static bool nsbmp_convert(struct content *c)
{
nsbmp_content *bmp = (nsbmp_content *) c;
@@ -171,7 +162,7 @@ static bool nsbmp_convert(struct content *c)
/* exit as a success */
bmp->bitmap = bmp->bmp->bitmap;
- bitmap_modified(bmp->bitmap);
+ guit->bitmap->modified(bmp->bitmap);
content_set_ready(c);
content_set_done(c);
diff --git a/image/gif.c b/image/gif.c
index c2f0ae477..871b1cc2c 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -36,14 +36,9 @@
#include <stdlib.h>
#include <libnsgif.h>
-#include "utils/config.h"
-#include "utils/log.h"
#include "utils/messages.h"
-#include "utils/utils.h"
#include "utils/nsoption.h"
#include "content/content_protected.h"
-#include "content/hlcache.h"
-#include "desktop/plotters.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_internal.h"
@@ -68,24 +63,21 @@ typedef struct nsgif_content {
*/
static void *nsgif_bitmap_create(int width, int height)
{
- return bitmap_create(width, height, BITMAP_NEW);
+ return guit->bitmap->create(width, height, BITMAP_NEW);
}
-/* The Bitmap callbacks function table;
- * necessary for interaction with nsgiflib.
- */
-static gif_bitmap_callback_vt gif_bitmap_callbacks = {
- .bitmap_create = nsgif_bitmap_create,
- .bitmap_destroy = bitmap_destroy,
- .bitmap_get_buffer = bitmap_get_buffer,
- .bitmap_set_opaque = bitmap_set_opaque,
- .bitmap_test_opaque = bitmap_test_opaque,
- .bitmap_modified = bitmap_modified
-};
static nserror nsgif_create_gif_data(nsgif_content *c)
{
union content_msg_data msg_data;
+ gif_bitmap_callback_vt gif_bitmap_callbacks = {
+ .bitmap_create = nsgif_bitmap_create,
+ .bitmap_destroy = guit->bitmap->destroy,
+ .bitmap_get_buffer = guit->bitmap->get_buffer,
+ .bitmap_set_opaque = guit->bitmap->set_opaque,
+ .bitmap_test_opaque = guit->bitmap->test_opaque,
+ .bitmap_modified = guit->bitmap->modified
+ };
/* Initialise our data structure */
c->gif = calloc(sizeof(gif_animation), 1);
diff --git a/image/ico.c b/image/ico.c
index e455a59d9..b6743cb7c 100644
--- a/image/ico.c
+++ b/image/ico.c
@@ -20,22 +20,18 @@
* Content for image/ico (implementation)
*/
-#include <assert.h>
-#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libnsbmp.h>
-#include "utils/config.h"
+
+#include "utils/log.h"
+#include "utils/messages.h"
#include "content/content_protected.h"
-#include "content/hlcache.h"
-#include "desktop/plotters.h"
+#include "desktop/gui_internal.h"
+
+#include "image/image.h"
#include "image/bitmap.h"
-#include "image/bmp.h"
#include "image/ico.h"
-#include "image/image.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
typedef struct nsico_content {
struct content base;
@@ -44,10 +40,36 @@ typedef struct nsico_content {
} nsico_content;
+/**
+ * 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 *nsico_bitmap_create(int width, int height, unsigned int bmp_state)
+{
+ unsigned int bitmap_state = BITMAP_NEW;
+
+ /* 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 the created bitmap */
+ return guit->bitmap->create(width, height, bitmap_state);
+}
static nserror nsico_create_ico_data(nsico_content *c)
{
union content_msg_data msg_data;
+ bmp_bitmap_callback_vt bmp_bitmap_callbacks = {
+ .bitmap_create = nsico_bitmap_create,
+ .bitmap_destroy = guit->bitmap->destroy,
+ .bitmap_get_buffer = guit->bitmap->get_buffer,
+ .bitmap_get_bpp = guit->bitmap->get_bpp
+ };
c->ico = calloc(sizeof(ico_collection), 1);
if (c->ico == NULL) {
@@ -173,7 +195,7 @@ static bool nsico_redraw(struct content *c, struct content_redraw_data *data,
return false;
} else {
LOG(("Decoding bitmap"));
- bitmap_modified(bmp->bitmap);
+ guit->bitmap->modified(bmp->bitmap);
}
}
@@ -243,7 +265,7 @@ static void *nsico_get_internal(const struct content *c, void *context)
if (bmp_decode(bmp) != BMP_OK) {
return NULL;
} else {
- bitmap_modified(bmp->bitmap);
+ guit->bitmap->modified(bmp->bitmap);
}
}
diff --git a/image/image.c b/image/image.c
index e0c9a435b..339f7751e 100644
--- a/image/image.c
+++ b/image/image.c
@@ -16,19 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <assert.h>
-#include <stdint.h>
#include <stdbool.h>
-#include <string.h>
+#include <stdlib.h>
-#include "utils/utils.h"
-#include "utils/errors.h"
-#include "utils/config.h"
#include "utils/log.h"
-#include "desktop/plotters.h"
+#include "utils/messages.h"
#include "content/content.h"
-#include "image/bitmap.h"
+#include "desktop/plotters.h"
+#include "desktop/gui_internal.h"
+#include "image/bitmap.h"
#include "image/bmp.h"
#include "image/gif.h"
#include "image/ico.h"
@@ -38,7 +35,6 @@
#include "image/rsvg.h"
#include "image/svg.h"
#include "image/webp.h"
-
#include "image/image.h"
/**
@@ -109,7 +105,7 @@ nserror image_init(void)
bool image_bitmap_plot(struct bitmap *bitmap,
- struct content_redraw_data *data,
+ struct content_redraw_data *data,
const struct rect *clip,
const struct redraw_context *ctx)
{
@@ -121,15 +117,15 @@ bool image_bitmap_plot(struct bitmap *bitmap,
plot_style_t fill_style;
struct rect area;
- width = bitmap_get_width(bitmap);
+ width = guit->bitmap->get_width(bitmap);
if (width == 1) {
- height = bitmap_get_height(bitmap);
+ height = guit->bitmap->get_height(bitmap);
if (height == 1) {
/* optimise 1x1 bitmap plot */
- pixel = bitmap_get_buffer(bitmap);
+ pixel = guit->bitmap->get_buffer(bitmap);
fill_style.fill_colour = pixel_to_colour(pixel);
- if (bitmap_get_opaque(bitmap) ||
+ if (guit->bitmap->get_opaque(bitmap) ||
((fill_style.fill_colour & 0xff000000) == 0xff000000)) {
area = *clip;
@@ -147,8 +143,8 @@ bool image_bitmap_plot(struct bitmap *bitmap,
fill_style.stroke_type = PLOT_OP_TYPE_NONE;
fill_style.fill_type = PLOT_OP_TYPE_SOLID;
- return ctx->plot->rectangle(area.x0, area.y0,
- area.x1, area.y1,
+ return ctx->plot->rectangle(area.x0, area.y0,
+ area.x1, area.y1,
&fill_style);
} else if ((fill_style.fill_colour & 0xff000000) == 0) {
@@ -157,7 +153,7 @@ bool image_bitmap_plot(struct bitmap *bitmap,
}
}
}
-
+
/* do the plot */
if (data->repeat_x)
flags |= BITMAPF_REPEAT_X;
@@ -166,6 +162,4 @@ bool image_bitmap_plot(struct bitmap *bitmap,
return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
bitmap, data->background_colour, flags);
-
-
}
diff --git a/image/image_cache.c b/image/image_cache.c
index 565636c06..ac3679081 100644
--- a/image/image_cache.c
+++ b/image/image_cache.c
@@ -229,7 +229,7 @@ static void image_cache__free_bitmap(struct image_cache_entry_s *centry)
image_cache->current_age - centry->bitmap_age,
centry->redraw_count));
#endif
- bitmap_destroy(centry->bitmap);
+ guit->bitmap->destroy(centry->bitmap);
centry->bitmap = NULL;
image_cache->total_bitmap_size -= centry->bitmap_size;
image_cache->bitmap_count--;
@@ -484,7 +484,7 @@ nserror image_cache_add(struct content *content,
/* set bitmap entry if one is passed, free extant one if present */
if (bitmap != NULL) {
if (centry->bitmap != NULL) {
- bitmap_destroy(centry->bitmap);
+ guit->bitmap->destroy(centry->bitmap);
} else {
image_cache_stats_bitmap_add(centry);
}
diff --git a/image/jpeg.c b/image/jpeg.c
index a5d77b55b..309dec0a1 100644
--- a/image/jpeg.c
+++ b/image/jpeg.c
@@ -23,19 +23,17 @@
* This implementation uses the IJG JPEG library.
*/
-#include <assert.h>
-#include <setjmp.h>
-#include <string.h>
-#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
-
-#include "content/content_protected.h"
-#include "desktop/plotters.h"
-#include "image/image_cache.h"
+#include <setjmp.h>
#include "utils/log.h"
#include "utils/messages.h"
-#include "utils/utils.h"
+#include "content/content_protected.h"
+#include "desktop/gui_internal.h"
+
+#include "image/image_cache.h"
+#include "image/bitmap.h"
#define JPEG_INTERNAL_OPTIONS
#include "jpeglib.h"
@@ -224,23 +222,23 @@ jpeg_cache_convert(struct content *c)
height = cinfo.output_height;
/* create opaque bitmap (jpegs cannot be transparent) */
- bitmap = bitmap_create(width, height, BITMAP_NEW | BITMAP_OPAQUE);
+ bitmap = guit->bitmap->create(width, height, BITMAP_NEW | BITMAP_OPAQUE);
if (bitmap == NULL) {
/* empty bitmap could not be created */
jpeg_destroy_decompress(&cinfo);
return NULL;
}
- pixels = bitmap_get_buffer(bitmap);
+ pixels = guit->bitmap->get_buffer(bitmap);
if (pixels == NULL) {
/* bitmap with no buffer available */
- bitmap_destroy(bitmap);
+ guit->bitmap->destroy(bitmap);
jpeg_destroy_decompress(&cinfo);
return NULL;
}
/* Convert scanlines from jpeg into bitmap */
- rowstride = bitmap_get_rowstride(bitmap);
+ rowstride = guit->bitmap->get_rowstride(bitmap);
do {
JSAMPROW scanlines[1];
@@ -265,7 +263,7 @@ jpeg_cache_convert(struct content *c)
}
#endif
} while (cinfo.output_scanline != cinfo.output_height);
- bitmap_modified(bitmap);
+ guit->bitmap->modified(bitmap);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
diff --git a/image/png.c b/image/png.c
index acf375e14..de2059f5a 100644
--- a/image/png.c
+++ b/image/png.c
@@ -18,25 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <assert.h>
#include <stdbool.h>
-#include <string.h>
#include <stdlib.h>
-
#include <png.h>
-#include "desktop/plotters.h"
-
+#include "utils/log.h"
+#include "utils/messages.h"
#include "content/content_protected.h"
+#include "desktop/gui_internal.h"
-#include "image/bitmap.h"
#include "image/image_cache.h"
+#include "image/bitmap.h"
#include "image/png.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
-
/* accommodate for old versions of libpng (beware security holes!) */
#ifndef png_jmpbuf
@@ -164,14 +158,14 @@ static void info_callback(png_structp png_s, png_infop info)
}
/* Claim the required memory for the converted PNG */
- png_c->bitmap = bitmap_create(width, height, BITMAP_NEW);
+ png_c->bitmap = guit->bitmap->create(width, height, BITMAP_NEW);
if (png_c->bitmap == NULL) {
/* Failed to create bitmap skip pre-conversion */
longjmp(png_jmpbuf(png_s), CBERR_NOPRE);
}
- png_c->rowstride = bitmap_get_rowstride(png_c->bitmap);
- png_c->bpp = bitmap_get_bpp(png_c->bitmap);
+ png_c->rowstride = guit->bitmap->get_rowstride(png_c->bitmap);
+ png_c->bpp = guit->bitmap->get_bpp(png_c->bitmap);
nspng_setup_transforms(png_s, info);
@@ -198,7 +192,7 @@ static void row_callback(png_structp png_s, png_bytep new_row,
return;
/* Get bitmap buffer */
- buffer = bitmap_get_buffer(png_c->bitmap);
+ buffer = guit->bitmap->get_buffer(png_c->bitmap);
if (buffer == NULL) {
/* No buffer, bail out */
longjmp(png_jmpbuf(png_s), 1);
@@ -404,9 +398,9 @@ png_cache_read_fn(png_structp png_ptr, png_bytep data, png_size_t length)
*/
static png_bytep *calc_row_pointers(struct bitmap *bitmap)
{
- int height = bitmap_get_height(bitmap);
- unsigned char *buffer= bitmap_get_buffer(bitmap);
- size_t rowstride = bitmap_get_rowstride(bitmap);
+ int height = guit->bitmap->get_height(bitmap);
+ unsigned char *buffer= guit->bitmap->get_buffer(bitmap);
+ size_t rowstride = guit->bitmap->get_rowstride(bitmap);
png_bytep *row_ptrs;
int hloop;
@@ -481,7 +475,7 @@ png_cache_convert(struct content *c)
height = png_get_image_height(png_ptr, info_ptr);
/* Claim the required memory for the converted PNG */
- bitmap = bitmap_create(width, height, BITMAP_NEW);
+ bitmap = guit->bitmap->create(width, height, BITMAP_NEW);
if (bitmap == NULL) {
/* cleanup and bail */
goto png_cache_convert_error;
@@ -500,8 +494,9 @@ png_cache_convert_error:
free((png_bytep *) row_pointers);
- if (bitmap != NULL)
- bitmap_modified((struct bitmap *)bitmap);
+ if (bitmap != NULL) {
+ guit->bitmap->modified((struct bitmap *)bitmap);
+ }
return (struct bitmap *)bitmap;
}
@@ -527,8 +522,8 @@ static bool nspng_convert(struct content *c)
}
if (png_c->bitmap != NULL) {
- bitmap_set_opaque(png_c->bitmap, bitmap_test_opaque(png_c->bitmap));
- bitmap_modified(png_c->bitmap);
+ guit->bitmap->set_opaque(png_c->bitmap, guit->bitmap->test_opaque(png_c->bitmap));
+ guit->bitmap->modified(png_c->bitmap);
}
image_cache_add(c, png_c->bitmap, png_cache_convert);