summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-10-28 21:06:38 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-10-28 21:06:38 +0000
commit35df6a39826009e8dd7ec9d2724afcdca5789e10 (patch)
treed9cfd0515fa99bcf2c12ec14af6e5c40969d1f0f
parent23ec9ceb5bb32a5348f8491243d41a14564c71f5 (diff)
downloadlibnsfb-35df6a39826009e8dd7ec9d2724afcdca5789e10.tar.gz
libnsfb-35df6a39826009e8dd7ec9d2724afcdca5789e10.tar.bz2
Test if we're dithering already before turning it on. (No functional change atm, but when bitmap tiling is moved into nsfb, error diffusion will be able to cross tile boundaries.)
-rw-r--r--include/palette.h7
-rw-r--r--src/plot/common.c20
2 files changed, 20 insertions, 7 deletions
diff --git a/include/palette.h b/include/palette.h
index a4b9f77..04bdd4f 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -28,7 +28,7 @@ struct nsfb_palette_s {
uint8_t last; /**< Last used palette index */
nsfb_colour_t data[256]; /**< Palette for index modes */
- bool dither; /**< Whether to use error diffusion */
+ bool dither; /**< Whether error diffusion was requested */
struct {
int width; /**< Length of error value buffer ring*/
int current; /**< Current pos in ring buffer*/
@@ -53,6 +53,11 @@ 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 bool nsfb_palette_dithering_on(struct nsfb_palette_s *palette)
+{
+ return palette->dither;
+}
+
/** 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)
diff --git a/src/plot/common.c b/src/plot/common.c
index f8c4a70..998e3a6 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -249,6 +249,7 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
int dxr, dyr; /* scale factor (remainder) */
int rx, ry, rxs; /* remainder trackers */
nsfb_bbox_t clipped; /* clipped display */
+ bool set_dither = false; /* true iff we enabled dithering here */
/* The part of the scaled image actually displayed is cropped to the
* current context. */
@@ -272,8 +273,11 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
else
rwidth = width;
- if (nsfb->palette != NULL) {
+ /* Enable error diffusion for paletted screens, if not already on */
+ if (nsfb->palette != NULL &&
+ nsfb_palette_dithering_on(nsfb->palette) == false) {
nsfb_palette_dither_init(nsfb->palette, rwidth);
+ set_dither = true;
}
/* get veritcal (y) and horizontal (x) scale factors; both integer
@@ -379,7 +383,7 @@ static bool bitmap_scaled(nsfb_t *nsfb, const nsfb_bbox_t *loc,
}
}
- if (nsfb->palette != NULL) {
+ if (set_dither) {
nsfb_palette_dither_fini(nsfb->palette);
}
@@ -404,6 +408,7 @@ bitmap(nsfb_t *nsfb,
int width = loc->x1 - loc->x0;
int height = loc->y1 - loc->y0;
nsfb_bbox_t clipped; /* clipped display */
+ bool set_dither = false; /* true iff we enabled dithering here */
if (width == 0 || height == 0)
return true;
@@ -429,9 +434,12 @@ 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);
- }
+ /* Enable error diffusion for paletted screens, if not already on */
+ if (nsfb->palette != NULL &&
+ nsfb_palette_dithering_on(nsfb->palette) == false) {
+ nsfb_palette_dither_init(nsfb->palette, width);
+ set_dither = true;
+ }
xoff = clipped.x0 - x;
yoff = (clipped.y0 - y) * bmp_stride;
@@ -476,7 +484,7 @@ bitmap(nsfb_t *nsfb,
}
}
- if (nsfb->palette != NULL) {
+ if (set_dither) {
nsfb_palette_dither_fini(nsfb->palette);
}