Fast pixel blending with ARM
Algorithm to blend two RGB565 colors together
Here is an algorithm to blend two RGB565 colors together using ARM assembly. This is very efficient as it uses a minimal number of registers and executes in only 6 ARM operations.
RGB565 Channel Format
| 16-bit RGB565 | |||
| Red - 5 |
Green - 5 |
Blue - 5 |
|
Color blender example
| Red - | 0xF800 | |
| + | White | 0xFFDF |
| = | Pink | 0xFBCF |
Code
# Average two RBG565 format colors together
#
# dst - 0x0000FFFF
# src - 0xFFFF0000
.macro blend_color_rgb565 dst, src
mov \dst, \dst, ror #11 @ Move RGB565 to GB-R 5-65
adds \dst, \src, ror #11 @ Add source color using carry for green channel overflow
mov \dst, \dst, ror #22 @ Rotate back to normal form plus shift right one for divide by two
bic \dst, \dst, #0x420 @ Clear underflowing green bit and high blue bit
orrcs \dst, \dst, #0x400 @ Use carry to add back overflowed high green bit
bic \dst, \dst, #0x80000000 @ Clear rotated underflowing blue bit
.endm
# Example
mov r0, #0xF800 @ Assign red to r0
mov r1, #0xFF00
orr r1, r1, 0x00DF @ Assign white to r1
# Call macro to blend colors together
blend_color_rgb565 r0, r1
# Use blended color r0 for application...