netsurf: branch master updated. 5743009283e83e95fb2bd4ada7715595019853cd
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/5743009283e83e95fb2bd...
...commit http://git.netsurf-browser.org/netsurf.git/commit/5743009283e83e95fb2bd4a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/5743009283e83e95fb2bd4ada...
The branch, master has been updated
via 5743009283e83e95fb2bd4ada7715595019853cd (commit)
from aea01d19789ffd6e256bffc1c7f714994a8170fb (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/5743009283e83e95fb2...
commit 5743009283e83e95fb2bd4ada7715595019853cd
Author: John-Mark Bell <jmb(a)netsurf-browser.org>
Commit: John-Mark Bell <jmb(a)netsurf-browser.org>
Fix extraction of @size attribute.
diff --git a/css/select.c b/css/select.c
index 042f123..b745a2f 100644
--- a/css/select.c
+++ b/css/select.c
@@ -2611,7 +2611,7 @@ node_presentational_hint_font_size(nscss_select_ctx *ctx,
dom_string_unref(node_name);
- err = dom_element_get_attribute(node, corestring_dom_align, &size);
+ err = dom_element_get_attribute(node, corestring_dom_size, &size);
if ((err != DOM_NO_ERR) || (size == NULL)) {
return CSS_PROPERTY_NOT_SET;
}
-----------------------------------------------------------------------
Summary of changes:
css/select.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/css/select.c b/css/select.c
index 042f123..b745a2f 100644
--- a/css/select.c
+++ b/css/select.c
@@ -2611,7 +2611,7 @@ node_presentational_hint_font_size(nscss_select_ctx *ctx,
dom_string_unref(node_name);
- err = dom_element_get_attribute(node, corestring_dom_align, &size);
+ err = dom_element_get_attribute(node, corestring_dom_size, &size);
if ((err != DOM_NO_ERR) || (size == NULL)) {
return CSS_PROPERTY_NOT_SET;
}
--
NetSurf Browser
10 years, 12 months
libnsfb: branch master updated. 480b2353d815540dca310edc8496da1d3f1b3295
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsfb.git/shortlog/480b2353d815540dca310...
...commit http://git.netsurf-browser.org/libnsfb.git/commit/480b2353d815540dca310ed...
...tree http://git.netsurf-browser.org/libnsfb.git/tree/480b2353d815540dca310edc8...
The branch, master has been updated
via 480b2353d815540dca310edc8496da1d3f1b3295 (commit)
via 1fbc4a8b2dfc030f174aaf475f7ea6820864d1a3 (commit)
from 0804bb7e067e66d4b05a6c45f9736b1e20505b96 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsfb.git/commitdiff/480b2353d815540dca3...
commit 480b2353d815540dca310edc8496da1d3f1b3295
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Split 32bpp support into xrgba, xbgr, and common. Should allow for BGR surfaces as well as RGB.
diff --git a/src/plot/32bpp-common.c b/src/plot/32bpp-common.c
new file mode 100644
index 0000000..9626acf
--- /dev/null
+++ b/src/plot/32bpp-common.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include "common.c"
+
+static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
+{
+ int w;
+ uint32_t *pvid;
+ uint32_t ent;
+ uint32_t llen;
+ uint32_t width;
+ uint32_t height;
+
+ if (!nsfb_plot_clip_ctx(nsfb, rect))
+ return true; /* fill lies outside current clipping region */
+
+ ent = colour_to_pixel(nsfb, c);
+ width = rect->x1 - rect->x0;
+ height = rect->y1 - rect->y0;
+ llen = (nsfb->linelen >> 2) - width;
+
+ pvid = get_xy_loc(nsfb, rect->x0, rect->y0);
+
+ while (height-- > 0) {
+ w = width;
+ while (w >= 16) {
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ w-=16;
+ }
+ while (w >= 4) {
+ *pvid++ = ent; *pvid++ = ent;
+ *pvid++ = ent; *pvid++ = ent;
+ w-=4;
+ }
+ while (w > 0) {
+ *pvid++ = ent;
+ w--;
+ }
+ pvid += llen;
+ }
+
+ return true;
+}
+
+/*
+ * Local Variables:
+ * c-basic-offset:8
+ * End:
+ */
diff --git a/src/plot/32bpp-xbgr8888.c b/src/plot/32bpp-xbgr8888.c
new file mode 100644
index 0000000..9050903
--- /dev/null
+++ b/src/plot/32bpp-xbgr8888.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <stdbool.h>
+#include <endian.h>
+#include <stdlib.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_plot_util.h"
+
+#include "nsfb.h"
+#include "plot.h"
+
+
+#define UNUSED __attribute__((unused))
+
+static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
+{
+ return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
+}
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ /* TODO: FIX */
+ return (pixel >> 8) & ~0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ /* TODO: FIX */
+ return (c << 8);
+}
+#else /* __BYTE_ORDER == __BIG_ENDIAN */
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ return pixel | 0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ return c;
+}
+#endif
+
+#define PLOT_TYPE uint32_t
+#define PLOT_LINELEN(ll) ((ll) >> 2)
+
+#include "32bpp-common.c"
+
+const nsfb_plotter_fns_t _nsfb_32bpp_xbgr8888_plotters = {
+ .line = line,
+ .fill = fill,
+ .point = point,
+ .bitmap = bitmap,
+ .glyph8 = glyph8,
+ .glyph1 = glyph1,
+ .readrect = readrect,
+};
+
+/*
+ * Local Variables:
+ * c-basic-offset:8
+ * End:
+ */
diff --git a/src/plot/32bpp-xrgb8888.c b/src/plot/32bpp-xrgb8888.c
new file mode 100644
index 0000000..548c970
--- /dev/null
+++ b/src/plot/32bpp-xrgb8888.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <stdbool.h>
+#include <endian.h>
+#include <stdlib.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_plot_util.h"
+
+#include "nsfb.h"
+#include "plot.h"
+
+
+#define UNUSED __attribute__((unused))
+
+static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
+{
+ return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
+}
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ return (pixel >> 8) & ~0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ return (c << 8);
+}
+#else /* __BYTE_ORDER == __BIG_ENDIAN */
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ return ((pixel & 0xFF) << 16) |
+ ((pixel & 0xFF00)) |
+ ((pixel & 0xFF0000) >> 16);
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ return ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
+}
+#endif
+
+#define PLOT_TYPE uint32_t
+#define PLOT_LINELEN(ll) ((ll) >> 2)
+
+#include "32bpp-common.c"
+
+const nsfb_plotter_fns_t _nsfb_32bpp_xrgb8888_plotters = {
+ .line = line,
+ .fill = fill,
+ .point = point,
+ .bitmap = bitmap,
+ .glyph8 = glyph8,
+ .glyph1 = glyph1,
+ .readrect = readrect,
+};
+
+/*
+ * Local Variables:
+ * c-basic-offset:8
+ * End:
+ */
diff --git a/src/plot/32bpp.c b/src/plot/32bpp.c
deleted file mode 100644
index aae1b39..0000000
--- a/src/plot/32bpp.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2009 Vincent Sanders <vince(a)simtec.co.uk>
- * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
- *
- * This file is part of libnsfb, http://www.netsurf-browser.org/
- * Licenced under the MIT License,
- * http://www.opensource.org/licenses/mit-license.php
- */
-
-#include <stdbool.h>
-#include <endian.h>
-#include <stdlib.h>
-
-#include "libnsfb.h"
-#include "libnsfb_plot.h"
-#include "libnsfb_plot_util.h"
-
-#include "nsfb.h"
-#include "plot.h"
-
-
-#define UNUSED __attribute__((unused))
-
-static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
-{
- return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
-}
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
-{
- return (pixel >> 8) & ~0xFF000000U;
-}
-
-/* convert a colour value to a 32bpp pixel value ready for screen output */
-static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
-{
- return (c << 8);
-}
-#else /* __BYTE_ORDER == __BIG_ENDIAN */
-static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
-{
- return ((pixel & 0xFF) << 16) |
- ((pixel & 0xFF00)) |
- ((pixel & 0xFF0000) >> 16);
-}
-
-/* convert a colour value to a 32bpp pixel value ready for screen output */
-static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
-{
- return ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
-}
-#endif
-
-#define PLOT_TYPE uint32_t
-#define PLOT_LINELEN(ll) ((ll) >> 2)
-
-#include "common.c"
-
-static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
-{
- int w;
- uint32_t *pvid;
- uint32_t ent;
- uint32_t llen;
- uint32_t width;
- uint32_t height;
-
- if (!nsfb_plot_clip_ctx(nsfb, rect))
- return true; /* fill lies outside current clipping region */
-
- ent = colour_to_pixel(nsfb, c);
- width = rect->x1 - rect->x0;
- height = rect->y1 - rect->y0;
- llen = (nsfb->linelen >> 2) - width;
-
- pvid = get_xy_loc(nsfb, rect->x0, rect->y0);
-
- while (height-- > 0) {
- w = width;
- while (w >= 16) {
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- w-=16;
- }
- while (w >= 4) {
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- w-=4;
- }
- while (w > 0) {
- *pvid++ = ent;
- w--;
- }
- pvid += llen;
- }
-
- return true;
-}
-
-const nsfb_plotter_fns_t _nsfb_32bpp_plotters = {
- .line = line,
- .fill = fill,
- .point = point,
- .bitmap = bitmap,
- .glyph8 = glyph8,
- .glyph1 = glyph1,
- .readrect = readrect,
-};
-
-/*
- * Local Variables:
- * c-basic-offset:8
- * End:
- */
diff --git a/src/plot/Makefile b/src/plot/Makefile
index e99f440..71ebc61 100644
--- a/src/plot/Makefile
+++ b/src/plot/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := api.c util.c generic.c 32bpp.c 16bpp.c 8bpp.c
+DIR_SOURCES := api.c util.c generic.c 32bpp-xrgb8888.c 32bpp-xbgr8888.c 16bpp.c 8bpp.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/plot/generic.c b/src/plot/generic.c
index 6a627ff..0c3d9e8 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -28,7 +28,8 @@ extern const nsfb_plotter_fns_t _nsfb_1bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_8bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_16bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_24bpp_plotters;
-extern const nsfb_plotter_fns_t _nsfb_32bpp_plotters;
+extern const nsfb_plotter_fns_t _nsfb_32bpp_xrgb8888_plotters;
+extern const nsfb_plotter_fns_t _nsfb_32bpp_xbgr8888_plotters;
static bool set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
{
@@ -860,13 +861,13 @@ bool select_plotters(nsfb_t *nsfb)
case NSFB_FMT_XBGR8888: /* 32bpp Unused Blue Green Red */
case NSFB_FMT_ABGR8888: /* 32bpp Alpha Blue Green Red */
- table = &_nsfb_32bpp_plotters;
+ table = &_nsfb_32bpp_xbgr8888_plotters;
nsfb->bpp = 32;
break;
case NSFB_FMT_XRGB8888: /* 32bpp Unused Red Green Blue */
case NSFB_FMT_ARGB8888: /* 32bpp Alpha Red Green Blue */
- table = &_nsfb_32bpp_plotters;
+ table = &_nsfb_32bpp_xrgb8888_plotters;
nsfb->bpp = 32;
break;
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index 0554e26..48052a8 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -411,7 +411,8 @@ sdlcopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
}
-static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
+static int sdl_set_geometry(nsfb_t *nsfb, int width, int height,
+ enum nsfb_format_e format)
{
if (nsfb->surface_priv != NULL)
return -1; /* fail if surface already initialised */
@@ -431,6 +432,8 @@ static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_forma
static int sdl_initialise(nsfb_t *nsfb)
{
SDL_Surface *sdl_screen;
+ SDL_PixelFormat *sdl_fmt;
+ enum nsfb_format_e fmt;
if (nsfb->surface_priv != NULL)
return -1;
@@ -455,6 +458,32 @@ static int sdl_initialise(nsfb_t *nsfb)
return -1;
}
+ /* find out what pixel format we got */
+ sdl_fmt = sdl_screen->format;
+
+ switch (sdl_fmt->BitsPerPixel) {
+ case 32:
+ if (sdl_fmt->Rshift == 0)
+ fmt = NSFB_FMT_XBGR8888;
+ else
+ fmt = NSFB_FMT_XRGB8888;
+ break;
+
+ default:
+ fmt = nsfb->format;
+ break;
+ }
+
+ /* If we didn't get what we asked for, reselect plotters */
+ if (nsfb->format != fmt) {
+ nsfb->format = fmt;
+
+ if (sdl_set_geometry(nsfb, nsfb->width, nsfb->height,
+ nsfb->format) != 0) {
+ return -1;
+ }
+ }
+
nsfb->surface_priv = sdl_screen;
if (nsfb->bpp == 8) {
commitdiff http://git.netsurf-browser.org/libnsfb.git/commitdiff/1fbc4a8b2dfc030f174...
commit 1fbc4a8b2dfc030f174aaf475f7ea6820864d1a3
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix error text.
diff --git a/src/plot/common.c b/src/plot/common.c
index c9f9dc1..f8c4a70 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -10,7 +10,7 @@
*/
#ifndef PLOT_TYPE
-#error PLOT_TYPE must be set to uint16_6 or uint32_t
+#error PLOT_TYPE must be set to uint8_t, uint16_t, or uint32_t
#endif
#ifndef PLOT_LINELEN
#error PLOT_LINELEN must be a macro to increment a line length
-----------------------------------------------------------------------
Summary of changes:
src/plot/{32bpp.c => 32bpp-common.c} | 58 -------------------------
src/plot/32bpp-xbgr8888.c | 74 ++++++++++++++++++++++++++++++++
src/plot/{32bpp.c => 32bpp-xrgb8888.c} | 51 +---------------------
src/plot/Makefile | 2 +-
src/plot/common.c | 2 +-
src/plot/generic.c | 7 ++-
src/surface/sdl.c | 31 +++++++++++++-
7 files changed, 112 insertions(+), 113 deletions(-)
copy src/plot/{32bpp.c => 32bpp-common.c} (55%)
create mode 100644 src/plot/32bpp-xbgr8888.c
rename src/plot/{32bpp.c => 32bpp-xrgb8888.c} (53%)
diff --git a/src/plot/32bpp.c b/src/plot/32bpp-common.c
similarity index 55%
copy from src/plot/32bpp.c
copy to src/plot/32bpp-common.c
index aae1b39..9626acf 100644
--- a/src/plot/32bpp.c
+++ b/src/plot/32bpp-common.c
@@ -7,54 +7,6 @@
* http://www.opensource.org/licenses/mit-license.php
*/
-#include <stdbool.h>
-#include <endian.h>
-#include <stdlib.h>
-
-#include "libnsfb.h"
-#include "libnsfb_plot.h"
-#include "libnsfb_plot_util.h"
-
-#include "nsfb.h"
-#include "plot.h"
-
-
-#define UNUSED __attribute__((unused))
-
-static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
-{
- return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
-}
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
-{
- return (pixel >> 8) & ~0xFF000000U;
-}
-
-/* convert a colour value to a 32bpp pixel value ready for screen output */
-static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
-{
- return (c << 8);
-}
-#else /* __BYTE_ORDER == __BIG_ENDIAN */
-static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
-{
- return ((pixel & 0xFF) << 16) |
- ((pixel & 0xFF00)) |
- ((pixel & 0xFF0000) >> 16);
-}
-
-/* convert a colour value to a 32bpp pixel value ready for screen output */
-static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
-{
- return ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
-}
-#endif
-
-#define PLOT_TYPE uint32_t
-#define PLOT_LINELEN(ll) ((ll) >> 2)
-
#include "common.c"
static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
@@ -104,16 +56,6 @@ static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
return true;
}
-const nsfb_plotter_fns_t _nsfb_32bpp_plotters = {
- .line = line,
- .fill = fill,
- .point = point,
- .bitmap = bitmap,
- .glyph8 = glyph8,
- .glyph1 = glyph1,
- .readrect = readrect,
-};
-
/*
* Local Variables:
* c-basic-offset:8
diff --git a/src/plot/32bpp-xbgr8888.c b/src/plot/32bpp-xbgr8888.c
new file mode 100644
index 0000000..9050903
--- /dev/null
+++ b/src/plot/32bpp-xbgr8888.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2009 Vincent Sanders <vince(a)simtec.co.uk>
+ * Copyright 2010 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+#include <stdbool.h>
+#include <endian.h>
+#include <stdlib.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+#include "libnsfb_plot_util.h"
+
+#include "nsfb.h"
+#include "plot.h"
+
+
+#define UNUSED __attribute__((unused))
+
+static inline uint32_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
+{
+ return (void *)(nsfb->ptr + (y * nsfb->linelen) + (x << 2));
+}
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ /* TODO: FIX */
+ return (pixel >> 8) & ~0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ /* TODO: FIX */
+ return (c << 8);
+}
+#else /* __BYTE_ORDER == __BIG_ENDIAN */
+static inline nsfb_colour_t pixel_to_colour(UNUSED nsfb_t *nsfb, uint32_t pixel)
+{
+ return pixel | 0xFF000000U;
+}
+
+/* convert a colour value to a 32bpp pixel value ready for screen output */
+static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
+{
+ return c;
+}
+#endif
+
+#define PLOT_TYPE uint32_t
+#define PLOT_LINELEN(ll) ((ll) >> 2)
+
+#include "32bpp-common.c"
+
+const nsfb_plotter_fns_t _nsfb_32bpp_xbgr8888_plotters = {
+ .line = line,
+ .fill = fill,
+ .point = point,
+ .bitmap = bitmap,
+ .glyph8 = glyph8,
+ .glyph1 = glyph1,
+ .readrect = readrect,
+};
+
+/*
+ * Local Variables:
+ * c-basic-offset:8
+ * End:
+ */
diff --git a/src/plot/32bpp.c b/src/plot/32bpp-xrgb8888.c
similarity index 53%
rename from src/plot/32bpp.c
rename to src/plot/32bpp-xrgb8888.c
index aae1b39..548c970 100644
--- a/src/plot/32bpp.c
+++ b/src/plot/32bpp-xrgb8888.c
@@ -55,56 +55,9 @@ static inline uint32_t colour_to_pixel(UNUSED nsfb_t *nsfb, nsfb_colour_t c)
#define PLOT_TYPE uint32_t
#define PLOT_LINELEN(ll) ((ll) >> 2)
-#include "common.c"
+#include "32bpp-common.c"
-static bool fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c)
-{
- int w;
- uint32_t *pvid;
- uint32_t ent;
- uint32_t llen;
- uint32_t width;
- uint32_t height;
-
- if (!nsfb_plot_clip_ctx(nsfb, rect))
- return true; /* fill lies outside current clipping region */
-
- ent = colour_to_pixel(nsfb, c);
- width = rect->x1 - rect->x0;
- height = rect->y1 - rect->y0;
- llen = (nsfb->linelen >> 2) - width;
-
- pvid = get_xy_loc(nsfb, rect->x0, rect->y0);
-
- while (height-- > 0) {
- w = width;
- while (w >= 16) {
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- w-=16;
- }
- while (w >= 4) {
- *pvid++ = ent; *pvid++ = ent;
- *pvid++ = ent; *pvid++ = ent;
- w-=4;
- }
- while (w > 0) {
- *pvid++ = ent;
- w--;
- }
- pvid += llen;
- }
-
- return true;
-}
-
-const nsfb_plotter_fns_t _nsfb_32bpp_plotters = {
+const nsfb_plotter_fns_t _nsfb_32bpp_xrgb8888_plotters = {
.line = line,
.fill = fill,
.point = point,
diff --git a/src/plot/Makefile b/src/plot/Makefile
index e99f440..71ebc61 100644
--- a/src/plot/Makefile
+++ b/src/plot/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := api.c util.c generic.c 32bpp.c 16bpp.c 8bpp.c
+DIR_SOURCES := api.c util.c generic.c 32bpp-xrgb8888.c 32bpp-xbgr8888.c 16bpp.c 8bpp.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/plot/common.c b/src/plot/common.c
index c9f9dc1..f8c4a70 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -10,7 +10,7 @@
*/
#ifndef PLOT_TYPE
-#error PLOT_TYPE must be set to uint16_6 or uint32_t
+#error PLOT_TYPE must be set to uint8_t, uint16_t, or uint32_t
#endif
#ifndef PLOT_LINELEN
#error PLOT_LINELEN must be a macro to increment a line length
diff --git a/src/plot/generic.c b/src/plot/generic.c
index 6a627ff..0c3d9e8 100644
--- a/src/plot/generic.c
+++ b/src/plot/generic.c
@@ -28,7 +28,8 @@ extern const nsfb_plotter_fns_t _nsfb_1bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_8bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_16bpp_plotters;
extern const nsfb_plotter_fns_t _nsfb_24bpp_plotters;
-extern const nsfb_plotter_fns_t _nsfb_32bpp_plotters;
+extern const nsfb_plotter_fns_t _nsfb_32bpp_xrgb8888_plotters;
+extern const nsfb_plotter_fns_t _nsfb_32bpp_xbgr8888_plotters;
static bool set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip)
{
@@ -860,13 +861,13 @@ bool select_plotters(nsfb_t *nsfb)
case NSFB_FMT_XBGR8888: /* 32bpp Unused Blue Green Red */
case NSFB_FMT_ABGR8888: /* 32bpp Alpha Blue Green Red */
- table = &_nsfb_32bpp_plotters;
+ table = &_nsfb_32bpp_xbgr8888_plotters;
nsfb->bpp = 32;
break;
case NSFB_FMT_XRGB8888: /* 32bpp Unused Red Green Blue */
case NSFB_FMT_ARGB8888: /* 32bpp Alpha Red Green Blue */
- table = &_nsfb_32bpp_plotters;
+ table = &_nsfb_32bpp_xrgb8888_plotters;
nsfb->bpp = 32;
break;
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index 0554e26..48052a8 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -411,7 +411,8 @@ sdlcopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
}
-static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format)
+static int sdl_set_geometry(nsfb_t *nsfb, int width, int height,
+ enum nsfb_format_e format)
{
if (nsfb->surface_priv != NULL)
return -1; /* fail if surface already initialised */
@@ -431,6 +432,8 @@ static int sdl_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_forma
static int sdl_initialise(nsfb_t *nsfb)
{
SDL_Surface *sdl_screen;
+ SDL_PixelFormat *sdl_fmt;
+ enum nsfb_format_e fmt;
if (nsfb->surface_priv != NULL)
return -1;
@@ -455,6 +458,32 @@ static int sdl_initialise(nsfb_t *nsfb)
return -1;
}
+ /* find out what pixel format we got */
+ sdl_fmt = sdl_screen->format;
+
+ switch (sdl_fmt->BitsPerPixel) {
+ case 32:
+ if (sdl_fmt->Rshift == 0)
+ fmt = NSFB_FMT_XBGR8888;
+ else
+ fmt = NSFB_FMT_XRGB8888;
+ break;
+
+ default:
+ fmt = nsfb->format;
+ break;
+ }
+
+ /* If we didn't get what we asked for, reselect plotters */
+ if (nsfb->format != fmt) {
+ nsfb->format = fmt;
+
+ if (sdl_set_geometry(nsfb, nsfb->width, nsfb->height,
+ nsfb->format) != 0) {
+ return -1;
+ }
+ }
+
nsfb->surface_priv = sdl_screen;
if (nsfb->bpp == 8) {
--
NetSurf Framebuffer library
10 years, 12 months
netsurf: branch master updated. aea01d19789ffd6e256bffc1c7f714994a8170fb
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/aea01d19789ffd6e256bf...
...commit http://git.netsurf-browser.org/netsurf.git/commit/aea01d19789ffd6e256bffc...
...tree http://git.netsurf-browser.org/netsurf.git/tree/aea01d19789ffd6e256bffc1c...
The branch, master has been updated
via aea01d19789ffd6e256bffc1c7f714994a8170fb (commit)
from 56465288983f3b3d9f97f97faccbcf673cc35ba5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/aea01d19789ffd6e256...
commit aea01d19789ffd6e256bffc1c7f714994a8170fb
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix to define variable at start of block, for GCC 2.95.2.
diff --git a/render/html.c b/render/html.c
index a4725ca..b651510 100644
--- a/render/html.c
+++ b/render/html.c
@@ -423,6 +423,7 @@ html_process_encoding_change(struct content *c,
const char *encoding;
const char *source_data;
unsigned long source_size;
+ union content_msg_data msg_data;
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
@@ -433,8 +434,6 @@ html_process_encoding_change(struct content *c,
html->encoding = talloc_strdup(c, encoding);
if (html->encoding == NULL) {
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
@@ -458,8 +457,6 @@ html_process_encoding_change(struct content *c,
talloc_free(html->encoding);
html->encoding = talloc_strdup(c, "Windows-1252");
if (html->encoding == NULL) {
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
@@ -474,8 +471,6 @@ html_process_encoding_change(struct content *c,
&html->document);
if (html->parser == NULL) {
- union content_msg_data msg_data;
-
/** @todo add a message callback function and pass the
* parser errors back instead of everything being
* OOM
@@ -500,8 +495,6 @@ html_process_encoding_change(struct content *c,
return true;
}
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-----------------------------------------------------------------------
Summary of changes:
render/html.c | 9 +--------
1 files changed, 1 insertions(+), 8 deletions(-)
diff --git a/render/html.c b/render/html.c
index a4725ca..b651510 100644
--- a/render/html.c
+++ b/render/html.c
@@ -423,6 +423,7 @@ html_process_encoding_change(struct content *c,
const char *encoding;
const char *source_data;
unsigned long source_size;
+ union content_msg_data msg_data;
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
@@ -433,8 +434,6 @@ html_process_encoding_change(struct content *c,
html->encoding = talloc_strdup(c, encoding);
if (html->encoding == NULL) {
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
@@ -458,8 +457,6 @@ html_process_encoding_change(struct content *c,
talloc_free(html->encoding);
html->encoding = talloc_strdup(c, "Windows-1252");
if (html->encoding == NULL) {
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
return false;
@@ -474,8 +471,6 @@ html_process_encoding_change(struct content *c,
&html->document);
if (html->parser == NULL) {
- union content_msg_data msg_data;
-
/** @todo add a message callback function and pass the
* parser errors back instead of everything being
* OOM
@@ -500,8 +495,6 @@ html_process_encoding_change(struct content *c,
return true;
}
- union content_msg_data msg_data;
-
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
--
NetSurf Browser
10 years, 12 months
netsurf: branch master updated. 56465288983f3b3d9f97f97faccbcf673cc35ba5
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/56465288983f3b3d9f97f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/56465288983f3b3d9f97f97...
...tree http://git.netsurf-browser.org/netsurf.git/tree/56465288983f3b3d9f97f97fa...
The branch, master has been updated
via 56465288983f3b3d9f97f97faccbcf673cc35ba5 (commit)
from 761c42840d1655a0aa4061f1b63a6f1feb7b81c5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/56465288983f3b3d9f9...
commit 56465288983f3b3d9f97f97faccbcf673cc35ba5
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Fix cases of returning pointers as bool for GCC 2.95.2.
diff --git a/desktop/cookies.c b/desktop/cookies.c
index 71e9c01..224e8b8 100644
--- a/desktop/cookies.c
+++ b/desktop/cookies.c
@@ -247,7 +247,7 @@ static bool cookies_update_cookie_node(struct node *node,
messages_get("Yes") :
messages_get("No")));
- return node;
+ return true;
}
/**
diff --git a/desktop/sslcert.c b/desktop/sslcert.c
index bd53357..d63d3a2 100644
--- a/desktop/sslcert.c
+++ b/desktop/sslcert.c
@@ -237,7 +237,7 @@ bool sslcert_load_tree(struct tree *tree,
data->tree = tree;
- return tree;
+ return true;
}
diff --git a/image/image_cache.c b/image/image_cache.c
index 50961b1..c136908 100644
--- a/image/image_cache.c
+++ b/image/image_cache.c
@@ -746,7 +746,7 @@ bool image_cache_redraw(struct content *c,
centry = image_cache__find(c);
if (centry == NULL) {
LOG(("Could not find cache entry for content (%p)", c));
- return NULL;
+ return false;
}
if (centry->bitmap == NULL) {
-----------------------------------------------------------------------
Summary of changes:
desktop/cookies.c | 2 +-
desktop/sslcert.c | 2 +-
image/image_cache.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/desktop/cookies.c b/desktop/cookies.c
index 71e9c01..224e8b8 100644
--- a/desktop/cookies.c
+++ b/desktop/cookies.c
@@ -247,7 +247,7 @@ static bool cookies_update_cookie_node(struct node *node,
messages_get("Yes") :
messages_get("No")));
- return node;
+ return true;
}
/**
diff --git a/desktop/sslcert.c b/desktop/sslcert.c
index bd53357..d63d3a2 100644
--- a/desktop/sslcert.c
+++ b/desktop/sslcert.c
@@ -237,7 +237,7 @@ bool sslcert_load_tree(struct tree *tree,
data->tree = tree;
- return tree;
+ return true;
}
diff --git a/image/image_cache.c b/image/image_cache.c
index 50961b1..c136908 100644
--- a/image/image_cache.c
+++ b/image/image_cache.c
@@ -746,7 +746,7 @@ bool image_cache_redraw(struct content *c,
centry = image_cache__find(c);
if (centry == NULL) {
LOG(("Could not find cache entry for content (%p)", c));
- return NULL;
+ return false;
}
if (centry->bitmap == NULL) {
--
NetSurf Browser
10 years, 12 months
netsurf: branch master updated. 761c42840d1655a0aa4061f1b63a6f1feb7b81c5
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/761c42840d1655a0aa406...
...commit http://git.netsurf-browser.org/netsurf.git/commit/761c42840d1655a0aa4061f...
...tree http://git.netsurf-browser.org/netsurf.git/tree/761c42840d1655a0aa4061f1b...
The branch, master has been updated
via 761c42840d1655a0aa4061f1b63a6f1feb7b81c5 (commit)
from 19c8654f775eeb4b63cf68bd1793a31738a2424a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/761c42840d1655a0aa4...
commit 761c42840d1655a0aa4061f1b63a6f1feb7b81c5
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Install netsurf.png too.
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 9263857..3ca0540 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -163,7 +163,7 @@ EXETARGET := nsfb
NETSURF_FRAMEBUFFER_RESOURCE_LIST := adblock.css credits.html \
default.css internal.css licence.html messages \
- quirks.css welcome.html
+ netsurf.png quirks.css welcome.html
install-framebuffer:
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_BIN)
-----------------------------------------------------------------------
Summary of changes:
framebuffer/Makefile.target | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 9263857..3ca0540 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -163,7 +163,7 @@ EXETARGET := nsfb
NETSURF_FRAMEBUFFER_RESOURCE_LIST := adblock.css credits.html \
default.css internal.css licence.html messages \
- quirks.css welcome.html
+ netsurf.png quirks.css welcome.html
install-framebuffer:
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_BIN)
--
NetSurf Browser
10 years, 12 months
netsurf: branch master updated. 19c8654f775eeb4b63cf68bd1793a31738a2424a
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/19c8654f775eeb4b63cf6...
...commit http://git.netsurf-browser.org/netsurf.git/commit/19c8654f775eeb4b63cf68b...
...tree http://git.netsurf-browser.org/netsurf.git/tree/19c8654f775eeb4b63cf68bd1...
The branch, master has been updated
via 19c8654f775eeb4b63cf68bd1793a31738a2424a (commit)
from 84e1bf89d96c0be4fb811a4802a664b7d8aa4e7c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/19c8654f775eeb4b63c...
commit 19c8654f775eeb4b63cf68bd1793a31738a2424a
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add missing resources to intall target.
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 71f7fc2..9263857 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -161,11 +161,15 @@ EXETARGET := nsfb
# Install target
# ----------------------------------------------------------------------------
+NETSURF_FRAMEBUFFER_RESOURCE_LIST := adblock.css credits.html \
+ default.css internal.css licence.html messages \
+ quirks.css welcome.html
+
install-framebuffer:
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_BIN)
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_RESOURCES)
@cp -v $(EXETARGET) $(DESTDIR)/$(NETSURF_FRAMEBUFFER_BIN)netsurf$(SUBTARGET)
- @for F in default.css messages; do cp -vL framebuffer/res/$$F $(DESTDIR)/$(NETSURF_FRAMEBUFFER_RESOURCES); done
+ @for F in $(NETSURF_FRAMEBUFFER_RESOURCE_LIST); do cp -vL framebuffer/res/$$F $(DESTDIR)/$(NETSURF_FRAMEBUFFER_RESOURCES); done
# ----------------------------------------------------------------------------
# Package target
-----------------------------------------------------------------------
Summary of changes:
framebuffer/Makefile.target | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 71f7fc2..9263857 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -161,11 +161,15 @@ EXETARGET := nsfb
# Install target
# ----------------------------------------------------------------------------
+NETSURF_FRAMEBUFFER_RESOURCE_LIST := adblock.css credits.html \
+ default.css internal.css licence.html messages \
+ quirks.css welcome.html
+
install-framebuffer:
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_BIN)
mkdir -p $(DESTDIR)$(NETSURF_FRAMEBUFFER_RESOURCES)
@cp -v $(EXETARGET) $(DESTDIR)/$(NETSURF_FRAMEBUFFER_BIN)netsurf$(SUBTARGET)
- @for F in default.css messages; do cp -vL framebuffer/res/$$F $(DESTDIR)/$(NETSURF_FRAMEBUFFER_RESOURCES); done
+ @for F in $(NETSURF_FRAMEBUFFER_RESOURCE_LIST); do cp -vL framebuffer/res/$$F $(DESTDIR)/$(NETSURF_FRAMEBUFFER_RESOURCES); done
# ----------------------------------------------------------------------------
# Package target
--
NetSurf Browser
10 years, 12 months
netsurf: branch master updated. 84e1bf89d96c0be4fb811a4802a664b7d8aa4e7c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/84e1bf89d96c0be4fb811...
...commit http://git.netsurf-browser.org/netsurf.git/commit/84e1bf89d96c0be4fb811a4...
...tree http://git.netsurf-browser.org/netsurf.git/tree/84e1bf89d96c0be4fb811a480...
The branch, master has been updated
via 84e1bf89d96c0be4fb811a4802a664b7d8aa4e7c (commit)
from ae8a3ede3e1e4d139f8e564cf393c1ab8914cd44 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/84e1bf89d96c0be4fb8...
commit 84e1bf89d96c0be4fb811a4802a664b7d8aa4e7c
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add OSK icon.
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 8cca120..71f7fc2 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -95,6 +95,7 @@ FB_IMAGE_scrollr := framebuffer/res/icons/scrollr.png
FB_IMAGE_scrollu := framebuffer/res/icons/scrollu.png
FB_IMAGE_scrolld := framebuffer/res/icons/scrolld.png
+FB_IMAGE_osk_image := framebuffer/res/icons/osk.png
FB_IMAGE_pointer_image := framebuffer/res/pointers/default.png
FB_IMAGE_hand_image := framebuffer/res/pointers/point.png
diff --git a/framebuffer/fbtk/osk.c b/framebuffer/fbtk/osk.c
index 02c9e45..1d57f15 100644
--- a/framebuffer/fbtk/osk.c
+++ b/framebuffer/fbtk/osk.c
@@ -173,17 +173,15 @@ fbtk_enable_oskb(fbtk_widget_t *fbtk)
fbtk_set_text(widget, kbdbase[kloop].t);
}
- widget = fbtk_create_text_button(osk,
- fbtk_get_width(osk) - furniture_width,
- fbtk_get_height(osk) - furniture_width,
- furniture_width,
- furniture_width,
- FB_FRAME_COLOUR,
- FB_COLOUR_BLACK,
- osk_close,
- NULL);
- fbtk_set_text(widget, "\xe2\x8c\xa8");
-
+ widget = fbtk_create_button(osk,
+ fbtk_get_width(osk) - furniture_width,
+ fbtk_get_height(osk) - furniture_width,
+ furniture_width,
+ furniture_width,
+ FB_FRAME_COLOUR,
+ &osk_image,
+ osk_close,
+ NULL);
}
/* exported function documented in fbtk.h */
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index e33df38..3bcc1be 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1377,7 +1377,15 @@ create_normal_browser_window(struct gui_window *gw, int furniture_width)
FB_FRAME_COLOUR, FB_COLOUR_BLACK,
fb_osk_click,
NULL);
- fbtk_set_text(widget, "\xe2\x8c\xa8");
+ widget = fbtk_create_button(gw->window,
+ fbtk_get_width(gw->window) - furniture_width,
+ fbtk_get_height(gw->window) - furniture_width,
+ furniture_width,
+ furniture_width,
+ FB_FRAME_COLOUR,
+ &osk_image,
+ fb_osk_click,
+ NULL);
} else {
widget = fbtk_create_fill(gw->window,
fbtk_get_width(gw->window) - furniture_width,
diff --git a/framebuffer/image_data.h b/framebuffer/image_data.h
index a6d8b6a..cf349f5 100644
--- a/framebuffer/image_data.h
+++ b/framebuffer/image_data.h
@@ -38,6 +38,8 @@ extern struct fbtk_bitmap scrollr;
extern struct fbtk_bitmap scrollu;
extern struct fbtk_bitmap scrolld;
+extern struct fbtk_bitmap osk_image;
+
extern struct fbtk_bitmap pointer_image;
extern struct fbtk_bitmap hand_image;
extern struct fbtk_bitmap caret_image;
diff --git a/framebuffer/res/icons/osk.png b/framebuffer/res/icons/osk.png
new file mode 100644
index 0000000..1e64fed
Binary files /dev/null and b/framebuffer/res/icons/osk.png differ
-----------------------------------------------------------------------
Summary of changes:
framebuffer/Makefile.target | 1 +
framebuffer/fbtk/osk.c | 20 +++++++++-----------
framebuffer/gui.c | 10 +++++++++-
framebuffer/image_data.h | 2 ++
framebuffer/res/icons/osk.png | Bin 0 -> 262 bytes
5 files changed, 21 insertions(+), 12 deletions(-)
create mode 100644 framebuffer/res/icons/osk.png
diff --git a/framebuffer/Makefile.target b/framebuffer/Makefile.target
index 8cca120..71f7fc2 100644
--- a/framebuffer/Makefile.target
+++ b/framebuffer/Makefile.target
@@ -95,6 +95,7 @@ FB_IMAGE_scrollr := framebuffer/res/icons/scrollr.png
FB_IMAGE_scrollu := framebuffer/res/icons/scrollu.png
FB_IMAGE_scrolld := framebuffer/res/icons/scrolld.png
+FB_IMAGE_osk_image := framebuffer/res/icons/osk.png
FB_IMAGE_pointer_image := framebuffer/res/pointers/default.png
FB_IMAGE_hand_image := framebuffer/res/pointers/point.png
diff --git a/framebuffer/fbtk/osk.c b/framebuffer/fbtk/osk.c
index 02c9e45..1d57f15 100644
--- a/framebuffer/fbtk/osk.c
+++ b/framebuffer/fbtk/osk.c
@@ -173,17 +173,15 @@ fbtk_enable_oskb(fbtk_widget_t *fbtk)
fbtk_set_text(widget, kbdbase[kloop].t);
}
- widget = fbtk_create_text_button(osk,
- fbtk_get_width(osk) - furniture_width,
- fbtk_get_height(osk) - furniture_width,
- furniture_width,
- furniture_width,
- FB_FRAME_COLOUR,
- FB_COLOUR_BLACK,
- osk_close,
- NULL);
- fbtk_set_text(widget, "\xe2\x8c\xa8");
-
+ widget = fbtk_create_button(osk,
+ fbtk_get_width(osk) - furniture_width,
+ fbtk_get_height(osk) - furniture_width,
+ furniture_width,
+ furniture_width,
+ FB_FRAME_COLOUR,
+ &osk_image,
+ osk_close,
+ NULL);
}
/* exported function documented in fbtk.h */
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index e33df38..3bcc1be 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1377,7 +1377,15 @@ create_normal_browser_window(struct gui_window *gw, int furniture_width)
FB_FRAME_COLOUR, FB_COLOUR_BLACK,
fb_osk_click,
NULL);
- fbtk_set_text(widget, "\xe2\x8c\xa8");
+ widget = fbtk_create_button(gw->window,
+ fbtk_get_width(gw->window) - furniture_width,
+ fbtk_get_height(gw->window) - furniture_width,
+ furniture_width,
+ furniture_width,
+ FB_FRAME_COLOUR,
+ &osk_image,
+ fb_osk_click,
+ NULL);
} else {
widget = fbtk_create_fill(gw->window,
fbtk_get_width(gw->window) - furniture_width,
diff --git a/framebuffer/image_data.h b/framebuffer/image_data.h
index a6d8b6a..cf349f5 100644
--- a/framebuffer/image_data.h
+++ b/framebuffer/image_data.h
@@ -38,6 +38,8 @@ extern struct fbtk_bitmap scrollr;
extern struct fbtk_bitmap scrollu;
extern struct fbtk_bitmap scrolld;
+extern struct fbtk_bitmap osk_image;
+
extern struct fbtk_bitmap pointer_image;
extern struct fbtk_bitmap hand_image;
extern struct fbtk_bitmap caret_image;
diff --git a/framebuffer/res/icons/osk.png b/framebuffer/res/icons/osk.png
new file mode 100644
index 0000000..1e64fed
Binary files /dev/null and b/framebuffer/res/icons/osk.png differ
--
NetSurf Browser
10 years, 12 months
libnsfb: branch master updated. 0804bb7e067e66d4b05a6c45f9736b1e20505b96
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/libnsfb.git/shortlog/0804bb7e067e66d4b05a6...
...commit http://git.netsurf-browser.org/libnsfb.git/commit/0804bb7e067e66d4b05a6c4...
...tree http://git.netsurf-browser.org/libnsfb.git/tree/0804bb7e067e66d4b05a6c45f...
The branch, master has been updated
via 0804bb7e067e66d4b05a6c45f9736b1e20505b96 (commit)
via 46f3c9ea3793d146337c81bf8858d99238c05e86 (commit)
from 1983c37933d2a753c4c913527c94392682bf7b98 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/libnsfb.git/commitdiff/0804bb7e067e66d4b05...
commit 0804bb7e067e66d4b05a6c45f9736b1e20505b96
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add error diffusion to palette based rendering. Only used for bitmap and scaled bitmap plots. Doesn't do serpentine path, since that would need changes to the common bitmap rendering code.
diff --git a/include/palette.h b/include/palette.h
index 845c1bc..f975ef2 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -27,21 +27,35 @@ struct nsfb_palette_s {
enum nsfb_palette_type_e type; /**< Palette type */
uint8_t last; /**< Last used palette index */
nsfb_colour_t data[256]; /**< Palette for index modes */
+
+ bool dither; /**< Whether to use error diffusion */
+ struct {
+ int width; /**< Length of error value buffer ring*/
+ int current; /**< Current pos in ring buffer*/
+ int *data; /**< Ring buffer error values */
+ int data_len; /**< Max size of ring */
+ } dither_ctx;
};
+
/** Create an empty palette object. */
-bool nsfb_palette_new(struct nsfb_palette_s **palette);
+bool nsfb_palette_new(struct nsfb_palette_s **palette, int width);
/** Free a palette object. */
void nsfb_palette_free(struct nsfb_palette_s *palette);
+/** Init error diffusion for a plot. */
+void nsfb_palette_dither_init(struct nsfb_palette_s *palette, int width);
+
+/** Finalise error diffusion after a plot. */
+void nsfb_palette_dither_fini(struct nsfb_palette_s *palette);
+
/** Generate libnsfb 8bpp default palette. */
void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette);
-
-static inline uint8_t nsfb_palette_best_match(
- const struct nsfb_palette_s *palette,
- nsfb_colour_t c)
+/** Find best palette match for given colour. */
+static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s *palette,
+ nsfb_colour_t c, int *r_error, int *g_error, int *b_error)
{
uint8_t best_col = 0;
@@ -68,6 +82,9 @@ static inline uint8_t nsfb_palette_best_match(
best_col = col;
best_distance = cur_distance;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
/* Index into grayscale part */
col = (( c & 0xFF) +
@@ -82,6 +99,9 @@ static inline uint8_t nsfb_palette_best_match(
if (cur_distance < best_distance) {
best_distance = cur_distance;
best_col = col;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
}
break;
@@ -97,6 +117,9 @@ static inline uint8_t nsfb_palette_best_match(
if (cur_distance < best_distance) {
best_distance = cur_distance;
best_col = col;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
}
}
break;
@@ -108,4 +131,101 @@ static inline uint8_t nsfb_palette_best_match(
return best_col;
}
+/** Find best palette match for given colour, with error diffusion. */
+static inline uint8_t nsfb_palette_best_match_dither(
+ struct nsfb_palette_s *palette, nsfb_colour_t c)
+{
+ int r, g, b;
+ int current;
+ int error;
+ int width = palette->dither_ctx.width;
+ uint8_t best_col_index;
+
+ if (palette == NULL)
+ return 0;
+
+ if (palette->dither == false)
+ return nsfb_palette_best_match(palette, c, &r, &g, &b);
+
+ current = palette->dither_ctx.current;
+
+ /* Get RGB components of colour, and apply error */
+ r = ( c & 0xFF) + palette->dither_ctx.data[current ];
+ g = ((c >> 8) & 0xFF) + palette->dither_ctx.data[current + 1];
+ b = ((c >> 16) & 0xFF) + palette->dither_ctx.data[current + 2];
+
+ /* Clamp new RGB components to range */
+ if (r < 0) r = 0;
+ if (r > 255) r = 255;
+ if (g < 0) g = 0;
+ if (g > 255) g = 255;
+ if (b < 0) b = 0;
+ if (b > 255) b = 255;
+
+ /* Reset error diffusion slots to 0 */
+ palette->dither_ctx.data[current ] = 0;
+ palette->dither_ctx.data[current + 1] = 0;
+ palette->dither_ctx.data[current + 2] = 0;
+
+ /* Rebuild colour from modified components */
+ c = r + (g << 8) + (b << 16);
+
+ /* Get best match for pixel, and find errors for each component */
+ best_col_index = nsfb_palette_best_match(palette, c, &r, &g, &b);
+
+ /* Advance one set of error diffusion slots */
+ current += 3;
+ if (current >= width)
+ current = 0;
+ palette->dither_ctx.current = current;
+
+ /* Save errors
+ *
+ * [*]-[N]
+ * / | \
+ * [l]-[m]-[r]
+ */
+ error = current;
+
+ /* Error for [N] (next) */
+ if (error != 0) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r * 7 / 16;
+ palette->dither_ctx.data[error + 1] += g * 7 / 16;
+ palette->dither_ctx.data[error + 2] += b * 7 / 16;
+ }
+
+ error += width - 2 * 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [l] (below, left) */
+ if (error >= 0 && error != 3) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r * 3 / 16;
+ palette->dither_ctx.data[error + 1] += g * 3 / 16;
+ palette->dither_ctx.data[error + 2] += b * 3 / 16;
+ }
+
+ error += 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [m] (below, middle) */
+ palette->dither_ctx.data[error ] += r * 5 / 16;
+ palette->dither_ctx.data[error + 1] += g * 5 / 16;
+ palette->dither_ctx.data[error + 2] += b * 5 / 16;
+
+ error += 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [r] (below, right) */
+ if (error != 0) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r / 16;
+ palette->dither_ctx.data[error + 1] += g / 16;
+ palette->dither_ctx.data[error + 2] += b / 16;
+ }
+
+ return best_col_index;
+}
+
#endif /* PALETTE_H */
diff --git a/src/palette.c b/src/palette.c
index eba95cd..d600001 100644
--- a/src/palette.c
+++ b/src/palette.c
@@ -13,12 +13,13 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <string.h>
#include "palette.h"
/** Create an empty palette object. */
-bool nsfb_palette_new(struct nsfb_palette_s **palette)
+bool nsfb_palette_new(struct nsfb_palette_s **palette, int width)
{
*palette = malloc(sizeof(struct nsfb_palette_s));
if (*palette == NULL) {
@@ -28,14 +29,41 @@ bool nsfb_palette_new(struct nsfb_palette_s **palette)
(*palette)->type = NSFB_PALETTE_EMPTY;
(*palette)->last = 0;
+ (*palette)->dither = false;
+ (*palette)->dither_ctx.data_len = width * 3;
+ (*palette)->dither_ctx.data = malloc(width * 3 * sizeof(int));
+ if ((*palette)->dither_ctx.data == NULL) {
+ nsfb_palette_free(*palette);
+ return false;
+ }
+
return true;
}
/** Free a palette object. */
void nsfb_palette_free(struct nsfb_palette_s *palette)
{
- if (palette != NULL)
+ if (palette != NULL) {
+ if (palette->dither_ctx.data != NULL) {
+ free(palette->dither_ctx.data);
+ }
free(palette);
+ }
+}
+
+/** Init error diffusion for a plot. */
+void nsfb_palette_dither_init(struct nsfb_palette_s *palette, int width)
+{
+ palette->dither = true;
+ memset(palette->dither_ctx.data, 0, palette->dither_ctx.data_len);
+ palette->dither_ctx.width = width * 3;
+ palette->dither_ctx.current = 0;
+}
+
+/** Finalise error diffusion after a plot. */
+void nsfb_palette_dither_fini(struct nsfb_palette_s *palette)
+{
+ palette->dither = false;
}
/** Generate libnsfb 8bpp default palette. */
diff --git a/src/plot/8bpp.c b/src/plot/8bpp.c
index 05574d8..0245542 100644
--- a/src/plot/8bpp.c
+++ b/src/plot/8bpp.c
@@ -39,7 +39,7 @@ static uint8_t colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c)
if (nsfb->palette == NULL)
return 0;
- return nsfb_palette_best_match(nsfb->palette, c);
+ return nsfb_palette_best_match_dither(nsfb->palette, c);
}
#define PLOT_TYPE uint8_t
diff --git a/src/plot/common.c b/src/plot/common.c
index 185e323..c9f9dc1 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -16,6 +16,8 @@
#error PLOT_LINELEN must be a macro to increment a line length
#endif
+#include "palette.h"
+
#define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0))
static bool
@@ -249,8 +251,7 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
nsfb_bbox_t clipped; /* clipped display */
/* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
+ * current context. */
clipped.x0 = x;
clipped.y0 = y;
clipped.x1 = x + width;
@@ -271,6 +272,10 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
else
rwidth = width;
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_init(nsfb->palette, rwidth);
+ }
+
/* get veritcal (y) and horizontal (x) scale factors; both integer
* part and remainder */
dx = bmp_width / width;
@@ -299,7 +304,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0);
pvideo_limit = pvideo + PLOT_LINELEN(nsfb->linelen) * rheight;
if (alpha) {
- for (; pvideo < pvideo_limit; pvideo += PLOT_LINELEN(nsfb->linelen)) {
+ for (; pvideo < pvideo_limit;
+ pvideo += PLOT_LINELEN(nsfb->linelen)) {
/* looping through render area vertically */
xoff = xoffs;
rx = rxs;
@@ -322,7 +328,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
xloop)));
}
/* plot pixel */
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
/* handle horizontal interpolation */
xoff += dx;
@@ -341,7 +348,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
}
}
} else {
- for (; pvideo < pvideo_limit; pvideo += PLOT_LINELEN(nsfb->linelen)) {
+ for (; pvideo < pvideo_limit;
+ pvideo += PLOT_LINELEN(nsfb->linelen)) {
/* looping through render area vertically */
xoff = xoffs;
rx = rxs;
@@ -350,7 +358,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
/* get value of source pixel in question */
abpixel = pixel[yoff + xoff];
/* plot pixel */
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
/* handle horizontal interpolation */
xoff += dx;
@@ -369,6 +378,11 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
}
}
}
+
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_fini(nsfb->palette);
+ }
+
return true;
}
@@ -391,17 +405,16 @@ bitmap(nsfb_t *nsfb,
int height = loc->y1 - loc->y0;
nsfb_bbox_t clipped; /* clipped display */
- if (width == 0 || height == 0)
- return true;
+ if (width == 0 || height == 0)
+ return true;
/* Scaled bitmaps are handled by a separate function */
if (width != bmp_width || height != bmp_height)
return bitmap_scaled(nsfb, loc, pixel, bmp_width, bmp_height,
bmp_stride, alpha);
- /* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
+ /* The part of the image actually displayed is cropped to the
+ * current context. */
clipped.x0 = x;
clipped.y0 = y;
clipped.x1 = x + width;
@@ -416,6 +429,10 @@ bitmap(nsfb_t *nsfb,
if (width > (clipped.x1 - clipped.x0))
width = (clipped.x1 - clipped.x0);
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_init(nsfb->palette, width);
+ }
+
xoff = clipped.x0 - x;
yoff = (clipped.y0 - y) * bmp_stride;
height = height * bmp_stride + yoff;
@@ -428,16 +445,22 @@ bitmap(nsfb_t *nsfb,
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
if ((abpixel & 0xFF000000) != 0) {
- /* pixel is not transparent; have to
- * plot something */
- if ((abpixel & 0xFF000000) != 0xFF000000) {
- /* pixel is not opaque; need to
- * blend */
- abpixel = nsfb_plot_ablend(abpixel,
- pixel_to_colour(nsfb, *(pvideo + xloop)));
+ /* pixel is not transparent; have to
+ * plot something */
+ if ((abpixel & 0xFF000000) !=
+ 0xFF000000) {
+ /* pixel is not opaque; need to
+ * blend */
+ abpixel = nsfb_plot_ablend(
+ abpixel,
+ pixel_to_colour(
+ nsfb,
+ *(pvideo +
+ xloop)));
}
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
}
pvideo += PLOT_LINELEN(nsfb->linelen);
@@ -446,11 +469,17 @@ bitmap(nsfb_t *nsfb,
for (yloop = yoff; yloop < height; yloop += bmp_stride) {
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
pvideo += PLOT_LINELEN(nsfb->linelen);
}
}
+
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_fini(nsfb->palette);
+ }
+
return true;
}
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index 7a86dc1..0554e26 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -458,7 +458,7 @@ static int sdl_initialise(nsfb_t *nsfb)
nsfb->surface_priv = sdl_screen;
if (nsfb->bpp == 8) {
- nsfb_palette_new(&nsfb->palette);
+ nsfb_palette_new(&nsfb->palette, nsfb->width);
set_palette(nsfb);
}
commitdiff http://git.netsurf-browser.org/libnsfb.git/commitdiff/46f3c9ea3793d146337...
commit 46f3c9ea3793d146337c81bf8858d99238c05e86
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add palette object. Optimise matching colour in case where we chose the palette. In other cases, we still have to seach all the colours, but that doesn't ever seem to be used.
diff --git a/include/libnsfb.h b/include/libnsfb.h
index 739617e..da8e5f6 100644
--- a/include/libnsfb.h
+++ b/include/libnsfb.h
@@ -13,6 +13,7 @@
#include <stdint.h>
+typedef struct nsfb_palette_s nsfb_palette_t;
typedef struct nsfb_cursor_s nsfb_cursor_t;
typedef struct nsfb_s nsfb_t;
typedef struct nsfb_event_s nsfb_event_t;
diff --git a/include/nsfb.h b/include/nsfb.h
index 5caff9b..9a61775 100644
--- a/include/nsfb.h
+++ b/include/nsfb.h
@@ -28,7 +28,7 @@ struct nsfb_s {
uint8_t *ptr; /**< Base of video memory. */
int linelen; /**< length of a video line. */
- nsfb_colour_t palette[256]; /**< palette for index modes */
+ struct nsfb_palette_s *palette; /**< palette for index modes */
nsfb_cursor_t *cursor; /**< cursor */
struct nsfb_surface_rtns_s *surface_rtns; /**< surface routines. */
diff --git a/include/palette.h b/include/palette.h
new file mode 100644
index 0000000..845c1bc
--- /dev/null
+++ b/include/palette.h
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2012 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * This is the *internal* interface for the cursor.
+ */
+
+#ifndef PALETTE_H
+#define PALETTE_H 1
+
+#include <stdint.h>
+#include <limits.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+
+enum nsfb_palette_type_e {
+ NSFB_PALETTE_EMPTY, /**< empty palette object */
+ NSFB_PALETTE_NSFB_8BPP, /**< libnsfb's own 8bpp palette */
+ NSFB_PALETTE_OTHER /**< any other palette */
+};
+
+struct nsfb_palette_s {
+ enum nsfb_palette_type_e type; /**< Palette type */
+ uint8_t last; /**< Last used palette index */
+ nsfb_colour_t data[256]; /**< Palette for index modes */
+};
+
+/** Create an empty palette object. */
+bool nsfb_palette_new(struct nsfb_palette_s **palette);
+
+/** Free a palette object. */
+void nsfb_palette_free(struct nsfb_palette_s *palette);
+
+/** Generate libnsfb 8bpp default palette. */
+void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette);
+
+
+static inline uint8_t nsfb_palette_best_match(
+ const struct nsfb_palette_s *palette,
+ nsfb_colour_t c)
+{
+ uint8_t best_col = 0;
+
+ nsfb_colour_t palent;
+ int col;
+ int dr, dg, db; /* delta red, green blue values */
+
+ int cur_distance;
+ int best_distance = INT_MAX;
+
+ switch (palette->type) {
+ case NSFB_PALETTE_NSFB_8BPP:
+ /* Index into colour cube part */
+ dr = ((( c & 0xFF) * 5) + 128) / 256;
+ dg = ((((c >> 8) & 0xFF) * 7) + 128) / 256;
+ db = ((((c >> 16) & 0xFF) * 4) + 128) / 256;
+ col = 40 * dr + 5 * dg + db;
+
+ palent = palette->data[col];
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8 ) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+
+ best_col = col;
+ best_distance = cur_distance;
+
+ /* Index into grayscale part */
+ col = (( c & 0xFF) +
+ ((c >> 8) & 0xFF) +
+ ((c >> 16) & 0xFF) + (45 / 2)) / (15 * 3) - 1 + 240;
+ palent = palette->data[col];
+
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+ if (cur_distance < best_distance) {
+ best_distance = cur_distance;
+ best_col = col;
+ }
+ break;
+
+ case NSFB_PALETTE_OTHER:
+ /* Try all colours in palette */
+ for (col = 0; col <= palette->last; col++) {
+ palent = palette->data[col];
+
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+ if (cur_distance < best_distance) {
+ best_distance = cur_distance;
+ best_col = col;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return best_col;
+}
+
+#endif /* PALETTE_H */
diff --git a/src/Makefile b/src/Makefile
index 283a99f..3c6e2f0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := libnsfb.c dump.c cursor.c
+DIR_SOURCES := libnsfb.c dump.c cursor.c palette.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/libnsfb.c b/src/libnsfb.c
index 6f14c99..a341088 100644
--- a/src/libnsfb.c
+++ b/src/libnsfb.c
@@ -15,6 +15,7 @@
#include "libnsfb_plot.h"
#include "libnsfb_event.h"
#include "nsfb.h"
+#include "palette.h"
#include "surface.h"
/* exported interface documented in libnsfb.h */
@@ -50,6 +51,10 @@ int
nsfb_free(nsfb_t *nsfb)
{
int ret;
+
+ if (nsfb->palette != NULL)
+ nsfb_palette_free(nsfb->palette);
+
ret = nsfb->surface_rtns->finalise(nsfb);
free(nsfb);
return ret;
diff --git a/src/palette.c b/src/palette.c
new file mode 100644
index 0000000..eba95cd
--- /dev/null
+++ b/src/palette.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2012 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+/** \file
+ * Palette (implementation).
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+
+#include "palette.h"
+
+
+/** Create an empty palette object. */
+bool nsfb_palette_new(struct nsfb_palette_s **palette)
+{
+ *palette = malloc(sizeof(struct nsfb_palette_s));
+ if (*palette == NULL) {
+ return false;
+ }
+
+ (*palette)->type = NSFB_PALETTE_EMPTY;
+ (*palette)->last = 0;
+
+ return true;
+}
+
+/** Free a palette object. */
+void nsfb_palette_free(struct nsfb_palette_s *palette)
+{
+ if (palette != NULL)
+ free(palette);
+}
+
+/** Generate libnsfb 8bpp default palette. */
+void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette)
+{
+ int rloop, gloop, bloop;
+ int loop = 0;
+ uint8_t r, g, b;
+
+ /* Build a linear 6-8-5 levels RGB colour cube palette.
+ * This accounts for 240 colours */
+#define RLIM 6
+#define GLIM 8
+#define BLIM 5
+ for (rloop = 0; rloop < RLIM; rloop++) {
+ for (gloop = 0; gloop < GLIM; gloop++) {
+ for (bloop = 0; bloop < BLIM; bloop++) {
+ r = ((rloop * 255 * 2) + RLIM - 1) /
+ (2 * (RLIM - 1));
+ g = ((gloop * 255 * 2) + GLIM - 1) /
+ (2 * (GLIM - 1));
+ b = ((bloop * 255 * 2) + BLIM - 1) /
+ (2 * (BLIM - 1));
+
+ palette->data[loop] = r | g << 8 | b << 16;
+ loop++;
+ }
+ }
+ }
+#undef RLIM
+#undef GLIM
+#undef BLIM
+
+ /* Should have 240 colours set */
+ assert(loop == 240);
+
+ /* Fill index 240 to index 255 with grayscales */
+ /* Note: already have full black and full white from RGB cube */
+ for (; loop < 256; loop++) {
+ int ngray = loop - 240 + 1;
+ r = ngray * 15; /* 17*15 = 255 */
+
+ g = b = r;
+
+ palette->data[loop] = r | g << 8 | b << 16;
+ }
+
+ /* Set palette details */
+ palette->type = NSFB_PALETTE_NSFB_8BPP;
+ palette->last = 255;
+}
diff --git a/src/plot/8bpp.c b/src/plot/8bpp.c
index b72303d..05574d8 100644
--- a/src/plot/8bpp.c
+++ b/src/plot/8bpp.c
@@ -10,7 +10,6 @@
#include <stdbool.h>
#include <endian.h>
#include <stdlib.h>
-#include <limits.h>
#include <string.h>
#include "libnsfb.h"
@@ -18,6 +17,7 @@
#include "libnsfb_plot_util.h"
#include "nsfb.h"
+#include "palette.h"
#include "plot.h"
static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
@@ -28,34 +28,18 @@ static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
static inline nsfb_colour_t pixel_to_colour(nsfb_t *nsfb, uint8_t pixel)
{
- return nsfb->palette[pixel];
+ if (nsfb->palette == NULL)
+ return 0;
+
+ return nsfb->palette->data[pixel];
}
static uint8_t colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c)
{
- nsfb_colour_t palent;
- int col;
-
- int dr, dg, db; /* delta red, green blue values */
-
- int cur_distance;
- int best_distance = INT_MAX;
- uint8_t best_col = 0;
-
- for (col = 0; col < 256; col++) {
- palent = nsfb->palette[col];
-
- dr = (c & 0xFF) - (palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
- cur_distance = ((dr * dr) + (dg * dg) + (db *db));
- if (cur_distance < best_distance) {
- best_distance = cur_distance;
- best_col = col;
- }
- }
+ if (nsfb->palette == NULL)
+ return 0;
- return best_col;
+ return nsfb_palette_best_match(nsfb->palette, c);
}
#define PLOT_TYPE uint8_t
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index d598b8a..7a86dc1 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -6,7 +6,6 @@
* http://www.opensource.org/licenses/mit-license.php
*/
-#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <SDL/SDL.h>
@@ -18,6 +17,7 @@
#include "nsfb.h"
#include "surface.h"
+#include "palette.h"
#include "plot.h"
#include "cursor.h"
@@ -353,49 +353,19 @@ set_palette(nsfb_t *nsfb)
{
SDL_Surface *sdl_screen = nsfb->surface_priv;
SDL_Color palette[256];
- int rloop, gloop, bloop;
int loop = 0;
- /* Build a linear 6-8-5 levels RGB colour cube palette.
- * This accounts for 240 colours */
-#define RLIM 6
-#define GLIM 8
-#define BLIM 5
- for (rloop = 0; rloop < RLIM; rloop++) {
- for (gloop = 0; gloop < GLIM; gloop++) {
- for (bloop = 0; bloop < BLIM; bloop++) {
- palette[loop].r = ((rloop * 255 * 2) + RLIM - 1) / (2 * (RLIM - 1));
- palette[loop].g = ((gloop * 255 * 2) + GLIM - 1) / (2 * (GLIM - 1));
- palette[loop].b = ((bloop * 255 * 2) + BLIM - 1) / (2 * (BLIM - 1));
-
- nsfb->palette[loop] = palette[loop].r |
- palette[loop].g << 8 |
- palette[loop].b << 16;
- loop++;
- }
- }
- }
-#undef RLIM
-#undef GLIM
-#undef BLIM
-
- /* Should have 240 colours set */
- assert(loop == 240);
+ /* Get libnsfb palette */
+ nsfb_palette_generate_nsfb_8bpp(nsfb->palette);
- /* Fill index 240 to index 255 with grayscales */
- /* Note: already have full black and full white from RGB cube */
- for (; loop < 256; loop++) {
- int ngray = loop - 240 + 1;
- palette[loop].r = ngray * 15; /* 17*15 = 255 */
-
- palette[loop].g = palette[loop].b = palette[loop].r;
-
- nsfb->palette[loop] = palette[loop].r |
- palette[loop].g << 8 |
- palette[loop].b << 16;
+ /* Create SDL palette from nsfb palette */
+ for (loop = 0; loop < 256; loop++) {
+ palette[loop].r = (nsfb->palette->data[loop] ) & 0xFF;
+ palette[loop].g = (nsfb->palette->data[loop] >> 8) & 0xFF;
+ palette[loop].b = (nsfb->palette->data[loop] >> 16) & 0xFF;
}
- /* Set palette */
+ /* Set SDL palette */
SDL_SetColors(sdl_screen, palette, 0, 256);
}
@@ -487,8 +457,10 @@ static int sdl_initialise(nsfb_t *nsfb)
nsfb->surface_priv = sdl_screen;
- if (nsfb->bpp == 8)
+ if (nsfb->bpp == 8) {
+ nsfb_palette_new(&nsfb->palette);
set_palette(nsfb);
+ }
nsfb->ptr = sdl_screen->pixels;
nsfb->linelen = sdl_screen->pitch;
-----------------------------------------------------------------------
Summary of changes:
include/libnsfb.h | 1 +
include/nsfb.h | 2 +-
include/palette.h | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/Makefile | 2 +-
src/libnsfb.c | 5 +
src/palette.c | 117 +++++++++++++++++++++++++++
src/plot/8bpp.c | 32 ++------
src/plot/common.c | 69 +++++++++++-----
src/surface/sdl.c | 52 +++---------
9 files changed, 425 insertions(+), 86 deletions(-)
create mode 100644 include/palette.h
create mode 100644 src/palette.c
diff --git a/include/libnsfb.h b/include/libnsfb.h
index 739617e..da8e5f6 100644
--- a/include/libnsfb.h
+++ b/include/libnsfb.h
@@ -13,6 +13,7 @@
#include <stdint.h>
+typedef struct nsfb_palette_s nsfb_palette_t;
typedef struct nsfb_cursor_s nsfb_cursor_t;
typedef struct nsfb_s nsfb_t;
typedef struct nsfb_event_s nsfb_event_t;
diff --git a/include/nsfb.h b/include/nsfb.h
index 5caff9b..9a61775 100644
--- a/include/nsfb.h
+++ b/include/nsfb.h
@@ -28,7 +28,7 @@ struct nsfb_s {
uint8_t *ptr; /**< Base of video memory. */
int linelen; /**< length of a video line. */
- nsfb_colour_t palette[256]; /**< palette for index modes */
+ struct nsfb_palette_s *palette; /**< palette for index modes */
nsfb_cursor_t *cursor; /**< cursor */
struct nsfb_surface_rtns_s *surface_rtns; /**< surface routines. */
diff --git a/include/palette.h b/include/palette.h
new file mode 100644
index 0000000..f975ef2
--- /dev/null
+++ b/include/palette.h
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2012 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * This is the *internal* interface for the cursor.
+ */
+
+#ifndef PALETTE_H
+#define PALETTE_H 1
+
+#include <stdint.h>
+#include <limits.h>
+
+#include "libnsfb.h"
+#include "libnsfb_plot.h"
+
+enum nsfb_palette_type_e {
+ NSFB_PALETTE_EMPTY, /**< empty palette object */
+ NSFB_PALETTE_NSFB_8BPP, /**< libnsfb's own 8bpp palette */
+ NSFB_PALETTE_OTHER /**< any other palette */
+};
+
+struct nsfb_palette_s {
+ enum nsfb_palette_type_e type; /**< Palette type */
+ uint8_t last; /**< Last used palette index */
+ nsfb_colour_t data[256]; /**< Palette for index modes */
+
+ bool dither; /**< Whether to use error diffusion */
+ struct {
+ int width; /**< Length of error value buffer ring*/
+ int current; /**< Current pos in ring buffer*/
+ int *data; /**< Ring buffer error values */
+ int data_len; /**< Max size of ring */
+ } dither_ctx;
+};
+
+
+/** Create an empty palette object. */
+bool nsfb_palette_new(struct nsfb_palette_s **palette, int width);
+
+/** Free a palette object. */
+void nsfb_palette_free(struct nsfb_palette_s *palette);
+
+/** Init error diffusion for a plot. */
+void nsfb_palette_dither_init(struct nsfb_palette_s *palette, int width);
+
+/** Finalise error diffusion after a plot. */
+void nsfb_palette_dither_fini(struct nsfb_palette_s *palette);
+
+/** Generate libnsfb 8bpp default palette. */
+void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette);
+
+/** Find best palette match for given colour. */
+static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s *palette,
+ nsfb_colour_t c, int *r_error, int *g_error, int *b_error)
+{
+ uint8_t best_col = 0;
+
+ nsfb_colour_t palent;
+ int col;
+ int dr, dg, db; /* delta red, green blue values */
+
+ int cur_distance;
+ int best_distance = INT_MAX;
+
+ switch (palette->type) {
+ case NSFB_PALETTE_NSFB_8BPP:
+ /* Index into colour cube part */
+ dr = ((( c & 0xFF) * 5) + 128) / 256;
+ dg = ((((c >> 8) & 0xFF) * 7) + 128) / 256;
+ db = ((((c >> 16) & 0xFF) * 4) + 128) / 256;
+ col = 40 * dr + 5 * dg + db;
+
+ palent = palette->data[col];
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8 ) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+
+ best_col = col;
+ best_distance = cur_distance;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
+
+ /* Index into grayscale part */
+ col = (( c & 0xFF) +
+ ((c >> 8) & 0xFF) +
+ ((c >> 16) & 0xFF) + (45 / 2)) / (15 * 3) - 1 + 240;
+ palent = palette->data[col];
+
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+ if (cur_distance < best_distance) {
+ best_distance = cur_distance;
+ best_col = col;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
+ }
+ break;
+
+ case NSFB_PALETTE_OTHER:
+ /* Try all colours in palette */
+ for (col = 0; col <= palette->last; col++) {
+ palent = palette->data[col];
+
+ dr = ( c & 0xFF) - ( palent & 0xFF);
+ dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
+ db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ cur_distance = (dr * dr) + (dg * dg) + (db * db);
+ if (cur_distance < best_distance) {
+ best_distance = cur_distance;
+ best_col = col;
+ *r_error = dr;
+ *g_error = dg;
+ *b_error = db;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return best_col;
+}
+
+/** Find best palette match for given colour, with error diffusion. */
+static inline uint8_t nsfb_palette_best_match_dither(
+ struct nsfb_palette_s *palette, nsfb_colour_t c)
+{
+ int r, g, b;
+ int current;
+ int error;
+ int width = palette->dither_ctx.width;
+ uint8_t best_col_index;
+
+ if (palette == NULL)
+ return 0;
+
+ if (palette->dither == false)
+ return nsfb_palette_best_match(palette, c, &r, &g, &b);
+
+ current = palette->dither_ctx.current;
+
+ /* Get RGB components of colour, and apply error */
+ r = ( c & 0xFF) + palette->dither_ctx.data[current ];
+ g = ((c >> 8) & 0xFF) + palette->dither_ctx.data[current + 1];
+ b = ((c >> 16) & 0xFF) + palette->dither_ctx.data[current + 2];
+
+ /* Clamp new RGB components to range */
+ if (r < 0) r = 0;
+ if (r > 255) r = 255;
+ if (g < 0) g = 0;
+ if (g > 255) g = 255;
+ if (b < 0) b = 0;
+ if (b > 255) b = 255;
+
+ /* Reset error diffusion slots to 0 */
+ palette->dither_ctx.data[current ] = 0;
+ palette->dither_ctx.data[current + 1] = 0;
+ palette->dither_ctx.data[current + 2] = 0;
+
+ /* Rebuild colour from modified components */
+ c = r + (g << 8) + (b << 16);
+
+ /* Get best match for pixel, and find errors for each component */
+ best_col_index = nsfb_palette_best_match(palette, c, &r, &g, &b);
+
+ /* Advance one set of error diffusion slots */
+ current += 3;
+ if (current >= width)
+ current = 0;
+ palette->dither_ctx.current = current;
+
+ /* Save errors
+ *
+ * [*]-[N]
+ * / | \
+ * [l]-[m]-[r]
+ */
+ error = current;
+
+ /* Error for [N] (next) */
+ if (error != 0) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r * 7 / 16;
+ palette->dither_ctx.data[error + 1] += g * 7 / 16;
+ palette->dither_ctx.data[error + 2] += b * 7 / 16;
+ }
+
+ error += width - 2 * 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [l] (below, left) */
+ if (error >= 0 && error != 3) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r * 3 / 16;
+ palette->dither_ctx.data[error + 1] += g * 3 / 16;
+ palette->dither_ctx.data[error + 2] += b * 3 / 16;
+ }
+
+ error += 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [m] (below, middle) */
+ palette->dither_ctx.data[error ] += r * 5 / 16;
+ palette->dither_ctx.data[error + 1] += g * 5 / 16;
+ palette->dither_ctx.data[error + 2] += b * 5 / 16;
+
+ error += 3;
+ if (error >= width)
+ error -= width;
+ /* Error for [r] (below, right) */
+ if (error != 0) {
+ /* The pixel exists */
+ palette->dither_ctx.data[error ] += r / 16;
+ palette->dither_ctx.data[error + 1] += g / 16;
+ palette->dither_ctx.data[error + 2] += b / 16;
+ }
+
+ return best_col_index;
+}
+
+#endif /* PALETTE_H */
diff --git a/src/Makefile b/src/Makefile
index 283a99f..3c6e2f0 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
# Sources
-DIR_SOURCES := libnsfb.c dump.c cursor.c
+DIR_SOURCES := libnsfb.c dump.c cursor.c palette.c
include $(NSBUILD)/Makefile.subdir
diff --git a/src/libnsfb.c b/src/libnsfb.c
index 6f14c99..a341088 100644
--- a/src/libnsfb.c
+++ b/src/libnsfb.c
@@ -15,6 +15,7 @@
#include "libnsfb_plot.h"
#include "libnsfb_event.h"
#include "nsfb.h"
+#include "palette.h"
#include "surface.h"
/* exported interface documented in libnsfb.h */
@@ -50,6 +51,10 @@ int
nsfb_free(nsfb_t *nsfb)
{
int ret;
+
+ if (nsfb->palette != NULL)
+ nsfb_palette_free(nsfb->palette);
+
ret = nsfb->surface_rtns->finalise(nsfb);
free(nsfb);
return ret;
diff --git a/src/palette.c b/src/palette.c
new file mode 100644
index 0000000..d600001
--- /dev/null
+++ b/src/palette.c
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012 Michael Drake <tlsa(a)netsurf-browser.org>
+ *
+ * This file is part of libnsfb, http://www.netsurf-browser.org/
+ * Licenced under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+/** \file
+ * Palette (implementation).
+ */
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "palette.h"
+
+
+/** Create an empty palette object. */
+bool nsfb_palette_new(struct nsfb_palette_s **palette, int width)
+{
+ *palette = malloc(sizeof(struct nsfb_palette_s));
+ if (*palette == NULL) {
+ return false;
+ }
+
+ (*palette)->type = NSFB_PALETTE_EMPTY;
+ (*palette)->last = 0;
+
+ (*palette)->dither = false;
+ (*palette)->dither_ctx.data_len = width * 3;
+ (*palette)->dither_ctx.data = malloc(width * 3 * sizeof(int));
+ if ((*palette)->dither_ctx.data == NULL) {
+ nsfb_palette_free(*palette);
+ return false;
+ }
+
+ return true;
+}
+
+/** Free a palette object. */
+void nsfb_palette_free(struct nsfb_palette_s *palette)
+{
+ if (palette != NULL) {
+ if (palette->dither_ctx.data != NULL) {
+ free(palette->dither_ctx.data);
+ }
+ free(palette);
+ }
+}
+
+/** Init error diffusion for a plot. */
+void nsfb_palette_dither_init(struct nsfb_palette_s *palette, int width)
+{
+ palette->dither = true;
+ memset(palette->dither_ctx.data, 0, palette->dither_ctx.data_len);
+ palette->dither_ctx.width = width * 3;
+ palette->dither_ctx.current = 0;
+}
+
+/** Finalise error diffusion after a plot. */
+void nsfb_palette_dither_fini(struct nsfb_palette_s *palette)
+{
+ palette->dither = false;
+}
+
+/** Generate libnsfb 8bpp default palette. */
+void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette)
+{
+ int rloop, gloop, bloop;
+ int loop = 0;
+ uint8_t r, g, b;
+
+ /* Build a linear 6-8-5 levels RGB colour cube palette.
+ * This accounts for 240 colours */
+#define RLIM 6
+#define GLIM 8
+#define BLIM 5
+ for (rloop = 0; rloop < RLIM; rloop++) {
+ for (gloop = 0; gloop < GLIM; gloop++) {
+ for (bloop = 0; bloop < BLIM; bloop++) {
+ r = ((rloop * 255 * 2) + RLIM - 1) /
+ (2 * (RLIM - 1));
+ g = ((gloop * 255 * 2) + GLIM - 1) /
+ (2 * (GLIM - 1));
+ b = ((bloop * 255 * 2) + BLIM - 1) /
+ (2 * (BLIM - 1));
+
+ palette->data[loop] = r | g << 8 | b << 16;
+ loop++;
+ }
+ }
+ }
+#undef RLIM
+#undef GLIM
+#undef BLIM
+
+ /* Should have 240 colours set */
+ assert(loop == 240);
+
+ /* Fill index 240 to index 255 with grayscales */
+ /* Note: already have full black and full white from RGB cube */
+ for (; loop < 256; loop++) {
+ int ngray = loop - 240 + 1;
+ r = ngray * 15; /* 17*15 = 255 */
+
+ g = b = r;
+
+ palette->data[loop] = r | g << 8 | b << 16;
+ }
+
+ /* Set palette details */
+ palette->type = NSFB_PALETTE_NSFB_8BPP;
+ palette->last = 255;
+}
diff --git a/src/plot/8bpp.c b/src/plot/8bpp.c
index b72303d..0245542 100644
--- a/src/plot/8bpp.c
+++ b/src/plot/8bpp.c
@@ -10,7 +10,6 @@
#include <stdbool.h>
#include <endian.h>
#include <stdlib.h>
-#include <limits.h>
#include <string.h>
#include "libnsfb.h"
@@ -18,6 +17,7 @@
#include "libnsfb_plot_util.h"
#include "nsfb.h"
+#include "palette.h"
#include "plot.h"
static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
@@ -28,34 +28,18 @@ static inline uint8_t *get_xy_loc(nsfb_t *nsfb, int x, int y)
static inline nsfb_colour_t pixel_to_colour(nsfb_t *nsfb, uint8_t pixel)
{
- return nsfb->palette[pixel];
+ if (nsfb->palette == NULL)
+ return 0;
+
+ return nsfb->palette->data[pixel];
}
static uint8_t colour_to_pixel(nsfb_t *nsfb, nsfb_colour_t c)
{
- nsfb_colour_t palent;
- int col;
-
- int dr, dg, db; /* delta red, green blue values */
-
- int cur_distance;
- int best_distance = INT_MAX;
- uint8_t best_col = 0;
-
- for (col = 0; col < 256; col++) {
- palent = nsfb->palette[col];
-
- dr = (c & 0xFF) - (palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
- cur_distance = ((dr * dr) + (dg * dg) + (db *db));
- if (cur_distance < best_distance) {
- best_distance = cur_distance;
- best_col = col;
- }
- }
+ if (nsfb->palette == NULL)
+ return 0;
- return best_col;
+ return nsfb_palette_best_match_dither(nsfb->palette, c);
}
#define PLOT_TYPE uint8_t
diff --git a/src/plot/common.c b/src/plot/common.c
index 185e323..c9f9dc1 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -16,6 +16,8 @@
#error PLOT_LINELEN must be a macro to increment a line length
#endif
+#include "palette.h"
+
#define SIGN(x) ((x<0) ? -1 : ((x>0) ? 1 : 0))
static bool
@@ -249,8 +251,7 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
nsfb_bbox_t clipped; /* clipped display */
/* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
+ * current context. */
clipped.x0 = x;
clipped.y0 = y;
clipped.x1 = x + width;
@@ -271,6 +272,10 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
else
rwidth = width;
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_init(nsfb->palette, rwidth);
+ }
+
/* get veritcal (y) and horizontal (x) scale factors; both integer
* part and remainder */
dx = bmp_width / width;
@@ -299,7 +304,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
pvideo = get_xy_loc(nsfb, clipped.x0, clipped.y0);
pvideo_limit = pvideo + PLOT_LINELEN(nsfb->linelen) * rheight;
if (alpha) {
- for (; pvideo < pvideo_limit; pvideo += PLOT_LINELEN(nsfb->linelen)) {
+ for (; pvideo < pvideo_limit;
+ pvideo += PLOT_LINELEN(nsfb->linelen)) {
/* looping through render area vertically */
xoff = xoffs;
rx = rxs;
@@ -322,7 +328,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
xloop)));
}
/* plot pixel */
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
/* handle horizontal interpolation */
xoff += dx;
@@ -341,7 +348,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
}
}
} else {
- for (; pvideo < pvideo_limit; pvideo += PLOT_LINELEN(nsfb->linelen)) {
+ for (; pvideo < pvideo_limit;
+ pvideo += PLOT_LINELEN(nsfb->linelen)) {
/* looping through render area vertically */
xoff = xoffs;
rx = rxs;
@@ -350,7 +358,8 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
/* get value of source pixel in question */
abpixel = pixel[yoff + xoff];
/* plot pixel */
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
/* handle horizontal interpolation */
xoff += dx;
@@ -369,6 +378,11 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
}
}
}
+
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_fini(nsfb->palette);
+ }
+
return true;
}
@@ -391,17 +405,16 @@ bitmap(nsfb_t *nsfb,
int height = loc->y1 - loc->y0;
nsfb_bbox_t clipped; /* clipped display */
- if (width == 0 || height == 0)
- return true;
+ if (width == 0 || height == 0)
+ return true;
/* Scaled bitmaps are handled by a separate function */
if (width != bmp_width || height != bmp_height)
return bitmap_scaled(nsfb, loc, pixel, bmp_width, bmp_height,
bmp_stride, alpha);
- /* The part of the scaled image actually displayed is cropped to the
- * current context.
- */
+ /* The part of the image actually displayed is cropped to the
+ * current context. */
clipped.x0 = x;
clipped.y0 = y;
clipped.x1 = x + width;
@@ -416,6 +429,10 @@ bitmap(nsfb_t *nsfb,
if (width > (clipped.x1 - clipped.x0))
width = (clipped.x1 - clipped.x0);
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_init(nsfb->palette, width);
+ }
+
xoff = clipped.x0 - x;
yoff = (clipped.y0 - y) * bmp_stride;
height = height * bmp_stride + yoff;
@@ -428,16 +445,22 @@ bitmap(nsfb_t *nsfb,
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
if ((abpixel & 0xFF000000) != 0) {
- /* pixel is not transparent; have to
- * plot something */
- if ((abpixel & 0xFF000000) != 0xFF000000) {
- /* pixel is not opaque; need to
- * blend */
- abpixel = nsfb_plot_ablend(abpixel,
- pixel_to_colour(nsfb, *(pvideo + xloop)));
+ /* pixel is not transparent; have to
+ * plot something */
+ if ((abpixel & 0xFF000000) !=
+ 0xFF000000) {
+ /* pixel is not opaque; need to
+ * blend */
+ abpixel = nsfb_plot_ablend(
+ abpixel,
+ pixel_to_colour(
+ nsfb,
+ *(pvideo +
+ xloop)));
}
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
}
pvideo += PLOT_LINELEN(nsfb->linelen);
@@ -446,11 +469,17 @@ bitmap(nsfb_t *nsfb,
for (yloop = yoff; yloop < height; yloop += bmp_stride) {
for (xloop = 0; xloop < width; xloop++) {
abpixel = pixel[yloop + xloop + xoff];
- *(pvideo + xloop) = colour_to_pixel(nsfb, abpixel);
+ *(pvideo + xloop) = colour_to_pixel(
+ nsfb, abpixel);
}
pvideo += PLOT_LINELEN(nsfb->linelen);
}
}
+
+ if (nsfb->palette != NULL) {
+ nsfb_palette_dither_fini(nsfb->palette);
+ }
+
return true;
}
diff --git a/src/surface/sdl.c b/src/surface/sdl.c
index d598b8a..0554e26 100644
--- a/src/surface/sdl.c
+++ b/src/surface/sdl.c
@@ -6,7 +6,6 @@
* http://www.opensource.org/licenses/mit-license.php
*/
-#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <SDL/SDL.h>
@@ -18,6 +17,7 @@
#include "nsfb.h"
#include "surface.h"
+#include "palette.h"
#include "plot.h"
#include "cursor.h"
@@ -353,49 +353,19 @@ set_palette(nsfb_t *nsfb)
{
SDL_Surface *sdl_screen = nsfb->surface_priv;
SDL_Color palette[256];
- int rloop, gloop, bloop;
int loop = 0;
- /* Build a linear 6-8-5 levels RGB colour cube palette.
- * This accounts for 240 colours */
-#define RLIM 6
-#define GLIM 8
-#define BLIM 5
- for (rloop = 0; rloop < RLIM; rloop++) {
- for (gloop = 0; gloop < GLIM; gloop++) {
- for (bloop = 0; bloop < BLIM; bloop++) {
- palette[loop].r = ((rloop * 255 * 2) + RLIM - 1) / (2 * (RLIM - 1));
- palette[loop].g = ((gloop * 255 * 2) + GLIM - 1) / (2 * (GLIM - 1));
- palette[loop].b = ((bloop * 255 * 2) + BLIM - 1) / (2 * (BLIM - 1));
-
- nsfb->palette[loop] = palette[loop].r |
- palette[loop].g << 8 |
- palette[loop].b << 16;
- loop++;
- }
- }
- }
-#undef RLIM
-#undef GLIM
-#undef BLIM
-
- /* Should have 240 colours set */
- assert(loop == 240);
+ /* Get libnsfb palette */
+ nsfb_palette_generate_nsfb_8bpp(nsfb->palette);
- /* Fill index 240 to index 255 with grayscales */
- /* Note: already have full black and full white from RGB cube */
- for (; loop < 256; loop++) {
- int ngray = loop - 240 + 1;
- palette[loop].r = ngray * 15; /* 17*15 = 255 */
-
- palette[loop].g = palette[loop].b = palette[loop].r;
-
- nsfb->palette[loop] = palette[loop].r |
- palette[loop].g << 8 |
- palette[loop].b << 16;
+ /* Create SDL palette from nsfb palette */
+ for (loop = 0; loop < 256; loop++) {
+ palette[loop].r = (nsfb->palette->data[loop] ) & 0xFF;
+ palette[loop].g = (nsfb->palette->data[loop] >> 8) & 0xFF;
+ palette[loop].b = (nsfb->palette->data[loop] >> 16) & 0xFF;
}
- /* Set palette */
+ /* Set SDL palette */
SDL_SetColors(sdl_screen, palette, 0, 256);
}
@@ -487,8 +457,10 @@ static int sdl_initialise(nsfb_t *nsfb)
nsfb->surface_priv = sdl_screen;
- if (nsfb->bpp == 8)
+ if (nsfb->bpp == 8) {
+ nsfb_palette_new(&nsfb->palette, nsfb->width);
set_palette(nsfb);
+ }
nsfb->ptr = sdl_screen->pixels;
nsfb->linelen = sdl_screen->pitch;
--
NetSurf Framebuffer library
10 years, 12 months
netsurf: branch master updated. ae8a3ede3e1e4d139f8e564cf393c1ab8914cd44
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/ae8a3ede3e1e4d139f8e5...
...commit http://git.netsurf-browser.org/netsurf.git/commit/ae8a3ede3e1e4d139f8e564...
...tree http://git.netsurf-browser.org/netsurf.git/tree/ae8a3ede3e1e4d139f8e564cf...
The branch, master has been updated
via ae8a3ede3e1e4d139f8e564cf393c1ab8914cd44 (commit)
from 718237c2a502817536bc206344cefcd699fd4fd3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/ae8a3ede3e1e4d139f8...
commit ae8a3ede3e1e4d139f8e564cf393c1ab8914cd44
Author: John-Mark Bell <jmb(a)netsurf-browser.org>
Commit: John-Mark Bell <jmb(a)netsurf-browser.org>
Fix bug #3572539: handle empty option elements.
diff --git a/render/box_construct.c b/render/box_construct.c
index 5b22e99..37fdede 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -2867,9 +2867,12 @@ bool box_select_add_option(struct form_control *control, dom_node *n)
if (err != DOM_NO_ERR)
return false;
- text = squash_whitespace(dom_string_data(content));
-
- dom_string_unref(content);
+ if (content != NULL) {
+ text = squash_whitespace(dom_string_data(content));
+ dom_string_unref(content);
+ } else {
+ text = strdup("");
+ }
if (text == NULL)
goto no_memory;
-----------------------------------------------------------------------
Summary of changes:
render/box_construct.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/render/box_construct.c b/render/box_construct.c
index 5b22e99..37fdede 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -2867,9 +2867,12 @@ bool box_select_add_option(struct form_control *control, dom_node *n)
if (err != DOM_NO_ERR)
return false;
- text = squash_whitespace(dom_string_data(content));
-
- dom_string_unref(content);
+ if (content != NULL) {
+ text = squash_whitespace(dom_string_data(content));
+ dom_string_unref(content);
+ } else {
+ text = strdup("");
+ }
if (text == NULL)
goto no_memory;
--
NetSurf Browser
10 years, 12 months
netsurf: branch master updated. 718237c2a502817536bc206344cefcd699fd4fd3
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/718237c2a502817536bc2...
...commit http://git.netsurf-browser.org/netsurf.git/commit/718237c2a502817536bc206...
...tree http://git.netsurf-browser.org/netsurf.git/tree/718237c2a502817536bc20634...
The branch, master has been updated
via 718237c2a502817536bc206344cefcd699fd4fd3 (commit)
from 07f86cfc1de55028627f3cdca8138df43dc35b08 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/718237c2a502817536b...
commit 718237c2a502817536bc206344cefcd699fd4fd3
Author: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Commit: Chris Young <chris(a)unsatisfactorysoftware.co.uk>
Add debug symbols as they are incredibly useful to have on the auto-builds, and can always be overridden for release builds.
diff --git a/Makefile.defaults b/Makefile.defaults
index 8ee569c..9a8d207 100644
--- a/Makefile.defaults
+++ b/Makefile.defaults
@@ -261,7 +261,7 @@ ifeq ($(TARGET),amiga)
NETSURF_AMIGA_USE_CAIRO := YES
# Optimisation levels
- CFLAGS += -O2 -Wuninitialized
+ CFLAGS += -O2 -Wuninitialized -gstabs
endif
-----------------------------------------------------------------------
Summary of changes:
Makefile.defaults | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/Makefile.defaults b/Makefile.defaults
index 8ee569c..9a8d207 100644
--- a/Makefile.defaults
+++ b/Makefile.defaults
@@ -261,7 +261,7 @@ ifeq ($(TARGET),amiga)
NETSURF_AMIGA_USE_CAIRO := YES
# Optimisation levels
- CFLAGS += -O2 -Wuninitialized
+ CFLAGS += -O2 -Wuninitialized -gstabs
endif
--
NetSurf Browser
10 years, 12 months