Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page # any_image.hpp Go to the documentation of this file.
    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://opensource.adobe.com/gil for most recent version including documentation.
    00009 */
    00010 /*************************************************************************************************/
    00011
    00012 #ifndef GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
    00013 #define GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
    00014
    00023
    00024 #include "any_image_view.hpp"
    00025 #include "../../image.hpp"
    00026
    00027 //#ifdef _MSC_VER
    00028 //#pragma warning(push)
    00029 //#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)
    00030 //#endif
    00031
    00032 namespace boost { namespace gil {
    00033
    00034 namespace detail {
    00035     template <typename T> struct get_view_t       { typedef typename T::view_t type; };
    00036     template <typename Images> struct images_get_views_t : public mpl::transform<Images, get_view_t<mpl::_1> > {};
    00037
    00038     template <typename T> struct get_const_view_t { typedef typename T::const_view_t type; };
    00039     template <typename Images> struct images_get_const_views_t : public mpl::transform<Images, get_const_view_t<mpl::_1> > {};
    00040
    00041     struct recreate_image_fnobj {
    00042         typedef void result_type;
    00043         const point2<std::ptrdiff_t>& _dimensions;
    00044         unsigned _alignment;
    00045
    00046         recreate_image_fnobj(const point2<std::ptrdiff_t>& dims, unsigned alignment) : _dimensions(dims), _alignment(alignment) {}
    00047         template <typename Image> result_type operator()(Image& img) const { img.recreate(_dimensions,_alignment); }
    00048     };
    00049
    00050     template <typename AnyView>  // Models AnyViewConcept
    00051     struct any_image_get_view {
    00052         typedef AnyView result_type;
    00053         template <typename Image> result_type operator()(      Image& img) const { return result_type(view(img)); }
    00054     };
    00055
    00056     template <typename AnyConstView>  // Models AnyConstViewConcept
    00057     struct any_image_get_const_view {
    00058         typedef AnyConstView result_type;
    00059         template <typename Image> result_type operator()(const Image& img) const { return result_type(const_view(img)); }
    00060     };
    00061 }
    00062
    00073 template <typename ImageTypes>
    00074 class any_image : public variant<ImageTypes> {
    00075     typedef variant<ImageTypes> parent_t;
    00076 public:
    00077     typedef any_image_view<typename detail::images_get_const_views_t<ImageTypes>::type> const_view_t;
    00078     typedef any_image_view<typename detail::images_get_views_t<ImageTypes>::type>       view_t;
    00079     typedef std::ptrdiff_t x_coord_t;
    00080     typedef std::ptrdiff_t y_coord_t;
    00081     typedef point2<std::ptrdiff_t> point_t;
    00082
    00083     any_image()                                                          : parent_t() {}
    00084     template <typename T> explicit any_image(const T& obj)               : parent_t(obj) {}
    00085     template <typename T> explicit any_image(T& obj, bool do_swap)       : parent_t(obj,do_swap) {}
    00086     any_image(const any_image& v)                                        : parent_t((const parent_t&)v)    {}
    00087
    00088     template <typename T> any_image& operator=(const T& obj)             { parent_t::operator=(obj); return *this; }
    00089     any_image&                       operator=(const any_image& v)       { parent_t::operator=((const parent_t&)v); return *this;}
    00090
    00091     void recreate(const point_t& dims, unsigned alignment=1)               { apply_operation(*this,detail::recreate_image_fnobj(dims,alignment)); }
    00092     void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1) { recreate(point2<std::ptrdiff_t>(width,height),alignment); }
    00093
    00094     std::size_t num_channels()  const { return apply_operation(*this, detail::any_type_get_num_channels()); }
    00095     point_t     dimensions()    const { return apply_operation(*this, detail::any_type_get_dimensions()); }
    00096     x_coord_t   width()         const { return dimensions().x; }
    00097     y_coord_t   height()        const { return dimensions().y; }
    00098 };
    00099
    00103
    00105
    00107 template <typename Types>  GIL_FORCEINLINE // Models ImageVectorConcept
    00108 typename any_image<Types>::view_t view(any_image<Types>& anyImage) {
    00109     return apply_operation(anyImage, detail::any_image_get_view<typename any_image<Types>::view_t>());
    00110 }
    00111
    00113 template <typename Types> GIL_FORCEINLINE // Models ImageVectorConcept
    00114 typename any_image<Types>::const_view_t const_view(const any_image<Types>& anyImage) {
    00115     return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<Types>::const_view_t>());
    00116 }
    00118
    00119 } }  // namespace boost::gil
    00120
    00121 //#ifdef _MSC_VER
    00122 //#pragma warning(pop)
    00123 //#endif
    00124
    00125 #endif