From cc11912da1e2881803828330f85b0fe177b570b6 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 14 Apr 2015 23:08:02 +0100 Subject: Convert framebuffer frontend to bitmap operations table. --- framebuffer/bitmap.c | 55 +++++++++++++++++++++++++++++++---------------- framebuffer/bitmap.h | 26 ++++++++++++++++++++++ framebuffer/framebuffer.c | 3 ++- framebuffer/gui.c | 4 +++- 4 files changed, 68 insertions(+), 20 deletions(-) create mode 100644 framebuffer/bitmap.h (limited to 'framebuffer') diff --git a/framebuffer/bitmap.c b/framebuffer/bitmap.c index fb45d6e95..713cf840a 100644 --- a/framebuffer/bitmap.c +++ b/framebuffer/bitmap.c @@ -16,16 +16,22 @@ * along with this program. If not, see . */ +/** + * \file + * Framebuffer implementation of generic bitmap interface. + */ + #include #include #include #include - #include #include "image/bitmap.h" #include "utils/log.h" +#include "framebuffer/bitmap.h" + /** * Create a bitmap. * @@ -34,8 +40,7 @@ * \param state a flag word indicating the initial state * \return an opaque struct bitmap, or NULL on memory exhaustion */ - -void *bitmap_create(int width, int height, unsigned int state) +static void *bitmap_create(int width, int height, unsigned int state) { nsfb_t *bm; @@ -72,8 +77,7 @@ void *bitmap_create(int width, int height, unsigned int state) * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). */ - -unsigned char *bitmap_get_buffer(void *bitmap) +static unsigned char *bitmap_get_buffer(void *bitmap) { nsfb_t *bm = bitmap; unsigned char *bmpptr; @@ -92,8 +96,7 @@ unsigned char *bitmap_get_buffer(void *bitmap) * \param bitmap a bitmap, as returned by bitmap_create() * \return width of a pixel row in the bitmap */ - -size_t bitmap_get_rowstride(void *bitmap) +static size_t bitmap_get_rowstride(void *bitmap) { nsfb_t *bm = bitmap; int bmpstride; @@ -111,8 +114,7 @@ size_t bitmap_get_rowstride(void *bitmap) * * \param bitmap a bitmap, as returned by bitmap_create() */ - -void bitmap_destroy(void *bitmap) +static void bitmap_destroy(void *bitmap) { nsfb_t *bm = bitmap; @@ -130,8 +132,7 @@ void bitmap_destroy(void *bitmap) * \param flags flags controlling how the bitmap is saved. * \return true on success, false on error and error reported */ - -bool bitmap_save(void *bitmap, const char *path, unsigned flags) +static bool bitmap_save(void *bitmap, const char *path, unsigned flags) { return true; } @@ -142,7 +143,7 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags) * * \param bitmap a bitmap, as returned by bitmap_create() */ -void bitmap_modified(void *bitmap) { +static void bitmap_modified(void *bitmap) { } /** @@ -151,7 +152,7 @@ void bitmap_modified(void *bitmap) { * \param bitmap a bitmap, as returned by bitmap_create() * \param opaque whether the bitmap should be plotted opaque */ -void bitmap_set_opaque(void *bitmap, bool opaque) +static void bitmap_set_opaque(void *bitmap, bool opaque) { nsfb_t *bm = bitmap; @@ -171,7 +172,7 @@ void bitmap_set_opaque(void *bitmap, bool opaque) * \param bitmap a bitmap, as returned by bitmap_create() * \return whether the bitmap is opaque */ -bool bitmap_test_opaque(void *bitmap) +static bool bitmap_test_opaque(void *bitmap) { int tst; nsfb_t *bm = bitmap; @@ -203,7 +204,7 @@ bool bitmap_test_opaque(void *bitmap) * * \param bitmap a bitmap, as returned by bitmap_create() */ -bool bitmap_get_opaque(void *bitmap) +bool framebuffer_bitmap_get_opaque(void *bitmap) { nsfb_t *bm = bitmap; enum nsfb_format_e format; @@ -218,7 +219,7 @@ bool bitmap_get_opaque(void *bitmap) return true; } -int bitmap_get_width(void *bitmap) +static int bitmap_get_width(void *bitmap) { nsfb_t *bm = bitmap; int width; @@ -230,7 +231,7 @@ int bitmap_get_width(void *bitmap) return(width); } -int bitmap_get_height(void *bitmap) +static int bitmap_get_height(void *bitmap) { nsfb_t *bm = bitmap; int height; @@ -243,11 +244,29 @@ int bitmap_get_height(void *bitmap) } /* get bytes per pixel */ -size_t bitmap_get_bpp(void *bitmap) +static size_t bitmap_get_bpp(void *bitmap) { return 4; } +static struct gui_bitmap_table bitmap_table = { + .create = bitmap_create, + .destroy = bitmap_destroy, + .set_opaque = bitmap_set_opaque, + .get_opaque = framebuffer_bitmap_get_opaque, + .test_opaque = bitmap_test_opaque, + .get_buffer = bitmap_get_buffer, + .get_rowstride = bitmap_get_rowstride, + .get_width = bitmap_get_width, + .get_height = bitmap_get_height, + .get_bpp = bitmap_get_bpp, + .save = bitmap_save, + .modified = bitmap_modified, +}; + +struct gui_bitmap_table *framebuffer_bitmap_table = &bitmap_table; + + /* * Local Variables: * c-basic-offset:8 diff --git a/framebuffer/bitmap.h b/framebuffer/bitmap.h new file mode 100644 index 000000000..0a72f19c8 --- /dev/null +++ b/framebuffer/bitmap.h @@ -0,0 +1,26 @@ +/* + * Copyright 2015 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef NS_FB_BITMAP_H +#define NS_FB_BITMAP_H + +extern struct gui_bitmap_table *framebuffer_bitmap_table; + +bool framebuffer_bitmap_get_opaque(void *bitmap); + +#endif /* NS_FB_BITMAP_H */ diff --git a/framebuffer/framebuffer.c b/framebuffer/framebuffer.c index 0988c6b33..927e6318f 100644 --- a/framebuffer/framebuffer.c +++ b/framebuffer/framebuffer.c @@ -37,6 +37,7 @@ #include "framebuffer/fbtk.h" #include "framebuffer/framebuffer.h" #include "framebuffer/font.h" +#include "framebuffer/bitmap.h" /* netsurf framebuffer library handle */ static nsfb_t *nsfb; @@ -215,7 +216,7 @@ framebuffer_plot_bitmap(int x, int y, * a flat fill of the area. Can only be done when image is fully * opaque. */ if ((width == 1) && (height == 1)) { - if (bitmap_get_opaque(bm)) { + if (framebuffer_bitmap_get_opaque(bm)) { /** TODO: Currently using top left pixel. Maybe centre * pixel or average value would be better. */ return nsfb_plot_rectangle_fill(nsfb, &clipbox, diff --git a/framebuffer/gui.c b/framebuffer/gui.c index e178d28fb..56fe41bc4 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -54,6 +54,7 @@ #include "framebuffer/font.h" #include "framebuffer/clipboard.h" #include "framebuffer/fetch.h" +#include "framebuffer/bitmap.h" #include "content/urldb.h" #include "content/fetch.h" @@ -106,7 +107,7 @@ static struct gui_drag { */ static void die(const char *error) { - LOG(("%s", error)); + fprintf(stderr, "%s\n", error); exit(1); } @@ -2081,6 +2082,7 @@ main(int argc, char** argv) .clipboard = framebuffer_clipboard_table, .fetch = framebuffer_fetch_table, .utf8 = framebuffer_utf8_table, + .bitmap = framebuffer_bitmap_table, }; ret = netsurf_register(&framebuffer_table); -- cgit v1.2.3