@@ -129,25 +129,27 @@ struct test_image_5x5_kernel_1x9_boundary_extend_zero
129
129
auto img_view = gil::view (img);
130
130
image_t img_out (img), img_expected_row (img_view.width (), img_view.height ());
131
131
image_t img_expected_col (img_view.width (), img_view.height ());
132
+ unsigned int const kernel_shift_offset = 2 ;
132
133
133
134
for (std::ptrdiff_t y = 0 ; y < img_view.height (); ++y)
134
135
{
135
136
auto img_it = img_view.row_begin (y);
136
137
auto img_expected_row_it = gil::view (img_expected_row).row_begin (y);
137
- for (std::ptrdiff_t x = 2 ; x < img_view.width (); ++x)
138
+ for (std::ptrdiff_t x = kernel_shift_offset ; x < img_view.width (); ++x)
138
139
img_expected_row_it[x] = img_it[x - 2 ];
139
140
}
140
141
for (std::ptrdiff_t x = 0 ; x < img_view.width (); ++x)
141
142
{
142
143
auto img_expected_row_it = gil::view (img_expected_row).col_begin (x);
143
144
auto img_expected_col_it = gil::view (img_expected_col).col_begin (x);
144
- for (std::ptrdiff_t y = 2 ; y < img_view.height (); ++y)
145
+ for (std::ptrdiff_t y = kernel_shift_offset ; y < img_view.height (); ++y)
145
146
img_expected_col_it[y] = img_expected_row_it[y - 2 ];
146
147
}
147
148
148
- auto const kernel = fixture::create_kernel<channel_t >({0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 });
149
- gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel, gil::view (img_out),
150
- boost::gil::boundary_option::extend_zero);
149
+ auto const kernel_shift_by_two = fixture::create_kernel<channel_t >(
150
+ {0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 });
151
+ gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel_shift_by_two,
152
+ gil::view (img_out), boost::gil::boundary_option::extend_zero);
151
153
152
154
BOOST_TEST (gil::equal_pixels (gil::const_view (img_out), gil::const_view (img_expected_col)));
153
155
}
@@ -169,12 +171,13 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
169
171
auto img = fixture::generate_image<image_t >(5 , 5 , fixture::random_value<channel_t >{});
170
172
auto img_view = gil::view (img);
171
173
image_t img_out (img), img_expected_row (img);
174
+ unsigned int const kernel_shift_offset = 2 ;
172
175
173
176
for (std::ptrdiff_t y = 0 ; y < img_view.height (); ++y)
174
177
{
175
178
auto img_it = img_view.row_begin (y);
176
179
auto img_expected_row_it = gil::view (img_expected_row).row_begin (y);
177
- for (std::ptrdiff_t x = 2 ; x < img_view.width (); ++x)
180
+ for (std::ptrdiff_t x = kernel_shift_offset ; x < img_view.width (); ++x)
178
181
img_expected_row_it[x] = img_it[x - 2 ];
179
182
img_expected_row_it[1 ] = img_it[0 ];
180
183
}
@@ -183,14 +186,14 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
183
186
{
184
187
auto img_expected_row_it = gil::view (img_expected_row).col_begin (x);
185
188
auto img_expected_col_it = gil::view (img_expected_col).col_begin (x);
186
- for (std::ptrdiff_t y = 2 ; y < img_view.height (); ++y)
189
+ for (std::ptrdiff_t y = kernel_shift_offset ; y < img_view.height (); ++y)
187
190
img_expected_col_it[y] = img_expected_row_it[y - 2 ];
188
191
img_expected_col_it[1 ] = img_expected_row_it[0 ];
189
192
}
190
193
191
- auto const kernel = fixture::create_kernel<channel_t >({0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 });
192
- gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel, gil::view (img_out) ,
193
- boost::gil::boundary_option::extend_constant);
194
+ auto const kernel_shift_by_two = fixture::create_kernel<channel_t >({0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 });
195
+ gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel_shift_by_two ,
196
+ gil::view (img_out), boost::gil::boundary_option::extend_constant);
194
197
195
198
BOOST_TEST (gil::equal_pixels (gil::const_view (img_out), gil::const_view (img_expected_col)));
196
199
}
@@ -201,7 +204,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_constant
201
204
}
202
205
};
203
206
204
- struct test_image_5x5_kernel_1x9_boundary_output_zero
207
+ struct test_image_5x5_kernel_1x3_boundary_output_zero
205
208
{
206
209
template <typename Image>
207
210
void operator ()(Image const &)
@@ -213,36 +216,37 @@ struct test_image_5x5_kernel_1x9_boundary_output_zero
213
216
auto img_view = gil::view (img);
214
217
image_t img_out (img), img_expected_row (img_view.width (), img_view.height ());
215
218
image_t img_expected_col (img_view.width (), img_view.height ());
219
+ unsigned int const kernel_shift_offset = 1 ;
216
220
217
221
for (std::ptrdiff_t y = 0 ; y < img_view.height (); ++y)
218
222
{
219
223
auto img_it = img_view.row_begin (y);
220
224
auto img_expected_row_it = gil::view (img_expected_row).row_begin (y);
221
- for (std::ptrdiff_t x = 1 ; x < img_view.width () - 1 ; ++x)
225
+ for (std::ptrdiff_t x = kernel_shift_offset ; x < img_view.width () - 1 ; ++x)
222
226
img_expected_row_it[x] = img_it[x - 1 ];
223
227
}
224
228
for (std::ptrdiff_t x = 0 ; x < img_view.width (); ++x)
225
229
{
226
230
auto img_expected_row_it = gil::view (img_expected_row).col_begin (x);
227
231
auto img_expected_col_it = gil::view (img_expected_col).col_begin (x);
228
- for (std::ptrdiff_t y = 1 ; y < img_view.height () - 1 ; ++y)
232
+ for (std::ptrdiff_t y = kernel_shift_offset ; y < img_view.height () - 1 ; ++y)
229
233
img_expected_col_it[y] = img_expected_row_it[y - 1 ];
230
234
}
231
235
232
- auto const kernel = fixture::create_kernel<channel_t >({0 , 0 , 1 });
233
- gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel, gil::view (img_out) ,
234
- boost::gil::boundary_option::output_zero);
236
+ auto const kernel_shift_by_one = fixture::create_kernel<channel_t >({0 , 0 , 1 });
237
+ gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel_shift_by_one ,
238
+ gil::view (img_out), boost::gil::boundary_option::output_zero);
235
239
236
240
BOOST_TEST (gil::equal_pixels (gil::const_view (img_out), gil::const_view (img_expected_col)));
237
241
}
238
242
static void run ()
239
243
{
240
244
boost::mp11::mp_for_each<fixture::image_types>(
241
- test_image_5x5_kernel_1x9_boundary_output_zero {});
245
+ test_image_5x5_kernel_1x3_boundary_output_zero {});
242
246
}
243
247
};
244
248
245
- struct test_image_5x5_kernel_1x9_boundary_output_ignore
249
+ struct test_image_5x5_kernel_1x3_boundary_output_ignore
246
250
{
247
251
template <typename Image>
248
252
void operator ()(Image const &)
@@ -253,37 +257,38 @@ struct test_image_5x5_kernel_1x9_boundary_output_ignore
253
257
auto img = fixture::generate_image<image_t >(5 , 5 , fixture::random_value<channel_t >{});
254
258
auto img_view = gil::view (img);
255
259
image_t img_out (img), img_expected_row (img);
260
+ unsigned int const kernel_shift_offset = 1 ;
256
261
257
262
for (std::ptrdiff_t y = 0 ; y < img_view.height (); ++y)
258
263
{
259
264
auto img_it = img_view.row_begin (y);
260
265
auto img_expected_row_it = gil::view (img_expected_row).row_begin (y);
261
- for (std::ptrdiff_t x = 1 ; x < img_view.width () - 1 ; ++x)
266
+ for (std::ptrdiff_t x = kernel_shift_offset ; x < img_view.width () - 1 ; ++x)
262
267
img_expected_row_it[x] = img_it[x - 1 ];
263
268
}
264
269
image_t img_expected_col (img_expected_row);
265
270
for (std::ptrdiff_t x = 0 ; x < img_view.width (); ++x)
266
271
{
267
272
auto img_expected_row_it = gil::view (img_expected_row).col_begin (x);
268
273
auto img_expected_col_it = gil::view (img_expected_col).col_begin (x);
269
- for (std::ptrdiff_t y = 1 ; y < img_view.height () - 1 ; ++y)
274
+ for (std::ptrdiff_t y = kernel_shift_offset ; y < img_view.height () - 1 ; ++y)
270
275
img_expected_col_it[y] = img_expected_row_it[y - 1 ];
271
276
}
272
277
273
- auto const kernel = fixture::create_kernel<channel_t >({0 , 0 , 1 });
274
- gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel, gil::view (img_out) ,
275
- gil::boundary_option::output_ignore);
278
+ auto const kernel_shift_by_one = fixture::create_kernel<channel_t >({0 , 0 , 1 });
279
+ gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel_shift_by_one ,
280
+ gil::view (img_out), gil:: boundary_option::output_ignore);
276
281
277
282
BOOST_TEST (gil::equal_pixels (gil::const_view (img_out), gil::const_view (img_expected_col)));
278
283
}
279
284
static void run ()
280
285
{
281
286
boost::mp11::mp_for_each<fixture::image_types>(
282
- test_image_5x5_kernel_1x9_boundary_output_ignore {});
287
+ test_image_5x5_kernel_1x3_boundary_output_ignore {});
283
288
}
284
289
};
285
290
286
- struct test_image_5x5_kernel_1x9_boundary_extend_padded
291
+ struct test_image_5x5_kernel_1x3_boundary_extend_padded
287
292
{
288
293
template <typename Image>
289
294
void operator ()(Image const &)
@@ -294,26 +299,27 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
294
299
auto img = fixture::generate_image<image_t >(5 , 5 , fixture::random_value<channel_t >{});
295
300
auto img_view = gil::view (img);
296
301
image_t img_out (img), img_expected_row (img);
302
+ unsigned int const kernel_shift_offset = 1 ;
297
303
298
304
for (std::ptrdiff_t y = 0 ; y < img_view.height (); ++y)
299
305
{
300
306
auto img_it = img_view.row_begin (y);
301
307
auto img_expected_row_it = gil::view (img_expected_row).row_begin (y);
302
- for (std::ptrdiff_t x = 1 ; x < img_view.width (); ++x)
308
+ for (std::ptrdiff_t x = kernel_shift_offset ; x < img_view.width (); ++x)
303
309
img_expected_row_it[x] = img_it[x - 1 ];
304
310
}
305
311
image_t img_expected_col (img_expected_row);
306
312
for (std::ptrdiff_t x = 0 ; x < img_view.width (); ++x)
307
313
{
308
314
auto img_expected_row_it = gil::view (img_expected_row).col_begin (x);
309
315
auto img_expected_col_it = gil::view (img_expected_col).col_begin (x);
310
- for (std::ptrdiff_t y = 1 ; y < img_view.width (); ++y)
316
+ for (std::ptrdiff_t y = kernel_shift_offset ; y < img_view.width (); ++y)
311
317
img_expected_col_it[y] = img_expected_row_it[y - 1 ];
312
318
}
313
319
314
- auto const kernel = fixture::create_kernel<channel_t >({0 , 0 , 1 });
315
- gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel, gil::view (img_out) ,
316
- gil::boundary_option::extend_padded);
320
+ auto const kernel_shift_by_one = fixture::create_kernel<channel_t >({0 , 0 , 1 });
321
+ gil::detail::convolve_1d<pixel_t >(gil::const_view (img_out), kernel_shift_by_one ,
322
+ gil::view (img_out), gil:: boundary_option::extend_padded);
317
323
318
324
// First row and first column of "img_out" and "img_expected_col" are intentionally made
319
325
// similar.
@@ -333,7 +339,7 @@ struct test_image_5x5_kernel_1x9_boundary_extend_padded
333
339
static void run ()
334
340
{
335
341
boost::mp11::mp_for_each<fixture::image_types>(
336
- test_image_5x5_kernel_1x9_boundary_extend_padded {});
342
+ test_image_5x5_kernel_1x3_boundary_extend_padded {});
337
343
}
338
344
};
339
345
@@ -346,8 +352,8 @@ int main()
346
352
347
353
test_image_5x5_kernel_1x9_boundary_extend_zero::run ();
348
354
test_image_5x5_kernel_1x9_boundary_extend_constant::run ();
349
- test_image_5x5_kernel_1x9_boundary_output_zero ::run ();
350
- test_image_5x5_kernel_1x9_boundary_output_ignore ::run ();
351
- test_image_5x5_kernel_1x9_boundary_extend_padded ::run ();
355
+ test_image_5x5_kernel_1x3_boundary_output_zero ::run ();
356
+ test_image_5x5_kernel_1x3_boundary_output_ignore ::run ();
357
+ test_image_5x5_kernel_1x3_boundary_extend_padded ::run ();
352
358
return ::boost::report_errors ();
353
359
}
0 commit comments