Skip to content

Commit 389b89d

Browse files
committed
Set osd by providing size / format
1 parent 33afdc2 commit 389b89d

File tree

3 files changed

+70
-70
lines changed

3 files changed

+70
-70
lines changed

bmp/bitmap.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ MI_RGN_PaletteTable_t g_stPaletteTable = {{// index0 ~ index15
692692
{0xFF, 0xAD, 0x52, 0xD6}, //
693693
{0xFF, 0xCC, 0xCC, 0xCC}, // 0x739C -> Gray (Light) {0xFF, 0xCC, 0xCC, 0xCC}
694694
{0xFF, 0x77, 0x77, 0x77}, // 0x18C6 -> Gray (Dark)
695-
{0x00, 0, 0, 0}, // transparent index 15, 0x0A
696-
{0x00, 0, 0, 0}, // 0x7BDE -> transparent
695+
{0x00, 0, 0, 0}, // transparent index 15, 0x0A
696+
{0x00, 0, 0, 0}, // 0x7BDE -> transparent
697697
// index17 ~ index31
698698
{0xFF, 0xF0, 0xF0, 0xF0}, // this is the predefined TRANSARANT Color index17
699699
{0, 0, 255, 60}, {0, 128, 0, 90}, {255, 0, 0, 120}, {0, 255, 255, 150}, {255, 255, 0, 180},
@@ -1114,14 +1114,13 @@ int getRowStride(int width, int BitsPerPixel) {
11141114
return stride;
11151115
}
11161116

1117-
void convertBitmap1555ToI4(
1118-
uint16_t *srcBitmap, uint32_t width, uint32_t height, uint8_t *destBitmap, int singleColor, int colourBackground) {
1117+
void convertBitmap1555ToI4(uint16_t *srcBitmap, uint32_t width, uint32_t height,
1118+
uint8_t *destBitmap, int singleColor, int colourBackground) {
11191119
MI_RGN_PaletteTable_t *paletteTable = &g_stPaletteTable;
11201120
// Calculate the number of bytes required per line without padding
1121-
1121+
11221122
if (singleColor == -1) // The color that we assume as transparent
11231123
singleColor = 15;
1124-
11251124

11261125
unsigned char u8Value = 0;
11271126
uint32_t u32Stride = (width + 1) / 2;
@@ -1154,12 +1153,12 @@ void convertBitmap1555ToI4(
11541153
if (paletteIndex != 15 & paletteIndex >= 0) {
11551154
paletteIndex = singleColor;
11561155
}
1157-
if (colourBackground>=0 && paletteIndex==15)
1158-
paletteIndex=colourBackground;
1156+
if (colourBackground >= 0 && paletteIndex == 15)
1157+
paletteIndex = colourBackground;
11591158

1160-
// No Fucking idea why this is different for x86 and Sigmastar, BUT
1161-
// !!! SigmaStar I4 format needs it reversit 4bit pairs. 0x0A,
1162-
// 0x0B needs to be 0XBA
1159+
// No Fucking idea why this is different for x86 and Sigmastar, BUT
1160+
// !!! SigmaStar I4 format needs it reversit 4bit pairs. 0x0A,
1161+
// 0x0B needs to be 0XBA
11631162
#ifdef __SIGMASTAR__
11641163
if (u32X % 2) { // this is the secret of distorted image !!!
11651164
#else

msposd.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1386,15 +1386,17 @@ int main(int argc, char **argv) {
13861386
matrix_size = atoi(optarg);
13871387
break;
13881388

1389-
case 'z':
1389+
case 'z': {
13901390
char buffer[16];
13911391
strncpy(buffer, optarg, sizeof(buffer));
13921392
char *limit = strchr(buffer, 'x');
13931393
if (limit) {
1394-
buffer[limit - buffer] = '\0';
1394+
*limit = '\0';
13951395
set_resolution(atoi(buffer), atoi(limit + 1));
1396+
DrawOSD = true;
13961397
}
13971398
break;
1399+
}
13981400

13991401
case '1':
14001402
mspVTXenabled = true;

osd.c

+56-57
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ int msg_layout = 0;
678678
/// white font
679679
int msg_colour = 0;
680680

681-
int msg_colour_background=-1;
681+
int msg_colour_background = -1;
682682

683683
static unsigned long long LastCleared = 0;
684684
static bool osd_msg_enabled = false;
@@ -1110,10 +1110,9 @@ static void draw_Ladder() {
11101110
static int droppedTTL = 0;
11111111
static bool first_wfb_read = true;
11121112

1113-
11141113
void fill(char *str) {
11151114
unsigned int rxb_l, txb_l, cpu_l[7];
1116-
char out[MAX_STATUS_MSG_LEN+100] = "";
1115+
char out[MAX_STATUS_MSG_LEN + 100] = "";
11171116
char param = 0;
11181117
int ipos = 0, opos = 0;
11191118

@@ -1311,30 +1310,29 @@ void fill(char *str) {
13111310
msg_colour--;
13121311

13131312
ipos += 3;
1314-
}
1315-
} else if (str[ipos + 1] == 'G' && isdigit(str[ipos + 2]) ) {
1316-
if (!DrawOSD) {// we need to keep &Cx
1313+
}
1314+
} else if (str[ipos + 1] == 'G' && isdigit(str[ipos + 2])) {
1315+
if (!DrawOSD) { // we need to keep &Cx
13171316
strncat(out, str + ipos, 1);
13181317
opos++;
13191318
} else {
13201319
// Extract the one digit after $C as an integer
1321-
1322-
msg_colour_background = str[ipos + 2]-'0';
1320+
1321+
msg_colour_background = str[ipos + 2] - '0';
13231322
if (msg_colour_background == 0)
13241323
msg_colour_background = COLOR_WHITE;
13251324
else if (msg_colour_background == 1)
13261325
msg_colour_background = COLOR_BLACK;
13271326
else if (msg_colour_background == 8)
1328-
msg_colour_background = 9;//semi-transparent
1329-
else if (msg_colour_background == 9)//remove it, i.e. make it transparent
1327+
msg_colour_background = 9; // semi-transparent
1328+
else if (msg_colour_background == 9) // remove it, i.e. make it transparent
13301329
msg_colour_background = -1;
13311330
else
13321331
msg_colour_background--;
1333-
1332+
13341333
ipos += 2;
13351334
}
1336-
}
1337-
else if (str[ipos + 1] == '&') {
1335+
} else if (str[ipos + 1] == '&') {
13381336
ipos++;
13391337
strcat(out, "&");
13401338
opos++;
@@ -1398,27 +1396,26 @@ void remove_carriage_returns(char *out) {
13981396
out[j] = '\0'; // Null-terminate the modified string
13991397
}
14001398

1401-
1402-
#define MAX_LINES 100 // Maximum number of lines we expect to handle
1399+
#define MAX_LINES 100 // Maximum number of lines we expect to handle
14031400
void split_lines(char *str, char *lines[MAX_LINES], int *line_count) {
1404-
*line_count = 0; // Initialize the line count
1405-
lines[(*line_count)++] = str; // Store the pointer to the first line
1406-
1407-
while (*str) {
1408-
if (*str == '\n') {//'@'
1409-
*str = '\0'; // Replace the carriage return with a null terminator
1410-
if (*(str + 1) != '\0') { // Check if it's not the end of the string
1411-
lines[(*line_count)++] = str + 1; // Store the pointer to the next line
1412-
}
1413-
}
1414-
str++;
1415-
}
1401+
*line_count = 0; // Initialize the line count
1402+
lines[(*line_count)++] = str; // Store the pointer to the first line
1403+
1404+
while (*str) {
1405+
if (*str == '\n') { //'@'
1406+
*str = '\0'; // Replace the carriage return with a null terminator
1407+
if (*(str + 1) != '\0') { // Check if it's not the end of the string
1408+
lines[(*line_count)++] = str + 1; // Store the pointer to the next line
1409+
}
1410+
}
1411+
str++;
1412+
}
14161413
}
14171414

14181415
char osdmsg[MAX_STATUS_MSG_LEN];
14191416

14201417
bool DrawTextOnOSDBitmap(char *msg) {
1421-
char *font;
1418+
char *font;
14221419
#ifdef _x86
14231420
asprintf(&font, "fonts/%s.ttf", osds[FULL_OVERLAY_ID].font);
14241421
#else
@@ -1475,7 +1472,7 @@ bool DrawTextOnOSDBitmap(char *msg) {
14751472
if (!DrawOSD && out_sock > 0) { // send the line to the ground
14761473
static uint8_t msg_buffer[256];
14771474
static uint8_t payload_buffer[256];
1478-
//out[79] = 0; // just in case
1475+
// out[79] = 0; // just in case
14791476
int msglen = strlen(&out[0]);
14801477

14811478
payload_buffer[0] = MSP_DISPLAYPORT_INFO_MSG;
@@ -1495,38 +1492,40 @@ bool DrawTextOnOSDBitmap(char *msg) {
14951492
if ((osds[FULL_OVERLAY_ID].size < 5.0) || (osds[FULL_OVERLAY_ID].size > 99.0))
14961493
osds[FULL_OVERLAY_ID].size = 20.0;
14971494

1495+
RECT rect; // = measure_text(font, osds[FULL_OVERLAY_ID].size, out);
14981496

1499-
RECT rect;// = measure_text(font, osds[FULL_OVERLAY_ID].size, out);
1497+
if (bitmapText.pData != NULL) {
1498+
free(bitmapText.pData);
1499+
bitmapText.pData = NULL;
1500+
}
1501+
char *lines[MAX_LINES]; // Array to hold pointers to each line
1502+
int line_count = 0;
1503+
1504+
split_lines(out, lines, &line_count); // Here we will modify the message
1505+
int maxwidth = 0;
15001506

1501-
if (bitmapText.pData != NULL) {
1502-
free(bitmapText.pData);
1503-
bitmapText.pData = NULL;
1507+
for (int i = 0; i < line_count; i++) {
1508+
// printf("OSD Statistics Line %d: %s\n", i + 1, lines[i]);
1509+
rect = measure_text(font, osds[FULL_OVERLAY_ID].size, lines[i]);
1510+
maxwidth = (rect.width > maxwidth) ? rect.width : maxwidth;
15041511
}
1505-
char *lines[MAX_LINES]; // Array to hold pointers to each line
1506-
int line_count = 0;
1507-
1508-
split_lines(out, lines, &line_count);//Here we will modify the message
1509-
int maxwidth=0;
1510-
1511-
for (int i = 0; i < line_count; i++) {
1512-
//printf("OSD Statistics Line %d: %s\n", i + 1, lines[i]);
1513-
rect = measure_text(font, osds[FULL_OVERLAY_ID].size, lines[i]);
1514-
maxwidth=(rect.width>maxwidth)?rect.width:maxwidth;
1515-
}
1516-
1517-
bitmapText.u32Height = line_count * rect.height ;// preview_height;//rows *
1518-
bitmapText.u32Width = MIN( (maxwidth + 15) & ~15, bmpBuff.u32Width-16) ;// should be multiple of 16 OVERLAY_WIDTH-16
1519-
bitmapText.pData = (unsigned char *) malloc(bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));
1512+
1513+
bitmapText.u32Height = line_count * rect.height; // preview_height;//rows *
1514+
bitmapText.u32Width = MIN((maxwidth + 15) & ~15,
1515+
bmpBuff.u32Width - 16); // should be multiple of 16 OVERLAY_WIDTH-16
1516+
bitmapText.pData =
1517+
(unsigned char *)malloc(bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));
15201518
memset(bitmapText.pData, 0, bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));
15211519

1522-
for(int i=0;i<line_count;i++){
1523-
BITMAP bitmapTextLine = raster_text(font, osds[FULL_OVERLAY_ID].size, lines[i]); // allocates new bitmap, Bus error on goke ?!
1524-
//raster_text always return argb1555
1525-
copyRectARGB1555(bitmapTextLine.pData, bitmapTextLine.u32Width, bitmapTextLine.u32Height,
1526-
bitmapText.pData, bitmapText.u32Width, bitmapText.u32Height,
1527-
0, 0, MIN(bitmapTextLine.u32Width,bitmapText.u32Width) , MIN(bitmapTextLine.u32Height, bitmapText.u32Height),
1528-
0, i*rect.height);
1529-
free(bitmapTextLine.pData); // Free the memory allocated by raster_text !!!
1520+
for (int i = 0; i < line_count; i++) {
1521+
BITMAP bitmapTextLine = raster_text(font, osds[FULL_OVERLAY_ID].size,
1522+
lines[i]); // allocates new bitmap, Bus error on goke ?!
1523+
// raster_text always return argb1555
1524+
copyRectARGB1555(bitmapTextLine.pData, bitmapTextLine.u32Width,
1525+
bitmapTextLine.u32Height, bitmapText.pData, bitmapText.u32Width,
1526+
bitmapText.u32Height, 0, 0, MIN(bitmapTextLine.u32Width, bitmapText.u32Width),
1527+
MIN(bitmapTextLine.u32Height, bitmapText.u32Height), 0, i * rect.height);
1528+
free(bitmapTextLine.pData); // Free the memory allocated by raster_text !!!
15301529
}
15311530

15321531
if (PIXEL_FORMAT_DEFAULT ==
@@ -1537,7 +1536,7 @@ bool DrawTextOnOSDBitmap(char *msg) {
15371536
getRowStride(bitmapText.u32Width, PIXEL_FORMAT_BitsPerPixel));
15381537

15391538
convertBitmap1555ToI4(bitmapText.pData, bitmapText.u32Width, bitmapText.u32Height,
1540-
destBitmap, msg_colour,msg_colour_background);
1539+
destBitmap, msg_colour, msg_colour_background);
15411540

15421541
free(bitmapText.pData); // free ARGB1555 bitmap
15431542
// This is inefficient, we use 4 times more memory, but the buffer

0 commit comments

Comments
 (0)