old.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // Copyright 2007-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_JPEG_OLD_HPP
  9. #define BOOST_GIL_EXTENSION_IO_JPEG_OLD_HPP
  10. #include <boost/gil/extension/io/jpeg.hpp>
  11. namespace boost { namespace gil {
  12. /// \ingroup JPEG_IO
  13. /// \brief Returns the width and height of the JPEG file at the specified location.
  14. /// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file
  15. template<typename String>
  16. inline point_t jpeg_read_dimensions(String const& filename)
  17. {
  18. using backend_t = typename get_reader_backend<String, jpeg_tag>::type;
  19. backend_t backend = read_image_info(filename, jpeg_tag());
  20. return { backend._info._width, backend._info._height };
  21. }
  22. /// \ingroup JPEG_IO
  23. /// \brief Loads the image specified by the given jpeg 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 JPEG library or by the I/O extension.
  25. /// Throws std::ios_base::failure if the file is not a valid JPEG 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 jpeg_read_view( const String& filename
  32. , const View& view
  33. )
  34. {
  35. read_view( filename
  36. , view
  37. , jpeg_tag()
  38. );
  39. }
  40. /// \ingroup JPEG_IO
  41. /// \brief Allocates a new image whose dimensions are determined by the given jpeg 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 JPEG library or by the I/O extension.
  43. /// Throws std::ios_base::failure if the file is not a valid JPEG 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 jpeg_read_image( const String& filename
  50. , Image& img
  51. )
  52. {
  53. read_image( filename
  54. , img
  55. , jpeg_tag()
  56. );
  57. }
  58. /// \ingroup JPEG_IO
  59. /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
  60. /// Throws std::ios_base::failure if the file is not a valid JPEG 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 jpeg_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. , jpeg_tag()
  75. );
  76. }
  77. /// \ingroup JPEG_IO
  78. /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
  79. /// Throws std::ios_base::failure if the file is not a valid JPEG 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 jpeg_read_and_convert_view( const String& filename
  85. , const View& view
  86. )
  87. {
  88. read_and_convert_view( filename
  89. , view
  90. , jpeg_tag()
  91. );
  92. }
  93. /// \ingroup JPEG_IO
  94. /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
  95. /// Throws std::ios_base::failure if the file is not a valid JPEG file
  96. template< typename String
  97. , typename Image
  98. , typename CC
  99. >
  100. inline
  101. void jpeg_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. , jpeg_tag()
  110. );
  111. }
  112. /// \ingroup JPEG_IO
  113. /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
  114. /// Throws std::ios_base::failure if the file is not a valid JPEG file
  115. template< typename String
  116. , typename Image
  117. >
  118. inline
  119. void jpeg_read_and_convert_image( const String filename
  120. , Image& img
  121. )
  122. {
  123. read_and_convert_image( filename
  124. , img
  125. , jpeg_tag()
  126. );
  127. }
  128. /// \ingroup JPEG_IO
  129. /// \brief Saves the view to a jpeg file specified by the given jpeg image file name.
  130. /// Triggers a compile assert if the view color space and channel depth are not supported by the JPEG 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 jpeg_write_view( const String& filename
  137. , const View& view
  138. , int quality = jpeg_quality::default_value
  139. )
  140. {
  141. write_view( filename
  142. , view
  143. , image_write_info< jpeg_tag >( quality )
  144. );
  145. }
  146. } // namespace gil
  147. } // namespace boost
  148. #endif