summaryrefslogtreecommitdiff
path: root/src/plot
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2012-09-27 13:46:10 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2012-09-27 13:46:10 +0100
commit46f3c9ea3793d146337c81bf8858d99238c05e86 (patch)
tree7fd5c6aaeed21e01f8ea5565d9b65016f34657ec /src/plot
parent1983c37933d2a753c4c913527c94392682bf7b98 (diff)
downloadlibnsfb-46f3c9ea3793d146337c81bf8858d99238c05e86.tar.gz
libnsfb-46f3c9ea3793d146337c81bf8858d99238c05e86.tar.bz2
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.
Diffstat (limited to 'src/plot')
-rw-r--r--src/plot/8bpp.c32
1 files changed, 8 insertions, 24 deletions
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