summaryrefslogtreecommitdiff
path: root/include/palette.h
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2013-10-30 08:24:50 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2013-10-30 08:24:50 +0000
commit1a1da46f6bc8bbb35afd29b49361107e954bfafa (patch)
tree192ddb2c90835b38c806112011b77e485b54aa46 /include/palette.h
parent599c4eca7ced6d3dcb08c95c743b411a61bed289 (diff)
downloadlibnsfb-1a1da46f6bc8bbb35afd29b49361107e954bfafa.tar.gz
libnsfb-1a1da46f6bc8bbb35afd29b49361107e954bfafa.tar.bz2
A few tidyups.
Diffstat (limited to 'include/palette.h')
-rw-r--r--include/palette.h37
1 files changed, 19 insertions, 18 deletions
diff --git a/include/palette.h b/include/palette.h
index 04bdd4f..a853254 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -145,6 +145,7 @@ static inline uint8_t nsfb_palette_best_match_dither(
int current;
int error;
int width = palette->dither_ctx.width;
+ int *data = palette->dither_ctx.data;
uint8_t best_col_index;
if (palette == NULL)
@@ -156,9 +157,9 @@ static inline uint8_t nsfb_palette_best_match_dither(
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];
+ r = ( c & 0xFF) + data[current ];
+ g = ((c >> 8) & 0xFF) + data[current + 1];
+ b = ((c >> 16) & 0xFF) + data[current + 2];
/* Clamp new RGB components to range */
if (r < 0) r = 0;
@@ -169,9 +170,9 @@ static inline uint8_t nsfb_palette_best_match_dither(
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;
+ data[current ] = 0;
+ data[current + 1] = 0;
+ data[current + 2] = 0;
/* Rebuild colour from modified components */
c = r + (g << 8) + (b << 16);
@@ -196,9 +197,9 @@ static inline uint8_t nsfb_palette_best_match_dither(
/* 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;
+ data[error ] += r * 7 / 16;
+ data[error + 1] += g * 7 / 16;
+ data[error + 2] += b * 7 / 16;
}
error += width - 2 * 3;
@@ -207,18 +208,18 @@ static inline uint8_t nsfb_palette_best_match_dither(
/* 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;
+ data[error ] += r * 3 / 16;
+ data[error + 1] += g * 3 / 16;
+ 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;
+ data[error ] += r * 5 / 16;
+ data[error + 1] += g * 5 / 16;
+ data[error + 2] += b * 5 / 16;
error += 3;
if (error >= width)
@@ -226,9 +227,9 @@ static inline uint8_t nsfb_palette_best_match_dither(
/* 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;
+ data[error ] += r / 16;
+ data[error + 1] += g / 16;
+ data[error + 2] += b / 16;
}
return best_col_index;