annotate DEPENDENCIES/generic/include/boost/gil/extension/io/jpeg_io.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 Copyright 2005-2007 Adobe Systems Incorporated
Chris@16 3
Chris@16 4 Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7
Chris@16 8 See http://opensource.adobe.com/gil for most recent version including documentation.
Chris@16 9 */
Chris@16 10
Chris@16 11 /*************************************************************************************************/
Chris@16 12
Chris@16 13 #ifndef GIL_JPEG_IO_H
Chris@16 14 #define GIL_JPEG_IO_H
Chris@16 15
Chris@16 16 /// \file
Chris@16 17 /// \brief Support for reading and writing JPEG files
Chris@16 18 /// Requires libjpeg
Chris@16 19 /// \author Hailin Jin and Lubomir Bourdev \n
Chris@16 20 /// Adobe Systems Incorporated
Chris@16 21 /// \date 2005-2007 \n Last updated September 24, 2006
Chris@16 22
Chris@16 23 #include <cstdio>
Chris@16 24 #include <algorithm>
Chris@16 25 #include <string>
Chris@16 26 #include <boost/static_assert.hpp>
Chris@16 27 #include <boost/shared_ptr.hpp>
Chris@16 28 extern "C" {
Chris@16 29 #include <jpeglib.h>
Chris@16 30 }
Chris@16 31 #include "io_error.hpp"
Chris@16 32 #include "jpeg_io_private.hpp"
Chris@16 33
Chris@16 34 namespace boost { namespace gil {
Chris@16 35
Chris@16 36 /// \ingroup JPEG_IO
Chris@16 37 /// \brief Determines whether the given view type is supported for reading
Chris@16 38 template <typename View>
Chris@16 39 struct jpeg_read_support {
Chris@16 40 BOOST_STATIC_CONSTANT(bool,is_supported=
Chris@16 41 (detail::jpeg_read_support_private<typename channel_type<View>::type,
Chris@16 42 typename color_space_type<View>::type>::is_supported));
Chris@16 43 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=
Chris@16 44 (detail::jpeg_read_support_private<typename channel_type<View>::type,
Chris@16 45 typename color_space_type<View>::type>::color_type));
Chris@16 46 BOOST_STATIC_CONSTANT(bool, value=is_supported);
Chris@16 47 };
Chris@16 48
Chris@16 49 /// \ingroup JPEG_IO
Chris@16 50 /// \brief Returns the width and height of the JPEG file at the specified location.
Chris@16 51 /// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file
Chris@16 52 inline point2<std::ptrdiff_t> jpeg_read_dimensions(const char* filename) {
Chris@16 53 detail::jpeg_reader m(filename);
Chris@16 54 return m.get_dimensions();
Chris@16 55 }
Chris@16 56
Chris@16 57 /// \ingroup JPEG_IO
Chris@16 58 /// \brief Returns the width and height of the JPEG file at the specified location.
Chris@16 59 /// Throws std::ios_base::failure if the location does not correspond to a valid JPEG file
Chris@16 60 inline point2<std::ptrdiff_t> jpeg_read_dimensions(const std::string& filename) {
Chris@16 61 return jpeg_read_dimensions(filename.c_str());
Chris@16 62 }
Chris@16 63
Chris@16 64 /// \ingroup JPEG_IO
Chris@16 65 /// \brief Loads the image specified by the given jpeg image file name into the given view.
Chris@16 66 /// 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.
Chris@16 67 /// Throws std::ios_base::failure if the file is not a valid JPEG file, or if its color space or channel depth are not
Chris@16 68 /// compatible with the ones specified by View, or if its dimensions don't match the ones of the view.
Chris@16 69 template <typename View>
Chris@16 70 inline void jpeg_read_view(const char* filename,const View& view) {
Chris@16 71 BOOST_STATIC_ASSERT(jpeg_read_support<View>::is_supported);
Chris@16 72
Chris@16 73 detail::jpeg_reader m(filename);
Chris@16 74 m.apply(view);
Chris@16 75 }
Chris@16 76
Chris@16 77 /// \ingroup JPEG_IO
Chris@16 78 /// \brief Loads the image specified by the given jpeg image file name into the given view.
Chris@16 79 template <typename View>
Chris@16 80 inline void jpeg_read_view(const std::string& filename,const View& view) {
Chris@16 81 jpeg_read_view(filename.c_str(),view);
Chris@16 82 }
Chris@16 83
Chris@16 84 /// \ingroup JPEG_IO
Chris@16 85 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, and loads the pixels into it.
Chris@16 86 /// 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.
Chris@16 87 /// Throws std::ios_base::failure if the file is not a valid JPEG file, or if its color space or channel depth are not
Chris@16 88 /// compatible with the ones specified by Image
Chris@16 89 template <typename Image>
Chris@16 90 inline void jpeg_read_image(const char* filename,Image& im) {
Chris@16 91 BOOST_STATIC_ASSERT(jpeg_read_support<typename Image::view_t>::is_supported);
Chris@16 92
Chris@16 93 detail::jpeg_reader m(filename);
Chris@16 94 m.read_image(im);
Chris@16 95 }
Chris@16 96
Chris@16 97 /// \ingroup JPEG_IO
Chris@16 98 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, and loads the pixels into it.
Chris@16 99 template <typename Image>
Chris@16 100 inline void jpeg_read_image(const std::string& filename,Image& im) {
Chris@16 101 jpeg_read_image(filename.c_str(),im);
Chris@16 102 }
Chris@16 103
Chris@16 104 /// \ingroup JPEG_IO
Chris@16 105 /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
Chris@16 106 /// 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.
Chris@16 107 template <typename View,typename CC>
Chris@16 108 inline void jpeg_read_and_convert_view(const char* filename,const View& view,CC cc) {
Chris@16 109 detail::jpeg_reader_color_convert<CC> m(filename,cc);
Chris@16 110 m.apply(view);
Chris@16 111 }
Chris@16 112
Chris@16 113 /// \ingroup JPEG_IO
Chris@16 114 /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
Chris@16 115 /// 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.
Chris@16 116 template <typename View>
Chris@16 117 inline void jpeg_read_and_convert_view(const char* filename,const View& view) {
Chris@16 118 detail::jpeg_reader_color_convert<default_color_converter> m(filename,default_color_converter());
Chris@16 119 m.apply(view);
Chris@16 120 }
Chris@16 121
Chris@16 122 /// \ingroup JPEG_IO
Chris@16 123 /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
Chris@16 124 template <typename View,typename CC>
Chris@16 125 inline void jpeg_read_and_convert_view(const std::string& filename,const View& view,CC cc) {
Chris@16 126 jpeg_read_and_convert_view(filename.c_str(),view);
Chris@16 127 }
Chris@16 128
Chris@16 129 /// \ingroup JPEG_IO
Chris@16 130 /// \brief Loads and color-converts the image specified by the given jpeg image file name into the given view.
Chris@16 131 template <typename View>
Chris@16 132 inline void jpeg_read_and_convert_view(const std::string& filename,const View& view) {
Chris@16 133 jpeg_read_and_convert_view(filename.c_str(),view);
Chris@16 134 }
Chris@16 135
Chris@16 136 /// \ingroup JPEG_IO
Chris@16 137 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
Chris@16 138 /// Throws std::ios_base::failure if the file is not a valid JPEG file
Chris@16 139 template <typename Image,typename CC>
Chris@16 140 inline void jpeg_read_and_convert_image(const char* filename,Image& im,CC cc) {
Chris@16 141 detail::jpeg_reader_color_convert<CC> m(filename,cc);
Chris@16 142 m.read_image(im);
Chris@16 143 }
Chris@16 144
Chris@16 145 /// \ingroup JPEG_IO
Chris@16 146 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
Chris@16 147 /// Throws std::ios_base::failure if the file is not a valid JPEG file
Chris@16 148 template <typename Image>
Chris@16 149 inline void jpeg_read_and_convert_image(const char* filename,Image& im) {
Chris@16 150 detail::jpeg_reader_color_convert<default_color_converter> m(filename,default_color_converter());
Chris@16 151 m.read_image(im);
Chris@16 152 }
Chris@16 153
Chris@16 154 /// \ingroup JPEG_IO
Chris@16 155 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
Chris@16 156 template <typename Image,typename CC>
Chris@16 157 inline void jpeg_read_and_convert_image(const std::string& filename,Image& im,CC cc) {
Chris@16 158 jpeg_read_and_convert_image(filename.c_str(),im);
Chris@16 159 }
Chris@16 160
Chris@16 161 /// \ingroup JPEG_IO
Chris@16 162 /// \brief Allocates a new image whose dimensions are determined by the given jpeg image file, loads and color-converts the pixels into it.
Chris@16 163 template <typename Image>
Chris@16 164 inline void jpeg_read_and_convert_image(const std::string& filename,Image& im) {
Chris@16 165 jpeg_read_and_convert_image(filename.c_str(),im);
Chris@16 166 }
Chris@16 167
Chris@16 168 /// \ingroup JPEG_IO
Chris@16 169 /// \brief Determines whether the given view type is supported for writing
Chris@16 170 template <typename View>
Chris@16 171 struct jpeg_write_support {
Chris@16 172 BOOST_STATIC_CONSTANT(bool,is_supported=
Chris@16 173 (detail::jpeg_write_support_private<typename channel_type<View>::type,
Chris@16 174 typename color_space_type<View>::type>::is_supported));
Chris@16 175 BOOST_STATIC_CONSTANT(J_COLOR_SPACE,color_type=
Chris@16 176 (detail::jpeg_write_support_private<typename channel_type<View>::type,
Chris@16 177 typename color_space_type<View>::type>::color_type));
Chris@16 178 BOOST_STATIC_CONSTANT(bool, value=is_supported);
Chris@16 179 };
Chris@16 180
Chris@16 181 /// \ingroup JPEG_IO
Chris@16 182 /// \brief Saves the view to a jpeg file specified by the given jpeg image file name.
Chris@16 183 /// 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.
Chris@16 184 /// Throws std::ios_base::failure if it fails to create the file.
Chris@16 185 template <typename View>
Chris@16 186 inline void jpeg_write_view(const char* filename,const View& view,int quality=100) {
Chris@16 187 BOOST_STATIC_ASSERT(jpeg_write_support<View>::is_supported);
Chris@16 188
Chris@16 189 detail::jpeg_writer m(filename);
Chris@16 190 m.apply(view,quality);
Chris@16 191 }
Chris@16 192
Chris@16 193 /// \ingroup JPEG_IO
Chris@16 194 /// \brief Saves the view to a jpeg file specified by the given jpeg image file name.
Chris@16 195 template <typename View>
Chris@16 196 inline void jpeg_write_view(const std::string& filename,const View& view,int quality=100) {
Chris@16 197 jpeg_write_view(filename.c_str(),view,quality);
Chris@16 198 }
Chris@16 199
Chris@16 200 } } // namespace boost::gil
Chris@16 201
Chris@16 202 #endif