Skip to content

Commit

Permalink
Preparing for bitmap support
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 10, 2024
1 parent 9a9125a commit 3c2220f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/hal/sstar/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void *i6_audio_thread(void)
{
int ret;

i6_aud_frm frame, echoFrame;
i6_aud_frm frame;
i6_aud_efrm echoFrame;

while (keepRunning) {
if ((ret = i6_aud.fnGetFrame(_i6_aud_dev, _i6_aud_chn,
Expand Down
3 changes: 2 additions & 1 deletion src/hal/sstar/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ void *i6f_audio_thread(void)
{
int ret;

i6f_aud_frm frame, echoFrame;
i6f_aud_frm frame;
i6f_aud_efrm echoFrame;

while (keepRunning) {
if ((ret = i6f_aud.fnGetFrame(_i6f_aud_dev, _i6f_aud_chn,
Expand Down
57 changes: 57 additions & 0 deletions src/region.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,63 @@ void region_fill_formatted(char* str)
strncpy(str, out, 80);
}

static inline int region_open_bitmap(char *path, FILE *file)
{
unsigned short type;

if (!path)
REGION_ERROR("Filename is empty!\n");
if (!(file = fopen(path, "rb")))
REGION_ERROR("Opening the bitmap failed!\n");
if (fread(&type, 1, sizeof(type), file) != sizeof(type))
REGION_ERROR("Reading the bitmap failed!\n");
if (type != 0x4d42)
REGION_ERROR("Only bitmap files are currently supported!\n");

return EXIT_SUCCESS;
}

int region_parse_bitmap(FILE *file, bitmapfile *bmpFile, bitmapinfo *bmpInfo)
{
if (fread(bmpFile, 1, sizeof(bitmapfile), file) != sizeof(bitmapfile))
REGION_ERROR("Extracting the bitmap file header failed!\n");
if (fread(bmpInfo, 1, sizeof(bitmapinfo), file) != sizeof(bitmapinfo))
REGION_ERROR("Extracting the bitmap info failed!\n");

if (bmpInfo->bitCount / 8 < 2)
REGION_ERROR("Indexed or <4bpp bitmaps are not supported!\n");
if (bmpInfo->height < 0)
REGION_ERROR("Flipped bitmaps are not supported!\n");

return EXIT_SUCCESS;
}

int region_prepare_bitmap(char *path, hal_bitmap *bitmap)
{
bitmapfile bmpFile;
bitmapinfo bmpInfo;
FILE *file;

if (region_open_bitmap(path, file))
return EXIT_FAILURE;

if (region_parse_bitmap(file, &bmpFile, &bmpInfo))
REGION_ERROR("Bitmap file \"%s\" cannot be processed!\n", path);

if (!(bitmap->data = malloc(2 * bmpInfo.width * bmpInfo.height)))
REGION_ERROR("Allocating the bitmap memory failed!\n");

if (fseek(file, bmpFile.offBits, 0))
REGION_ERROR("Navigating to the bitmap image data failed!\n");

for (int h = 0; h < bmpInfo.height; h++) {
for (int w = 0; w < bmpInfo.width; w++) {
switch (bmpInfo.bitCount) {

}
}
}
}

void *region_thread(void)
{
Expand Down
30 changes: 30 additions & 0 deletions src/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,38 @@
#include <pthread.h>
#include <time.h>

#define REGION_ERROR(x, ...) \
do { \
fprintf(stderr, "[region] \033[31m"); \
fprintf(stderr, (x), ##__VA_ARGS__); \
fprintf(stderr, "\033[0m"); \
return EXIT_FAILURE; \
} while (0)

extern int sysinfo (struct sysinfo *__info);

typedef struct {
unsigned int size;
unsigned short reserved1;
unsigned short reserved2;
unsigned int offBits;
} bitmapfile;

typedef struct {
unsigned short size;
unsigned int width;
int height;
unsigned short planes;
unsigned short bitCount;
unsigned int compression;
unsigned int sizeImage;
unsigned int xPerMeter;
unsigned int yPerMeter;
unsigned int clrUsed;
unsigned int clrImportant;
unsigned char bgraColors[4];
} bitmapinfo;

typedef struct {
double size;
int hand, color;
Expand Down

0 comments on commit 3c2220f

Please sign in to comment.