old.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. Copyright 2007-2008 Christian Henning
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_EXTENSION_IO_JPEG_OLD_HPP
  9. #define BOOST_GIL_EXTENSION_IO_JPEG_OLD_HPP
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file
  12. /// \brief
  13. /// \author Christian Henning \n
  14. ///
  15. /// \date 2007-2008 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/gil/extension/io/jpeg.hpp>
  19. namespace boost { namespace gil {
  20. /// \ingroup JPEG_IO
  21. /// \brief Returns the width and height of the JPEG file at the specified location.
  22. /// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file
  23. template< typename String >
  24. inline
  25. point2< std::ptrdiff_t > jpeg_read_dimensions( const String& filename )
  26. {
  27. typedef typename get_reader_backend< String
  28. , jpeg_tag
  29. >::type backend_t;
  30. backend_t backend = read_image_info( filename
  31. , jpeg_tag()
  32. );
  33. return point2< std::ptrdiff_t >( backend._info._width
  34. , backend._info._height
  35. );
  36. }
  37. /// \ingroup JPEG_IO
  38. /// \brief Loads the image specified by the given jpeg image file name into the given view.
  39. /// 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.
  40. /// Throws std::ios_base::failure if the file is not a valid JPEG file, or if its color space or channel depth are not
  41. /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
  42. template< typename String
  43. , typename View
  44. >
  45. inline
  46. void jpeg_read_view( const String& filename
  47. , const View& view
  48. )
  49. {
  50. read_view( filename
  51. , view
  52. , jpeg_tag()
  53. );
  54. }
  55. /// \ingroup JPEG_IO
  56. /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, and loads the pixels into it.
  57. /// 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.
  58. /// Throws std::ios_base::failure if the file is not a valid JPEG file, or if its color space or channel depth are not
  59. /// compatible with the ones specified by Image
  60. template< typename String
  61. , typename Image
  62. >
  63. inline
  64. void jpeg_read_image( const String& filename
  65. , Image& img
  66. )
  67. {
  68. read_image( filename
  69. , img
  70. , jpeg_tag()
  71. );
  72. }
  73. /// \ingroup JPEG_IO
  74. /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
  75. /// 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.
  76. template< typename String
  77. , typename View
  78. , typename CC
  79. >
  80. inline
  81. void jpeg_read_and_convert_view( const String& filename
  82. , const View& view
  83. , CC cc
  84. )
  85. {
  86. read_and_convert_view( filename
  87. , view
  88. , cc
  89. , jpeg_tag()
  90. );
  91. }
  92. /// \ingroup JPEG_IO
  93. /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
  94. /// 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.
  95. template< typename String
  96. , typename View
  97. >
  98. inline
  99. void jpeg_read_and_convert_view( const String& filename
  100. , const View& view
  101. )
  102. {
  103. read_and_convert_view( filename
  104. , view
  105. , jpeg_tag()
  106. );
  107. }
  108. /// \ingroup JPEG_IO
  109. /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
  110. /// Throws std::ios_base::failure if the file is not a valid JPEG file
  111. template< typename String
  112. , typename Image
  113. , typename CC
  114. >
  115. inline
  116. void jpeg_read_and_convert_image( const String& filename
  117. , Image& img
  118. , CC cc
  119. )
  120. {
  121. read_and_convert_image( filename
  122. , img
  123. , cc
  124. , jpeg_tag()
  125. );
  126. }
  127. /// \ingroup JPEG_IO
  128. /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
  129. /// Throws std::ios_base::failure if the file is not a valid JPEG file
  130. template< typename String
  131. , typename Image
  132. >
  133. inline
  134. void jpeg_read_and_convert_image( const String filename
  135. , Image& img
  136. )
  137. {
  138. read_and_convert_image( filename
  139. , img
  140. , jpeg_tag()
  141. );
  142. }
  143. /// \ingroup JPEG_IO
  144. /// \brief Saves the view to a jpeg file specified by the given jpeg image file name.
  145. /// 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.
  146. /// Throws std::ios_base::failure if it fails to create the file.
  147. template< typename String
  148. , typename View
  149. >
  150. inline
  151. void jpeg_write_view( const String& filename
  152. , const View& view
  153. , int quality = jpeg_quality::default_value
  154. )
  155. {
  156. write_view( filename
  157. , view
  158. , image_write_info< jpeg_tag >( quality )
  159. );
  160. }
  161. } // namespace gil
  162. } // namespace boost
  163. #endif