Adobe Systems, Inc.

any_image.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2006 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
00010 #define GIL_DYNAMICIMAGE_ANY_IMAGE_HPP
00011 
00020 
00021 #include "any_image_view.hpp"
00022 #include "../../core/image.hpp"
00023 
00024 ADOBE_GIL_NAMESPACE_BEGIN
00025 
00026 namespace detail {
00027 template <typename ITYPES> struct get_views_from_images;
00028 template <typename ITYPES> struct get_const_views_from_images;
00029 }
00030 
00031 
00038 template <typename IMAGE_TYPES>
00039 class any_image : public variant<IMAGE_TYPES> {
00040     typedef variant<IMAGE_TYPES> parent_t;
00041 //  struct get_const_view_t { template <typename T> struct apply { typedef typename T::const_view_t type; }; };
00042 //  struct get_view_t       { template <typename T> struct apply { typedef typename T::view_t type; }; };
00043 public:
00044 //  typedef any_image_view<typename boost::mpl::transform<IMAGE_TYPES, get_const_view_t>::type> const_view_t;
00045 //  typedef any_image_view<typename boost::mpl::transform<IMAGE_TYPES, get_view_t      >::type> view_t;
00046     typedef any_image_view<typename detail::get_const_views_from_images<IMAGE_TYPES>::type> const_view_t;
00047     typedef any_image_view<typename detail::get_views_from_images<IMAGE_TYPES>::type>       view_t;
00048 
00049     any_image()                                                          : parent_t() {}
00050     template <typename T> explicit any_image(const T& obj)               : parent_t(obj) {}
00051     template <typename T> explicit any_image(T& obj, bool do_swap)       : parent_t(obj,do_swap) {}
00052     any_image(const any_image& v)                                        : parent_t((const parent_t&)v) {}
00053 
00054     template <typename T> any_image& operator=(const T& obj)             { parent_t::operator=(obj); return *this; }
00055     any_image&                       operator=(const any_image& v)       { parent_t::operator=((const parent_t&)v); return *this;}
00056 };
00057 
00058 namespace detail {
00059     template <typename AnyView>  // Models AnyViewConcept
00060     struct any_image_get_view {
00061         typedef AnyView result_type;
00062         template <typename V> result_type operator()(      image<V>& img) const { return result_type(view(img)); }
00063     };
00064     template <typename AnyConstView>  // Models AnyConstViewConcept
00065     struct any_image_get_const_view {
00066         typedef AnyConstView result_type;
00067         template <typename V> result_type operator()(const image<V>& img) const { return result_type(const_view(img)); }
00068     };
00069 }
00070 
00074 
00076 
00078 template <typename TYPES>  GIL_FORCEINLINE // Models ImageVectorConcept
00079 typename any_image<TYPES>::view_t view(any_image<TYPES>& anyImage) { 
00080     return apply_operation(anyImage, detail::any_image_get_view<typename any_image<TYPES>::view_t>());
00081 }
00082 
00084 template <typename TYPES> GIL_FORCEINLINE // Models ImageVectorConcept
00085 typename any_image<TYPES>::const_view_t const_view(const any_image<TYPES>& anyImage) { 
00086     return apply_operation(anyImage, detail::any_image_get_const_view<typename any_image<TYPES>::const_view_t>());
00087 }
00089 
00093 
00095 
00097 template <typename TYPES> GIL_FORCEINLINE 
00098 int get_num_channels(const any_image<TYPES>& a)      { return apply_operation(a, detail::any_type_get_num_channels()); }
00099 
00101 template <typename TYPES> GIL_FORCEINLINE 
00102 int get_width(const any_image<TYPES>& a)      { return apply_operation(a, detail::any_type_get_dimensions()).x; }
00103 
00105 template <typename TYPES> GIL_FORCEINLINE 
00106 int get_height(const any_image<TYPES>& a)      { return apply_operation(a, detail::any_type_get_dimensions()).y; }
00107 
00109 template <typename TYPES> GIL_FORCEINLINE 
00110 point2<int> get_dimensions(const any_image<TYPES>& v)      { return apply_operation(v, detail::any_type_get_dimensions()); }
00111 
00112 namespace detail {
00113     struct resize_clobber_image_fnobj {
00114         typedef void result_type;
00115         const point2<int>& _size;
00116 
00117         resize_clobber_image_fnobj(const point2<int>& sz) : _size(sz) {}
00118         template <typename IMAGE> result_type operator()(IMAGE& img) const { resize_clobber_image(img, _size); }
00119     };
00120 }
00121 
00123 template <typename TYPES> GIL_FORCEINLINE
00124 void resize_clobber_image(any_image<TYPES>& img, int w, int h) {
00125     resize_clobber_image(img,point2<int>(w,h));
00126 }
00127 
00129 template <typename TYPES> GIL_FORCEINLINE
00130 void resize_clobber_image(any_image<TYPES>& img, const point2<int>& sz) {
00131     apply_operation(img,detail::resize_clobber_image_fnobj(sz));
00132 }
00133 
00135 
00136 
00137 ADOBE_GIL_NAMESPACE_END
00138 
00139 #endif

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google