Skip to content

Commit

Permalink
Creating/freeing the bitmap struct, polishing up some things
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Apr 9, 2024
1 parent 1b78d07 commit 28b5549
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 48 deletions.
1 change: 0 additions & 1 deletion osd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ void overlays()
{
char img[32];
sprintf(img, "/tmp/osd%d.bmp", id);
fprintf(stderr, "access=%s %d\n", img, access(img, F_OK));
if (!access(img, F_OK))
load_region(id, PIXEL_FORMAT_1555);
else
Expand Down
43 changes: 10 additions & 33 deletions osd/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ int *clients;
static void start_server();
static void respond(int);

typedef struct
{
char *name, *value;
} header_t;
static header_t reqhdr[17] = {{"\0", "\0"}};

char *method,
Expand Down Expand Up @@ -65,20 +61,16 @@ void serve_forever()
char *request_header(const char *name)
{
header_t *h = reqhdr;
while (h->name)
{
for (; h->name; h++)
if (!strcmp(h->name, name))
return h->value;
h++;
}
return NULL;
}

header_t *request_headers(void) { return reqhdr; }

static void unescape_uri(char *uri)
{
char chr = 0;
char *src = uri;
char *dst = uri;

Expand All @@ -88,18 +80,10 @@ static void unescape_uri(char *uri)
dst = src;
while (*src && !isspace((int)(*src)))
{
if (*src == '+')
chr = ' ';
else if ((*src == '%') && src[1] && src[2])
{
src++;
chr = ((*src & 0x0F) + 9 * (*src > '9')) * 16;
src++;
chr += ((*src & 0x0F) + 9 * (*src > '9'));
}
else
chr = *src;
*dst++ = chr;
*dst++ = (*src == '+') ? ' ' :
((*src == '%') && src[1] && src[2]) ?
((*++src & 0x0F) + 9 * (*src > '9')) * 16 + ((*++src & 0x0F) + 9 * (*src > '9')) :
*src;
src++;
}
*dst = '\0';
Expand Down Expand Up @@ -153,15 +137,14 @@ void start_server()

void respond(int slot)
{
int rcvd;
int total = 0;
int rcvd, total = 0;

buf = malloc(BUF_SIZE);

rcvd = recv(clients[slot], buf + total, BUF_SIZE - total, 0);

if (rcvd < 0)
goto finish;
fputs("recv() error\n", stderr);
else if (rcvd == 0)
fputs("Client disconnected unexpectedly.\n", stderr);

Expand Down Expand Up @@ -189,11 +172,9 @@ void respond(int slot)
if (!k)
break;
v = strtok(NULL, "\r\n");
while (*v && *v == ' ')
v++;
while (*v && *v == ' ' && v++);
h->name = k;
h->value = v;
h++;
h++->value = v;
fprintf(stderr, "[H] %s: %s\n", k, v);
e = v + 1 + strlen(v);
if (e[1] == '\r' && e[2] == '\n')
Expand Down Expand Up @@ -224,12 +205,8 @@ void respond(int slot)
}

if (!t)
{
t = strtok(NULL, "\r\n");
payload = t;
}
payload = t = strtok(NULL, "\r\n");

finish:
int clientfd = clients[slot];
dup2(clientfd, STDOUT_FILENO);
close(clientfd);
Expand Down
5 changes: 5 additions & 0 deletions osd/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ extern "C"

#include "common.h"

typedef struct
{
char *name, *value;
} header_t;

extern char *method, // "GET" or "POST"
*uri, // "/index.html" things before '?'
*query, // "a=1&b=2" things after '?'
Expand Down
29 changes: 15 additions & 14 deletions osd/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int create_region(int handle, int x, int y, int width, int height)
stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.eAlphaMode = E_MI_RGN_PIXEL_ALPHA;
stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8BgAlpha = 0;
stChnAttr.unPara.stOsdChnPort.stOsdAlphaAttr.stAlphaPara.stArgb1555Alpha.u8FgAlpha = 255;
stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.bEnableColorInv = 0;
// stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.bEnableColorInv = 0;
// stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.eInvertColorMode = E_MI_RGN_BELOW_LUMA_THRESHOLD;
// stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16LumaThreshold = 128;
// stChnAttr.unPara.stOsdChnPort.stColorInvertAttr.u16WDivNum = stRegion.stOsdInitParam.stSize.u32Width * inv16;
Expand All @@ -141,11 +141,11 @@ int create_region(int handle, int x, int y, int width, int height)
stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bQpDisable = 0;
stChnAttr.unChnAttr.stOverlayChn.stQpInfo.bAbsQp = 0;
stChnAttr.unChnAttr.stOverlayChn.stQpInfo.s32Qp = 0;
//stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = width;
//stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = height;
//stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128;
//stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH;
//stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = 0;
// stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Height = width;
// stChnAttr.unChnAttr.stOverlayChn.stInvertColor.stInvColArea.u32Width = height;
// stChnAttr.unChnAttr.stOverlayChn.stInvertColor.u32LumThresh = 128;
// stChnAttr.unChnAttr.stOverlayChn.stInvertColor.enChgMod = LESSTHAN_LUM_THRESH;
// stChnAttr.unChnAttr.stOverlayChn.stInvertColor.bInvColEn = 0;
#ifndef __16CV300__
stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[0] = 0x3e0;
stChnAttr.unChnAttr.stOverlayChn.u16ColorLUT[1] = 0x7FFF;
Expand Down Expand Up @@ -207,8 +207,7 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int
return -1;
}

bitmap->pData = malloc(s32BytesPerPix * (bmpInfo.bmiHeader.biWidth) * (bmpInfo.bmiHeader.biHeight));
if (bitmap->pData == NULL)
if (!(bitmap->pData = malloc(s32BytesPerPix * bmpInfo.bmiHeader.biWidth * bmpInfo.bmiHeader.biHeight)))
{
fprintf(stderr, "malloc osd memory err!\n");
return -1;
Expand All @@ -227,7 +226,7 @@ int prepare_bitmap(const char *filename, BITMAP *bitmap, int bFil, unsigned int
if (enPixelFmt == PIXEL_FORMAT_2BPP)
{
s32Width = DIV_UP(bmpInfo.bmiHeader.biWidth, 4);
pu8Data = malloc((s32Width) * (bmpInfo.bmiHeader.biHeight));
pu8Data = malloc(s32Width * bmpInfo.bmiHeader.biHeight);
if (NULL == pu8Data)
{
fprintf(stderr, "malloc osd memory err!\n");
Expand Down Expand Up @@ -311,13 +310,15 @@ int set_bitmap(unsigned int handle, BITMAP *bitmap)

int load_region(unsigned int handle, int enPixelFmt)
{
BITMAP* bitmap;
BITMAP bitmap;
int s32Ret;
char path[32];
sprintf(path, "/tmp/osd%d.bmp", handle);
prepare_bitmap(path, bitmap, 0, 0, enPixelFmt);

int s32Ret = set_bitmap(handle, bitmap);
free(bitmap->pData);
if (!(s32Ret = prepare_bitmap(path, &bitmap, 0, 0, enPixelFmt)))
{
s32Ret = set_bitmap(handle, &bitmap);
free(bitmap.pData);
}
return s32Ret;
}

Expand Down

0 comments on commit 28b5549

Please sign in to comment.