62,615
社区成员
发帖
与我相关
我的任务
分享
13 #include "bitmap.h"
12 #include "transform.h"
11 #include "util.h"
10
9 /// @Synopsis readHead /*{{{*/
8 /// @Param _file_path
7 /// @Param _file_header
6 /// @Param _info_header
5 void readHead(unsigned char* _file_path, BitmapFileHeader* _file_header, BitmapInfoHeader* _info_header){
4 FILE* bmp_file = fopen( _file_path,"rb");
3
2 if( bmp_file == NULL ){
1 fprintf(stderr,"can not open bmp file %s\n",_file_path);
0 exit(1);
1 }else{
2 // read file header
3 fread( _file_header, sizeof(BitmapFileHeader), 1, bmp_file);
4 // read info header
5 /*fseek(bmp_file, sizeof( BitmapFileHeader ) , 1);*/
6 fread( _info_header, sizeof(BitmapInfoHeader), 1, bmp_file);
7 }
8 fclose( bmp_file );
9 }/*}}}*/
10 /// @Synopsis readData /*{{{*/
11 /// @Param _info_header
12 /// @Param _matrix
13 void readData(unsigned char* _file_path, BitmapFileHeader* _file_header, BitmapInfoHeader* _info_header, Bitmap24PixelRgb** _matrix){
14 FILE* bmp_file = fopen( _file_path,"rb");
15
16 if( bmp_file == NULL ){
17 fprintf(stderr,"can not open bmp file %s\n", _file_path);
18 exit(1);
19 }else{
20 fseek(bmp_file, _file_header->offset , 1);
21
22 /*Bitmap24PixelRgb** temp_matrix = matrix( Bitmap24PixelRgb, _info_header->height , _info_header->width );*/
23 unsigned int t_y;
24 unsigned int t_x;
25 for (t_y = 0; t_y < _info_header->height; t_y++) {
26 for (t_x = 0; t_x < _info_header->width; t_x++) {
27 /*fread( &temp_matrix[t_y][t_x] , sizeof( Bitmap24PixelRgb ) , 1 ,bmp_file );*/
28 fread( &_matrix[t_y][t_x] , sizeof( Bitmap24PixelRgb ) , 1 ,bmp_file );
29 }
30 }
31
32 /*unsigned int y_max = _info_header->height -1;*/
33 /*unsigned int x_max = _info_header->width - 1;*/
34 /*unsigned int y;*/
35 /*unsigned int x;*/
36 /*for( y=0; y < _info_header->height ; y++){*/
37 /*for( x=0; x< _info_header->width; x++){*/
38 /*_matrix[y][x] = temp_matrix[ y_max - y ][x];*/
39 /*}*/
40 /*}*/
41 /*free(temp_matrix);*/
42 }