summaryrefslogtreecommitdiff
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
parent599c4eca7ced6d3dcb08c95c743b411a61bed289 (diff)
downloadlibnsfb-1a1da46f6bc8bbb35afd29b49361107e954bfafa.tar.gz
libnsfb-1a1da46f6bc8bbb35afd29b49361107e954bfafa.tar.bz2
A few tidyups.
-rw-r--r--include/palette.h37
-rw-r--r--src/plot/common.c19
2 files changed, 27 insertions, 29 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;
diff --git a/src/plot/common.c b/src/plot/common.c
index 3aa36cd..063f68d 100644
--- a/src/plot/common.c
+++ b/src/plot/common.c
@@ -496,8 +496,6 @@ bitmap_tiles_x(nsfb_t *nsfb,
const nsfb_bbox_t *loc,
int tiles_x,
const nsfb_colour_t *pixel,
- int bmp_width,
- int bmp_height,
int bmp_stride,
bool alpha)
{
@@ -733,15 +731,7 @@ bitmap_tiles(nsfb_t *nsfb,
}
} else {
/* Unscaled */
- if (tiles_x != 1) {
- for (ty = 0; ty < tiles_y; ty++) {
- ok &= bitmap_tiles_x(nsfb, &tloc, tiles_x,
- pixel, bmp_width, bmp_height,
- bmp_stride, alpha);
- tloc.y0 += height;
- tloc.y1 += height;
- }
- } else if (tiles_x == 1) {
+ if (tiles_x == 1 || !set_dither) {
for (ty = 0; ty < tiles_y; ty++) {
for (tx = 0; tx < tiles_x; tx++) {
ok &= bitmap(nsfb, &tloc, pixel,
@@ -755,6 +745,13 @@ bitmap_tiles(nsfb_t *nsfb,
tloc.x1 = loc->x1 + skip;
tloc.y1 += height;
}
+ } else if (tiles_x > 1) {
+ for (ty = 0; ty < tiles_y; ty++) {
+ ok &= bitmap_tiles_x(nsfb, &tloc, tiles_x,
+ pixel, bmp_stride, alpha);
+ tloc.y0 += height;
+ tloc.y1 += height;
+ }
}
}