27 #ifndef MLN_CORE_INTERNAL_PIXEL_IMPL_HH
28 # define MLN_CORE_INTERNAL_PIXEL_IMPL_HH
37 # include <mln/core/concept/image.hh>
38 # include <mln/core/internal/force_exact.hh>
39 # include <mln/util/pix.hh>
54 template <
bool is_fastest,
typename I,
typename E>
55 struct pixel_impl_base_;
58 template <
typename I,
typename E>
59 struct pixel_impl_base_< false, I, E >
61 typedef mlc_if(mlc_is_const(I),
const mln_value(I), mln_value(I)) value_ptr_t;
63 pixel_impl_base_(I& image, value_ptr_t* value_ptr)
75 value_ptr_t* value_ptr_;
79 template <
typename I,
typename E>
80 struct pixel_impl_base_< true, I, E >
82 typedef mlc_if(mlc_is_const(I),
const mln_value(I), mln_value(I)) value_ptr_t;
83 typedef mlc_unconst(I) unconst_image_t;
85 pixel_impl_base_(I& image, value_ptr_t* value_ptr)
91 unsigned offset()
const
93 return value_ptr_ - image_.buffer();
96 operator util::pix<unconst_image_t>()
const
98 util::pix<unconst_image_t> tmp(image_, image_.point_at_index(offset()));
108 value_ptr_t* value_ptr_;
115 template <
typename I,
typename E>
118 :
public pixel_impl_base_< mlc_is(mln_trait_image_speed(I),
119 trait::image::speed::fastest)::value,
122 typedef pixel_impl_base_< mlc_is(mln_trait_image_speed(I),
123 trait::image::speed::fastest)::
value,
132 typedef mln_value(I) value;
135 typedef mln_lvalue(I) lvalue;
138 typedef mln_rvalue(I) rvalue;
153 value** address_() const;
158 using super_::image_;
161 using super_::value_ptr_;
164 pixel_impl_(I& image);
167 bool is_valid_() const;
174 template <typename I, typename E>
175 class pixel_impl_< const I, E >
177 : public pixel_impl_base_< mlc_is(mln_trait_image_speed(I),
178 trait::image::speed::fastest)::value,
181 typedef pixel_impl_base_< mlc_is(mln_trait_image_speed(I),
182 trait::image::speed::fastest)::value,
188 typedef const I image;
191 typedef mln_value(I) value;
194 typedef mln_rvalue(I) rvalue;
202 const I& ima() const;
206 const value** address_() const;
212 using super_::image_;
215 using super_::value_ptr_;
218 pixel_impl_(const I& image);
221 bool is_valid_() const;
225 #ifndef MLN_INCLUDE_ONLY
229 template <
typename I,
typename E>
232 pixel_impl_<I, E>::is_valid_()
const
234 return this->value_ptr_ != 0 && internal::force_exact<E>(*this).is_valid();
237 template <
typename I,
typename E>
239 pixel_impl_<I, E>::pixel_impl_(I& image) :
244 template <
typename I,
typename E>
247 pixel_impl_<I, E>::val()
249 mln_precondition(is_valid_());
250 return *this->value_ptr_;
253 template <
typename I,
typename E>
256 pixel_impl_<I, E>::val()
const
258 mln_precondition(is_valid_());
259 return *this->value_ptr_;
262 template <
typename I,
typename E>
265 pixel_impl_<I, E>::ima()
const
268 return const_cast<I&
>(this->image_);
271 template <
typename I,
typename E>
274 pixel_impl_<I, E>::address_()
const
276 return (value**)(& this->value_ptr_);
282 template <
typename I,
typename E>
285 pixel_impl_<const I, E>::is_valid_()
const
287 return this->value_ptr_ != 0 && internal::force_exact<E>(*this).is_valid();
290 template <
typename I,
typename E>
292 pixel_impl_<const I, E>::pixel_impl_(
const I& image) :
297 template <
typename I,
typename E>
300 pixel_impl_<const I, E>::val()
const
302 mln_precondition(is_valid_());
303 return *this->value_ptr_;
306 template <
typename I,
typename E>
309 pixel_impl_<const I, E>::ima()
const
314 template <
typename I,
typename E>
316 const mln_value(I) **
317 pixel_impl_<const I, E>::address_()
const
319 return (
const value**)(& this->value_ptr_);
322 #endif // ! MLN_INCLUDE_ONLY
329 #endif // ! MLN_CORE_INTERNAL_PIXEL_IMPL_HH