-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmap_printer.c
52 lines (42 loc) · 1.33 KB
/
bitmap_printer.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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
#include <stdio.h>
#include <stdlib.h>
#include "bitmap.h"
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "Usage: bitmap_printer input_bmp\n");
exit(1);
}
FILE *image = fopen(argv[1], "rb");
if (image == NULL) {
perror("fopen");
exit(1);
}
// Read in bitmap file metadata
int pixel_array_offset, width, height;
read_bitmap_metadata(image, &pixel_array_offset, &width, &height);
// Print out metadata.
printf("Pixel array offset: %d\n", pixel_array_offset);
printf("Width: %d\n", width);
printf("Height: %d\n", width);
// Read in the pixel data
struct pixel **pixels = read_pixel_array(image, pixel_array_offset, width, height);
// Print out some pixels from each of the image's corners.
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
print_pixel(pixels[i][j]);
print_pixel(pixels[i][height - 1 - j]);
print_pixel(pixels[width - 1 - i][j]);
print_pixel(pixels[width - 1 - i][height - 1 - j]);
}
}
// Clean up: you need to do this!
return 0;
}