| 1 | // |
| 2 | // Copyright 2005-2007 Adobe Systems Incorporated |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0 |
| 5 | // See accompanying file LICENSE_1_0.txt or copy at |
| 6 | // http://www.boost.org/LICENSE_1_0.txt |
| 7 | // |
| 8 | #include <boost/gil.hpp> |
| 9 | |
| 10 | #include <boost/core/lightweight_test.hpp> |
| 11 | |
| 12 | #include <cstddef> |
| 13 | #include <ctime> |
| 14 | #include <iostream> |
| 15 | |
| 16 | // GIL performance test suite |
| 17 | // |
| 18 | // Available tests: |
| 19 | // fill_pixels() on rgb8_image_t with rgb8_pixel_t |
| 20 | // fill_pixels() on rgb8_planar_image_t with rgb8_pixel_t |
| 21 | // fill_pixels() on rgb8_image_t with bgr8_pixel_t |
| 22 | // fill_pixels() on rgb8_planar_image_t with bgr8_pixel_t |
| 23 | // for_each_pixel() on rgb8_image_t |
| 24 | // for_each_pixel() on rgb8_planar_t |
| 25 | // copy_pixels() between rgb8_image_t and rgb8_image_t |
| 26 | // copy_pixels() between rgb8_image_t and bgr8_image_t |
| 27 | // copy_pixels() between rgb8_planar_image_t and rgb8_planar_image_t |
| 28 | // copy_pixels() between rgb8_image_t and rgb8_planar_image_t |
| 29 | // copy_pixels() between rgb8_planar_image_t and rgb8_image_t |
| 30 | // transform_pixels() between rgb8_image_t and rgb8_image_t |
| 31 | // transform_pixels() between rgb8_planar_image_t and rgb8_planar_image_t |
| 32 | // transform_pixels() between rgb8_planar_image_t and rgb8_image_t |
| 33 | // transform_pixels() between rgb8_image_t and rgb8_planar_image_t |
| 34 | |
| 35 | using namespace boost::gil; |
| 36 | |
| 37 | // returns time in milliseconds per call |
| 38 | template <typename Op> |
| 39 | double measure_time(Op op, std::size_t num_loops) { |
| 40 | clock_t begin=clock(); |
| 41 | for (std::size_t ii=0; ii<num_loops; ++ii) op(); |
| 42 | return double(clock()-begin)/double(num_loops); |
| 43 | } |
| 44 | |
| 45 | // image dimension |
| 46 | std::size_t width=1000, height=400; |
| 47 | |
| 48 | // macros for standard GIL views |
| 49 | #define RGB_VIEW(T) image_view<memory_based_2d_locator<memory_based_step_iterator<pixel<T,rgb_layout_t>*>>> |
| 50 | #define BGR_VIEW(T) image_view<memory_based_2d_locator<memory_based_step_iterator<pixel<T,bgr_layout_t>*>>> |
| 51 | #define RGB_PLANAR_VIEW(T) image_view<memory_based_2d_locator<memory_based_step_iterator<planar_pixel_iterator<T*,rgb_t>>>> |
| 52 | |
| 53 | template <typename View, typename P> |
| 54 | struct fill_gil_t { |
| 55 | View _v; |
| 56 | P _p; |
| 57 | fill_gil_t(const View& v_in,const P& p_in) : _v(v_in), _p(p_in) {} |
| 58 | void operator()() const {fill_pixels(_v,_p);} |
| 59 | }; |
| 60 | template <typename View, typename P> struct fill_nongil_t; |
| 61 | template <typename T, typename P> |
| 62 | struct fill_nongil_t<RGB_VIEW(T), P> |
| 63 | { |
| 64 | using View = RGB_VIEW(T); |
| 65 | View _v; |
| 66 | P _p; |
| 67 | fill_nongil_t(const View& v_in,const P& p_in) : _v(v_in), _p(p_in) {} |
| 68 | void operator()() const { |
| 69 | T* first=(T*)_v.row_begin(0); |
| 70 | T* last=first+_v.size()*3; |
| 71 | while(first!=last) { |
| 72 | first[0]=boost::gil::at_c<0>(_p); |
| 73 | first[1]=boost::gil::at_c<1>(_p); |
| 74 | first[2]=boost::gil::at_c<2>(_p); |
| 75 | first+=3; |
| 76 | } |
| 77 | } |
| 78 | }; |
| 79 | template <typename T1, typename T2> |
| 80 | struct fill_nongil_t<RGB_VIEW(T1), pixel<T2,bgr_layout_t>> |
| 81 | { |
| 82 | using View = RGB_VIEW(T1); |
| 83 | using P = pixel<T2, bgr_layout_t>; |
| 84 | View _v; |
| 85 | P _p; |
| 86 | fill_nongil_t(const View& v_in,const P& p_in) : _v(v_in), _p(p_in) {} |
| 87 | void operator()() const { |
| 88 | T1* first=(T1*)_v.row_begin(0); |
| 89 | T1* last=first+_v.size()*3; |
| 90 | while(first!=last) { |
| 91 | first[0]=boost::gil::at_c<2>(_p); |
| 92 | first[1]=boost::gil::at_c<1>(_p); |
| 93 | first[2]=boost::gil::at_c<0>(_p); |
| 94 | first+=3; |
| 95 | } |
| 96 | } |
| 97 | }; |
| 98 | template <typename T1, typename T2> |
| 99 | struct fill_nongil_t<RGB_PLANAR_VIEW(T1), pixel<T2,rgb_layout_t>> |
| 100 | { |
| 101 | using View = RGB_PLANAR_VIEW(T1); |
| 102 | using P = pixel<T2, rgb_layout_t>; |
| 103 | View _v; |
| 104 | P _p; |
| 105 | fill_nongil_t(const View& v_in,const P& p_in) : _v(v_in), _p(p_in) {} |
| 106 | void operator()() const { |
| 107 | std::size_t size=_v.size(); |
| 108 | T1* first; |
| 109 | first=(T1*)boost::gil::at_c<0>(_v.row_begin(0)); |
| 110 | std::fill(first,first+size,boost::gil::at_c<0>(_p)); |
| 111 | first=(T1*)boost::gil::at_c<1>(_v.row_begin(0)); |
| 112 | std::fill(first,first+size,boost::gil::at_c<1>(_p)); |
| 113 | first=(T1*)boost::gil::at_c<2>(_v.row_begin(0)); |
| 114 | std::fill(first,first+size,boost::gil::at_c<2>(_p)); |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | template <typename T1, typename T2> |
| 119 | struct fill_nongil_t<RGB_PLANAR_VIEW(T1), pixel<T2,bgr_layout_t>> |
| 120 | { |
| 121 | using View = RGB_PLANAR_VIEW(T1); |
| 122 | using P = pixel<T2,bgr_layout_t>; |
| 123 | View _v; |
| 124 | P _p; |
| 125 | fill_nongil_t(const View& v_in,const P& p_in) : _v(v_in), _p(p_in) {} |
| 126 | void operator()() const { |
| 127 | std::size_t size=_v.size(); |
| 128 | T1* first; |
| 129 | first=(T1*)boost::gil::at_c<0>(_v.row_begin(0)); |
| 130 | std::fill(first,first+size,boost::gil::at_c<2>(_p)); |
| 131 | first=(T1*)boost::gil::at_c<1>(_v.row_begin(0)); |
| 132 | std::fill(first,first+size,boost::gil::at_c<1>(_p)); |
| 133 | first=(T1*)boost::gil::at_c<2>(_v.row_begin(0)); |
| 134 | std::fill(first,first+size,boost::gil::at_c<1>(_p)); |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | template <typename View, typename P> |
| 139 | void test_fill(std::size_t trials) { |
| 140 | image<typename View::value_type, is_planar<View>::value> im(width,height); |
| 141 | std::cout << "GIL: " << measure_time(fill_gil_t<View,P>(view(im),P()),trials) << std::endl; |
| 142 | std::cout << "Non-GIL: " << measure_time(fill_nongil_t<View,P>(view(im),P()),trials) << std::endl; |
| 143 | }; |
| 144 | |
| 145 | template <typename T> |
| 146 | struct rgb_fr_t { |
| 147 | void operator()(pixel<T,rgb_layout_t>& p) const {p[0]=0;p[1]=1;p[2]=2;} |
| 148 | void operator()(const planar_pixel_reference<T&,rgb_t>& p) const {p[0]=0;p[1]=1;p[2]=2;} |
| 149 | }; |
| 150 | template <typename View, typename F> |
| 151 | struct for_each_gil_t { |
| 152 | View _v; |
| 153 | F _f; |
| 154 | for_each_gil_t(const View& v_in,const F& f_in) : _v(v_in), _f(f_in) {} |
| 155 | void operator()() const {for_each_pixel(_v,_f);} |
| 156 | }; |
| 157 | template <typename View, typename F> struct for_each_nongil_t; |
| 158 | template <typename T, typename T2> |
| 159 | struct for_each_nongil_t<RGB_VIEW(T), rgb_fr_t<T2>> |
| 160 | { |
| 161 | using View = RGB_VIEW(T); |
| 162 | using F = rgb_fr_t<T2>; |
| 163 | View _v; |
| 164 | F _f; |
| 165 | for_each_nongil_t(const View& v_in,const F& f_in) : _v(v_in), _f(f_in) {} |
| 166 | void operator()() const { |
| 167 | T* first=(T*)_v.row_begin(0); |
| 168 | T* last=first+_v.size()*3; |
| 169 | while(first!=last) { |
| 170 | first[0]=0; |
| 171 | first[1]=1; |
| 172 | first[2]=2; |
| 173 | first+=3; |
| 174 | } |
| 175 | } |
| 176 | }; |
| 177 | template <typename T1, typename T2> |
| 178 | struct for_each_nongil_t<RGB_PLANAR_VIEW(T1), rgb_fr_t<T2>> |
| 179 | { |
| 180 | using View = RGB_PLANAR_VIEW(T1); |
| 181 | using F = rgb_fr_t<T2>; |
| 182 | View _v; |
| 183 | F _f; |
| 184 | for_each_nongil_t(const View& v_in,const F& f_in) : _v(v_in), _f(f_in) {} |
| 185 | void operator()() const { |
| 186 | T1 *first0, *first1, *first2, *last0; |
| 187 | first0=(T1*)boost::gil::at_c<0>(_v.row_begin(0)); |
| 188 | first1=(T1*)boost::gil::at_c<1>(_v.row_begin(0)); |
| 189 | first2=(T1*)boost::gil::at_c<2>(_v.row_begin(0)); |
| 190 | last0=first0+_v.size(); |
| 191 | while(first0!=last0) { |
| 192 | *first0++=0; |
| 193 | *first1++=1; |
| 194 | *first2++=2; |
| 195 | } |
| 196 | } |
| 197 | }; |
| 198 | |
| 199 | template <typename View, typename F> |
| 200 | void test_for_each(std::size_t trials) { |
| 201 | image<typename View::value_type, is_planar<View>::value> im(width,height); |
| 202 | std::cout << "GIL: " <<measure_time(for_each_gil_t<View,F>(view(im),F()),trials) << std::endl; |
| 203 | std::cout << "Non-GIL: " <<measure_time(for_each_nongil_t<View,F>(view(im),F()),trials) << std::endl; |
| 204 | } |
| 205 | |
| 206 | // copy |
| 207 | template <typename View1, typename View2> |
| 208 | struct copy_gil_t { |
| 209 | View1 _v1; |
| 210 | View2 _v2; |
| 211 | copy_gil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 212 | void operator()() const {copy_pixels(_v1,_v2);} |
| 213 | }; |
| 214 | template <typename View1, typename View2> struct copy_nongil_t; |
| 215 | template <typename T1, typename T2> |
| 216 | struct copy_nongil_t<RGB_VIEW(T1),RGB_VIEW(T2)> |
| 217 | { |
| 218 | using View1 = RGB_VIEW(T1); |
| 219 | using View2 = RGB_VIEW(T2); |
| 220 | View1 _v1; |
| 221 | View2 _v2; |
| 222 | copy_nongil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 223 | void operator()() const { |
| 224 | T1* first1=(T1*)_v1.row_begin(0); |
| 225 | T1* last1=first1+_v1.size()*3; |
| 226 | T2* first2=(T2*)_v2.row_begin(0); |
| 227 | std::copy(first1,last1,first2); |
| 228 | } |
| 229 | }; |
| 230 | template <typename T1, typename T2> |
| 231 | struct copy_nongil_t<RGB_VIEW(T1),BGR_VIEW(T2)> |
| 232 | { |
| 233 | using View1 = RGB_VIEW(T1); |
| 234 | using View2 = BGR_VIEW(T2); |
| 235 | View1 _v1; |
| 236 | View2 _v2; |
| 237 | copy_nongil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 238 | void operator()() const { |
| 239 | T1* first1=(T1*)_v1.row_begin(0); |
| 240 | T1* last1=first1+_v1.size()*3; |
| 241 | T2* first2=(T2*)_v2.row_begin(0); |
| 242 | while(first1!=last1) { |
| 243 | first2[2]=first1[0]; |
| 244 | first2[1]=first1[1]; |
| 245 | first2[0]=first1[2]; |
| 246 | first1+=3; first2+=3; |
| 247 | } |
| 248 | } |
| 249 | }; |
| 250 | template <typename T1, typename T2> |
| 251 | struct copy_nongil_t<RGB_PLANAR_VIEW(T1),RGB_PLANAR_VIEW(T2)> |
| 252 | { |
| 253 | using View1 = RGB_PLANAR_VIEW(T1); |
| 254 | using View2 = RGB_PLANAR_VIEW(T2); |
| 255 | View1 _v1; |
| 256 | View2 _v2; |
| 257 | copy_nongil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 258 | void operator()() const { |
| 259 | std::size_t size=_v1.size(); |
| 260 | T1* first10=(T1*)boost::gil::at_c<0>(_v1.row_begin(0)); |
| 261 | T1* first11=(T1*)boost::gil::at_c<1>(_v1.row_begin(0)); |
| 262 | T1* first12=(T1*)boost::gil::at_c<2>(_v1.row_begin(0)); |
| 263 | T2* first20=(T2*)boost::gil::at_c<0>(_v2.row_begin(0)); |
| 264 | T2* first21=(T2*)boost::gil::at_c<1>(_v2.row_begin(0)); |
| 265 | T2* first22=(T2*)boost::gil::at_c<2>(_v2.row_begin(0)); |
| 266 | std::copy(first10,first10+size,first20); |
| 267 | std::copy(first11,first11+size,first21); |
| 268 | std::copy(first12,first12+size,first22); |
| 269 | } |
| 270 | }; |
| 271 | template <typename T1, typename T2> |
| 272 | struct copy_nongil_t<RGB_VIEW(T1),RGB_PLANAR_VIEW(T2)> |
| 273 | { |
| 274 | using View1 = RGB_VIEW(T1); |
| 275 | using View2 = RGB_PLANAR_VIEW(T2); |
| 276 | View1 _v1; |
| 277 | View2 _v2; |
| 278 | copy_nongil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 279 | void operator()() const { |
| 280 | T1* first=(T1*)_v1.row_begin(0); |
| 281 | T1* last=first+_v1.size()*3; |
| 282 | T2* first0=(T2*)boost::gil::at_c<0>(_v2.row_begin(0)); |
| 283 | T2* first1=(T2*)boost::gil::at_c<1>(_v2.row_begin(0)); |
| 284 | T2* first2=(T2*)boost::gil::at_c<2>(_v2.row_begin(0)); |
| 285 | while(first!=last) { |
| 286 | *first0++=first[0]; |
| 287 | *first1++=first[1]; |
| 288 | *first2++=first[2]; |
| 289 | first+=3; |
| 290 | } |
| 291 | } |
| 292 | }; |
| 293 | template <typename T1, typename T2> |
| 294 | struct copy_nongil_t<RGB_PLANAR_VIEW(T1),RGB_VIEW(T2)> |
| 295 | { |
| 296 | using View1 = RGB_PLANAR_VIEW(T1); |
| 297 | using View2 = RGB_VIEW(T2); |
| 298 | View1 _v1; |
| 299 | View2 _v2; |
| 300 | copy_nongil_t(const View1& v1_in,const View2& v2_in) : _v1(v1_in), _v2(v2_in) {} |
| 301 | void operator()() const { |
| 302 | T1* first=(T1*)_v2.row_begin(0); |
| 303 | T1* last=first+_v2.size()*3; |
| 304 | T2* first0=(T2*)boost::gil::at_c<0>(_v1.row_begin(0)); |
| 305 | T2* first1=(T2*)boost::gil::at_c<1>(_v1.row_begin(0)); |
| 306 | T2* first2=(T2*)boost::gil::at_c<2>(_v1.row_begin(0)); |
| 307 | while(first!=last) { |
| 308 | first[0]=*first0++; |
| 309 | first[1]=*first1++; |
| 310 | first[2]=*first2++; |
| 311 | first+=3; |
| 312 | } |
| 313 | } |
| 314 | }; |
| 315 | template <typename View1, typename View2> |
| 316 | void test_copy(std::size_t trials) { |
| 317 | image<typename View1::value_type, is_planar<View1>::value> im1(width,height); |
| 318 | image<typename View2::value_type, is_planar<View2>::value> im2(width,height); |
| 319 | std::cout << "GIL: " <<measure_time(copy_gil_t<View1,View2>(view(im1),view(im2)),trials) << std::endl; |
| 320 | std::cout << "Non-GIL: " <<measure_time(copy_nongil_t<View1,View2>(view(im1),view(im2)),trials) << std::endl; |
| 321 | } |
| 322 | |
| 323 | // transform() |
| 324 | template <typename T,typename Pixel> |
| 325 | struct bgr_to_rgb_t { |
| 326 | pixel<T,rgb_layout_t> operator()(const Pixel& p) const { |
| 327 | return pixel<T,rgb_layout_t>(T(get_color(p,blue_t())*0.1f), |
| 328 | T(get_color(p,green_t())*0.2f), |
| 329 | T(get_color(p,red_t())*0.3f)); |
| 330 | } |
| 331 | }; |
| 332 | template <typename View1, typename View2, typename F> |
| 333 | struct transform_gil_t { |
| 334 | View1 _v1; |
| 335 | View2 _v2; |
| 336 | F _f; |
| 337 | transform_gil_t(const View1& v1_in,const View2& v2_in,const F& f_in) : _v1(v1_in),_v2(v2_in),_f(f_in) {} |
| 338 | void operator()() const {transform_pixels(_v1,_v2,_f);} |
| 339 | }; |
| 340 | template <typename View1, typename View2, typename F> struct transform_nongil_t; |
| 341 | template <typename T1, typename T2, typename F> |
| 342 | struct transform_nongil_t<RGB_VIEW(T1),RGB_VIEW(T2),F> |
| 343 | { |
| 344 | using View1 = RGB_VIEW(T1); |
| 345 | using View2 = RGB_VIEW(T2); |
| 346 | View1 _v1; |
| 347 | View2 _v2; |
| 348 | F _f; |
| 349 | transform_nongil_t(const View1& v1_in,const View2& v2_in,const F& f_in) : _v1(v1_in),_v2(v2_in),_f(f_in) {} |
| 350 | void operator()() const { |
| 351 | T1* first1=(T1*)_v1.row_begin(0); |
| 352 | T2* first2=(T1*)_v2.row_begin(0); |
| 353 | T1* last1=first1+_v1.size()*3; |
| 354 | while(first1!=last1) { |
| 355 | first2[0]=T2(first1[2]*0.1f); |
| 356 | first2[1]=T2(first1[1]*0.2f); |
| 357 | first2[2]=T2(first1[0]*0.3f); |
| 358 | first1+=3; first2+=3; |
| 359 | } |
| 360 | } |
| 361 | }; |
| 362 | template <typename T1, typename T2, typename F> |
| 363 | struct transform_nongil_t<RGB_PLANAR_VIEW(T1),RGB_PLANAR_VIEW(T2),F> |
| 364 | { |
| 365 | using View1 = RGB_PLANAR_VIEW(T1); |
| 366 | using View2 = RGB_PLANAR_VIEW(T2); |
| 367 | View1 _v1; |
| 368 | View2 _v2; |
| 369 | F _f; |
| 370 | transform_nongil_t(const View1& v1_in,const View2& v2_in,const F& f_in) : _v1(v1_in),_v2(v2_in),_f(f_in) {} |
| 371 | void operator()() const { |
| 372 | T1* first10=(T1*)boost::gil::at_c<0>(_v1.row_begin(0)); |
| 373 | T1* first11=(T1*)boost::gil::at_c<1>(_v1.row_begin(0)); |
| 374 | T1* first12=(T1*)boost::gil::at_c<2>(_v1.row_begin(0)); |
| 375 | T1* first20=(T2*)boost::gil::at_c<0>(_v2.row_begin(0)); |
| 376 | T1* first21=(T2*)boost::gil::at_c<1>(_v2.row_begin(0)); |
| 377 | T1* first22=(T2*)boost::gil::at_c<2>(_v2.row_begin(0)); |
| 378 | T1* last10=first10+_v1.size(); |
| 379 | while(first10!=last10) { |
| 380 | *first20++=T2(*first12++*0.1f); |
| 381 | *first21++=T2(*first11++*0.2f); |
| 382 | *first22++=T2(*first10++*0.3f); |
| 383 | } |
| 384 | } |
| 385 | }; |
| 386 | template <typename T1, typename T2, typename F> |
| 387 | struct transform_nongil_t<RGB_VIEW(T1),RGB_PLANAR_VIEW(T2),F> |
| 388 | { |
| 389 | using View1 = RGB_VIEW(T1); |
| 390 | using View2 = RGB_PLANAR_VIEW(T2); |
| 391 | View1 _v1; |
| 392 | View2 _v2; |
| 393 | F _f; |
| 394 | transform_nongil_t(const View1& v1_in,const View2& v2_in,const F& f_in) : _v1(v1_in),_v2(v2_in),_f(f_in) {} |
| 395 | void operator()() const { |
| 396 | T1* first1=(T1*)_v1.row_begin(0); |
| 397 | T1* last1=first1+_v1.size()*3; |
| 398 | T1* first20=(T2*)boost::gil::at_c<0>(_v2.row_begin(0)); |
| 399 | T1* first21=(T2*)boost::gil::at_c<1>(_v2.row_begin(0)); |
| 400 | T1* first22=(T2*)boost::gil::at_c<2>(_v2.row_begin(0)); |
| 401 | while(first1!=last1) { |
| 402 | *first20++=T2(first1[2]*0.1f); |
| 403 | *first21++=T2(first1[1]*0.2f); |
| 404 | *first22++=T2(first1[0]*0.3f); |
| 405 | first1+=3; |
| 406 | } |
| 407 | } |
| 408 | }; |
| 409 | template <typename T1, typename T2, typename F> |
| 410 | struct transform_nongil_t<RGB_PLANAR_VIEW(T1),RGB_VIEW(T2),F> |
| 411 | { |
| 412 | using View1 = RGB_PLANAR_VIEW(T1); |
| 413 | using View2 = RGB_VIEW(T2); |
| 414 | View1 _v1; |
| 415 | View2 _v2; |
| 416 | F _f; |
| 417 | transform_nongil_t(const View1& v1_in,const View2& v2_in,const F& f_in) : _v1(v1_in),_v2(v2_in),_f(f_in) {} |
| 418 | void operator()() const { |
| 419 | T1* first10=(T1*)boost::gil::at_c<0>(_v1.row_begin(0)); |
| 420 | T1* first11=(T1*)boost::gil::at_c<1>(_v1.row_begin(0)); |
| 421 | T1* first12=(T1*)boost::gil::at_c<2>(_v1.row_begin(0)); |
| 422 | T2* first2=(T1*)_v2.row_begin(0); |
| 423 | T1* last2=first2+_v1.size()*3; |
| 424 | while(first2!=last2) { |
| 425 | first2[0]=T2(*first12++*0.1f); |
| 426 | first2[1]=T2(*first11++*0.2f); |
| 427 | first2[2]=T2(*first10++*0.3f); |
| 428 | first2+=3; |
| 429 | } |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | template <typename View1, typename View2, typename F> |
| 434 | void test_transform(std::size_t trials) { |
| 435 | image<typename View1::value_type, is_planar<View1>::value> im1(width,height); |
| 436 | image<typename View2::value_type, is_planar<View2>::value> im2(width,height); |
| 437 | //std::cout << "GIL: " <<measure_time(transform_gil_t<View1,View2,F>(view(im1),view(im2),F()),trials) << std::endl; |
| 438 | //std::cout << "Non-GIL: "<<measure_time(transform_nongil_t<View1,View2,F>(view(im1),view(im2),F()),trials) << std::endl; |
| 439 | } |
| 440 | |
| 441 | void test_performance() |
| 442 | { |
| 443 | #ifdef NDEBUG |
| 444 | std::size_t num_trials=1000; |
| 445 | #else |
| 446 | std::size_t num_trials=1; |
| 447 | #endif |
| 448 | |
| 449 | // fill() |
| 450 | std::cout<<"test fill_pixels() on rgb8_image_t with rgb8_pixel_t" <<std::endl; |
| 451 | test_fill<rgb8_view_t,rgb8_pixel_t>(trials: num_trials); |
| 452 | std::cout<<std::endl; |
| 453 | |
| 454 | std::cout<<"test fill_pixels() on rgb8_planar_image_t with rgb8_pixel_t" <<std::endl; |
| 455 | test_fill<rgb8_planar_view_t,rgb8_pixel_t>(trials: num_trials); |
| 456 | std::cout<<std::endl; |
| 457 | |
| 458 | std::cout<<"test fill_pixels() on rgb8_image_t with bgr8_pixel_t" <<std::endl; |
| 459 | test_fill<rgb8_view_t,bgr8_pixel_t>(trials: num_trials); |
| 460 | std::cout<<std::endl; |
| 461 | |
| 462 | std::cout<<"test fill_pixels() on rgb8_planar_image_t with bgr8_pixel_t" <<std::endl; |
| 463 | test_fill<rgb8_planar_view_t,bgr8_pixel_t>(trials: num_trials); |
| 464 | std::cout<<std::endl; |
| 465 | |
| 466 | // for_each() |
| 467 | std::cout<<"test for_each_pixel() on rgb8_image_t" <<std::endl; |
| 468 | test_for_each<rgb8_view_t,rgb_fr_t<uint8_t> >(trials: num_trials); |
| 469 | std::cout<<std::endl; |
| 470 | |
| 471 | std::cout<<"test for_each_pixel() on rgb8_planar_image_t" <<std::endl; |
| 472 | test_for_each<rgb8_planar_view_t,rgb_fr_t<uint8_t> >(trials: num_trials); |
| 473 | std::cout<<std::endl; |
| 474 | |
| 475 | // copy() |
| 476 | std::cout<<"test copy_pixels() between rgb8_image_t and rgb8_image_t" <<std::endl; |
| 477 | test_copy<rgb8_view_t,rgb8_view_t>(trials: num_trials); |
| 478 | std::cout<<std::endl; |
| 479 | |
| 480 | std::cout<<"test copy_pixels() between rgb8_image_t and bgr8_image_t" <<std::endl; |
| 481 | test_copy<rgb8_view_t,bgr8_view_t>(trials: num_trials); |
| 482 | std::cout<<std::endl; |
| 483 | |
| 484 | std::cout<<"test copy_pixels() between rgb8_planar_image_t and rgb8_planar_image_t" <<std::endl; |
| 485 | test_copy<rgb8_planar_view_t,rgb8_planar_view_t>(trials: num_trials); |
| 486 | std::cout<<std::endl; |
| 487 | |
| 488 | std::cout<<"test copy_pixels() between rgb8_image_t and rgb8_planar_image_t" <<std::endl; |
| 489 | test_copy<rgb8_view_t,rgb8_planar_view_t>(trials: num_trials); |
| 490 | std::cout<<std::endl; |
| 491 | |
| 492 | std::cout<<"test copy_pixels() between rgb8_planar_image_t and rgb8_image_t" <<std::endl; |
| 493 | test_copy<rgb8_planar_view_t,rgb8_view_t>(trials: num_trials); |
| 494 | std::cout<<std::endl; |
| 495 | |
| 496 | // transform() |
| 497 | std::cout<<"test transform_pixels() between rgb8_image_t and rgb8_image_t" <<std::endl; |
| 498 | test_transform<rgb8_view_t,rgb8_view_t,bgr_to_rgb_t<uint8_t,pixel<uint8_t,rgb_layout_t> > >(trials: num_trials); |
| 499 | std::cout<<std::endl; |
| 500 | |
| 501 | std::cout<<"test transform_pixels() between rgb8_planar_image_t and rgb8_planar_image_t" <<std::endl; |
| 502 | test_transform<rgb8_planar_view_t,rgb8_planar_view_t,bgr_to_rgb_t<uint8_t,planar_pixel_reference<uint8_t,rgb_t> > >(trials: num_trials); |
| 503 | std::cout<<std::endl; |
| 504 | |
| 505 | std::cout<<"test transform_pixels() between rgb8_image_t and rgb8_planar_image_t" <<std::endl; |
| 506 | test_transform<rgb8_view_t,rgb8_planar_view_t,bgr_to_rgb_t<uint8_t,pixel<uint8_t,rgb_layout_t> > >(trials: num_trials); |
| 507 | std::cout<<std::endl; |
| 508 | |
| 509 | std::cout<<"test transform_pixels() between rgb8_planar_image_t and rgb8_image_t" <<std::endl; |
| 510 | test_transform<rgb8_planar_view_t,rgb8_view_t,bgr_to_rgb_t<uint8_t,planar_pixel_reference<uint8_t,rgb_t> > >(trials: num_trials); |
| 511 | std::cout<<std::endl; |
| 512 | } |
| 513 | |
| 514 | int main() |
| 515 | { |
| 516 | |
| 517 | test_performance(); |
| 518 | |
| 519 | return ::boost::report_errors(); |
| 520 | } |
| 521 | |