Skip to content

Commit

Permalink
建立为导出函数库项目
Browse files Browse the repository at this point in the history
  • Loading branch information
duguying committed Jul 20, 2014
1 parent b78bbb3 commit a91bd3d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 47 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 0 additions & 21 deletions src/bmp.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions src/bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "memory.h"
#include "math.h"
#include "matrix.h"
#include "common.h"

#pragma pack(push)
#pragma pack(1)
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _COMMON_H_
#define _COMMON_H_

#if defined _WIN32
#define iexp __declspec(dllexport)
#else
# define iexp
#endif

#endif
22 changes: 22 additions & 0 deletions src/matrix.c
Original file line number Diff line number Diff line change
@@ -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;
}

}
17 changes: 17 additions & 0 deletions src/matrix.h
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a91bd3d

Please sign in to comment.