summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-04-13 23:19:04 +0100
committerVincent Sanders <vince@kyllikki.org>2015-04-13 23:19:04 +0100
commitf37e52c39475e6efd3740c5ae1ec4f290662928f (patch)
tree88d01618e903975743a3cb74bff9bf8df54c2a45
parent7a28131e4953934150967eb7886bc06678e249e8 (diff)
downloadnetsurf-f37e52c39475e6efd3740c5ae1ec4f290662928f.tar.gz
netsurf-f37e52c39475e6efd3740c5ae1ec4f290662928f.tar.bz2
Move bitmap operations into an operation table.
The generic bitmap handlers provided by each frontend are called back from the core and therefore should be in an operation table. This was one of the very few remaining interfaces stopping the core code from being split into a library.
-rw-r--r--content/content.c3
-rw-r--r--content/urldb.c21
-rw-r--r--desktop/browser_history.c9
-rw-r--r--desktop/gui_factory.c79
-rw-r--r--desktop/gui_table.h10
-rw-r--r--desktop/knockout.c8
-rw-r--r--desktop/treeview.c63
-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
15 files changed, 324 insertions, 194 deletions
diff --git a/content/content.c b/content/content.c
index a27647bd3..a6ca97817 100644
--- a/content/content.c
+++ b/content/content.c
@@ -34,6 +34,7 @@
#include "content/hlcache.h"
#include "image/bitmap.h"
#include "desktop/browser.h"
+#include "desktop/gui_internal.h"
#include "utils/nsoption.h"
#include "utils/http.h"
@@ -1243,7 +1244,7 @@ bool content__get_opaque(struct content *c)
struct bitmap *bitmap = NULL;
bitmap = c->handler->get_internal(c, NULL);
if (bitmap != NULL) {
- opaque = bitmap_get_opaque(bitmap);
+ opaque = guit->bitmap->get_opaque(bitmap);
}
}
diff --git a/content/urldb.c b/content/urldb.c
index f77f597c4..a9476d72a 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -95,19 +95,20 @@
#include <string.h>
#include <strings.h>
#include <time.h>
-
#include <curl/curl.h>
-#include "image/bitmap.h"
-#include "content/content.h"
-#include "content/urldb.h"
-#include "desktop/cookie_manager.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/corestrings.h"
#include "utils/url.h"
#include "utils/utils.h"
#include "utils/bloom.h"
+#include "image/bitmap.h"
+#include "desktop/cookie_manager.h"
+#include "desktop/gui_internal.h"
+
+#include "content/content.h"
+#include "content/urldb.h"
struct cookie_internal_data {
char *name; /**< Cookie name */
@@ -2330,8 +2331,9 @@ static void urldb_destroy_path_node_content(struct path_data *node)
free(node->fragment[i]);
free(node->fragment);
- if (node->thumb)
- bitmap_destroy(node->thumb);
+ if (node->thumb) {
+ guit->bitmap->destroy(node->thumb);
+ }
free(node->urld.title);
@@ -3065,8 +3067,9 @@ void urldb_set_thumbnail(nsurl *url, struct bitmap *bitmap)
LOG(("Setting bitmap on %s", nsurl_access(url)));
- if (p->thumb && p->thumb != bitmap)
- bitmap_destroy(p->thumb);
+ if (p->thumb && p->thumb != bitmap) {
+ guit->bitmap->destroy(p->thumb);
+ }
p->thumb = bitmap;
}
diff --git a/desktop/browser_history.c b/desktop/browser_history.c
index 1991bf9a1..e7fd87583 100644
--- a/desktop/browser_history.c
+++ b/desktop/browser_history.c
@@ -37,6 +37,7 @@
#include "css/css.h"
#include "image/bitmap.h"
+#include "desktop/gui_internal.h"
#include "desktop/browser_history.h"
#include "desktop/browser_private.h"
#include "desktop/plotters.h"
@@ -511,9 +512,9 @@ nserror browser_window_history_add(struct browser_window *bw,
bitmap = urldb_get_thumbnail(nsurl);
if (bitmap == NULL) {
LOG(("Creating thumbnail for %s", nsurl_access(nsurl)));
- bitmap = bitmap_create(WIDTH, HEIGHT,
- BITMAP_NEW | BITMAP_CLEAR_MEMORY |
- BITMAP_OPAQUE);
+ bitmap = guit->bitmap->create(WIDTH, HEIGHT,
+ BITMAP_NEW | BITMAP_CLEAR_MEMORY |
+ BITMAP_OPAQUE);
if (bitmap != NULL) {
if (thumbnail_create(content, bitmap)) {
/* Successful thumbnail so register it
@@ -525,7 +526,7 @@ nserror browser_window_history_add(struct browser_window *bw,
* silently but clean up bitmap.
*/
LOG(("Thumbnail bitmap creation failed"));
- bitmap_destroy(bitmap);
+ guit->bitmap->destroy(bitmap);
bitmap = NULL;
}
}
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index df88b8c34..cab11eb0a 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -16,10 +16,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include "utils/errors.h"
+#include "utils/file.h"
+#include "image/bitmap.h"
#include "content/hlcache.h"
#include "content/backing_store.h"
-#include "utils/file.h"
#include "desktop/save_pdf.h"
#include "desktop/download.h"
#include "desktop/searchweb.h"
@@ -552,6 +558,71 @@ static nserror verify_file_register(struct gui_file_table *gft)
return NSERROR_OK;
}
+/**
+ * verify bitmap table is valid
+ *
+ * \param gbt The bitmap table to verify.
+ * \return NSERROR_OK if teh table is valid else NSERROR_BAD_PARAMETER.
+ */
+static nserror verify_bitmap_register(struct gui_bitmap_table *gbt)
+{
+ /* check table is present */
+ if (gbt == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ /* check the mandantory fields are set */
+ if (gbt->create == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->destroy == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->set_opaque == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_opaque == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->test_opaque == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_buffer == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_rowstride == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_width == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_height == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->get_bpp == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->save == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ if (gbt->modified == NULL) {
+ return NSERROR_BAD_PARAMETER;
+ }
+
+ return NSERROR_OK;
+}
+
static void gui_default_quit(void)
{
}
@@ -651,6 +722,12 @@ nserror netsurf_register(struct netsurf_table *gt)
return err;
}
+ /* bitmap table */
+ err = verify_bitmap_register(gt->bitmap);
+ if (err != NSERROR_OK) {
+ return err;
+ }
+
/* file table */
if (gt->file == NULL) {
gt->file = default_file_table;
diff --git a/desktop/gui_table.h b/desktop/gui_table.h
index 10f2bf17a..52cdde2ea 100644
--- a/desktop/gui_table.h
+++ b/desktop/gui_table.h
@@ -37,6 +37,7 @@ struct gui_utf8_table;
struct gui_search_table;
struct gui_search_web_table;
struct gui_llcache_table;
+struct gui_bitmap_table;
/**
* NetSurf operation function table
@@ -119,6 +120,15 @@ struct netsurf_table {
* uses the default implementation.
*/
struct gui_llcache_table *llcache;
+
+ /**
+ * Bitmap table.
+ *
+ * Used by the image convertors as a generic interface to
+ * native platform-specific image formats. The table
+ * is mandantory and must be provided.
+ */
+ struct gui_bitmap_table *bitmap;
};
#endif
diff --git a/desktop/knockout.c b/desktop/knockout.c
index 0321423fd..303ba8f6c 100644
--- a/desktop/knockout.c
+++ b/desktop/knockout.c
@@ -66,9 +66,12 @@
#include <string.h>
#include <stdio.h>
-#include "image/bitmap.h"
#include "utils/log.h"
+#include "utils/errors.h"
+#include "image/bitmap.h"
#include "content/content.h"
+
+#include "desktop/gui_internal.h"
#include "desktop/knockout.h"
#include "desktop/plotters.h"
@@ -772,8 +775,9 @@ bool knockout_plot_bitmap(int x, int y, int width, int height,
}
/* tiled bitmaps both knock out and get knocked out */
- if (bitmap_get_opaque(bitmap))
+ if (guit->bitmap->get_opaque(bitmap)) {
knockout_calculate(kx0, ky0, kx1, ky1, NULL);
+ }
knockout_boxes[knockout_box_cur].bbox.x0 = kx0;
knockout_boxes[knockout_box_cur].bbox.y0 = ky0;
knockout_boxes[knockout_box_cur].bbox.x1 = kx1;
diff --git a/desktop/treeview.c b/desktop/treeview.c
index f6134ae71..35458f7fb 100644
--- a/desktop/treeview.c
+++ b/desktop/treeview.c
@@ -3698,12 +3698,12 @@ static struct bitmap * treeview_generate_triangle_bitmap(
colour colour4 = fg;
/* Create the bitmap */
- b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
+ b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
if (b == NULL)
return NULL;
- rpos = bitmap_get_buffer(b);
- stride = bitmap_get_rowstride(b);
+ rpos = guit->bitmap->get_buffer(b);
+ stride = guit->bitmap->get_rowstride(b);
/* Draw the triangle */
for (y = 0; y < size; y++) {
@@ -3770,7 +3770,7 @@ static struct bitmap * treeview_generate_triangle_bitmap(
rpos += stride;
}
- bitmap_modified(b);
+ guit->bitmap->modified(b);
return b;
}
@@ -3793,29 +3793,29 @@ static struct bitmap * treeview_generate_copy_bitmap(
if (orig == NULL)
return NULL;
- assert(size == bitmap_get_width(orig));
- assert(size == bitmap_get_height(orig));
+ assert(size == guit->bitmap->get_width(orig));
+ assert(size == guit->bitmap->get_height(orig));
/* Create the bitmap */
- b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
+ b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
if (b == NULL)
return NULL;
- stride = bitmap_get_rowstride(b);
- assert(stride == bitmap_get_rowstride(orig));
+ stride = guit->bitmap->get_rowstride(b);
+ assert(stride == guit->bitmap->get_rowstride(orig));
- data = bitmap_get_buffer(b);
- orig_data = bitmap_get_buffer(orig);
+ data = guit->bitmap->get_buffer(b);
+ orig_data = guit->bitmap->get_buffer(orig);
/* Copy the bitmap */
memcpy(data, orig_data, stride * size);
- bitmap_modified(b);
+ guit->bitmap->modified(b);
/* We've not modified the original image, but we called
* bitmap_get_buffer(), so we need to pair that with a
* bitmap_modified() call to appease certain front ends. */
- bitmap_modified(orig);
+ guit->bitmap->modified(orig);
return b;
}
@@ -3841,19 +3841,19 @@ static struct bitmap * treeview_generate_rotate_bitmap(
if (orig == NULL)
return NULL;
- assert(size == bitmap_get_width(orig));
- assert(size == bitmap_get_height(orig));
+ assert(size == guit->bitmap->get_width(orig));
+ assert(size == guit->bitmap->get_height(orig));
/* Create the bitmap */
- b = bitmap_create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
+ b = guit->bitmap->create(size, size, BITMAP_NEW | BITMAP_OPAQUE);
if (b == NULL)
return NULL;
- stride = bitmap_get_rowstride(b);
- assert(stride == bitmap_get_rowstride(orig));
+ stride = guit->bitmap->get_rowstride(b);
+ assert(stride == guit->bitmap->get_rowstride(orig));
- rpos = bitmap_get_buffer(b);
- orig_data = bitmap_get_buffer(orig);
+ rpos = guit->bitmap->get_buffer(b);
+ orig_data = guit->bitmap->get_buffer(orig);
/* Copy the rotated bitmap */
for (y = 0; y < size; y++) {
@@ -3871,12 +3871,13 @@ static struct bitmap * treeview_generate_rotate_bitmap(
rpos += stride;
}
- bitmap_modified(b);
+ guit->bitmap->modified(b);
/* We've not modified the original image, but we called
* bitmap_get_buffer(), so we need to pair that with a
- * bitmap_modified() call to appease certain front ends. */
- bitmap_modified(orig);
+ * bitmap_modified() call to appease certain front ends.
+ */
+ guit->bitmap->modified(orig);
return b;
}
@@ -3988,14 +3989,14 @@ nserror treeview_fini(void)
hlcache_handle_release(treeview_res[i].c);
}
- bitmap_destroy(plot_style_odd.furn[TREE_FURN_EXPAND].bmp);
- bitmap_destroy(plot_style_odd.furn[TREE_FURN_EXPAND].sel);
- bitmap_destroy(plot_style_even.furn[TREE_FURN_EXPAND].bmp);
- bitmap_destroy(plot_style_even.furn[TREE_FURN_EXPAND].sel);
- bitmap_destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].bmp);
- bitmap_destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].sel);
- bitmap_destroy(plot_style_even.furn[TREE_FURN_CONTRACT].bmp);
- bitmap_destroy(plot_style_even.furn[TREE_FURN_CONTRACT].sel);
+ guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_EXPAND].bmp);
+ guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_EXPAND].sel);
+ guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_EXPAND].bmp);
+ guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_EXPAND].sel);
+ guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].bmp);
+ guit->bitmap->destroy(plot_style_odd.furn[TREE_FURN_CONTRACT].sel);
+ guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].bmp);
+ guit->bitmap->destroy(plot_style_even.furn[TREE_FURN_CONTRACT].sel);
tree_g.initialised = false;
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);