-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.txt
55 lines (43 loc) · 1.59 KB
/
scratch.txt
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
void box_blur(BMP_Image *image) {
int width = image->bip_header->width;
int height = image->bip_header->height;
int row_jump = width; // * sizeof(Pixel); //PITFALL!!
int col_jump = 1; //sizeof(Pixel);
Pixel *new_pixels = malloc(sizeof(Pixel) * width * height);
Pixel *new_cursor = new_pixels;
Pixel *cursor = image->pixels;
Pixel *neighbors[9];
// [0][1][2]
// [3][4][5]
// [6][7][8]
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (i == 0) {
neighbors[0] = NULL;
neighbors[1] = NULL;
neighbors[2] = NULL;
} else {
neighbors[0] = j == 0 ? NULL : cursor - row_jump - col_jump;
neighbors[1] = cursor - row_jump;
neighbors[2] = j == width - 1 ? NULL : cursor - row_jump + col_jump;
}
neighbors[3] = j == 0 ? NULL : cursor - col_jump;
neighbors[4] = cursor;
neighbors[5] = j == width - 1 ? NULL : cursor + col_jump;
if (i == height - 1) {
neighbors[6] = NULL;
neighbors[7] = NULL;
neighbors[8] = NULL;
} else {
neighbors[6] = j == 0 ? NULL : cursor + row_jump - col_jump;
neighbors[7] = cursor + row_jump;
neighbors[8] = j == width - 1 ? NULL : cursor + row_jump + col_jump;
}
blur(neighbors, new_cursor);
cursor++;
new_cursor++;
}
}
free(image->pixels);
image->pixels = new_pixels;
}