Skip to content

Commit ba98925

Browse files
committed
hard code 0 and 255 alpha levels
1 parent 37ad4b1 commit ba98925

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

libraries/pico_graphics/pico_graphics_pen_rgb565.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,30 @@ namespace pimoroni {
5454
uint16_t dest = *pdest;
5555
uint8_t alpha = *palpha >> 3;
5656

57-
// blend tha pixel
58-
// expand the pen colour to provide space to multiple all
59-
// channels at once
60-
uint32_t cs = 0;
61-
cs |= ((color & 0b1111100000000000) << 11); // red
62-
cs |= ((color & 0b0000011111100000) << 5); // green
63-
cs |= ((color & 0b0000000000011111) ); // blue
57+
if(alpha == 255) {
58+
*pdest = color;
59+
}if(alpha == 0) {
60+
}else{
61+
// blend tha pixel
62+
// expand the pen colour to provide space to multiple all
63+
// channels at once
64+
uint32_t cs = 0;
65+
cs |= ((color & 0b1111100000000000) << 11); // red
66+
cs |= ((color & 0b0000011111100000) << 5); // green
67+
cs |= ((color & 0b0000000000011111) ); // blue
6468

65-
uint32_t cd = 0;
66-
cd |= ((dest & 0b1111100000000000) << 11); // red
67-
cd |= ((dest & 0b0000011111100000) << 5); // green
68-
cd |= ((dest & 0b0000000000011111) ); // blue
69+
uint32_t cd = 0;
70+
cd |= ((dest & 0b1111100000000000) << 11); // red
71+
cd |= ((dest & 0b0000011111100000) << 5); // green
72+
cd |= ((dest & 0b0000000000011111) ); // blue
6973

70-
uint32_t cr = ((cs * alpha) + (cd * (31 - alpha)))>> 5;
74+
uint32_t cr = ((cs * alpha) + (cd * (31 - alpha)))>> 5;
7175

72-
// recombine the channels
73-
*pdest = ((cr >> 27) & 0b1111100000000000);
74-
*pdest |= ((cr >> 11) & 0b0000011111100000);
75-
*pdest |= ((cr >> 5) & 0b0000000000011111);
76+
// recombine the channels
77+
*pdest = ((cr >> 27) & 0b1111100000000000);
78+
*pdest |= ((cr >> 11) & 0b0000011111100000);
79+
*pdest |= ((cr >> 5) & 0b0000000000011111);
80+
}
7681

7782
pdest++;
7883
palpha++;

0 commit comments

Comments
 (0)