aboutsummaryrefslogtreecommitdiff
path: root/source/gfx.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/gfx.h')
-rw-r--r--source/gfx.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/source/gfx.h b/source/gfx.h
index 2a5c6f9..8586cb6 100644
--- a/source/gfx.h
+++ b/source/gfx.h
@@ -130,10 +130,24 @@ extern uint16_t DirectColourMaps [8][256];
extern uint8_t mul_brightness [16][32];
/* Could use BSWAP instruction on Intel port... */
+#ifdef ARM_ASM
+// by Harald Kipp, from http://www.ethernut.de/en/documents/arm-inline-asm.html
+#define SWAP_DWORD(val) \
+ __asm__ __volatile__ ( \
+ "eor r3, %1, %1, ror #16\n\t" \
+ "bic r3, r3, #0x00FF0000\n\t" \
+ "mov %0, %1, ror #8\n\t" \
+ "eor %0, %0, r3, lsr #8" \
+ : "=r" (val) \
+ : "0"(val) \
+ : "r3", "cc" \
+ );
+#else
#define SWAP_DWORD(dword) dword = ((((dword) & 0x000000ff) << 24) \
| (((dword) & 0x0000ff00) << 8) \
| (((dword) & 0x00ff0000) >> 8) \
| (((dword) & 0xff000000) >> 24))
+#endif
#ifdef FAST_LSB_WORD_ACCESS
#define READ_2BYTES(s) (*(uint16_t *) (s))
@@ -159,6 +173,19 @@ static INLINE uint16_t COLOR_ADD(uint16_t C1, uint16_t C2)
return C1;
else
return GFX.X2[(((C1 & RGB_REMOVE_LOW_BITS_MASK) + (C2 & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + (C1 & C2 & RGB_LOW_BITS_MASK)] | ((C1 ^ C2) & RGB_LOW_BITS_MASK);
+#elif PIXEL_FORMAT == RGB565
+ int sum, low_bits, carries, modulo, clamp;
+ if (C1 == 0)
+ return C2;
+ else if (C2 == 0)
+ return C1;
+
+ sum = C1 + C2;
+ low_bits = (C1 ^ C2) & 0x0821;
+ carries = (sum - low_bits) & 0x10820;
+ modulo = sum - carries;
+ clamp = carries - (carries >> 5);
+ return modulo | clamp;
#else
const int RED_MASK = 0x1F << RED_SHIFT_BITS;
const int GREEN_MASK = 0x1F << GREEN_SHIFT_BITS;
@@ -178,10 +205,14 @@ static INLINE uint16_t COLOR_ADD(uint16_t C1, uint16_t C2)
#endif
}
+#if defined(USE_OLD_COLOUR_OPS) || PIXEL_FORMAT != RGB565
#define COLOR_ADD1_2(C1, C2) \
(((((C1) & RGB_REMOVE_LOW_BITS_MASK) + \
((C2) & RGB_REMOVE_LOW_BITS_MASK)) >> 1) + \
(((C1) & (C2) & RGB_LOW_BITS_MASK) | ALPHA_BITS_MASK))
+#else
+#define COLOR_ADD1_2(C1, C2) ((C1) == (C2) ? (C1) : (((C1) + (C2) - (((C1) ^ (C2)) & 0x0821)) >> 1))
+#endif
#if defined(USE_OLD_COLOUR_OPS)
/* Pre-1.60 colour operations */
@@ -193,6 +224,20 @@ static INLINE uint16_t COLOR_ADD(uint16_t C1, uint16_t C2)
#else
static INLINE uint16_t COLOR_SUB(uint16_t C1, uint16_t C2)
{
+#if PIXEL_FORMAT == RGB565
+ int diff, low_bits, borrows, modulo, clamp;
+ if (C1 == 0)
+ return 0;
+ else if (C2 == 0)
+ return C1;
+
+ diff = C1 - C2 + 0x10820;
+ low_bits = (C1 ^ C2) & 0x10820;
+ borrows = (diff - low_bits) & 0x10820;
+ modulo = diff - borrows;
+ clamp = borrows - (borrows >> 5);
+ return modulo & clamp;
+#else
int rb1 = (C1 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK)) | ((0x20 << 0) | (0x20 << RED_SHIFT_BITS));
int rb2 = C2 & (THIRD_COLOR_MASK | FIRST_COLOR_MASK);
int rb = rb1 - rb2;
@@ -206,6 +251,7 @@ static INLINE uint16_t COLOR_SUB(uint16_t C1, uint16_t C2)
#endif
return retval;
+#endif
}
#endif