7
7
8
8
static enum read_status read_header (FILE * file , struct bmp_header * header );
9
9
static struct image read_image (FILE * file , uint32_t height , uint32_t width );
10
- static struct bmp_header new_header (const struct bmp_header * o_header , uint32_t height , uint32_t width );
11
- static void save_bmp (FILE * file , const struct bmp_header * header , const struct image img );
10
+ static struct bmp_header new_header (uint32_t height , uint32_t width );
11
+ static void save_bmp (FILE * file , const struct image img );
12
12
static struct image select_mode (struct image image , char mode , double angle );
13
+ static struct image read (const char * r_file );
14
+ static void write (const char * w_file , const struct image img , char transform , double angle );
13
15
14
16
enum open_status open_file (FILE * * file , const char * filename , const char * mod );
15
17
16
- void read_bmp_file (const char * r_file , const char * w_file , char transform , double angle ) {
18
+ void start (const char * r_file , const char * w_file , char transform , double angle ) {
19
+ struct image img = read (r_file );
20
+ write (w_file , img , transform , angle );
21
+ }
22
+
23
+ struct image read (const char * r_file ) {
17
24
FILE * file ;
18
25
if (open_file (& file , r_file , "rb" ) != OPEN_OK ) {
19
26
puts ("Something wrong with read file" );
@@ -24,19 +31,21 @@ void read_bmp_file(const char* r_file, const char* w_file, char transform, doubl
24
31
puts ("Invalid header" );
25
32
exit (READ_INVALID_HEADER );
26
33
}
27
-
28
34
fseek (file , header .bOffBits , SEEK_SET );
29
-
30
35
struct image image = read_image (file , header .biHeight , header .biWidth );
31
36
fclose (file );
37
+ return image ;
38
+ }
39
+
40
+ void write (const char * w_file , const struct image img , char transform , double angle ) {
41
+ FILE * file ;
32
42
33
43
if (open_file (& file , w_file , "wb" ) != OPEN_OK ) {
34
44
puts ("Somethign wrong with write file" );
35
45
exit (OPEN_ERR );
36
46
}
37
- image = select_mode (image , transform , angle );
38
- header = new_header (& header , image .height , image .width );
39
- save_bmp (file , & header , image );
47
+ struct image image = select_mode (img , transform , angle );
48
+ save_bmp (file , image );
40
49
fclose (file );
41
50
}
42
51
@@ -77,7 +86,7 @@ enum read_status read_header(FILE* file, struct bmp_header* header) {
77
86
return img ;
78
87
}
79
88
80
- struct bmp_header new_header (const struct bmp_header * o_header , uint32_t height , uint32_t width ) {
89
+ struct bmp_header new_header (uint32_t height , uint32_t width ) {
81
90
uint8_t padding = set_padding (width );
82
91
struct bmp_header new_header = {
83
92
BM ,
@@ -99,9 +108,10 @@ struct bmp_header new_header(const struct bmp_header* o_header, uint32_t height,
99
108
return new_header ;
100
109
}
101
110
102
- void save_bmp (FILE * file , const struct bmp_header * header , const struct image img ) {
103
- uint8_t padding = set_padding (header -> biWidth );
104
- fwrite (header , sizeof (struct bmp_header ), 1 , file );
111
+ void save_bmp (FILE * file , const struct image img ) {
112
+ uint8_t padding = set_padding (img .width );
113
+ struct bmp_header header = new_header (img .height , img .width );
114
+ fwrite (& header , sizeof (struct bmp_header ), 1 , file );
105
115
for (uint32_t i = 0 ; i < img .height ; i ++ ) {
106
116
fwrite (img .data + i * img .width , sizeof (struct pixel ), img .width , file );
107
117
fwrite (& padding , 1 , padding , file );
0 commit comments