✨ feat(plugin manager): integrated plugin manager, build success
This commit is contained in:
3
deps/bitmap/CMakeLists.txt
vendored
Normal file
3
deps/bitmap/CMakeLists.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
set(CMAKE_C_FLAGS "-std=c99")
|
||||
add_definitions(-fPIC)
|
||||
add_library(bitmap STATIC bitmap.c)
|
||||
59
deps/bitmap/bitmap.c
vendored
Normal file
59
deps/bitmap/bitmap.c
vendored
Normal file
@@ -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;
|
||||
}
|
||||
5
deps/bitmap/bitmap.h
vendored
Normal file
5
deps/bitmap/bitmap.h
vendored
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user