-
Notifications
You must be signed in to change notification settings - Fork 1
/
bitmap.h
executable file
·55 lines (45 loc) · 1.84 KB
/
bitmap.h
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
#ifndef BITMAP_H_
#define BITMAP_H_
// Use the following offsets to index into the `header`
// field of the Bitmap struct.
#define BMP_FILE_SIZE_OFFSET 2
#define BMP_HEADER_SIZE_OFFSET 10
#define BMP_WIDTH_OFFSET 18
#define BMP_HEIGHT_OFFSET 22
typedef struct {
unsigned char blue;
unsigned char green;
unsigned char red;
} Pixel;
typedef struct {
int headerSize; // The size of the header.
unsigned char *header; // The contents of the image header.
int width; // The width of the image, in pixels.
int height; // The height of the image, in pixels.
} Bitmap;
void run_filter(void (*filter)(), int scale_factor);
// Macros and functions for performing the two multi-row filters.
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define square(a) ((a) * (a))
/*
* Functions for the row-buffered filters
* --------------------------------------
*
* row0, row1, and row2 are interpreted as Pixel arrays of length 3.
* Together, they represent the three rows of a 3-by-3 pixel grid
* whose middle pixel is the one being transformed.
*
* These functions return the transformed pixel value of the middle pixel
* when applying the corresponding transformation (a gaussian blur or
* an edge detection operation), using the pixel values in the 3-by-3 grid.
*
* You aren't responsible for the calculations themselves, only for calling
* these functions properly on pointers representing the 3-by-3 grids.
*
* Note that these functions should be called *once per pixel in the image*;
* the returned Pixel values can be immediately written to stdout.
*/
Pixel apply_gaussian_kernel(Pixel *row0, Pixel *row1, Pixel *row2);
Pixel apply_edge_detection_kernel(Pixel *row0, Pixel *row1, Pixel *row2);
#endif /* BITMAP_H_*/