old.hpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Copyright 2008 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. #ifndef BOOST_GIL_EXTENSION_IO_PNM_OLD_HPP
  9. #define BOOST_GIL_EXTENSION_IO_PNM_OLD_HPP
  10. #include <boost/gil/extension/io/pnm.hpp>
  11. namespace boost { namespace gil {
  12. /// \ingroup PNM_IO
  13. /// \brief Returns the width and height of the PNM file at the specified location.
  14. /// Throws std::ios_base::failure if the location does not correspond to a valid PNM file
  15. template<typename String>
  16. inline point_t pnm_read_dimensions(String const& filename)
  17. {
  18. using backend_t = typename get_reader_backend<String, pnm_tag>::type;
  19. backend_t backend = read_image_info(filename, pnm_tag());
  20. return { backend._info._width, backend._info._height };
  21. }
  22. /// \ingroup PNM_IO
  23. /// \brief Loads the image specified by the given pnm image file name into the given view.
  24. /// Triggers a compile assert if the view color space and channel depth are not supported by the PNM library or by the I/O extension.
  25. /// Throws std::ios_base::failure if the file is not a valid PNM file, or if its color space or channel depth are not
  26. /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
  27. template< typename String
  28. , typename View
  29. >
  30. inline
  31. void pnm_read_view( const String& filename
  32. , const View& view
  33. )
  34. {
  35. read_view( filename
  36. , view
  37. , pnm_tag()
  38. );
  39. }
  40. /// \ingroup PNM_IO
  41. /// \brief Allocates a new image whose dimensions are determined by the given pnm image file, and loads the pixels into it.
  42. /// Triggers a compile assert if the image color space or channel depth are not supported by the PNM library or by the I/O extension.
  43. /// Throws std::ios_base::failure if the file is not a valid PNM file, or if its color space or channel depth are not
  44. /// compatible with the ones specified by Image
  45. template< typename String
  46. , typename Image
  47. >
  48. inline
  49. void pnm_read_image( const String& filename
  50. , Image& img
  51. )
  52. {
  53. read_image( filename
  54. , img
  55. , pnm_tag()
  56. );
  57. }
  58. /// \ingroup PNM_IO
  59. /// \brief Loads and color-converts the image specified by the given pnm image file name into the given view.
  60. /// Throws std::ios_base::failure if the file is not a valid PNM file, or if its dimensions don't match the ones of the view.
  61. template< typename String
  62. , typename View
  63. , typename CC
  64. >
  65. inline
  66. void pnm_read_and_convert_view( const String& filename
  67. , const View& view
  68. , CC cc
  69. )
  70. {
  71. read_and_convert_view( filename
  72. , view
  73. , cc
  74. , pnm_tag()
  75. );
  76. }
  77. /// \ingroup PNM_IO
  78. /// \brief Loads and color-converts the image specified by the given pnm image file name into the given view.
  79. /// Throws std::ios_base::failure if the file is not a valid PNM file, or if its dimensions don't match the ones of the view.
  80. template< typename String
  81. , typename View
  82. >
  83. inline
  84. void pnm_read_and_convert_view( const String& filename
  85. , const View& view
  86. )
  87. {
  88. read_and_convert_view( filename
  89. , view
  90. , pnm_tag()
  91. );
  92. }
  93. /// \ingroup PNM_IO
  94. /// \brief Allocates a new image whose dimensions are determined by the given pnm image file, loads and color-converts the pixels into it.
  95. /// Throws std::ios_base::failure if the file is not a valid PNM file
  96. template< typename String
  97. , typename Image
  98. , typename CC
  99. >
  100. inline
  101. void pnm_read_and_convert_image( const String& filename
  102. , Image& img
  103. , CC cc
  104. )
  105. {
  106. read_and_convert_image( filename
  107. , img
  108. , cc
  109. , pnm_tag()
  110. );
  111. }
  112. /// \ingroup PNM_IO
  113. /// \brief Allocates a new image whose dimensions are determined by the given pnm image file, loads and color-converts the pixels into it.
  114. /// Throws std::ios_base::failure if the file is not a valid PNM file
  115. template< typename String
  116. , typename Image
  117. >
  118. inline
  119. void pnm_read_and_convert_image( const String filename
  120. , Image& img
  121. )
  122. {
  123. read_and_convert_image( filename
  124. , img
  125. , pnm_tag()
  126. );
  127. }
  128. /// \ingroup PNM_IO
  129. /// \brief Saves the view to a pnm file specified by the given pnm image file name.
  130. /// Triggers a compile assert if the view color space and channel depth are not supported by the PNM library or by the I/O extension.
  131. /// Throws std::ios_base::failure if it fails to create the file.
  132. template< typename String
  133. , typename View
  134. >
  135. inline
  136. void pnm_write_view( const String& filename
  137. , const View& view
  138. )
  139. {
  140. write_view( filename
  141. , view
  142. , pnm_tag()
  143. );
  144. }
  145. } // namespace gil
  146. } // namespace boost
  147. #endif