Skip to content

Commit 4852123

Browse files
committed
Handling text outlines, describing errors on Rockchip
1 parent 3d8389b commit 4852123

File tree

10 files changed

+96
-18
lines changed

10 files changed

+96
-18
lines changed

doc/endpoints.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -212,28 +212,33 @@ Configures the night mode parameters.
212212

213213
Configures text or image overlays by their ID (0-9 at the moment).
214214

215-
| Method | Parameters | Description |
216-
|--------|------------|------------------------------------------------|
217-
| GET | `text` | Text to display (special specifiers supported) |
218-
| GET | `font` | Font name to be used |
219-
| GET | `size` | Font size (decimal in pt) |
220-
| GET | `color` | Color (hex format, 5-bit color precision) |
221-
| GET | `opal` | Opacity level (0-255) |
222-
| GET | `pos` | Position on main stream \[x,y\] |
223-
| GET | `posx` | X coordinate (write-only) |
224-
| GET | `posy` | Y coordinate (write-only) |
225-
| POST | file | Bitmap or PNG image to upload (replaces text) |
215+
| Method | Parameters | Description |
216+
|--------|------------|----------------------------------------------------|
217+
| GET | `text` | Text to display (special specifiers supported) |
218+
| GET | `img` | Local image path to display (`text` must be empty) |
219+
| GET | `font` | Font name to be used |
220+
| GET | `size` | Font size (decimal in pt) |
221+
| GET | `color` | Font color (hex format, RGB555 format) |
222+
| GET | `opal` | Opacity level (0-255) |
223+
| GET | `pos` | Position on main stream \[x,y\] |
224+
| GET | `posx` | X coordinate (write-only) |
225+
| GET | `posy` | Y coordinate (write-only) |
226+
| GET | `outl` | Outline color (hex format, RGB555 format) |
227+
| GET | `thick` | Outline thickness (0 to disable) |
228+
| POST | file | Bitmap or PNG image to upload (replaces text) |
226229

227230
**Response**
228231
```json
229232
{
230233
"id": 0,
231-
"color": "#ff0000",
234+
"color": "#ffff",
232235
"opal": 255,
233236
"pos": [16, 64],
234237
"font": "UbuntuMono-Regular",
235238
"size": 15.0,
236-
"text": "Backyard (%T)"
239+
"text": "Backyard (%T)",
240+
"outl": "#8000",
241+
"thick": 0.0
237242
}
238243
```
239244

doc/overlays.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Supported fonts (sourced from /usr/share/fonts/truetype/) can render Unicode cha
1414
curl http://192.168.1.17/api/osd/0?text=Entrée
1515
```
1616

17+
The text color is configurable (using a hexadecimal RGB555 representation) and can be made easier to read by applying an outline this way:
18+
```
19+
curl http://192.168.1.17/api/osd/1?color=%23FFFF&outl=%238000&thick=1.0
20+
```
21+
N.B. Hashtags have to be espaced with %23 in curl URL syntaxes
22+
1723
Empty strings are used to clear the regions:
1824
```
1925
curl http://192.168.1.17/api/osd/1?text=

res/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ <h2 class="unl">OSD</h2>
380380
<th>Position</th>
381381
<th>Font family</th>
382382
<th>Size</th>
383+
<th>Outline</th>
384+
<th>Thickness</th>
383385
<th>Text</th>
384386
<th>Local file</th>
385387
<th></th>
@@ -400,6 +402,9 @@ <h2 class="unl">OSD</h2>
400402
<td><input type="text" id="osd_font"></td>
401403
<td><input type="number" id="osd_size" step="0.1" size="3"
402404
style="width:5em"></td>
405+
<td><input type="color" id="osd_outl"></td>
406+
<td><input type="number" id="osd_thick" step="0.1" size="3"
407+
style="width:5em"></td>
403408
<td><input type="text" id="osd_text"></td>
404409
<td><input type="text" id="osd_img" placeholder="Leave empty for file uploads"></td>
405410
<td><a href="javascript:apiApply('osd')" class="btn">Apply</a></td>

src/app_config.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int save_app_config(void) {
138138
fprintf(file, " reg%d_posy: %d\n", i, osds[i].posy);
139139
fprintf(file, " reg%d_size: %.1f\n", i, osds[i].size);
140140
fprintf(file, " reg%d_color: %#04x\n", i, osds[i].color);
141+
fprintf(file, " reg%d_outl: %#04x\n", i, osds[i].outl);
142+
fprintf(file, " reg%d_thick: %.1f\n", i, osds[i].thick);
141143
}
142144

143145
fprintf(file, "jpeg:\n");
@@ -349,6 +351,10 @@ enum ConfigError parse_app_config(void) {
349351
parse_double(&ini, "osd", param, 0, INT_MAX, &osds[i].size);
350352
sprintf(param, "reg%d_color", i);
351353
parse_int(&ini, "osd", param, 0, USHRT_MAX, &osds[i].color);
354+
sprintf(param, "reg%d_outl", i);
355+
parse_int(&ini, "osd", param, 0, USHRT_MAX, &osds[i].outl);
356+
sprintf(param, "reg%d_thick", i);
357+
parse_double(&ini, "osd", param, 0, UCHAR_MAX, &osds[i].thick);
352358
osds[i].updt = 1;
353359
}
354360
}

src/error.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ char *errstr(int error) {
7474
error |= (module << 16); break;
7575
}
7676
break;
77+
case HAL_PLATFORM_RK:
78+
level = (error >> 13) & 0x7;
79+
error = error & 0xFF001FFF | (level > 0 ? (4 << 13) : 0);
80+
switch (module) {
81+
case RK_SYS_MOD_SYS:
82+
error |= (V4_SYS_MOD_SYS << 16); break;
83+
case RK_SYS_MOD_ISP:
84+
error |= (V4_SYS_MOD_ISP << 16); break;
85+
case RK_SYS_MOD_VI:
86+
error |= (V4_SYS_MOD_VIU << 16); break;
87+
case RK_SYS_MOD_VPSS:
88+
error |= (V4_SYS_MOD_VPSS << 16); break;
89+
case RK_SYS_MOD_VENC:
90+
error |= (V4_SYS_MOD_VENC << 16); break;
91+
case RK_SYS_MOD_RGN:
92+
error |= (V4_SYS_MOD_RGN << 16); break;
93+
case RK_SYS_MOD_AI:
94+
error |= (V4_SYS_MOD_AI << 16); break;
95+
default:
96+
error |= (module << 16); break;
97+
}
98+
break;
7799
#endif
78100
}
79101

src/region.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ void *region_thread(void) {
336336
strncpy(osds[id].font, DEF_FONT, sizeof(osds[id].font) - 1);
337337
osds[id].text[0] = '\0';
338338
osds[id].img[0] = '\0';
339+
osds[id].outl = DEF_OUTL;
340+
osds[id].thick = DEF_THICK;
339341
}
340342

341343
while (keepRunning) {
@@ -369,7 +371,8 @@ void *region_thread(void) {
369371
HAL_DANGER("region", "Font \"%s\" not found!\n", osds[id].font);
370372
continue;
371373
found_font:;
372-
hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out, osds[id].color);
374+
hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out, osds[id].color,
375+
osds[id].outl, osds[id].thick);
373376
hal_rect rect = { .height = bitmap.dim.height, .width = bitmap.dim.width,
374377
.x = osds[id].posx, .y = osds[id].posy };
375378
switch (plat) {

src/region.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
#define DEF_COLOR 0xFFFF
1717
#define DEF_FONT "UbuntuMono-Regular"
1818
#define DEF_OPAL 255
19+
#define DEF_OUTL 0x8000
1920
#define DEF_POSX 16
2021
#define DEF_POSY 16
2122
#define DEF_SIZE 32.0f
23+
#define DEF_THICK 0.0f
2224
#define DEF_TIMEFMT "%Y/%m/%d %H:%M:%S"
2325
#define MAX_OSD 10
2426

@@ -65,6 +67,8 @@ typedef struct {
6567
char font[32];
6668
char text[80];
6769
char img[64];
70+
int outl;
71+
double thick;
6872
} osd;
6973

7074
extern osd osds[MAX_OSD];

src/server.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,15 @@ void respond_request(http_request_t *req) {
12331233
osds[id].posy = y;
12341234
}
12351235
}
1236+
else if (EQUALS(key, "outl")) {
1237+
int result = color_parse(value);
1238+
osds[id].outl = result;
1239+
}
1240+
else if (EQUALS(key, "thick")) {
1241+
double result = strtod(value, &remain);
1242+
if (remain == value) continue;
1243+
osds[id].thick = result;
1244+
}
12361245
}
12371246
osds[id].updt = 1;
12381247
}
@@ -1245,9 +1254,11 @@ void respond_request(http_request_t *req) {
12451254
"Connection: close\r\n"
12461255
"\r\n"
12471256
"{\"id\":%d,\"color\":\"#%x\",\"opal\":%d,\"pos\":[%d,%d],"
1248-
"\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\",\"img\":\"%s\"}",
1257+
"\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\",\"img\":\"%s\","
1258+
"\"outl\":\"#%x\",\"thick\":%.1f}",
12491259
id, color, osds[id].opal, osds[id].posx, osds[id].posy,
1250-
osds[id].font, osds[id].size, osds[id].text, osds[id].img);
1260+
osds[id].font, osds[id].size, osds[id].text, osds[id].img,
1261+
osds[id].outl, osds[id].thick);
12511262
send_and_close(req->clntFd, response, respLen);
12521263
return;
12531264
}

src/text.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void text_copy_rendered(SFT_Image *dest, const SFT_Image *source, int x0, int y0
7373

7474
for (int y = 0; y < source->height; y++) {
7575
for (int x = 0; x < source->width; x++) {
76+
if (s[x] == 0) continue;
7677
double t = s[x] * inv255;
7778
unsigned short r = (1.0 - t) * ((d[x] & 0x7C00) >> 10) + t * maskr;
7879
unsigned short g = (1.0 - t) * ((d[x] & 0x3E0) >> 5) + t * maskg;
@@ -152,7 +153,8 @@ void text_dim_rendered(double *margin, double *height, double *width, const char
152153
*width = MAX(*width, lwidth) + 2 * *margin;
153154
}
154155

155-
hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color)
156+
hal_bitmap text_create_rendered(const char *font, double size, const char *text,
157+
int color, int outline, double thick)
156158
{
157159
text_load_font(&sft, font, size, &lmtx);
158160

@@ -185,6 +187,19 @@ hal_bitmap text_create_rendered(const char *font, double size, const char *text,
185187
text_new_rendered(&image, mtx.minWidth, mtx.minHeight, 0);
186188
sft_render(&sft, gid, image);
187189
sft_kerning(&sft, ogid, gid, &kerning);
190+
191+
if (thick <= 0) goto noOutline;
192+
193+
for (int dx = -thick; dx <= thick; dx++) {
194+
for (int dy = -thick; dy <= thick; dy++) {
195+
if (!dx && !dy) continue;
196+
text_copy_rendered(&canvas, &image,
197+
x + mtx.leftSideBearing + dx,
198+
y + mtx.yOffset + dy, outline);
199+
}
200+
}
201+
202+
noOutline:;
188203
x += kerning.xShift;
189204
text_copy_rendered(&canvas, &image, x + mtx.leftSideBearing,
190205
y + mtx.yOffset, color);

src/text.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
#include "hal/support.h"
66
#include "lib/schrift.h"
77

8-
hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color);
8+
hal_bitmap text_create_rendered(const char *font, double size, const char *text,
9+
int color, int outline, double thick);

0 commit comments

Comments
 (0)