-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.c
99 lines (75 loc) · 3.13 KB
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "bmp.h"
#include "utils.h"
#include <stdio.h>
#define WIDTH 1000
#define HEIGHT 1000
const color_t red = {.red = 255};
const color_t grn = {.green = 255};
const color_t blu = {.blue = 255};
const color_t yel = {.red = 255, .green = 255};
const color_t cyan = {.green = 255, .blue = 255};
const color_t white = { .red=255, .green = 255, .blue = 255};
/* generates image */
void generate_image(image_t *img) {
coord_t circle_width = 10;
/* red rectangle under the big yellow circle*/
bmp_draw_rect((point_t){ .x = 175, .y = 175},
(point_t){ .x = 350, .y = 350}, red, img);
/* big yellow circle in the middle */
bmp_draw_circ((point_t){ .x = 500, .y = 500}, 400, circle_width, yel, img);
/* small green circle out of bound in the upper-right */
bmp_draw_circ((point_t){ .x = 990, .y = 990}, 50, circle_width, grn, img);
/* filled white circle in the upper-left */
bmp_draw_circ((point_t){ .x = 150, .y = 850}, 80, 80, white, img);
/* small blue rectangle in the lower-left */
bmp_draw_rect((point_t){.x = 10, .y = 10},
(point_t){.x = 50, .y = 50}, blu, img);
/* left pair of lines */
log("left pair of lines");
bmp_draw_line((point_t){ .x = 0, .y = 0}, (point_t){ .x = 99, .y = 999 }, red, 1, img);
bmp_draw_line((point_t){ .x = 99, .y = 0}, (point_t){ .x = 0, .y = 999 }, yel, 1, img);
/* top pair of lines */
log("top pair of lines");
bmp_draw_line((point_t){ .x = 0, .y = 999}, (point_t){ .x = 999, .y = 900 }, red, 1, img);
bmp_draw_line((point_t){ .x = 0, .y = 900}, (point_t){ .x = 999, .y = 999 }, yel, 1, img);
/* bottom pair of lines */
log("bottom pair of lines");
bmp_draw_line((point_t){ .x = 999, .y = 0}, (point_t){ .x = 0, .y = 99 }, blu, 1, img);
bmp_draw_line((point_t){ .x = 999, .y = 99}, (point_t){ .x = 0, .y = 0 }, grn, 1, img);
/* right pair of lines */
log("right pair of lines");
bmp_draw_line((point_t){ .x = 999, .y = 0}, (point_t){ .x = 0, .y = 99 }, blu, 1, img);
bmp_draw_line((point_t){ .x = 999, .y = 99}, (point_t){ .x = 0, .y = 0 }, grn, 1, img);
}
int main(void) {
/* timer thingies */
timer_start(time_total);
timer_start(time_generation);
/* initialize empty image */
image_t *image = bmp_image_ctor(WIDTH, HEIGHT);
/* null check */
if (image == NULL) {
fprintf(stderr, "couldnt allocate or sth\n");
return 1;
}
/* generating of the picture itself */
generate_image(image);
/* timer thingies */
timer_end(time_generation, "image generation");
timer_start(time_saving);
/* save image into file */
int return_value = bmp_save("example.bmp", image);
/* free image */
bmp_image_dtor(image);
/* check if saving into file was successful */
if (return_value) {
fprintf(stderr, "Image couldn't be saved, abort\n");
return 1;
} else {
printf("Image successfully generated and saved.\n");
}
/* timer thingies */
timer_end(time_saving, "image saving");
timer_end(time_total, "total CPU time");
return 0;
}