27 #ifndef MLN_VALUE_GRAYLEVEL_HH
28 # define MLN_VALUE_GRAYLEVEL_HH
36 # include <mln/value/ops.hh>
38 # include <mln/core/contract.hh>
39 # include <mln/metal/math/pow.hh>
40 # include <mln/metal/math/max.hh>
41 # include <mln/metal/bexpr.hh>
42 # include <mln/literal/ops.hh>
44 # include <mln/value/graylevel_f.hh>
45 # include <mln/value/int_u.hh>
46 # include <mln/trait/value_.hh>
66 template <
unsigned n>
class gray_;
68 template <
unsigned n_src,
unsigned n_dest>
71 template <
unsigned n>
struct graylevel;
81 template <
unsigned n,
unsigned m >
87 template <
unsigned n,
unsigned m >
93 template <
unsigned n,
unsigned m >
99 template <
unsigned n,
unsigned m >
105 template <
unsigned n,
typename I >
106 struct set_binary_< op::
times,
113 template <
typename I,
unsigned n >
114 struct set_binary_< op::
times,
122 template <
unsigned n,
typename F >
123 struct set_binary_< op::
times,
130 template <
typename F,
unsigned n >
131 struct set_binary_< op::
times,
139 template <
unsigned n,
typename S >
142 typedef mln_value_equiv(S) E;
143 typedef mln::metal::
or_< mlc_equal(E,
float), mlc_equal(E,
double) > is_float;
144 typedef mlc_if(is_float, mln::
value::internal::gray_f, mln::
value::internal::gray_<n>)
ret;
147 template <
unsigned n, typename S >
148 struct set_precise_binary_< op::div, mln::
value::graylevel<n>, mln::
value::scalar_<S> >
155 template <
unsigned n>
156 struct value_< mln::value::graylevel<n> >
165 card = mln_value_card_from_(n)
168 typedef trait::value::nature::integer nature;
169 typedef trait::value::kind::gray
kind;
170 typedef mln_value_quant_from_(card) quant;
172 static const self_
min() {
return 0; }
173 static const self_
max() {
return card - 1; }
174 static const self_ epsilon() {
return 0; }
257 template <
unsigned n>
260 public Integer< graylevel<n> >,
281 template <
unsigned m>
284 template <
unsigned m>
304 unsigned value()
const;
307 float to_float()
const;
315 template <
typename T>
struct convert_;
318 template <
unsigned n>
329 template <
unsigned n>
330 std::ostream& operator<<(std::ostream& ostr, const graylevel<n>& g);
333 template <
unsigned n,
unsigned m>
338 template <
unsigned n, typename I>
340 operator+(const
graylevel<n>& lhs, const I& i);
343 template <
unsigned n, typename I>
345 operator+(const I& i, const
graylevel<n>& rhs);
348 template <
unsigned n,
unsigned m>
353 template <
unsigned n, typename I>
355 operator-(const
graylevel<n>& lhs, const I& i);
358 template <
unsigned n, typename I>
360 operator-(const I& i, const
graylevel<n>& rhs);
363 template <
unsigned n,
unsigned m>
370 template <
unsigned n, typename
T>
372 operator*(const
graylevel<n>& lhs, const
T& rhs);
375 template <
unsigned n, typename
T>
377 operator*(const
T& lhs, const
graylevel<n>& rhs);
380 template <
unsigned n, typename
T>
383 operator/(const
graylevel<n>& lhs, const
T& rhs);
388 template <
unsigned n, typename I>
393 template <typename I,
unsigned n>
398 template <
unsigned n, typename I>
403 template <typename I,
unsigned n>
410 template <
unsigned n, typename F>
415 template <typename F,
unsigned n>
421 template <
unsigned n, typename F>
426 template <typename F,
unsigned n>
430 # ifndef MLN_INCLUDE_ONLY
435 template <
unsigned n>
442 template <
unsigned n>
446 mln_precondition(val >= 0);
447 mln_precondition(
unsigned(val) <= mln_max(mln_enc(
int_u<n>)));
451 template <
unsigned n>
454 graylevel<n>::operator=(
int val)
456 mln_precondition(val >= 0);
457 mln_precondition(
unsigned(val) <= mln_max(mln_enc(
int_u<n>)));
462 template <
unsigned n>
464 graylevel<n>::graylevel(
const graylevel<n>& rhs) :
465 Integer< graylevel<n> >()
470 template <
unsigned n>
473 graylevel<n>::operator=(
const graylevel<n>& rhs)
479 template <
unsigned n>
480 template <
unsigned m>
482 graylevel<n>::graylevel(
const graylevel<m>& rhs)
484 this->v_ = internal::convert<m, n>(rhs.value());
487 template <
unsigned n>
488 template <
unsigned m>
491 graylevel<n>::operator=(
const graylevel<m>& rhs)
493 this->v_ = internal::convert<m, n>(rhs.value());
498 template <
unsigned n>
505 template <
unsigned n>
514 template <
unsigned n>
518 this->v_ = metal::math::pow_int<2, n - 1>
::value;
521 template <
unsigned n>
526 this->v_ = metal::math::pow_int<2, n - 1>
::value;
531 template <
unsigned n>
535 this->v_ = mln_max(mln_enc(
int_u<n>));
538 template <
unsigned n>
543 this->v_ = mln_max(mln_enc(
int_u<n>));
547 template <
unsigned n>
555 template <
unsigned n>
558 graylevel<n>::to_float()
const
561 return float(this->v_) / denom;
569 template <
unsigned n>
572 convert_< graylevel<n> >::value_at_index(
unsigned i)
574 mln_assertion(i <= mln_max(mln_equiv(graylevel<n>)));
575 return graylevel<n>(i);
578 template <
unsigned n>
581 convert_< graylevel<n> >::index_of_value(graylevel<n> v)
590 template <
unsigned n>
592 std::ostream& operator<<(std::ostream& ostr, const graylevel<n>& g)
594 return ostr << g.value() <<
"/gl" << n;
599 # endif // ! MLN_INCLUDE_ONLY
606 #include <mln/value/internal/gray_f.hh>
607 #include <mln/value/internal/gray_.hh>
609 #endif // ! MLN_VALUE_GRAYLEVEL_HH