回答編集履歴
1
リファクタリングした
test
CHANGED
@@ -43,3 +43,95 @@
|
|
43
43
|
|
44
44
|
|
45
45
|
> img[i][j].r = rr;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
----
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
リファクタリングしたコードを載せておきます。
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```cpp
|
58
|
+
|
59
|
+
void bmp_mosaic(bmp_header_t *hd, pixel_t img[MAX_Y][MAX_X]) {
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
int x, y, dx, dy;
|
64
|
+
|
65
|
+
unsigned int r, g, b;
|
66
|
+
|
67
|
+
int size = 16;
|
68
|
+
|
69
|
+
int pixelCount;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
for (y = 0; y < hd->biHeight; y += size) {
|
74
|
+
|
75
|
+
for (x = 0; x < hd->biWidth / 2; x += size) {
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
r = 0;
|
80
|
+
|
81
|
+
g = 0;
|
82
|
+
|
83
|
+
b = 0;
|
84
|
+
|
85
|
+
pixelCount = 0;
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
for (dy = 0; dy < size && y + dy < hd->biHeight; dy++) {
|
90
|
+
|
91
|
+
for (dx = 0; dx < size && x + dx < hd->biWidth; dx++) {
|
92
|
+
|
93
|
+
r += img[y + dy][x + dx].r;
|
94
|
+
|
95
|
+
g += img[y + dy][x + dx].g;
|
96
|
+
|
97
|
+
b += img[y + dy][x + dx].b;
|
98
|
+
|
99
|
+
pixelCount++;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
r /= pixelCount;
|
108
|
+
|
109
|
+
g /= pixelCount;
|
110
|
+
|
111
|
+
b /= pixelCount;
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
for (dy = 0; dy < size && y + dy < hd->biHeight; dy++) {
|
116
|
+
|
117
|
+
for (dx = 0; dx < size && x + dx < hd->biWidth; dx++) {
|
118
|
+
|
119
|
+
img[y + dy][x + dx].r = r;
|
120
|
+
|
121
|
+
img[y + dy][x + dx].g = g;
|
122
|
+
|
123
|
+
img[y + dy][x + dx].b = b;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
```
|