summaryrefslogtreecommitdiff
path: root/src/palette.c
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2012-09-28 11:19:34 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2012-09-28 11:19:34 +0100
commit0804bb7e067e66d4b05a6c45f9736b1e20505b96 (patch)
treee6b5e4ac559963dd0767e2ed39c878202f056c0f /src/palette.c
parent46f3c9ea3793d146337c81bf8858d99238c05e86 (diff)
downloadlibnsfb-0804bb7e067e66d4b05a6c45f9736b1e20505b96.tar.gz
libnsfb-0804bb7e067e66d4b05a6c45f9736b1e20505b96.tar.bz2
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.
Diffstat (limited to 'src/palette.c')
-rw-r--r--src/palette.c32
1 files changed, 30 insertions, 2 deletions
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. */