From 46f3c9ea3793d146337c81bf8858d99238c05e86 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Thu, 27 Sep 2012 13:46:10 +0100 Subject: 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. --- src/plot/8bpp.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) (limited to 'src/plot') 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 #include #include -#include #include #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 -- cgit v1.2.3