Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2-bit icons #41

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
65ae2a3
Add simple support for 2 bit icons
MarkusEngsner Mar 17, 2021
b5e8baf
Add support for custom 2 bit coloring
MarkusEngsner Mar 17, 2021
ae64978
Add transparency support to 2 bit drawing
MarkusEngsner Mar 17, 2021
0e88b64
Add tests for Draw2BitIcon()
MarkusEngsner Mar 17, 2021
4be8a03
Update variable naming to adhere to conventions
MarkusEngsner Mar 17, 2021
5cbd1c2
Implement Linear Interpolation for Draw2BitIcon()
MarkusEngsner Mar 19, 2021
9135a15
Add documentation regarding Draw2BitIcon
MarkusEngsner Mar 19, 2021
f0a6c49
Add more efficient color blending implementation
MarkusEngsner Mar 19, 2021
91d6437
Merge pull request #1 from MarkusEngsner/better_alpha_blending
MarkusEngsner Mar 19, 2021
630e857
Remove unused functions, add comments
MarkusEngsner Apr 6, 2021
7cf90a6
Remove unused imports
MarkusEngsner Apr 6, 2021
504dd17
Add debug painter support
MarkusEngsner Apr 6, 2021
c0c67e6
Fix Draw2BitIcon signature
MarkusEngsner Apr 6, 2021
433365f
Fix Draw2BitIcon tests
MarkusEngsner Apr 6, 2021
7eda424
Add Alpha blending tests
MarkusEngsner Apr 6, 2021
9cd654a
Add GetColor() test, fix Draw2BitIcon tests
MarkusEngsner Apr 6, 2021
7cc30ff
Remove unnecessary import
MarkusEngsner Apr 6, 2021
b7ab8d1
Update info file
MarkusEngsner Apr 6, 2021
f48db96
Move AlphaBlend into utils
MarkusEngsner Apr 6, 2021
e4e1329
Move GetColor() into painter, update tests
MarkusEngsner Apr 6, 2021
a4e80a5
Update info file about function placements
MarkusEngsner Apr 6, 2021
29ee014
Remove array import from IPainter.h
MarkusEngsner Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AXIOM_Remote_Firmware_Visualizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ FILE(GLOB FIRMWARE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/UI/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/Attribute.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/CentralDB.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/CentralDBObserver.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/GlobalSettings.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/GlobalSettings.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/Utils.cpp")
MESSAGE(STATUS "Firmware files: ${FIRMWARE_SOURCES}")

#FILE(GLOB BOOTLOADER_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../Bootloader/Periphery/USB/*.cpp")
Expand Down
42 changes: 42 additions & 0 deletions Firmware/Media/Icons/HelpIcon2Bit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef HELPICON2BIT_H
#define HELPICON2BIT_H

#include "../../UI/Widgets/Icon.h"

const Icon STATIC_SECTION HelpIcon2Bit = {
48, 48,
(const uint8_t[]){
0x0, 0x0, 0x0, 0x0, 0x40, 0xea, 0xab, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe4, 0xff,
0xff, 0x1b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xfe, 0xff, 0xff, 0xbf, 0x1, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0xd0, 0xff, 0xaf, 0xfa, 0xff, 0x7, 0x0, 0x0, 0x0, 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, 0x0, 0x0, 0x0, 0xe0,
0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe0, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0xe0, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40,
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x90, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0xe0, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe0,
0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x90, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0}};

#endif // HELPICON2BIT_H
25 changes: 25 additions & 0 deletions Firmware/Media/Icons/HomeIcon2Bit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef HOME_ICON2BIT_H
#define HOME_ICON2BIT_H

#include "../../UI/Widgets/Icon.h"

const Icon STATIC_SECTION HomeIcon2Bit = {
32, 32,
(const uint8_t[]){0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x1, 0x40, 0x15, 0x0,
0x0, 0x0, 0x0, 0xf0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54, 0x55, 0x1, 0x40, 0x55, 0x15, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}};

#endif // HOME_ICON2BIT_H
2 changes: 2 additions & 0 deletions Firmware/UI/Painter/IPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class IPainter
virtual void DrawImage(const uint8_t* data, uint16_t x, uint16_t y, uint16_t width, uint16_t height) = 0;
virtual void DrawPixel(uint16_t x, uint16_t y, uint16_t color) = 0;
virtual void DrawIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t color) = 0;
virtual void Draw2BitIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t foregroundColor,
uint16_t backgroundColor, bool transparency) = 0;
virtual void Fill(uint16_t fillColor) = 0;
virtual void Dim() = 0;

Expand Down
54 changes: 53 additions & 1 deletion Firmware/UI/Painter/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,39 @@ void Painter::DrawIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t color
_debugPainter->DrawIcon(this, image, x, y, color);
}
}

/*****************************************/

void Painter::Draw2BitIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t foregroundColor,
uint16_t backgroundColor, bool transparency)
{
// Note: Since icon is 2bit, Icon->Data should contain (Width * Height / 4) bytes.
for (uint16_t yIndex = 0; yIndex < image->Height; yIndex++)
{
const uint16_t yPos = y + yIndex;
for (uint16_t xIndex = 0; xIndex < image->Width; xIndex++)
{
const uint16_t xPos = x + xIndex;
const uint8_t currentByte = image->Data[(yIndex * image->Width + xIndex) >> 2];
const uint8_t currentBitNumber = 2 * (xIndex & 0x3); // Where in the byte the current bits are stored.
// The representation of the current pixel in the Icon array.
const uint8_t colorBits = (currentByte >> currentBitNumber) & 0x3;

// // Don't draw anything if it's already the correct color.
if (!(transparency && colorBits == 0))
{
const uint16_t bgColorToUse = transparency ? GetPixel(xPos, yPos) : backgroundColor;
const uint16_t newColor = GetColor(foregroundColor, bgColorToUse, colorBits);

DrawPixel(xPos, yPos, newColor);
}
}
}
if (_debugPainter != nullptr)
{
_debugPainter->DrawIcon(this, image, x, y, foregroundColor);
}
}

// uint8_t count = 0;

void Painter::DrawText(uint16_t x, uint16_t y, const char* text, uint16_t color, TextAlign align,
Expand Down Expand Up @@ -624,3 +654,25 @@ uint16_t Painter::ProcessByte(uint8_t data, uint16_t x, uint16_t xIndex, uint16_

return xIndex;
}

uint16_t Painter::GetPixel(uint16_t x, uint16_t y)
{
// TODO: add index checks?
return _framebuffer[y * _framebufferWidth + x];
}

uint16_t Painter::GetColor(uint16_t foregroundColor, uint16_t backgroundColor, uint8_t color_bits)
{
// TODO: add support for custom Lerp-points for 0x2 and 0x1
switch (color_bits)
{
case 0x3:
return foregroundColor;
case 0x2:
return utils::AlphaBlend(foregroundColor, backgroundColor, 178);
case 0x1:
return utils::AlphaBlend(foregroundColor, backgroundColor, 76);
default:
return backgroundColor;
}
}
4 changes: 4 additions & 0 deletions Firmware/UI/Painter/Painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Painter : public IPainter
void DrawPixel(uint16_t x, uint16_t y, uint16_t color) override;
virtual void DrawIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t color) override;
uint16_t ProcessByte(uint8_t data, uint16_t x, uint16_t xIndex, uint16_t yPos, uint16_t height, uint16_t color);
virtual void Draw2BitIcon(const Icon* image, uint16_t x, uint16_t y, uint16_t foregroundColor,
uint16_t backgroundColor, bool transparency) override;
uint16_t GetColor(uint16_t foregroundColor, uint16_t backgroundColor, uint8_t color_bits);
uint16_t GetPixel(uint16_t x, uint16_t y);
void Fill(uint16_t fillColor) override;
void Dim() override;

Expand Down
4 changes: 4 additions & 0 deletions Firmware/UI/Screens/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void MainPage::Draw(IPainter* painter)
{
painter->DrawIcon(&ApertusTextLogo, 58, 89, RGB565(194, 191, 188));
painter->DrawIcon(&ApertusRingLogo, 58 + ApertusTextLogo.Width, 89, RGB565(244, 114, 72));
painter->Draw2BitIcon(&HomeIcon2Bit, 10, 124, static_cast<uint16_t>(Color565::Orange),
static_cast<uint16_t>(Color565::Black), false);
painter->Draw2BitIcon(&HomeIcon2Bit, 50, 124, static_cast<uint16_t>(Color565::Cyan), 0, true);

for (uint8_t index = 0; index < 6; index++)
{
Expand All @@ -73,6 +76,7 @@ void MainPage::Draw(IPainter* painter)

widget->Draw(painter);
}
painter->Draw2BitIcon(&HelpIcon2Bit, 110, 170, static_cast<uint16_t>(Color565::Cyan), 0, true);
}

void MainPage::Update(Button button, int8_t knob, IMenuSystem* menuSystem)
Expand Down
2 changes: 2 additions & 0 deletions Firmware/UI/Screens/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "../../Media/Icons/ApertusTextLogo.h"
#include "../../Media/Icons/ApertusRingLogo.h"
#include "../../Media/Icons/HomeIcon2Bit.h"
#include "../../Media/Icons/HelpIcon2Bit.h"

#include "../ButtonDefinitions.h"

Expand Down
36 changes: 36 additions & 0 deletions Firmware/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "Utils.h"

/* fg: The foreground color
* bg: The background color
* alpha: how much of the foreground color that should be used: 0-255
* returns: a blended color between foreground and background
*/
uint16_t utils::AlphaBlend(uint16_t fg, uint16_t bg, uint8_t alpha)
{
// Source: https://stackoverflow.com/a/19068028
constexpr uint16_t maskRB = 63519U; // 0b1111100000011111, the red and blue bits
constexpr uint16_t maskG = 2016U; // 0b0000011111100000, the green bits
constexpr uint32_t maskMulRB = 4065216U; // 0b1111100000011111000000, the red and blue bits after multiplication
constexpr uint32_t maskMulG = 129024U; // 0b0000011111100000000000, the green bits after multiplication
constexpr uint16_t maxAlpha = 64U; // 6bits+1 with rounding: [0, 64]
/* Explanation of "6 bits + 1":
* If alpha > 6 bits, the blue bits get shifted into the red part
* This is only fine if all of the red bits have been shifted further,
* ie. only when alpha = 0b1_000_000
* Hence 6 bits + 1.
*/

alpha = (alpha + 2) >> 2; // convert from 8bit to (6bit+1) with rounding
const uint8_t beta = maxAlpha - alpha;

// The trick here is to perform the computations on the red and blue channels
// together, since there is no risk of bit overlap.
const uint32_t foreRB = static_cast<uint32_t>(fg & maskRB);
const uint32_t backRB = static_cast<uint32_t>(bg & maskRB);
const uint32_t redBlue = (alpha * foreRB + beta * backRB) & maskMulRB;
const uint32_t foreG = fg & maskG;
const uint32_t backG = bg & maskG;
const uint32_t green = (alpha * foreG + beta * backG) & maskMulG;

return (redBlue | green) >> 6; // divide by maxAlpha
}
2 changes: 2 additions & 0 deletions Firmware/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ static inline int8_t LimitRange(int8_t in, int8_t min, int8_t max)

namespace utils
{
uint16_t AlphaBlend(uint16_t fg, uint16_t bg, uint8_t alpha);

inline void CopyString(char* destination, const char* source, const size_t max_size)
{
memset(destination, 0, max_size);
Expand Down
3 changes: 2 additions & 1 deletion FirmwareTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ FILE(GLOB FIRMWARE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/UI/*.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/Attribute.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/CentralDB.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/CentralDBObserver.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/GlobalSettings.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/GlobalSettings.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../Firmware/Utils.cpp")

SET(TEST_SOURCES Main.cpp PainterTest.cpp MenuSystemTest.cpp CentralDBObserverTest.cpp)

Expand Down
10 changes: 10 additions & 0 deletions FirmwareTest/Images/Test2BitLine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef TEST_2_BIT_LINE_H
#define TEST_2_BIT_LINE_H

#include <stdint.h>

const Icon STATIC_SECTION Test2BitLine = {
8, 8,
(const uint8_t[]){0xff, 0x82, 0xff, 0xe1, 0xff, 0x82, 0xff, 0xe1, 0xff, 0x82, 0xff, 0xe1, 0xff, 0x82, 0xff, 0xe1}};

#endif // TEST_2_BIT_LINE_H
36 changes: 36 additions & 0 deletions FirmwareTest/Images/Test2BitLineOutput.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef TEST_2_BIT_LINE_OUTPUT_H
#define TEST_2_BIT_LINE_OUTPUT_H

#include <stdint.h>
#include <map>
#include "../../Firmware/Utils.h"

constexpr uint16_t Test2BitBGColor = 0x22;
constexpr uint16_t Test2BitFGColor = 0x111;
constexpr uint16_t Test2BitTransparentColor = 0x0;

constexpr uint8_t lowLerpThres = 76U;
constexpr uint8_t highLerpThres = 178U;

const std::map<uint8_t, uint16_t> noTransmapping{
{0x0, Test2BitBGColor},
{0x1, utils::AlphaBlend(Test2BitFGColor, Test2BitBGColor, lowLerpThres)},
{0x2, utils::AlphaBlend(Test2BitFGColor, Test2BitBGColor, highLerpThres)},
{0x3, Test2BitFGColor}};

const std::map<uint8_t, uint16_t> withTransMapping{
{0x0, Test2BitTransparentColor},
{0x1, utils::AlphaBlend(Test2BitFGColor, Test2BitTransparentColor, lowLerpThres)},
{0x2, utils::AlphaBlend(Test2BitFGColor, Test2BitTransparentColor, highLerpThres)},
{0x3, Test2BitFGColor}};

// The Test2Icon, with each pixel stored as an element.
// Makes it easier to check the results.
uint8_t Test2BitFramebufferRepr[] = {
0x3, 0x3, 0x3, 0x3, 0x2, 0x0, 0x0, 0x2, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 0x2, 0x3, // 2 rows here
0x3, 0x3, 0x3, 0x3, 0x2, 0x0, 0x0, 0x2, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 0x2, 0x3,
0x3, 0x3, 0x3, 0x3, 0x2, 0x0, 0x0, 0x2, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 0x2, 0x3,
0x3, 0x3, 0x3, 0x3, 0x2, 0x0, 0x0, 0x2, 0x3, 0x3, 0x3, 0x3, 0x1, 0x0, 0x2, 0x3,
};

#endif // TEST_2_BIT_LINE_OUTPUT_H
Loading