png_file_format_test.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // Copyright 2013 Christian Henning
  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. //#define BOOST_TEST_MODULE png_file_format_test_module
  9. #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
  10. #define BOOST_GIL_IO_ENABLE_GRAY_ALPHA
  11. #define BOOST_FILESYSTEM_VERSION 3
  12. #include <boost/gil/extension/io/png.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include "paths.hpp"
  15. using namespace std;
  16. using namespace boost::gil;
  17. namespace fs = boost::filesystem;
  18. using tag_t = png_tag;
  19. BOOST_AUTO_TEST_SUITE( gil_io_png_tests )
  20. #ifdef BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
  21. // Test will loop through the "in" folder to read and convert
  22. // the png's to rgb8_image_t's. Which then will be written in
  23. // the "out" folder.
  24. //
  25. // The file name structure is as followed:
  26. //
  27. // g04i2c08.png
  28. // || |||+---- bit-depth
  29. // || ||+----- color-type (descriptive)
  30. // || |+------ color-type (numerical)
  31. // || +------- interlaced or non-interlaced
  32. // |+--------- parameter of test (in this case gamma-value)
  33. // +---------- test feature (in this case gamma)
  34. BOOST_AUTO_TEST_CASE( file_format_test )
  35. {
  36. string in ( png_in + "PngSuite\\" );
  37. fs::path in_path = fs::system_complete( fs::path( in ));
  38. if ( fs::is_directory( in_path ) )
  39. {
  40. fs::directory_iterator end_iter;
  41. for( fs::directory_iterator dir_itr( in_path )
  42. ; dir_itr != end_iter
  43. ; ++dir_itr
  44. )
  45. {
  46. if ( fs::is_regular( dir_itr->status() )
  47. && ( fs::extension( dir_itr->path() ) == ".PNG" ))
  48. {
  49. rgb8_image_t img;
  50. string filename = in + dir_itr->path().leaf().string();
  51. read_and_convert_image( filename, img, tag_t() );
  52. #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  53. write_view( png_out + fs::basename( dir_itr->path() ) + ".png"
  54. , view( img )
  55. , png_tag()
  56. );
  57. #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
  58. }
  59. }
  60. }
  61. }
  62. #endif // BOOST_GIL_IO_USE_PNG_TEST_SUITE_IMAGES
  63. BOOST_AUTO_TEST_SUITE_END()