diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..ca43874 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,66 @@ +{ + "configurations": [ + { + "name": "Star6E", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "__SIGMASTAR__", + "__INFINITY6__" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + }, + { + "name": "Star6C", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "__SIGMASTAR__", + "__INFINITY6__", + "__INFINITY6C__" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + }, + { + "name": "native(x86)", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_x86" + ], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + }, + { + "name": "sigmastar-infinity6c", + "compilerPath": "/home/home/src/msposd/toolchain/sigmastar-infinity6c/bin/arm-linux-gcc", + "intelliSenseMode": "linux-gcc-arm", + "cStandard": "c11", + "includePath": [ + "/home/home/src/msposd", + "/home/home/src/msposd/sdk/infinity6/include", + "/home/home/src/msposd/toolchain/sigmastar-infinity6c/usr/include" + ], + "defines": [ + "__SIGMASTAR__", + "__INFINITY6__", + "__INFINITY6C__" + ], + "compilerArgs": [ + "-Wno-address-of-packed-member" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 8cdaed7..6f3ed7d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "name": "UDP_OSD", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/msposd", + "program": "${workspaceFolder}/msposd", "args": [ "--master", "127.0.0.1:14550", diff --git a/.vscode/settings.json b/.vscode/settings.json index 97fb600..9965cf7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,72 +1,86 @@ { - "workbench.colorTheme": "Default High Contrast", + "workbench.colorTheme": "Visual Studio Dark - C++", + "editor.formatOnSave": false, "editor.formatOnType": false, "editor.formatOnPaste": false, + + "C_Cpp.clang_format_path": "/usr/bin/clang-format", + "C_Cpp.clang_format_style": "file", + + "C_Cpp.intelliSenseEngine": "Default", + "C_Cpp.enhancedColorization": "Enabled", + "C_Cpp.dimInactiveRegions": true, + "C_Cpp.inactiveRegionOpacity": 0.5, + + "[c]": { "editor.semanticHighlighting.enabled": true }, + "[cpp]":{ "editor.semanticHighlighting.enabled": true }, + "files.associations": { - "mavlink.h": "c", - "system_error": "c", - "chrono": "c", - "common.h": "c", - "array": "c", - "string": "c", - "string_view": "c", - "msp_displayport.h": "c", - "msp.h": "c", - "graphics.h": "c", - "thread": "c", - "mi_rgn.h": "c", - "mi_common.h": "c", - "bitmap.h": "c", - "random": "c", - "format": "c", - "compare": "c", - "cstdint": "c", - "functional": "c", - "rope": "c", - "ranges": "c", - "variant": "c", - "lodepng.h": "c", - "any": "c", - "expected": "c", - "fstream": "c", - "future": "c", - "optional": "c", - "shared_mutex": "c", - "spanstream": "c", - "stacktrace": "c", - "stop_token": "c", - "syncstream": "c", - "tuple": "c", - "string.h": "c", - "mi_vpe.h": "c", - "bitset": "c", - "slist": "c", - "initializer_list": "c", - "span": "c", - "regex": "c", - "utility": "c", - "*.tcc": "c", - "iomanip": "c", - "istream": "c", - "streambuf": "c", - "*.def": "c", - "iterator": "c", - "charconv": "c", - "ratio": "c", - "type_traits": "c", - "hi_math.h": "c", - "cstdlib": "c", - "xlib.h": "c", - "stdbool.h": "c", - "xutil.h": "c", - "xatom.h": "c", - "region.h": "c", - "cairo-xlib.h": "c", - "stdint-uintn.h": "c", - "interface.h": "c", - "valarray": "c", - "complex": "c", - "source_location": "c" + "mavlink.h": "c", + "system_error": "c", + "chrono": "c", + "common.h": "c", + "array": "c", + "string": "c", + "string_view": "c", + "msp_displayport.h": "c", + "msp.h": "c", + "graphics.h": "c", + "thread": "c", + "mi_rgn.h": "c", + "mi_common.h": "c", + "bitmap.h": "c", + "random": "c", + "format": "c", + "compare": "c", + "cstdint": "c", + "functional": "c", + "rope": "c", + "ranges": "c", + "variant": "c", + "lodepng.h": "c", + "any": "c", + "expected": "c", + "fstream": "c", + "future": "c", + "optional": "c", + "shared_mutex": "c", + "spanstream": "c", + "stacktrace": "c", + "stop_token": "c", + "syncstream": "c", + "tuple": "c", + "string.h": "c", + "mi_vpe.h": "c", + "bitset": "c", + "slist": "c", + "initializer_list": "c", + "span": "c", + "regex": "c", + "utility": "c", + "*.tcc": "c", + "iomanip": "c", + "istream": "c", + "streambuf": "c", + "*.def": "c", + "iterator": "c", + "charconv": "c", + "ratio": "c", + "type_traits": "c", + "hi_math.h": "c", + "cstdlib": "c", + "xlib.h": "c", + "stdbool.h": "c", + "xutil.h": "c", + "xatom.h": "c", + "region.h": "c", + "cairo-xlib.h": "c", + "stdint-uintn.h": "c", + "interface.h": "c", + "valarray": "c", + "complex": "c", + "source_location": "c" } -} \ No newline at end of file + } + \ No newline at end of file diff --git a/bmp/lib/schrift.c b/bmp/lib/schrift.c index 1adfe6b..00d8e52 100644 --- a/bmp/lib/schrift.c +++ b/bmp/lib/schrift.c @@ -238,13 +238,14 @@ SFT_Font *sft_loadfile(char const *filename) { return font; } -void sft_freefont(SFT_Font *font) { +int sft_freefont(SFT_Font *font) { if (!font) - return; + return 0; /* Only unmap if we mapped it ourselves. */ if (font->source == SrcMapping) unmap_file(font); - free(font); + free(font); + return 1; } int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics) { @@ -481,29 +482,53 @@ static void unmap_file(SFT_Font *font) { #else static int map_file(SFT_Font *font, const char *filename) { - struct stat info; - int fd; - font->memory = MAP_FAILED; - font->size = 0; - font->source = SrcMapping; - if ((fd = open(filename, O_RDONLY)) < 0) { - return -1; - } - if (fstat(fd, &info) < 0) { - close(fd); - return -1; - } - /* FIXME do some basic validation on info.st_size maybe - it is signed for - * example, so it *could* be negative .. */ - font->memory = mmap(NULL, (size_t)info.st_size, PROT_READ, MAP_PRIVATE, fd, 0); - font->size = (uint_fast32_t)info.st_size; - close(fd); - return font->memory == MAP_FAILED ? -1 : 0; + FILE *fp; + size_t n; + long size; + + font->memory = NULL; + font->size = 0; + font->source = SrcMapping; /* still mark it so unmap_file knows it should free */ + + fp = fopen(filename, "rb"); + if (!fp) + return -1; + + if (fseek(fp, 0, SEEK_END) < 0) { + fclose(fp); + return -1; + } + size = ftell(fp); + if (size < 0) { + fclose(fp); + return -1; + } + rewind(fp); + + font->memory = malloc((size_t)size); + if (!font->memory) { + fclose(fp); + return -1; + } + + n = fread((void *)font->memory, 1, (size_t)size, fp); + fclose(fp); + + if (n != (size_t)size) { + free((void *)font->memory); + font->memory = NULL; + return -1; + } + + font->size = (uint_fast32_t)size; + return 0; } static void unmap_file(SFT_Font *font) { - assert(font->memory != MAP_FAILED); - munmap((void *)font->memory, font->size); + if (font->memory) { + free((void *)font->memory); + font->memory = NULL; + } } #endif diff --git a/bmp/lib/schrift.h b/bmp/lib/schrift.h index c27f619..d3788c1 100644 --- a/bmp/lib/schrift.h +++ b/bmp/lib/schrift.h @@ -73,7 +73,7 @@ const char *sft_version(void); SFT_Font *sft_loadmem(const void *mem, size_t size); SFT_Font *sft_loadfile(const char *filename); -void sft_freefont(SFT_Font *font); +int sft_freefont(SFT_Font *font); int sft_lmetrics(const SFT *sft, SFT_LMetrics *metrics); int sft_lookup(const SFT *sft, SFT_UChar codepoint, SFT_Glyph *glyph); diff --git a/bmp/macros.h b/bmp/macros.h new file mode 100644 index 0000000..c1521f1 --- /dev/null +++ b/bmp/macros.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include + +#define HAL_DANGER(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[31m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + } while (0) + +#define HAL_ERROR(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[31m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + return EXIT_FAILURE; \ + } while (0) + +#define HAL_INFO(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] ", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + } while (0) + +#define HAL_WARNING(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[33m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + } while (0) + +#ifndef CEILING +#define CEILING_POS(X) ((X-(int)(X)) > 0 ? (int)(X+1) : (int)(X)) +#define CEILING_NEG(X) (int)(X) +#define CEILING(X) ( ((X) > 0) ? CEILING_POS(X) : CEILING_NEG(X) ) +#endif + +#define EMPTY(x) (x[0] == '\0') +#define ENDS_WITH(a, b) \ + ((strlen(a) > strlen(b)) && !strcmp(a + strlen(a) - strlen(b), b)) +#define EQUALS(a, b) !strcmp(a, b) +#define EQUALS_CASE(a, b) !strcasecmp(a, b) +#define STARTS_WITH(a, b) !strncmp(a, b, strlen(b)) \ No newline at end of file diff --git a/bmp/region.c b/bmp/region.c index 0531d9c..09aafeb 100644 --- a/bmp/region.c +++ b/bmp/region.c @@ -1,5 +1,12 @@ #include "region.h" + +#if defined(__INFINITY6C__) +#include "bmp/star/i6c_hal.h" // always include prototypes +#include "bmp/star/i6c_hal.c" +#endif + + // https://wx.comake.online/doc/ds82ff82j7jsd9-SSD220/customer/development/mi/en/exclude/mi_rgn.html #ifdef __SIGMASTAR__ @@ -12,6 +19,28 @@ int PIXEL_FORMAT_DEFAULT = 3; // 0 for PIXEL_FORMAT_1555 , 4 for E_MI_RGN_PIXEL_ extern bool verbose; const double inv16 = 1.0 / 16.0; + + +int InitRGN_SigmaStar(){ +#if __INFINITY6C__ + if (i6c_hal_init()) + fprintf(stderr, "[%s:%d]MI_SYS_Init failed with!\n", __func__, __LINE__); + //int s32Ret = i6c_region_init(&g_stPaletteTable); + int s32Ret = i6c_region_init((i6c_rgn_pal *)&g_stPaletteTable); //We are sure the structure is the same + if (verbose) + printf("MI_RGN_Init_6c results: %d \n", s32Ret); + if (s32Ret) + fprintf(stderr, "[%s:%d]RGN_Init_6c failed with %#x!\n", __func__, __LINE__, s32Ret); + +#else + int s32Ret = MI_RGN_Init(DEV &g_stPaletteTable); + if (verbose) + printf("MI_RGN_Init results: %d\n", s32Ret); + if (s32Ret) + fprintf(stderr, "[%s:%d]RGN_Init failed with %#x!\n", __func__, __LINE__, s32Ret); +#endif +} + int create_region(int *handle, int x, int y, int width, int height) { int s32Ret = -1; #if !defined(_x86) && !defined(__ROCKCHIP__) @@ -25,7 +54,9 @@ int create_region(int *handle, int x, int y, int width, int height) { MI_RGN_ChnPortParam_t stChnAttrCurrent; #if __INFINITY6C__ - stChn.eModId = E_MI_MODULE_ID_VENC; + hal_rect rect = { .height = height, .width = width, + .x = x, .y = y }; + return i6c_region_create(0,rect,255); #else stChn.eModId = E_MI_RGN_MODID_VPE; #endif @@ -346,9 +377,9 @@ void *get_directBMP(int handle) { int s32Ret = GetCanvas(handle, &stCanvasInfo); if (s32Ret) - printf("GetCanvas Res: 0x%X, OSD Handle: %d CanvasStride: %d, Canvas size: %d:%d\r\n", - s32Ret, handle, stCanvasInfo.u32Stride, - stCanvasInfo.stSize.u32Width, stCanvasInfo.stSize.u32Height); + printf("GetCanvas Res: %X OSD Handle:%d CanvasStride: %d , Canvas size : %d:%d\r\n", + s32Ret, handle, stCanvasInfo.u32Stride, stCanvasInfo.stSize.u32Width, + stCanvasInfo.stSize.u32Height); return (void *)(stCanvasInfo.virtAddr); #endif return NULL; @@ -424,8 +455,8 @@ int unload_region(int *handle) { } #ifdef __SIGMASTAR__ -int GetCanvas(int handle, MI_RGN_CanvasInfo_t *stCanvasInfo) { - int s32Result = MI_RGN_GetCanvasInfo(DEV handle, stCanvasInfo); +int GetCanvas(int handle, MI_RGN_CanvasInfo_t *stCanvasInfo) { + int s32Result = MI_RGN_GetCanvasInfo(DEV handle, stCanvasInfo); if (s32Result != MI_RGN_OK) return s32Result; diff --git a/bmp/region.h b/bmp/region.h index 9daa309..41dfc9e 100644 --- a/bmp/region.h +++ b/bmp/region.h @@ -18,6 +18,7 @@ int set_bitmap(int handle, BITMAP *bitmap); unsigned long set_bitmapEx(int handle, BITMAP *bitmap, int BitsPerPixel); int unload_region(int *handle); void *get_directBMP(int handle); +int InitRGN_SigmaStar(); #ifdef __SIGMASTAR__ int GetCanvas(int handle, MI_RGN_CanvasInfo_t *stCanvasInfo); uint32_t ST_OSD_DrawPoint( diff --git a/bmp/star/i6c_common copy.h b/bmp/star/i6c_common copy.h new file mode 100644 index 0000000..f0fff04 --- /dev/null +++ b/bmp/star/i6c_common copy.h @@ -0,0 +1,119 @@ +#pragma once + +#include +#include +#include + +#include "../symbols.h" +#include "../types.h" + +#define I6C_VENC_CHN_NUM 12 + +typedef enum { + I6C_BAYER_RG, + I6C_BAYER_GR, + I6C_BAYER_BG, + I6C_BAYER_GB, + I6C_BAYER_R0, + I6C_BAYER_G0, + I6C_BAYER_B0, + I6C_BAYER_G1, + I6C_BAYER_G2, + I6C_BAYER_I0, + I6C_BAYER_G3, + I6C_BAYER_I1, + I6C_BAYER_END +} i6c_common_bayer; + +typedef enum { + I6C_COMPR_NONE, + I6C_COMPR_SEG, + I6C_COMPR_LINE, + I6C_COMPR_FRAME, + I6C_COMPR_8BIT, + I6C_COMPR_6BIT, + I6C_COMPR_IFC, + I6C_COMPR_SFBC0, + I6C_COMPR_SFBC1, + I6C_COMPR_SFBC2, + I6C_COMPR_END +} i6c_common_compr; + +typedef enum { + I6C_EDGE_SINGLE_UP, + I6C_EDGE_SINGLE_DOWN, + I6C_EDGE_DOUBLE, + I6C_EDGE_END +} i6c_common_edge; + +typedef enum { + I6C_HDR_OFF, + I6C_HDR_VC, + I6C_HDR_DOL, + I6C_HDR_EMBED, + I6C_HDR_LI, + I6C_HDR_END +} i6c_common_hdr; + +typedef enum { + I6C_INTF_BT656, + I6C_INTF_DIGITAL_CAMERA, + I6C_INTF_BT1120_STANDARD, + I6C_INTF_BT1120_INTERLEAVED, + I6C_INTF_MIPI, + I6C_INTF_LVDS, + I6C_INTF_END +} i6c_common_intf; + +typedef enum { + I6C_PREC_8BPP, + I6C_PREC_10BPP, + I6C_PREC_12BPP, + I6C_PREC_14BPP, + I6C_PREC_16BPP, + I6C_PREC_END +} i6c_common_prec; + +typedef enum { + I6C_PIXFMT_YUV422_YUYV, + I6C_PIXFMT_ARGB8888, + I6C_PIXFMT_ABGR8888, + I6C_PIXFMT_BGRA8888, + I6C_PIXFMT_RGB565, + I6C_PIXFMT_ARGB1555, + I6C_PIXFMT_ARGB4444, + I6C_PIXFMT_I2, + I6C_PIXFMT_I4, + I6C_PIXFMT_I8, + I6C_PIXFMT_YUV422SP, + I6C_PIXFMT_YUV420SP, + I6C_PIXFMT_YUV420SP_NV21, + I6C_PIXFMT_YUV420_TILE, + I6C_PIXFMT_YUV422_UYVY, + I6C_PIXFMT_YUV422_YVYU, + I6C_PIXFMT_YUV422_VYUY, + I6C_PIXFMT_YUV422P, + I6C_PIXFMT_YUV420P, + I6C_PIXFMT_YUV420_FBC, + I6C_PIXFMT_RGB_BAYER, + I6C_PIXFMT_RGB_BAYER_END = + I6C_PIXFMT_RGB_BAYER + I6C_PREC_END * I6C_BAYER_END - 1, + I6C_PIXFMT_RGB888, + I6C_PIXFMT_BGR888, + I6C_PIXFMT_GRAY8, + I6C_PIXFMT_RGB101010, + I6C_PIXFMT_RGB888P, + I6C_PIXFMT_END +} i6c_common_pixfmt; + +typedef struct { + unsigned short width; + unsigned short height; +} i6c_common_dim; + +typedef struct { + unsigned short x; + unsigned short y; + unsigned short width; + unsigned short height; +} i6c_common_rect; \ No newline at end of file diff --git a/bmp/star/i6c_common.h b/bmp/star/i6c_common.h new file mode 100644 index 0000000..f0fff04 --- /dev/null +++ b/bmp/star/i6c_common.h @@ -0,0 +1,119 @@ +#pragma once + +#include +#include +#include + +#include "../symbols.h" +#include "../types.h" + +#define I6C_VENC_CHN_NUM 12 + +typedef enum { + I6C_BAYER_RG, + I6C_BAYER_GR, + I6C_BAYER_BG, + I6C_BAYER_GB, + I6C_BAYER_R0, + I6C_BAYER_G0, + I6C_BAYER_B0, + I6C_BAYER_G1, + I6C_BAYER_G2, + I6C_BAYER_I0, + I6C_BAYER_G3, + I6C_BAYER_I1, + I6C_BAYER_END +} i6c_common_bayer; + +typedef enum { + I6C_COMPR_NONE, + I6C_COMPR_SEG, + I6C_COMPR_LINE, + I6C_COMPR_FRAME, + I6C_COMPR_8BIT, + I6C_COMPR_6BIT, + I6C_COMPR_IFC, + I6C_COMPR_SFBC0, + I6C_COMPR_SFBC1, + I6C_COMPR_SFBC2, + I6C_COMPR_END +} i6c_common_compr; + +typedef enum { + I6C_EDGE_SINGLE_UP, + I6C_EDGE_SINGLE_DOWN, + I6C_EDGE_DOUBLE, + I6C_EDGE_END +} i6c_common_edge; + +typedef enum { + I6C_HDR_OFF, + I6C_HDR_VC, + I6C_HDR_DOL, + I6C_HDR_EMBED, + I6C_HDR_LI, + I6C_HDR_END +} i6c_common_hdr; + +typedef enum { + I6C_INTF_BT656, + I6C_INTF_DIGITAL_CAMERA, + I6C_INTF_BT1120_STANDARD, + I6C_INTF_BT1120_INTERLEAVED, + I6C_INTF_MIPI, + I6C_INTF_LVDS, + I6C_INTF_END +} i6c_common_intf; + +typedef enum { + I6C_PREC_8BPP, + I6C_PREC_10BPP, + I6C_PREC_12BPP, + I6C_PREC_14BPP, + I6C_PREC_16BPP, + I6C_PREC_END +} i6c_common_prec; + +typedef enum { + I6C_PIXFMT_YUV422_YUYV, + I6C_PIXFMT_ARGB8888, + I6C_PIXFMT_ABGR8888, + I6C_PIXFMT_BGRA8888, + I6C_PIXFMT_RGB565, + I6C_PIXFMT_ARGB1555, + I6C_PIXFMT_ARGB4444, + I6C_PIXFMT_I2, + I6C_PIXFMT_I4, + I6C_PIXFMT_I8, + I6C_PIXFMT_YUV422SP, + I6C_PIXFMT_YUV420SP, + I6C_PIXFMT_YUV420SP_NV21, + I6C_PIXFMT_YUV420_TILE, + I6C_PIXFMT_YUV422_UYVY, + I6C_PIXFMT_YUV422_YVYU, + I6C_PIXFMT_YUV422_VYUY, + I6C_PIXFMT_YUV422P, + I6C_PIXFMT_YUV420P, + I6C_PIXFMT_YUV420_FBC, + I6C_PIXFMT_RGB_BAYER, + I6C_PIXFMT_RGB_BAYER_END = + I6C_PIXFMT_RGB_BAYER + I6C_PREC_END * I6C_BAYER_END - 1, + I6C_PIXFMT_RGB888, + I6C_PIXFMT_BGR888, + I6C_PIXFMT_GRAY8, + I6C_PIXFMT_RGB101010, + I6C_PIXFMT_RGB888P, + I6C_PIXFMT_END +} i6c_common_pixfmt; + +typedef struct { + unsigned short width; + unsigned short height; +} i6c_common_dim; + +typedef struct { + unsigned short x; + unsigned short y; + unsigned short width; + unsigned short height; +} i6c_common_rect; \ No newline at end of file diff --git a/bmp/star/i6c_hal.c b/bmp/star/i6c_hal.c new file mode 100644 index 0000000..640695b --- /dev/null +++ b/bmp/star/i6c_hal.c @@ -0,0 +1,158 @@ +#if defined(__INFINITY6C__) + +#include "i6c_hal.h" + +i6c_rgn_impl i6c_rgn; +i6c_sys_impl i6c_sys; + +char _i6c_venc_dev[2] = { 0, 8 }; +char _i6c_venc_port = 0; + +void i6c_hal_deinit(void) +{ + i6c_system_deinit(); + + i6c_rgn_unload(&i6c_rgn); + i6c_sys_unload(&i6c_sys); +} + +int i6c_hal_init(void) +{ + int ret; + + if (ret = i6c_sys_load(&i6c_sys)) + return ret; + if (ret = i6c_rgn_load(&i6c_rgn)) + return ret; + + if (ret = i6c_system_init()) + return ret; + + return EXIT_SUCCESS; +} + +int i6c_region_create(char handle, hal_rect rect, short opacity) +{ + int ret = EXIT_SUCCESS; + + i6c_sys_bind dest = { .module = I6C_SYS_MOD_VENC, .port =_i6c_venc_port }; + //i6c_sys_bind dest = { .module = I6C_SYS_MOD_VPE, .port =_i6c_venc_port }; + + i6c_rgn_cnf region, regionCurr; + i6c_rgn_chn attrib, attribCurr; + + region.type = I6C_RGN_TYPE_OSD; + region.pixFmt = PIXEL_FORMAT_DEFAULT;//I6C_RGN_PIXFMT_ARGB1555; + region.size.width = rect.width; + region.size.height = rect.height; + + if (i6c_rgn.fnGetRegionConfig(0, handle, ®ionCurr)) { + HAL_INFO("i6c_rgn", "Creating region %d...\n", handle); + if (ret = i6c_rgn.fnCreateRegion(0, handle, ®ion)) + return ret; + } else if (regionCurr.type != region.type || + regionCurr.size.height != region.size.height || + regionCurr.size.width != region.size.width) { + HAL_INFO("i6c_rgn", "Parameters are different, recreating " + "region %d...\n", handle); + for (dest.channel = 0; dest.channel < 2; dest.channel++) { + dest.device = _i6c_venc_dev[0]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + dest.device = _i6c_venc_dev[1]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + } + i6c_rgn.fnDestroyRegion(0, handle); + if (ret = i6c_rgn.fnCreateRegion(0, handle, ®ion)) + return ret; + } + + if (i6c_rgn.fnGetChannelConfig(0, handle, &dest, &attribCurr)) + HAL_INFO("i6c_rgn", "Attaching region %d...\n", handle); + else if (attribCurr.point.x != rect.x || attribCurr.point.x != rect.y || + attribCurr.osd.bgFgAlpha[1] != opacity) { + HAL_INFO("i6c_rgn", "Parameters are different, reattaching " + "region %d...\n", handle); + for (dest.channel = 0; dest.channel < 2; dest.channel++) { + dest.device = _i6c_venc_dev[0]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + dest.device = _i6c_venc_dev[1]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + } + } + + memset(&attrib, 0, sizeof(attrib)); + attrib.show = 1; + attrib.point.x = rect.x; + attrib.point.y = rect.y; + attrib.osd.layer = 0; + attrib.osd.constAlphaOn = 0; + attrib.osd.bgFgAlpha[0] = 0; + attrib.osd.bgFgAlpha[1] = opacity; + + for (dest.channel = 0; dest.channel < 2; dest.channel++) { + dest.device = _i6c_venc_dev[0]; + i6c_rgn.fnAttachChannel(0, handle, &dest, &attrib); + dest.device = _i6c_venc_dev[1]; + i6c_rgn.fnAttachChannel(0, handle, &dest, &attrib); + } + + return EXIT_SUCCESS; +} + +void i6c_region_deinit(void) +{ + i6c_rgn.fnDeinit(0); +} + +void i6c_region_destroy(char handle) +{ + i6c_sys_bind dest = { .module = I6C_SYS_MOD_VENC, .port =_i6c_venc_port }; + + for (dest.channel = 0; dest.channel < 2; dest.channel++) { + dest.device = _i6c_venc_dev[0]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + dest.device = _i6c_venc_dev[1]; + i6c_rgn.fnDetachChannel(0, handle, &dest); + } + i6c_rgn.fnDestroyRegion(0, handle); +} + +int i6c_region_init(i6c_rgn_pal *palette) +{ + //i6c_rgn_pal palette = {{{0, 0, 0, 0}}}; + i6c_rgn.fnInit(0, palette); +} + +int i6c_region_setbitmap(int handle, hal_bitmap *bitmap) +{ + i6c_rgn_bmp nativeBmp = { .data = bitmap->data, .pixFmt = I6C_RGN_PIXFMT_ARGB1555, + .size.height = bitmap->dim.height, .size.width = bitmap->dim.width }; + + return i6c_rgn.fnSetBitmap(0, handle, &nativeBmp); +} + +void i6c_system_deinit(void) +{ + i6c_sys.fnExit(0); +} + +int i6c_system_init(void) +{ + int ret; + + if (ret = i6c_sys.fnInit(0)) + return ret; + + printf("App built with headers v%s\n", I6C_SYS_API); + + { + i6c_sys_ver version; + if (ret = i6c_sys.fnGetVersion(0, &version)) + return ret; + puts(version.version); + } + + return EXIT_SUCCESS; +} + +#endif \ No newline at end of file diff --git a/bmp/star/i6c_hal.h b/bmp/star/i6c_hal.h new file mode 100644 index 0000000..22e4243 --- /dev/null +++ b/bmp/star/i6c_hal.h @@ -0,0 +1,28 @@ + +#ifndef I6C_HAL_H +#define I6C_HAL_H + +#pragma once + +#include "i6c_common.h" +#include "i6c_rgn.h" +#include "i6c_sys.h" + +#include +#include + + +extern char keepRunning; + +void i6c_hal_deinit(void); +int i6c_hal_init(void); + +int i6c_region_create(char handle, hal_rect rect, short opacity); +void i6c_region_deinit(void); +void i6c_region_destroy(char handle); +int i6c_region_init(i6c_rgn_pal *palette); +int i6c_region_setbitmap(int handle, hal_bitmap *bitmap); + +void i6c_system_deinit(void); +int i6c_system_init(void); +#endif \ No newline at end of file diff --git a/bmp/star/i6c_rgn.h b/bmp/star/i6c_rgn.h new file mode 100644 index 0000000..c384ebc --- /dev/null +++ b/bmp/star/i6c_rgn.h @@ -0,0 +1,158 @@ +#pragma once + +#include "i6c_common.h" +#include "i6c_sys.h" + +typedef enum { + I6C_RGN_PIXFMT_ARGB1555, + I6C_RGN_PIXFMT_ARGB4444, + I6C_RGN_PIXFMT_I2, + I6C_RGN_PIXFMT_I4, + I6C_RGN_PIXFMT_I8, + I6C_RGN_PIXFMT_RGB565, + I6C_RGN_PIXFMT_ARGB888, + I6C_RGN_PIXFMT_END +} i6c_rgn_pixfmt; + +typedef enum { + I6C_RGN_TYPE_OSD, + I6C_RGN_TYPE_COVER, + I6C_RGN_TYPE_END +} i6c_rgn_type; + +typedef struct { + unsigned int width; + unsigned int height; +} i6c_rgn_size; + +typedef struct { + i6c_rgn_pixfmt pixFmt; + i6c_rgn_size size; + void *data; +} i6c_rgn_bmp; + +typedef struct { + i6c_rgn_type type; + i6c_rgn_pixfmt pixFmt; + i6c_rgn_size size; +} i6c_rgn_cnf; + +typedef struct { + unsigned int layer; + i6c_rgn_size size; + unsigned int color; +} i6c_rgn_cov; + +typedef struct { + int invColOn; + int lowThanThresh; + unsigned int lumThresh; + unsigned short divWidth; + unsigned short divHeight; +} i6c_rgn_inv; + +typedef struct { + unsigned int layer; + int constAlphaOn; + union { + unsigned char bgFgAlpha[2]; + unsigned char constAlpha[2]; + }; + i6c_rgn_inv invert; +} i6c_rgn_osd; + +typedef struct { + unsigned int x; + unsigned int y; +} i6c_rgn_pnt; + +typedef struct { + int show; + i6c_rgn_pnt point; + union { + i6c_rgn_cov cover; + i6c_rgn_osd osd; + }; +} i6c_rgn_chn; + +typedef struct { + unsigned char alpha; + unsigned char red; + unsigned char green; + unsigned char blue; +} i6c_rgn_pale; + +typedef struct { + i6c_rgn_pale element[256]; +} i6c_rgn_pal; + +typedef struct { + void *handle; + + int (*fnDeinit)(unsigned short chip); + int (*fnInit)(unsigned short chip, i6c_rgn_pal *palette); + + int (*fnCreateRegion)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config); + int (*fnDestroyRegion)(unsigned short chip, unsigned int handle); + int (*fnGetRegionConfig)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config); + + int (*fnAttachChannel)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config); + int (*fnDetachChannel)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest); + int (*fnGetChannelConfig)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config); + int (*fnSetChannelConfig)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config); + + int (*fnSetBitmap)(unsigned short chip, unsigned int handle, i6c_rgn_bmp *bitmap); +} i6c_rgn_impl; + +static int i6c_rgn_load(i6c_rgn_impl *rgn_lib) { + if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_rgn", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(rgn_lib->fnDeinit = (int(*)(unsigned short chip)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_DeInit"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnInit = (int(*)(unsigned short chip, i6c_rgn_pal *palette)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Init"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Create"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned short chip, unsigned int handle)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Destroy"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_GetAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_AttachToChn"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_DetachFromChn"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_bmp *bitmap)) + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_SetBitMap"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void i6c_rgn_unload(i6c_rgn_impl *rgn_lib) { + if (rgn_lib->handle) dlclose(rgn_lib->handle); + rgn_lib->handle = NULL; + memset(rgn_lib, 0, sizeof(*rgn_lib)); +} \ No newline at end of file diff --git a/bmp/star/i6c_sys.h b/bmp/star/i6c_sys.h new file mode 100644 index 0000000..5ee7add --- /dev/null +++ b/bmp/star/i6c_sys.h @@ -0,0 +1,197 @@ +#pragma once + +#include "i6c_common.h" + +#define I6C_SYS_API "1.0" + +typedef enum { + I6C_SYS_LINK_FRAMEBASE = 0x1, + I6C_SYS_LINK_LOWLATENCY = 0x2, + I6C_SYS_LINK_REALTIME = 0x4, + I6C_SYS_LINK_AUTOSYNC = 0x8, + I6C_SYS_LINK_RING = 0x10 +} i6c_sys_link; + +typedef enum { + I6C_SYS_MOD_IVE, + I6C_SYS_MOD_VDF, + I6C_SYS_MOD_VENC, + I6C_SYS_MOD_RGN, + I6C_SYS_MOD_AI, + I6C_SYS_MOD_AO, + I6C_SYS_MOD_VIF, + I6C_SYS_MOD_VPE, + I6C_SYS_MOD_VDEC, + I6C_SYS_MOD_SYS, + I6C_SYS_MOD_FB, + I6C_SYS_MOD_HDMI, + I6C_SYS_MOD_DIVP, + I6C_SYS_MOD_GFX, + I6C_SYS_MOD_VDISP, + I6C_SYS_MOD_DISP, + I6C_SYS_MOD_OS, + I6C_SYS_MOD_IAE, + I6C_SYS_MOD_MD, + I6C_SYS_MOD_OD, + I6C_SYS_MOD_SHADOW, + I6C_SYS_MOD_WARP, + I6C_SYS_MOD_UAC, + I6C_SYS_MOD_LDC, + I6C_SYS_MOD_SD, + I6C_SYS_MOD_PANEL, + I6C_SYS_MOD_CIPHER, + I6C_SYS_MOD_SNR, + I6C_SYS_MOD_WLAN, + I6C_SYS_MOD_IPU, + I6C_SYS_MOD_MIPITX, + I6C_SYS_MOD_GYRO, + I6C_SYS_MOD_JPD, + I6C_SYS_MOD_ISP, + I6C_SYS_MOD_SCL, + I6C_SYS_MOD_WBC, + I6C_SYS_MOD_DSP, + I6C_SYS_MOD_PCIE, + I6C_SYS_MOD_DUMMY, + I6C_SYS_MOD_NIR, + I6C_SYS_MOD_DPU, + I6C_SYS_MOD_END, +} i6c_sys_mod; + +typedef enum { + I6C_SYS_POOL_ENCODER_RING, + I6C_SYS_POOL_CHANNEL, + I6C_SYS_POOL_DEVICE, + I6C_SYS_POOL_OUTPUT, + I6C_SYS_POOL_DEVICE_RING +} i6c_sys_pooltype; + +typedef struct { + i6c_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned int port; +} i6c_sys_bind; + +typedef struct { + i6c_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned char heapName[32]; + unsigned int heapSize; +} i6c_sys_poolchn; + +typedef struct { + i6c_sys_mod module; + unsigned int device; + unsigned int reserved; + unsigned char heapName[32]; + unsigned int heapSize; +} i6c_sys_pooldev; + +typedef struct { + unsigned int ringSize; + unsigned char heapName[32]; +} i6c_sys_poolenc; + +typedef struct { + i6c_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned int port; + unsigned char heapName[32]; + unsigned int heapSize; +} i6c_sys_poolout; + +typedef struct { + i6c_sys_mod module; + unsigned int device; + unsigned short maxWidth; + unsigned short maxHeight; + unsigned short ringLine; + unsigned char heapName[32]; +} i6c_sys_poolring; + +typedef struct { + i6c_sys_pooltype type; + char create; + union { + i6c_sys_poolchn channel; + i6c_sys_pooldev device; + i6c_sys_poolenc encode; + i6c_sys_poolout output; + i6c_sys_poolring ring; + } config; +} i6c_sys_pool; + +typedef struct { + unsigned char version[128]; +} i6c_sys_ver; + +typedef struct { + void *handle, *handleCamOsWrapper; + + int (*fnExit)(unsigned short chip); + int (*fnGetVersion)(unsigned short chip, i6c_sys_ver *version); + int (*fnInit)(unsigned short chip); + + int (*fnBind)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, i6c_sys_link *link); + int (*fnBindExt)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, + unsigned int srcFps, unsigned int dstFps, i6c_sys_link link, unsigned int linkParam); + int (*fnSetOutputDepth)(unsigned short chip, i6c_sys_bind *bind, unsigned int usrDepth, + unsigned int bufDepth); + int (*fnUnbind)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest); + + int (*fnConfigPool)(unsigned short chip, i6c_sys_pool *config); +} i6c_sys_impl; + +static int i6c_sys_load(i6c_sys_impl *sys_lib) { + if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_sys", "Failed to load dependency library!\nError: %s\n", dlerror()); + + if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_sys", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(sys_lib->fnExit = (int(*)(unsigned short chip)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_Exit"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnGetVersion = (int(*)(unsigned short chip, i6c_sys_ver *version)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_GetVersion"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnInit = (int(*)(unsigned short chip)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_Init"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnBind = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, i6c_sys_link *link)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_BindChnPort"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnBindExt = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, + unsigned int srcFps, unsigned int dstFps, i6c_sys_link link, unsigned int linkParam)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_BindChnPort2"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, i6c_sys_bind *bind, + unsigned int usrDepth, unsigned int bufDepth)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_UnBindChnPort"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnConfigPool = (int(*)(unsigned short chip, i6c_sys_pool *config)) + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void i6c_sys_unload(i6c_sys_impl *sys_lib) { + if (sys_lib->handle) dlclose(sys_lib->handle); + sys_lib->handle = NULL; + if (sys_lib->handleCamOsWrapper) dlclose(sys_lib->handleCamOsWrapper); + sys_lib->handleCamOsWrapper = NULL; + memset(sys_lib, 0, sizeof(*sys_lib)); +} \ No newline at end of file diff --git a/bmp/symbols.h b/bmp/symbols.h new file mode 100644 index 0000000..adfd19a --- /dev/null +++ b/bmp/symbols.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "macros.h" + +static void inline *hal_symbol_load(const char *module, void *handle, const char *symbol) { + void *function = dlsym(handle, symbol); + if (!function) { + HAL_DANGER(module, "Failed to acquire symbol %s!\n", symbol); + return (void*)0; + } + return function; +} \ No newline at end of file diff --git a/bmp/text.c b/bmp/text.c index a75278b..3bb64f7 100644 --- a/bmp/text.c +++ b/bmp/text.c @@ -107,8 +107,34 @@ static inline void calcdim(double *margin, double *height, double *width, const *width = MAX(*width, lwidth) + 2 * *margin; } +SFT *GetCachedFont(const char *font, double size) { + if (sft.font == NULL || strcmp(last_font_name, font) != 0 || size!=last_font_size) { + if (sft.font) { + sft_freefont(sft.font); + } + loadfont(&sft, font, size, &lmtx); + strncpy(last_font_name, font, sizeof(last_font_name) - 1); + last_font_name[sizeof(last_font_name) - 1] = '\0'; + last_font_size=size; + //printf("TrueType Font %s size:%f loaded.\n",last_font_name,last_font_size); + } + + return &sft; +} + +int FreeCachedFont() { + if (sft.font) { + //printf("Unload TrueType font %s sft.font = %p\n",last_font_name, sft.font); + sft_freefont(sft.font); + return 1; + } + + return 0; +} + RECT measure_text(const char *font, double size, const char *text) { - loadfont(&sft, font, size, &lmtx); + //loadfont(&sft, font, size, &lmtx); + GetCachedFont(font, size);//We will usually have only one font file. lets make it faster double margin, height, width; calcdim(&margin, &height, &width, text); @@ -118,12 +144,13 @@ RECT measure_text(const char *font, double size, const char *text) { rect.height += rect.height & 1; rect.width += rect.width & 1; - sft_freefont(sft.font); + //sft_freefont(sft.font); return rect; } BITMAP raster_text(const char *font, double size, const char *text, uint16_t color) { - loadfont(&sft, font, size, &lmtx); + //loadfont(&sft, font, size, &lmtx); + GetCachedFont(font, size);//We will usually have only one font file. lets make it faster double margin, height, width; @@ -175,6 +202,6 @@ BITMAP raster_text(const char *font, double size, const char *text, uint16_t col bitmap.pData = canvas.pixels; bitmap.enPixelFormat = PIXEL_FORMAT_1555; - sft_freefont(sft.font); + //sft_freefont(sft.font); return bitmap; } diff --git a/bmp/text.h b/bmp/text.h index ba63fb8..a0b1fe6 100644 --- a/bmp/text.h +++ b/bmp/text.h @@ -12,6 +12,8 @@ extern "C" { #include "common.h" static SFT sft; +static char last_font_name[256] = ""; +static double last_font_size=0; static SFT_Image canvas; static SFT_LMetrics lmtx; static BITMAP bitmap; @@ -19,6 +21,8 @@ static BITMAP bitmap; RECT measure_text(const char *font, double size, const char *text); BITMAP raster_text(const char *font, double size, const char *text, uint16_t color); +int FreeCachedFont(); + #ifdef __cplusplus #if __cplusplus } diff --git a/bmp/types.h b/bmp/types.h new file mode 100644 index 0000000..b2ec9b0 --- /dev/null +++ b/bmp/types.h @@ -0,0 +1,49 @@ +#pragma once + +#include "macros.h" + +#ifndef ALIGN_BACK +#define ALIGN_BACK(x, a) (((x) / (a)) * (a)) +#endif +#ifndef ALIGN_UP +#define ALIGN_UP(x, a) ((((x) + ((a)-1)) / a) * a) +#endif +#ifndef CEILING_2_POWER +#define CEILING_2_POWER(x, a) (((x) + ((a)-1)) & (~((a) - 1))) +#endif +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#endif + +typedef enum { + HAL_PLATFORM_UNK, + HAL_PLATFORM_I6, + HAL_PLATFORM_I6C, + HAL_PLATFORM_M6, + HAL_PLATFORM_V1, + HAL_PLATFORM_V2, + HAL_PLATFORM_V3, + HAL_PLATFORM_V4 +} hal_platform; + +typedef enum { + OP_READ = 0b1, + OP_WRITE = 0b10, + OP_MODIFY = 0b11 +} hal_register_op; + +typedef struct { + unsigned short width, height; +} hal_dim; + +typedef struct { + hal_dim dim; + void *data; +} hal_bitmap; + +typedef struct { + unsigned short x, y, width, height; +} hal_rect; \ No newline at end of file diff --git a/msposd_x b/msposd_x new file mode 100755 index 0000000..f15bd74 Binary files /dev/null and b/msposd_x differ diff --git a/osd.c b/osd.c index 968552b..606fe9a 100644 --- a/osd.c +++ b/osd.c @@ -2445,8 +2445,10 @@ static void InitMSPHook() { int rgn = 0; - osds = mmap( - NULL, sizeof(*osds) * MAX_OSD, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); +// osds = mmap(NULL, sizeof(*osds) * MAX_OSD, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0); + osds = malloc(sizeof(*osds) * MAX_OSD); + + for (int id = 0; id < MAX_OSD; id++) { osds[id].hand = id; @@ -2459,16 +2461,7 @@ static void InitMSPHook() { } #ifdef __SIGMASTAR__ -#if __INFINITY6C__ - if (MI_SYS_Init(0)) - fprintf(stderr, "[%s:%d]MI_SYS_Init failed with!\n", __func__, __LINE__); -#endif - - int s32Ret = MI_RGN_Init(DEV &g_stPaletteTable); - if (verbose) - printf("MI_RGN_Init results: %d\n", s32Ret); - if (s32Ret) - fprintf(stderr, "[%s:%d]RGN_Init failed with %#x!\n", __func__, __LINE__, s32Ret); + InitRGN_SigmaStar(); #endif int XOffs = (majestic_width - OVERLAY_WIDTH) / 2; @@ -2483,7 +2476,7 @@ static void InitMSPHook() { if (matrix_size == 9) YOffs = (majestic_height - OVERLAY_HEIGHT); // vertical bottom - // THIS IS NEEDED, the main region to draw inside + // THIS IS NEEDED, the main region to draw inside if (DrawOSD) rgn = create_region(&osds[FULL_OVERLAY_ID].hand, XOffs, YOffs, OVERLAY_WIDTH, OVERLAY_HEIGHT); @@ -2501,12 +2494,12 @@ static void InitMSPHook() { #endif BITMAP bitmap; int prepared = 0; - + // LOAD PNG TEST, if there is font file loaded, preview it if (/*true*/ bitmapFnt.pData != NULL) { // Split and show a review of the - // selected font for several seconds + // selected font for several seconds prepared = 1; - + bitmap.enPixelFormat = PIXEL_FORMAT_DEFAULT; int preview_height = current_display_info.font_height * current_display_info.char_height; @@ -2516,7 +2509,7 @@ static void InitMSPHook() { int fontPageHeight = rows * current_display_info.font_height; // OVERLAY_HEIGHT;; bitmap.u32Height = OVERLAY_HEIGHT; // preview_height;//rows * // current_display_info.font_height;//OVERLAY_HEIGHT; - bitmap.u32Width = OVERLAY_WIDTH; // bitmapFnt.u32Width * cols; + bitmap.u32Width = OVERLAY_WIDTH; // bitmapFnt.u32Width * cols; bitmap.pData = (unsigned char *)malloc( bitmap.u32Height * getRowStride(bitmap.u32Width, PIXEL_FORMAT_BitsPerPixel)); memset(bitmap.pData, 0, @@ -2547,7 +2540,7 @@ static void InitMSPHook() { bitmap.enPixelFormat-PIXEL_FORMAT_DEFAULT; */ -#ifdef __SIGMASTAR__ +#ifdef __SIGMASTAR__ if (verbose) printf("Set SS Font Review %d:%d\n", bitmap.u32Width, bitmap.u32Height); // For some reason this fails...?! @@ -2561,7 +2554,7 @@ static void InitMSPHook() { // This is how direct image memory works in sigmastar void *bmp = get_directBMP(osds[FULL_OVERLAY_ID].hand); memcpy(bmp, bitmap.pData, - bitmap.u32Height * getRowStride(bitmap.u32Width, PIXEL_FORMAT_BitsPerPixel)); + bitmap.u32Height * getRowStride(bitmap.u32Width, PIXEL_FORMAT_BitsPerPixel)); MI_RGN_UpdateCanvas(DEV osds[FULL_OVERLAY_ID].hand); if (true) { @@ -2599,14 +2592,16 @@ static void InitMSPHook() { #endif // free(bitmap.pData); - } else { // no font file still, show message on screen + } else { // no font file still, show message on screen + useDirectBMPBuffer = true; + printf("Use Direct Video Memory MODE!\n"); cntr = 0; char msgbuff[120]; sprintf(msgbuff, "&F48 &L23 Waiting for data on %s ...", _port_name); SetOSDMsg(msgbuff); draw_screenBMP(); } - + if (prepared) { if (verbose) printf("set_LOGO with u32Height:%d enPixelFormat %d\n", bitmap.u32Height, @@ -2627,6 +2622,8 @@ static void InitMSPHook() { } static void CloseMSP() { + + int deinit = 0; int s32Ret = 0; #ifdef __SIGMASTAR__ @@ -2649,8 +2646,11 @@ static void CloseMSP() { free(bmpBuff.pData); if (bmpFntSmall.pData != NULL) free(bmpFntSmall.pData); - - int res_mun = munmap(osds, sizeof(*osds) * MAX_OSD); - - printf("RGN_Destroy: %X, RGN_DeInit: %X, unmap: %d\n", s32Ret, deinit, res_mun); + + printf("TrueType Font released: %d\n",FreeCachedFont(sft.font) ); + + //int res_mun = munmap(osds, sizeof(*osds) * MAX_OSD); + if (osds!=NULL) + free(osds); + printf("RGN_Destroy: %X, RGN_DeInit: %X\n", s32Ret, deinit); }