From 3c2220fb7156c59a4a9810a696160ca12a3d733f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Mon, 10 Jun 2024 16:27:23 -0400 Subject: [PATCH] Preparing for bitmap support --- src/hal/sstar/i6_hal.c | 3 ++- src/hal/sstar/i6f_hal.c | 3 ++- src/region.c | 57 +++++++++++++++++++++++++++++++++++++++++ src/region.h | 30 ++++++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/src/hal/sstar/i6_hal.c b/src/hal/sstar/i6_hal.c index a19b440..b968dc6 100644 --- a/src/hal/sstar/i6_hal.c +++ b/src/hal/sstar/i6_hal.c @@ -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, diff --git a/src/hal/sstar/i6f_hal.c b/src/hal/sstar/i6f_hal.c index d0426de..e01955d 100644 --- a/src/hal/sstar/i6f_hal.c +++ b/src/hal/sstar/i6f_hal.c @@ -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, diff --git a/src/region.c b/src/region.c index d8c563b..4e46731 100644 --- a/src/region.c +++ b/src/region.c @@ -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) { diff --git a/src/region.h b/src/region.h index cca1839..8da96e7 100644 --- a/src/region.h +++ b/src/region.h @@ -23,8 +23,38 @@ #include #include +#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;