Skip to content

Commit

Permalink
Merge branch 'main' into srt
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorxda authored Feb 27, 2025
2 parents 18c22a2 + 389b89d commit bba65d8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 77 deletions.
21 changes: 10 additions & 11 deletions bmp/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ MI_RGN_PaletteTable_t g_stPaletteTable = {{// index0 ~ index15
{0xFF, 0xAD, 0x52, 0xD6}, //
{0xFF, 0xCC, 0xCC, 0xCC}, // 0x739C -> Gray (Light) {0xFF, 0xCC, 0xCC, 0xCC}
{0xFF, 0x77, 0x77, 0x77}, // 0x18C6 -> Gray (Dark)
{0x00, 0, 0, 0}, // transparent index 15, 0x0A
{0x00, 0, 0, 0}, // 0x7BDE -> transparent
{0x00, 0, 0, 0}, // transparent index 15, 0x0A
{0x00, 0, 0, 0}, // 0x7BDE -> transparent
// index17 ~ index31
{0xFF, 0xF0, 0xF0, 0xF0}, // this is the predefined TRANSARANT Color index17
{0, 0, 255, 60}, {0, 128, 0, 90}, {255, 0, 0, 120}, {0, 255, 255, 150}, {255, 255, 0, 180},
Expand Down Expand Up @@ -1114,14 +1114,13 @@ int getRowStride(int width, int BitsPerPixel) {
return stride;
}

void convertBitmap1555ToI4(
uint16_t *srcBitmap, uint32_t width, uint32_t height, uint8_t *destBitmap, int singleColor, int colourBackground) {
void convertBitmap1555ToI4(uint16_t *srcBitmap, uint32_t width, uint32_t height,
uint8_t *destBitmap, int singleColor, int colourBackground) {
MI_RGN_PaletteTable_t *paletteTable = &g_stPaletteTable;
// Calculate the number of bytes required per line without padding

if (singleColor == -1) // The color that we assume as transparent
singleColor = 15;


unsigned char u8Value = 0;
uint32_t u32Stride = (width + 1) / 2;
Expand Down Expand Up @@ -1154,12 +1153,12 @@ void convertBitmap1555ToI4(
if (paletteIndex != 15 & paletteIndex >= 0) {
paletteIndex = singleColor;
}
if (colourBackground>=0 && paletteIndex==15)
paletteIndex=colourBackground;
if (colourBackground >= 0 && paletteIndex == 15)
paletteIndex = colourBackground;

// No Fucking idea why this is different for x86 and Sigmastar, BUT
// !!! SigmaStar I4 format needs it reversit 4bit pairs. 0x0A,
// 0x0B needs to be 0XBA
// No Fucking idea why this is different for x86 and Sigmastar, BUT
// !!! SigmaStar I4 format needs it reversit 4bit pairs. 0x0A,
// 0x0B needs to be 0XBA
#ifdef __SIGMASTAR__
if (u32X % 2) { // this is the secret of distorted image !!!
#else
Expand Down
18 changes: 9 additions & 9 deletions msposd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,17 +1424,17 @@ int main(int argc, char **argv) {
matrix_size = atoi(optarg);
break;

case 'z':
{
char buffer[16];
strncpy(buffer, optarg, sizeof(buffer));
char *limit = strchr(buffer, 'x');
if (limit) {
buffer[limit - buffer] = '\0';
set_resolution(atoi(buffer), atoi(limit + 1));
}
case 'z': {
char buffer[16];
strncpy(buffer, optarg, sizeof(buffer));
char *limit = strchr(buffer, 'x');
if (limit) {
*limit = '\0';
set_resolution(atoi(buffer), atoi(limit + 1));
DrawOSD = true;
}
break;
}

case '1':
mspVTXenabled = true;
Expand Down
113 changes: 56 additions & 57 deletions osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ int msg_layout = 0;
/// white font
int msg_colour = 0;

int msg_colour_background=-1;
int msg_colour_background = -1;

static unsigned long long LastCleared = 0;
static bool osd_msg_enabled = false;
Expand Down Expand Up @@ -1115,10 +1115,9 @@ static void draw_Ladder() {
static int droppedTTL = 0;
static bool first_wfb_read = true;


void fill(char *str) {
unsigned int rxb_l, txb_l, cpu_l[7];
char out[MAX_STATUS_MSG_LEN+100] = "";
char out[MAX_STATUS_MSG_LEN + 100] = "";
char param = 0;
int ipos = 0, opos = 0;

Expand Down Expand Up @@ -1316,30 +1315,29 @@ void fill(char *str) {
msg_colour--;

ipos += 3;
}
} else if (str[ipos + 1] == 'G' && isdigit(str[ipos + 2]) ) {
if (!DrawOSD) {// we need to keep &Cx
}
} else if (str[ipos + 1] == 'G' && isdigit(str[ipos + 2])) {
if (!DrawOSD) { // we need to keep &Cx
strncat(out, str + ipos, 1);
opos++;
} else {
// Extract the one digit after $C as an integer
msg_colour_background = str[ipos + 2]-'0';

msg_colour_background = str[ipos + 2] - '0';
if (msg_colour_background == 0)
msg_colour_background = COLOR_WHITE;
else if (msg_colour_background == 1)
msg_colour_background = COLOR_BLACK;
else if (msg_colour_background == 8)
msg_colour_background = 9;//semi-transparent
else if (msg_colour_background == 9)//remove it, i.e. make it transparent
msg_colour_background = 9; // semi-transparent
else if (msg_colour_background == 9) // remove it, i.e. make it transparent
msg_colour_background = -1;
else
msg_colour_background--;

ipos += 2;
}
}
else if (str[ipos + 1] == '&') {
} else if (str[ipos + 1] == '&') {
ipos++;
strcat(out, "&");
opos++;
Expand Down Expand Up @@ -1403,28 +1401,27 @@ void remove_carriage_returns(char *out) {
out[j] = '\0'; // Null-terminate the modified string
}


#define MAX_LINES 100 // Maximum number of lines we expect to handle
#define MAX_LINES 100 // Maximum number of lines we expect to handle
void split_lines(char *str, char *lines[MAX_LINES], int *line_count) {
*line_count = 0; // Initialize the line count
lines[(*line_count)++] = str; // Store the pointer to the first line

while (*str) {
if (*str == '\n') {//'@'
*str = '\0'; // Replace the carriage return with a null terminator
if (*(str + 1) != '\0') { // Check if it's not the end of the string
lines[(*line_count)++] = str + 1; // Store the pointer to the next line
}
}
str++;
}
*line_count = 0; // Initialize the line count
lines[(*line_count)++] = str; // Store the pointer to the first line

while (*str) {
if (*str == '\n') { //'@'
*str = '\0'; // Replace the carriage return with a null terminator
if (*(str + 1) != '\0') { // Check if it's not the end of the string
lines[(*line_count)++] = str + 1; // Store the pointer to the next line
}
}
str++;
}
}

char osdmsg[MAX_STATUS_MSG_LEN];
char ready_osdmsg[MAX_STATUS_MSG_LEN+1];

bool DrawTextOnOSDBitmap(char *msg) {
char *font;
char *font;
#ifdef _x86
asprintf(&font, "fonts/%s.ttf", osds[FULL_OVERLAY_ID].font);
#else
Expand Down Expand Up @@ -1481,7 +1478,7 @@ bool DrawTextOnOSDBitmap(char *msg) {
if (!DrawOSD && out_sock > 0) { // send the line to the ground
static uint8_t msg_buffer[256];
static uint8_t payload_buffer[256];
//out[79] = 0; // just in case
// out[79] = 0; // just in case
int msglen = strlen(&out[0]);

payload_buffer[0] = MSP_DISPLAYPORT_INFO_MSG;
Expand All @@ -1504,38 +1501,40 @@ bool DrawTextOnOSDBitmap(char *msg) {
if ((osds[FULL_OVERLAY_ID].size < 5.0) || (osds[FULL_OVERLAY_ID].size > 99.0))
osds[FULL_OVERLAY_ID].size = 20.0;

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

RECT rect;// = measure_text(font, osds[FULL_OVERLAY_ID].size, out);
if (bitmapText.pData != NULL) {
free(bitmapText.pData);
bitmapText.pData = NULL;
}
char *lines[MAX_LINES]; // Array to hold pointers to each line
int line_count = 0;

split_lines(out, lines, &line_count); // Here we will modify the message
int maxwidth = 0;

if (bitmapText.pData != NULL) {
free(bitmapText.pData);
bitmapText.pData = NULL;
for (int i = 0; i < line_count; i++) {
// printf("OSD Statistics Line %d: %s\n", i + 1, lines[i]);
rect = measure_text(font, osds[FULL_OVERLAY_ID].size, lines[i]);
maxwidth = (rect.width > maxwidth) ? rect.width : maxwidth;
}
char *lines[MAX_LINES]; // Array to hold pointers to each line
int line_count = 0;

split_lines(out, lines, &line_count);//Here we will modify the message
int maxwidth=0;

for (int i = 0; i < line_count; i++) {
//printf("OSD Statistics Line %d: %s\n", i + 1, lines[i]);
rect = measure_text(font, osds[FULL_OVERLAY_ID].size, lines[i]);
maxwidth=(rect.width>maxwidth)?rect.width:maxwidth;
}

bitmapText.u32Height = line_count * rect.height ;// preview_height;//rows *
bitmapText.u32Width = MIN( (maxwidth + 15) & ~15, bmpBuff.u32Width-16) ;// should be multiple of 16 OVERLAY_WIDTH-16
bitmapText.pData = (unsigned char *) malloc(bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));

bitmapText.u32Height = line_count * rect.height; // preview_height;//rows *
bitmapText.u32Width = MIN((maxwidth + 15) & ~15,
bmpBuff.u32Width - 16); // should be multiple of 16 OVERLAY_WIDTH-16
bitmapText.pData =
(unsigned char *)malloc(bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));
memset(bitmapText.pData, 0, bitmapText.u32Height * getRowStride(bitmapText.u32Width, 16));

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

if (PIXEL_FORMAT_DEFAULT ==
Expand All @@ -1546,7 +1545,7 @@ bool DrawTextOnOSDBitmap(char *msg) {
getRowStride(bitmapText.u32Width, PIXEL_FORMAT_BitsPerPixel));

convertBitmap1555ToI4(bitmapText.pData, bitmapText.u32Width, bitmapText.u32Height,
destBitmap, msg_colour,msg_colour_background);
destBitmap, msg_colour, msg_colour_background);

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

0 comments on commit bba65d8

Please sign in to comment.