diff --git a/CMakeLists.txt b/CMakeLists.txt index 8777dc3..f1b8b66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,15 @@ include_directories("src") set(SRC_DIR "src/") set(TEST_DIR "tests/") -set(READIMG_LIST +set(IMAGE ${SRC_DIR}/bmp.c ${SRC_DIR}/transform.c - ${TEST_DIR}/bmp.c + ${SRC_DIR}/matrix.c ) +add_library(image SHARED ${IMAGE}) -add_executable(bmp ${READIMG_LIST}) - +set(IMAGE_TEST + ${TEST_DIR}/bmp.c + ) +add_executable(bmp ${IMAGE_TEST}) +target_link_libraries(bmp image) diff --git a/src/bmp.c b/src/bmp.c index 67fd030..d8122a8 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -1,11 +1,5 @@ #include "bmp.h" -Matrix* init_matrix(){ - Matrix* data = (Matrix*)malloc(sizeof(Matrix)); - memset(data, 0, sizeof(Matrix)); - return data; -} - Matrix* bmp_get_matrix(const char* image_path, Matrix* data_matrix){ size_t len_file_hdr = 0; size_t len_info_hdr = 0; @@ -170,21 +164,6 @@ Matrix* bmp_get_matrix(const char* image_path, Matrix* data_matrix){ return data_matrix; } -void free_matrix(Matrix* data_matrix){ - if (data_matrix->matrix != NULL) - { - free(data_matrix->matrix); - data_matrix->matrix = NULL; - } - - if (data_matrix != NULL) - { - free(data_matrix); - data_matrix = NULL; - } - -} - void bmp_info_print(const char* image_path){ size_t len_file_hdr = 0; size_t len_info_hdr = 0; diff --git a/src/bmp.h b/src/bmp.h index f884b82..fb3e5ec 100644 --- a/src/bmp.h +++ b/src/bmp.h @@ -6,6 +6,7 @@ #include "memory.h" #include "math.h" #include "matrix.h" +#include "common.h" #pragma pack(push) #pragma pack(1) @@ -42,30 +43,18 @@ typedef struct _RGBQUAD { #pragma pack(pop) -/** - * create and initial matrix - * @return pointer of matrix - */ -Matrix* init_matrix(); - /** * get matrix * @param image_path image file path * @param data_matrix pointer of matrix * @return pointer of matrix */ -Matrix* bmp_get_matrix(const char* image_path, Matrix* data_matrix); - -/** - * free matrix - * @param data_matrix pointer of matrix - */ -void free_matrix(Matrix* data_matrix); +iexp Matrix* bmp_get_matrix(const char* image_path, Matrix* data_matrix); /** * print the headers of bmp file * @param image_path file path */ -void bmp_info_print(const char* image_path); +iexp void bmp_info_print(const char* image_path); #endif diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..ae06de8 --- /dev/null +++ b/src/common.h @@ -0,0 +1,10 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#if defined _WIN32 + #define iexp __declspec(dllexport) +#else +# define iexp +#endif + +#endif \ No newline at end of file diff --git a/src/matrix.c b/src/matrix.c new file mode 100644 index 0000000..f3e1a44 --- /dev/null +++ b/src/matrix.c @@ -0,0 +1,22 @@ +#include "matrix.h" + +Matrix* init_matrix(){ + Matrix* data = (Matrix*)malloc(sizeof(Matrix)); + memset(data, 0, sizeof(Matrix)); + return data; +} + +void free_matrix(Matrix* data_matrix){ + if (data_matrix->matrix != NULL) + { + free(data_matrix->matrix); + data_matrix->matrix = NULL; + } + + if (data_matrix != NULL) + { + free(data_matrix); + data_matrix = NULL; + } + +} diff --git a/src/matrix.h b/src/matrix.h index 0064147..288fa96 100644 --- a/src/matrix.h +++ b/src/matrix.h @@ -1,6 +1,11 @@ #ifndef _MATRIX_H_ #define _MATRIX_H_ +#include "stdio.h" +#include "stdlib.h" +#include "memory.h" +#include "common.h" + #pragma pack(push) #pragma pack(1) @@ -30,4 +35,16 @@ typedef struct _Matrix #pragma pack(pop) +/** + * create and initial matrix + * @return pointer of matrix + */ +iexp Matrix* init_matrix(); + +/** + * free matrix + * @param data_matrix pointer of matrix + */ +iexp void free_matrix(Matrix* data_matrix); + #endif diff --git a/src/transform.h b/src/transform.h index a74a1f6..91d8e55 100644 --- a/src/transform.h +++ b/src/transform.h @@ -4,21 +4,21 @@ #include "stdio.h" #include "stdlib.h" #include "memory.h" -#include "math.h" #include "matrix.h" +#include "common.h" -void roll_x(Matrix* matrix); +iexp void roll_x(Matrix* matrix); -void roll_y(Matrix* matrix); +iexp void roll_y(Matrix* matrix); -void rotate_right(Matrix* matrix); +iexp void rotate_right(Matrix* matrix); -void rotate_left(Matrix* matrix); +iexp void rotate_left(Matrix* matrix); -void cut(size_t x1, size_t y1, size_t width, size_t height, Matrix* matrix); +iexp void cut(size_t x1, size_t y1, size_t width, size_t height, Matrix* matrix); -void zoom_in(Matrix* matrix); +iexp void zoom_in(Matrix* matrix); -void zoom_out(Matrix* matrix); +iexp void zoom_out(Matrix* matrix); #endif