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_DYNAMICIMAGE_ANY_IMAGE_HPP Chris@16: #define GIL_DYNAMICIMAGE_ANY_IMAGE_HPP Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file Chris@16: /// \brief Support for run-time instantiated images and image views Chris@16: /// \author Lubomir Bourdev and Hailin Jin \n Chris@16: /// Adobe Systems Incorporated Chris@16: /// Chris@16: /// Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: #include "any_image_view.hpp" Chris@16: #include "../../image.hpp" Chris@16: Chris@16: //#ifdef _MSC_VER Chris@16: //#pragma warning(push) Chris@16: //#pragma warning(disable : 4244) // conversion from 'std::ptrdiff_t' to 'int', possible loss of data. even if we static-assert the two types are the same (on visual studio 8) Chris@16: //#endif Chris@16: Chris@16: namespace boost { namespace gil { Chris@16: Chris@16: namespace detail { Chris@16: template struct get_view_t { typedef typename T::view_t type; }; Chris@16: template struct images_get_views_t : public mpl::transform > {}; Chris@16: Chris@16: template struct get_const_view_t { typedef typename T::const_view_t type; }; Chris@16: template struct images_get_const_views_t : public mpl::transform > {}; Chris@16: Chris@16: struct recreate_image_fnobj { Chris@16: typedef void result_type; Chris@16: const point2& _dimensions; Chris@16: unsigned _alignment; Chris@16: Chris@16: recreate_image_fnobj(const point2& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {} Chris@16: template result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); } Chris@16: }; Chris@16: Chris@16: template // Models AnyViewConcept Chris@16: struct any_image_get_view { Chris@16: typedef AnyView result_type; Chris@16: template result_type operator()( Image& img) const { return result_type(view(img)); } Chris@16: }; Chris@16: Chris@16: template // Models AnyConstViewConcept Chris@16: struct any_image_get_const_view { Chris@16: typedef AnyConstView result_type; Chris@16: template result_type operator()(const Image& img) const { return result_type(const_view(img)); } Chris@16: }; Chris@16: } Chris@16: Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: /// \ingroup ImageModel Chris@16: /// \brief Represents a run-time specified image. Note it does NOT model ImageConcept Chris@16: /// Chris@16: /// Represents an image whose type (color space, layout, planar/interleaved organization, etc) can be specified at run time. Chris@16: /// It is the runtime equivalent of \p image. Chris@16: /// Some of the requirements of ImageConcept, such as the \p value_type typedef cannot be fulfilled, since the language does not allow runtime type specification. Chris@16: /// Other requirements, such as access to the pixels, would be inefficient to provide. Thus \p any_image does not fully model ImageConcept. Chris@16: /// In particular, its \p view and \p const_view methods return \p any_image_view, which does not fully model ImageViewConcept. See \p any_image_view for more. Chris@16: //////////////////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: class any_image : public variant { Chris@16: typedef variant parent_t; Chris@16: public: Chris@16: typedef any_image_view::type> const_view_t; Chris@16: typedef any_image_view::type> view_t; Chris@16: typedef std::ptrdiff_t x_coord_t; Chris@16: typedef std::ptrdiff_t y_coord_t; Chris@16: typedef point2 point_t; Chris@16: Chris@16: any_image() : parent_t() {} Chris@16: template explicit any_image(const T& obj) : parent_t(obj) {} Chris@16: template explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {} Chris@16: any_image(const any_image& v) : parent_t((const parent_t&)v) {} Chris@16: Chris@16: template any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; } Chris@16: any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;} Chris@16: Chris@16: void recreate(const point_t& dims, unsigned alignment=1) { apply_operation(*this,detail::recreate_image_fnobj(dims,alignment)); } Chris@16: void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1) { recreate(point2(width,height),alignment); } Chris@16: Chris@16: std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); } Chris@16: point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); } Chris@16: x_coord_t width() const { return dimensions().x; } Chris@16: y_coord_t height() const { return dimensions().y; } Chris@16: }; Chris@16: Chris@16: ///@{ Chris@16: /// \name view, const_view Chris@16: /// \brief Get an image view from a run-time instantiated image Chris@16: Chris@16: /// \ingroup ImageModel Chris@16: Chris@16: /// \brief Returns the non-constant-pixel view of any image. The returned view is any view. Chris@16: template GIL_FORCEINLINE // Models ImageVectorConcept Chris@16: typename any_image::view_t view(any_image& anyImage) { Chris@16: return apply_operation(anyImage, detail::any_image_get_view::view_t>()); Chris@16: } Chris@16: Chris@16: /// \brief Returns the constant-pixel view of any image. The returned view is any view. Chris@16: template GIL_FORCEINLINE // Models ImageVectorConcept Chris@16: typename any_image::const_view_t const_view(const any_image& anyImage) { Chris@16: return apply_operation(anyImage, detail::any_image_get_const_view::const_view_t>()); Chris@16: } Chris@16: ///@} Chris@16: Chris@16: } } // namespace boost::gil Chris@16: Chris@16: //#ifdef _MSC_VER Chris@16: //#pragma warning(pop) Chris@16: //#endif Chris@16: Chris@16: #endif