diff options
| author | yangwei <[email protected]> | 2024-05-17 16:55:46 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2024-05-20 10:09:18 +0800 |
| commit | e0ec3f2d5211fe7fe002ec574afc3e05593f5bd7 (patch) | |
| tree | e8f2a071594d47fae94b6fac02343576a562040d /deps | |
| parent | db611561f612f673d5b0e57ab63f11b628109766 (diff) | |
✨ feat(plugin manager): integrated plugin manager, build success
Diffstat (limited to 'deps')
| -rw-r--r-- | deps/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | deps/bitmap/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | deps/bitmap/bitmap.c | 59 | ||||
| -rw-r--r-- | deps/bitmap/bitmap.h | 5 |
4 files changed, 69 insertions, 1 deletions
diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 3c9947a..8e10935 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -2,4 +2,5 @@ add_subdirectory(timeout) add_subdirectory(dablooms) add_subdirectory(toml) add_subdirectory(rbtree) -add_subdirectory(interval_tree)
\ No newline at end of file +add_subdirectory(interval_tree) +add_subdirectory(bitmap)
\ No newline at end of file diff --git a/deps/bitmap/CMakeLists.txt b/deps/bitmap/CMakeLists.txt new file mode 100644 index 0000000..4eefd63 --- /dev/null +++ b/deps/bitmap/CMakeLists.txt @@ -0,0 +1,3 @@ +set(CMAKE_C_FLAGS "-std=c99") +add_definitions(-fPIC) +add_library(bitmap STATIC bitmap.c)
\ No newline at end of file diff --git a/deps/bitmap/bitmap.c b/deps/bitmap/bitmap.c new file mode 100644 index 0000000..59fb4b7 --- /dev/null +++ b/deps/bitmap/bitmap.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +struct bitmap { + unsigned char *data; + int width; + int height; +}; + +struct bitmap * bitmap_new(int width, int height, int value) { + struct bitmap *bmp = (struct bitmap *)malloc(sizeof(struct bitmap)); + bmp->width = width; + bmp->height = height; + int size = (width * height + 7) / 8; // Calculate total bytes needed + bmp->data = (unsigned char *)calloc(size,1 ); + memset(bmp->data, value ? 0xFF : 0x00, size); + return bmp; +} + +int bitmap_set(struct bitmap *bmp, int x, int y, int value) { + if (x < 0 || y < 0 || x >= bmp->width || y >= bmp->height) { + return -1; // Return error code if coordinates are out of bounds + } + int idx = y * bmp->width + x; + if (value) + bmp->data[idx / 8] |= (1 << (idx % 8)); + else + bmp->data[idx / 8] &= ~(1 << (idx % 8)); + return 0; +} + +int bitmap_get(struct bitmap *bmp, int x, int y) { + if (x < 0 || y < 0 || x >= bmp->width || y >= bmp->height) { + return -1; // Return error code if coordinates are out of bounds + } + int idx = y * bmp->width + x; + return (bmp->data[idx / 8] & (1 << (idx % 8))) != 0; +} + +void bitmap_free(struct bitmap *bmp) { + if(bmp) + { + if(bmp->data)free(bmp->data); + free(bmp); + } +} + + + + +int test_bitmap() { + struct bitmap *bmp = bitmap_new(10, 5, 1); // Create a 10x5 bitmap + if (bitmap_set(bmp, 2, 2, 1) == 0) { // Set bit at position (2,2) + printf("Bit at (2,2): %d\n", bitmap_get(bmp, 2, 2)); // Get bit at position (2,2) + } + bitmap_free(bmp); + return 0; +} diff --git a/deps/bitmap/bitmap.h b/deps/bitmap/bitmap.h new file mode 100644 index 0000000..210ea35 --- /dev/null +++ b/deps/bitmap/bitmap.h @@ -0,0 +1,5 @@ +struct bitmap; +struct bitmap * bitmap_new(int width, int height, int value); +int bitmap_set(struct bitmap *bmp, int x, int y, int value); +int bitmap_get(struct bitmap *bmp, int x, int y); +void bitmap_free(struct bitmap *bmp);
\ No newline at end of file |
