summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-02-22 21:41:44 +0000
committerJens Arnold <amiconn@rockbox.org>2006-02-22 21:41:44 +0000
commite6dac9130d62688d7b547b6a7fcdb9b956d9bb04 (patch)
tree0996daa908f5f87b13e91836916c324de546ab16 /firmware
parent6922e80c9e38c515ed6254d927d10431e1009193 (diff)
downloadrockbox-e6dac9130d62688d7b547b6a7fcdb9b956d9bb04.tar.gz
rockbox-e6dac9130d62688d7b547b6a7fcdb9b956d9bb04.tar.bz2
rockbox-e6dac9130d62688d7b547b6a7fcdb9b956d9bb04.zip
Made LCD_RGBPACK() macro more efficient when used with variable arguments.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8789 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/lcd.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/firmware/export/lcd.h b/firmware/export/lcd.h
index 87dda891b9..ba0e216990 100644
--- a/firmware/export/lcd.h
+++ b/firmware/export/lcd.h
@@ -150,9 +150,11 @@ typedef void lcd_fastpixelfunc_type(fb_data *address);
#define LCD_MAX_RED 31
#define LCD_MAX_GREEN 63
#define LCD_MAX_BLUE 31
-#define _RGBPACK(r, g, b) ( ((((r) * 31 + 127) / 255) << 11) \
- |((((g) * 63 + 127) / 255) << 5) \
- | (((b) * 31 + 127) / 255))
+#define _RGBPACK(r, g, b) ( ((((r) * (31*257) + (127*257)) >> 16) << 11) \
+ |((((g) * (63*257) + (127*257)) >> 16) << 5) \
+ | (((b) * (31*257) + (127*257)) >> 16))
+/* Note: ((x * 257) >> 16) almost equals (x / 255), but it avoids the division,
+ * so it's faster when the macro is used for variable r, g, b in the source. */
#if (LCD_PIXELFORMAT == RGB565SWAPPED)
#define LCD_RGBPACK(r, g, b) ( ((_RGBPACK((r), (g), (b)) & 0xff00) >> 8) \
|((_RGBPACK((r), (g), (b)) & 0x00ff) << 8))
@@ -163,9 +165,9 @@ typedef void lcd_fastpixelfunc_type(fb_data *address);
#define LCD_MAX_RED 63
#define LCD_MAX_GREEN 63
#define LCD_MAX_BLUE 63
-#define LCD_RGBPACK(r, g, b) ( ((((r) * 63 + 127) / 255) << 12) \
- |((((g) * 63 + 127) / 255) << 6) \
- | (((b) * 63 + 127) / 255))
+#define LCD_RGBPACK(r, g, b) ( ((((r) * (63*257) + (127*257)) >> 16) << 12) \
+ |((((g) * (63*257) + (127*257)) >> 16) << 6) \
+ | (((b) * (63*257) + (127*257)) >> 16))
#else
/* other colour depths */
#endif