Chris@16: /* Chris@16: Copyright 2005-2007 Adobe Systems Incorporated Chris@16: Chris@16: Use, modification and distribution are subject to the Boost Software License, Chris@16: Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt). Chris@16: Chris@16: See http://opensource.adobe.com/gil for most recent version including documentation. Chris@16: */ Chris@16: /*************************************************************************************************/ Chris@16: Chris@16: #ifndef GIL_DYNAMIC_IO_H Chris@16: #define GIL_DYNAMIC_IO_H Chris@16: Chris@16: /// \file Chris@16: /// \brief Generic io functions for dealing with dynamic images Chris@16: // Chris@16: /// \author Hailin Jin and Lubomir Bourdev \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// \date 2005-2007 \n Last updated May 30, 2006 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include "../../gil_config.hpp" Chris@16: #include "io_error.hpp" Chris@16: #include "../dynamic_image/any_image.hpp" Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: namespace detail { Chris@16: Chris@16: template Chris@16: struct construct_matched_t { Chris@16: template Chris@16: static bool apply(any_image& im,Pred pred) { Chris@16: if (pred.template apply::type>()) { Chris@16: typename mpl::at_c::type x; Chris@16: im.move_in(x); Chris@16: return true; Chris@16: } else return construct_matched_t::apply(im,pred); Chris@16: } Chris@16: }; Chris@16: template <> Chris@16: struct construct_matched_t<0> { Chris@16: template Chris@16: static bool apply(any_image&,Pred) {return false;} Chris@16: }; Chris@16: Chris@16: // A function object that can be passed to apply_operation. Chris@16: // Given a predicate IsSupported taking a view type and returning an MPL boolean, Chris@16: // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise Chris@16: template Chris@16: class dynamic_io_fnobj { Chris@16: OpClass* _op; Chris@16: Chris@16: template Chris@16: void apply(const View& view,mpl::true_ ) {_op->apply(view);} Chris@16: template Chris@16: void apply(const View& view,mpl::false_) {io_error("dynamic_io: unsupported view type for the given file format");} Chris@16: public: Chris@16: dynamic_io_fnobj(OpClass* op) : _op(op) {} Chris@16: Chris@16: typedef void result_type; Chris@16: Chris@16: template Chris@16: void operator()(const View& view) {apply(view,typename IsSupported::template apply::type());} Chris@16: }; Chris@16: Chris@16: } // namespace detail Chris@16: Chris@16: /// \brief Within the any_image, constructs an image with the given dimensions Chris@16: /// and a type that satisfies the given predicate Chris@16: template Chris@16: inline bool construct_matched(any_image& im,Pred pred) { Chris@16: return detail::construct_matched_t::value>::apply(im,pred); Chris@16: } Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: #endif