Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
scale2x.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_UPSCALING_ART_SCALE2X_HH
27 # define MLN_UPSCALING_ART_SCALE2X_HH
28 
32 
33 
34 # include <mln/core/concept/box.hh>
35 # include <mln/core/concept/image.hh>
36 # include <mln/core/alias/neighb2d.hh>
37 # include <mln/core/alias/dpoint2d.hh>
38 
39 # include <mln/extension/adjust_duplicate.hh>
40 
41 
42 namespace mln
43 {
44 
45  namespace upscaling
46  {
47 
48  namespace art
49  {
50 
62  template <typename I>
63  mln_concrete(I)
64  scale2x(const Image<I>& input);
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69 
70  template <typename I>
71  mln_concrete(I)
72  scale2x(const Image<I>& input_)
73  {
74  trace::entering("mln::upscaling::art::scale2x");
75 
76  const I& input = exact(input_);
77  mln_precondition(input.is_valid());
78  mlc_is_a(mln_domain(I), Box)::check();
79 
81 
82  mln_domain(I) ext_domain(input.domain().pmin() * 2,
83  input.domain().pmax() * 2
84  + mln::down_right);
85 
86  mln_concrete(I) output(ext_domain);
87 
88  mln_piter(I) p(input.domain());
89  for_all(p)
90  {
91 
92  // A --\ 1 2
93  // C P B --/ 3 4
94  // D
95  mln_site(I)
96  pA = p + mln::up,
97  pB = p + mln::right,
98  pC = p + mln::left,
99  pD = p + mln::down,
100  pOut = p * 2;
101 
102  // IF C==A AND C!=D AND A!=B => 1=A
103  if (input(pC) == input(pA)
104  && input(pC) != input(pD)
105  && input(pA) != input(pB))
106  output(pOut) = input(pA);
107  else
108  output(pOut) = input(p);
109 
110  // IF A==B AND A!=C AND B!=D => 2=B
111  if (input(pA) == input(pB)
112  && input(pA) != input(pC)
113  && input(pB) != input(pD))
114  output(pOut + mln::right) = input(pB);
115  else
116  output(pOut + mln::right) = input(p);
117 
118  // IF D==C AND D!=B AND C!=A => 3=C
119  if (input(pD) == input(pC)
120  && input(pD) != input(pB)
121  && input(pC) != input(pA))
122  output(pOut + mln::down) = input(pC);
123  else
124  output(pOut + mln::down) = input(p);
125 
126  // IF B==D AND B!=A AND D!=C => 4=D
127  if (input(pB) == input(pD)
128  && input(pB) != input(pA)
129  && input(pD) != input(pC))
130  output(pOut + mln::down_right) = input(pD);
131  else
132  output(pOut + mln::down_right) = input(p);
133 
134  }
135 
136  trace::exiting("mln::upscaling::art::scale2x");
137  return output;
138  }
139 
140 
141 # endif // ! MLN_INCLUDE_ONLY
142 
143 
144  } // end of namespace mln::upscaling::art
145 
146  } // end of namespace mln::upscaling
147 
148 } // end of namespace mln
149 
150 
151 #endif // ! MLN_UPSCALING_ART_SCALE2X_HH