Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
8 changes: 6 additions & 2 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5847,14 +5847,18 @@ uint16_t mode_2Dscrollingtext(void) {

int letterWidth;
int letterHeight;
switch (map(SEGMENT.custom2, 0, 255, 1, 5)) {
switch (map(SEGMENT.custom2, 0, 255, 1, 9)) {
default:
case 1: letterWidth = 4; letterHeight = 6; break;
case 2: letterWidth = 5; letterHeight = 8; break;
case 3: letterWidth = 6; letterHeight = 8; break;
case 4: letterWidth = 7; letterHeight = 9; break;
case 5: letterWidth = 5; letterHeight = 12; break;
}
case 6: letterWidth = 12; letterHeight = 16; break;
case 7: letterWidth = 12; letterHeight = 24; break;
case 8: letterWidth = 16; letterHeight = 32; break;
case 9: letterWidth = 25; letterHeight = 57; break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to use characters with height above 32 as matrices with such dimensions become unmanageable.
Also font memory footprint becomes very large and we want to avoid that.

}
const bool zero = SEGMENT.check3;
const int yoffset = map(SEGMENT.intensity, 0, 255, -rows/2, rows/2) + (rows-letterHeight)/2;
char text[WLED_MAX_SEGNAME_LEN+1] = {'\0'};
Expand Down
59 changes: 46 additions & 13 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,40 +562,73 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
#include "src/font/console_font_5x12.h"
#include "src/font/console_font_6x8.h"
#include "src/font/console_font_7x9.h"
#include "src/font/console_font_12x16.h"
#include "src/font/console_font_12x24.h"
#include "src/font/console_font_16x32.h"
#include "src/font/console_font_25x57.h"
Comment on lines +565 to +568
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to make large fonts optional compile.
Please accommodate that.


// draws a raster font character on canvas
// only supports: 4x6=24, 5x8=40, 5x12=60, 6x8=48 and 7x9=63 fonts ATM
// only supports: 4x6=24, 5x8=40, 5x12=60, 6x8=48, 7x9=63, 12x16=192, 16x24=288, 16x32=512 and 25x57=1425 fonts ATM
void Segment::drawCharacter(unsigned char chr, int16_t x, int16_t y, uint8_t w, uint8_t h, uint32_t color, uint32_t col2) {
if (!isActive()) return; // not active
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though we added measures elsewhere this should remain here to prevent crash if segment changes during writing to it.

if (chr < 32 || chr > 126) return; // only ASCII 32-126 supported
chr -= 32; // align with font table entries
const uint16_t cols = virtualWidth();
const uint16_t rows = virtualHeight();
const int font = w*h;
int num_bytes;

if (w <= 8) {
num_bytes = 1;
}
else if(w <= 16){
num_bytes = 2;
}
else if (w <= 24){
num_bytes = 3;
}
else if (w <= 32){
num_bytes = 4;
}
else {
return;
}
Comment on lines +580 to +591
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple switch () may be cleaner.


CRGB col = CRGB(color);
CRGBPalette16 grad = CRGBPalette16(col, col2 ? CRGB(col2) : col);

// modifications to support characters whose width is > 8 bits
//if (w<5 || w>6 || h!=8) return;
for (int i = 0; i<h; i++) { // character height
int16_t y0 = y + i;
if (y0 < 0) continue; // drawing off-screen
if (y0 >= rows) break; // drawing off-screen
uint8_t bits = 0;
const uint8_t *bits = 0;
switch (font) {
case 24: bits = pgm_read_byte_near(&console_font_4x6[(chr * h) + i]); break; // 5x8 font
case 40: bits = pgm_read_byte_near(&console_font_5x8[(chr * h) + i]); break; // 5x8 font
case 48: bits = pgm_read_byte_near(&console_font_6x8[(chr * h) + i]); break; // 6x8 font
case 63: bits = pgm_read_byte_near(&console_font_7x9[(chr * h) + i]); break; // 7x9 font
case 60: bits = pgm_read_byte_near(&console_font_5x12[(chr * h) + i]); break; // 5x12 font
case 24: bits = &console_font_4x6[(chr * h * num_bytes) + (i * num_bytes)]; break; // 5x8 font
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea to manipulate flash memory directly is bad and against recommended practices. Use bits as it was intended - a regular variable, not pointer.

case 40: bits = &console_font_5x8[(chr * h * num_bytes) + (i * num_bytes)]; break; // 5x8 font
case 48: bits = &console_font_6x8[(chr * h * num_bytes) + (i * num_bytes)]; break; // 6x8 font
case 63: bits = &console_font_7x9[(chr * h * num_bytes) + (i * num_bytes)]; break; // 7x9 font
case 60: bits = &console_font_5x12[(chr * h * num_bytes) + (i * num_bytes)]; break; // 5x12 font
case 192: bits = &console_font_12x16[(chr * h * num_bytes) + (i * num_bytes)]; break; // 12x16 font
case 288: bits = &console_font_12x24[(chr * h * num_bytes) + (i * num_bytes)]; break; // 16x24 font
case 512: bits = &console_font_16x32[(chr * h * num_bytes) + (i * num_bytes)]; break; // 16x32 font
case 1425: bits = &console_font_25x57[(chr * h * num_bytes) + (i * num_bytes)]; break; // 25x57 font
default: return;
}
col = ColorFromPalette(grad, (i+1)*255/h, 255, NOBLEND);
for (int j = 0; j<w; j++) { // character width
int16_t x0 = x + (w-1) - j;
if ((x0 >= 0 || x0 < cols) && ((bits>>(j+(8-w))) & 0x01)) { // bit set & drawing on-screen
setPixelColorXY(x0, y0, col);

int j1 = 0;
int wb = w % 8;
if(wb == 0)
wb = 8; // get width of the first byte to process
for (int k = 1; k <= num_bytes; k++) { // loop through all bytes of the character
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check fx-blending branch to see planned enhancements to scrolling text and drawCharacter() function and accomodate that.
You may need to wait until fx-blending is merged to update this PR.

col = ColorFromPalette(grad, (i+1)*255/h, 255, NOBLEND);
for (int j = 0; j<wb; j++) { // character width in this byte
int16_t x0 = x + w - j1++; // run through pixels of font right to left
if ((x0 >= 0 || x0 < cols) && ((bits[num_bytes - k]>>(j+(8-wb))) & 0x01)) { // bit set & drawing on-screen
setPixelColorXY(x0, y0, col);
}
}
wb = 8; // process 8 bits for all other bytes
}
}
}
Expand Down
Loading