Gitweb links:
...log
http://git.netsurf-browser.org/libnsfb.git/shortlog/797266ea930ca103e7fa7...
...commit
http://git.netsurf-browser.org/libnsfb.git/commit/797266ea930ca103e7fa7a2...
...tree
http://git.netsurf-browser.org/libnsfb.git/tree/797266ea930ca103e7fa7a2e6...
The branch, master has been updated
via 797266ea930ca103e7fa7a2e683158d935683f8f (commit)
from 8e262181e6f85bc89dfed652d971a876c7e6e153 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnsfb.git/commit/?id=797266ea930ca103e7f...
commit 797266ea930ca103e7fa7a2e683158d935683f8f
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Avoid repeating some calculations.
diff --git a/include/palette.h b/include/palette.h
index b48d5f3..a4b9f77 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -66,18 +66,22 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
int cur_distance;
int best_distance = INT_MAX;
+ int r = ( c & 0xFF);
+ int g = ((c >> 8) & 0xFF);
+ int b = ((c >> 16) & 0xFF);
+
switch (palette->type) {
case NSFB_PALETTE_NSFB_8BPP:
/* Index into colour cube part */
- dr = ((( c & 0xFF) * 5) + 128) / 256;
- dg = ((((c >> 8) & 0xFF) * 7) + 128) / 256;
- db = ((((c >> 16) & 0xFF) * 4) + 128) / 256;
+ dr = ((r * 5) + 128) / 256;
+ dg = ((g * 7) + 128) / 256;
+ db = ((b * 4) + 128) / 256;
col = 40 * dr + 5 * dg + db;
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8 ) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - ( palent & 0xFF);
+ dg = g - ((palent >> 8) & 0xFF);
+ db = b - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
best_col = col;
@@ -87,14 +91,12 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
*b_error = db;
/* Index into grayscale part */
- col = (( c & 0xFF) +
- ((c >> 8) & 0xFF) +
- ((c >> 16) & 0xFF) + (45 / 2)) / (15 * 3) - 1 + 240;
+ col = (r + g + b + (45 / 2)) / (15 * 3) - 1 + 240;
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - (palent & 0xFF);
+ dg = g - (palent & 0xFF);
+ db = b - (palent & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_col = col;
@@ -109,9 +111,9 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
for (col = 0; col <= palette->last; col++) {
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - ( palent & 0xFF);
+ dg = g - ((palent >> 8) & 0xFF);
+ db = b - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_distance = cur_distance;
-----------------------------------------------------------------------
Summary of changes:
include/palette.h | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/include/palette.h b/include/palette.h
index b48d5f3..a4b9f77 100644
--- a/include/palette.h
+++ b/include/palette.h
@@ -66,18 +66,22 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
int cur_distance;
int best_distance = INT_MAX;
+ int r = ( c & 0xFF);
+ int g = ((c >> 8) & 0xFF);
+ int b = ((c >> 16) & 0xFF);
+
switch (palette->type) {
case NSFB_PALETTE_NSFB_8BPP:
/* Index into colour cube part */
- dr = ((( c & 0xFF) * 5) + 128) / 256;
- dg = ((((c >> 8) & 0xFF) * 7) + 128) / 256;
- db = ((((c >> 16) & 0xFF) * 4) + 128) / 256;
+ dr = ((r * 5) + 128) / 256;
+ dg = ((g * 7) + 128) / 256;
+ db = ((b * 4) + 128) / 256;
col = 40 * dr + 5 * dg + db;
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8 ) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - ( palent & 0xFF);
+ dg = g - ((palent >> 8) & 0xFF);
+ db = b - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
best_col = col;
@@ -87,14 +91,12 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
*b_error = db;
/* Index into grayscale part */
- col = (( c & 0xFF) +
- ((c >> 8) & 0xFF) +
- ((c >> 16) & 0xFF) + (45 / 2)) / (15 * 3) - 1 + 240;
+ col = (r + g + b + (45 / 2)) / (15 * 3) - 1 + 240;
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - (palent & 0xFF);
+ dg = g - (palent & 0xFF);
+ db = b - (palent & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_col = col;
@@ -109,9 +111,9 @@ static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s
*palette,
for (col = 0; col <= palette->last; col++) {
palent = palette->data[col];
- dr = ( c & 0xFF) - ( palent & 0xFF);
- dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
- db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
+ dr = r - ( palent & 0xFF);
+ dg = g - ((palent >> 8) & 0xFF);
+ db = b - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_distance = cur_distance;
--
NetSurf Framebuffer library