Skip to content

Commit

Permalink
Fixes and improvements mostly related to OSDs
Browse files Browse the repository at this point in the history
- Text rendering canvas could be insufficient due to floating conversions
- Foreground alpha was wrong on some cameras (opacity setting coming soon)
- New parameter to set the text color (ARGB1555 format, hexadecimal entry)
  • Loading branch information
wberube committed Jun 4, 2024
1 parent 33d4822 commit 6e69ae5
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/hal/hisi/v3_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ int v3_region_create(char handle, hal_rect rect)
memset(&attrib, 0, sizeof(attrib));
attrib.show = 1;
attrib.type = V3_RGN_TYPE_OVERLAY;
attrib.overlay.bgAlpha = 0;
attrib.overlay.fgAlpha = 128;
attrib.overlay.fgAlpha = 255;
attrib.overlay.point.x = rect.x;
attrib.overlay.point.y = rect.y;
attrib.overlay.layer = 7;
Expand Down
3 changes: 1 addition & 2 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ int v4_region_create(char handle, hal_rect rect)
memset(&attrib, 0, sizeof(attrib));
attrib.show = 1;
attrib.type = V4_RGN_TYPE_OVERLAY;
attrib.overlay.bgAlpha = 0;
attrib.overlay.fgAlpha = 128;
attrib.overlay.fgAlpha = 255;
attrib.overlay.point.x = rect.x;
attrib.overlay.point.y = rect.y;
attrib.overlay.layer = 7;
Expand Down
6 changes: 3 additions & 3 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ int t31_region_create(int *handle, hal_rect rect)
t31_osd_grp attrib, attribCurr;

region.type = T31_OSD_TYPE_PIC;
region.pixFmt = T31_PIXFMT_RGB555LE;
region.pixFmt = T31_PIXFMT_BGR555LE;
region.rect.p0.x = rect.x;
region.rect.p0.y = rect.y;
region.rect.p1.x = rect.x + rect.width - 1;
Expand All @@ -274,7 +274,7 @@ int t31_region_create(int *handle, hal_rect rect)
memset(&attrib, 0, sizeof(attrib));
attrib.show = 1;
attrib.alphaOn = 1;
attrib.fgAlpha = 128;
attrib.fgAlpha = 255;

t31_osd.fnRegisterRegion(*handle, _t31_osd_grp, &attrib);

Expand All @@ -294,7 +294,7 @@ int t31_region_setbitmap(int *handle, hal_bitmap *bitmap)
region.type = T31_OSD_TYPE_PIC;
region.rect.p1.x = region.rect.p0.x + bitmap->dim.width - 1;
region.rect.p1.y = region.rect.p0.y + bitmap->dim.height - 1;
region.pixFmt = T31_PIXFMT_RGB555LE;
region.pixFmt = T31_PIXFMT_BGR555LE;
region.data.picture = bitmap->data;
return t31_osd.fnSetRegionConfig(*handle, &region);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/rtsp/rtsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ static int __message_proc_sock(struct list_t *e, void *p)
case __METHOD_RECORDING: __method_record(con, h);break;
case __METHOD_TEARDOWN: __method_teardown(con, h);break;
case __METHOD_NONE:
/* state DISCONNECTED connections should be gabage collected immediately.
/* state DISCONNECTED connections should be garbage collected immediately.
but sending thread might watches the connection right now.
so the connection might live at here */
ASSERT(con->con_state == __CON_S_DISCONNECTED, return FAILURE);
Expand Down Expand Up @@ -587,7 +587,6 @@ static inline int __bind_rtp(struct connection_item_t *con )
/* reset socket */
if (con->server_rtp_fd != 0) {
CLOSE(con->server_rtp_fd);
//FCLOSE(con->fp_rtp_write);
con->server_rtp_fd = 0;
}
/* setup serve rsocket */
Expand Down
3 changes: 0 additions & 3 deletions src/lib/rtsp/rtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ struct connection_item_t {
int server_rtp_fd;
int cseq;

//FILE *fp_rtcp_write;
//FILE *fp_rtcp_read;
//FILE *fp_rtp_write;
FILE *fp_tcp_read;
FILE *fp_tcp_write;
enum __connection_state_e con_state;
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
if (app_config.osd_enable)
start_region_handler();

while (keepRunning) {};
while (keepRunning) sleep(1);

if (app_config.rtsp_enable) {
rtsp_finish(rtspHandle);
Expand Down
5 changes: 3 additions & 2 deletions src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ void *region_thread(void)
for (char id = 0; id < MAX_OSD; id++)
{
osds[id].hand = -1;
osds[id].color = DEF_COLOR;
osds[id].size = DEF_SIZE;
osds[id].posx = DEF_POSX;
osds[id].posy = DEF_POSY;
osds[id].posy = DEF_POSY + (DEF_SIZE * 3 / 2) * id;
osds[id].updt = 0;
strcpy(osds[id].font, DEF_FONT);
osds[id].text[0] = '\0';
Expand All @@ -132,7 +133,7 @@ void *region_thread(void)
char *font;
asprintf(&font, "/usr/share/fonts/truetype/%s.ttf", osds[id].font);
if (!access(font, F_OK)) {
hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out);
hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out, osds[id].color);
hal_rect rect = { .height = bitmap.dim.height, .width = bitmap.dim.width,
.x = osds[id].posx, .y = osds[id].posy };
switch (plat) {
Expand Down
3 changes: 2 additions & 1 deletion src/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "hal/support.h"
#include "text.h"

#define DEF_COLOR 0xFFFF
#define DEF_FONT "UbuntuMono-Regular"
#define DEF_POSX 16
#define DEF_POSY 16
Expand All @@ -25,7 +26,7 @@ extern int sysinfo (struct sysinfo *__info);

typedef struct {
double size;
int hand;
int hand, color;
short posx, posy;
char updt;
char font[32];
Expand Down
11 changes: 9 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,13 @@ void *server_thread(void *vargp) {
unescape_uri(value);
char *key = split(&value, "=");
if (!key || !*key || !value || !*value) continue;
if (equals(key, "color")) {
char base = 16;
if (strlen(value) > 1 && value[1] == 'x') base = 0;
short result = strtol(value, &remain, base);
if (remain != value)
osds[id].color = result;
}
if (equals(key, "font"))
strcpy(osds[id].font, !empty(value) ? value : DEF_FONT);
else if (equals(key, "text"))
Expand Down Expand Up @@ -710,8 +717,8 @@ void *server_thread(void *vargp) {
"Content-Type: application/json;charset=UTF-8\r\n" \
"Connection: close\r\n" \
"\r\n" \
"{\"id\":%d,\"pos\":[%d,%d],\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\"}",
id, osds[id].posx, osds[id].posy, osds[id].font, osds[id].size, osds[id].text);
"{\"id\":%d,\"color\":%#x,\"pos\":[%d,%d],\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\"}",
id, osds[id].color, osds[id].posx, osds[id].posy, osds[id].font, osds[id].size, osds[id].text);
send_to_fd(client_fd, response, respLen);
close_socket_fd(client_fd);
continue;
Expand Down
8 changes: 4 additions & 4 deletions src/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ hal_dim text_measure_rendered(const char *font, double size, const char *text)
return dim;
}

hal_bitmap text_create_rendered(const char *font, double size, const char *text)
hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color)
{
text_load_font(&sft, font, size, &lmtx);

double margin, height, width;
text_dim_rendered(&margin, &height, &width, text);
text_new_rendered(&canvas, width, height, 0);
text_new_rendered(&canvas, CEILING(width), CEILING(height), 0);

unsigned cps[strlen(text) + 1];
int n = utf8_to_utf32(text, cps, strlen(text) + 1);
Expand All @@ -198,12 +198,12 @@ hal_bitmap text_create_rendered(const char *font, double size, const char *text)
SFT_GMetrics mtx;
SFT_Kerning kerning;
text_load_glyph(&sft, cp, &gid, &mtx);
text_new_rendered(&image, mtx.minWidth, mtx.minHeight, 0x7FFF);
text_new_rendered(&image, mtx.minWidth, mtx.minHeight, 0);
sft_render(&sft, gid, image);
sft_kerning(&sft, ogid, gid, &kerning);
x += kerning.xShift;
text_copy_rendered(&canvas, &image, x + mtx.leftSideBearing,
y + mtx.yOffset, 0xFFFF);
y + mtx.yOffset, color);
x += mtx.advanceWidth;
free(image.pixels);
ogid = gid;
Expand Down
2 changes: 1 addition & 1 deletion src/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
return EXIT_FAILURE; \
} while (0)

hal_bitmap text_create_rendered(const char *font, double size, const char *text);
hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color);
hal_dim text_measure_rendered(const char *font, double size, const char *text);

0 comments on commit 6e69ae5

Please sign in to comment.