Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_UPSCALING_ART_SCALE2X_HH 00027 # define MLN_UPSCALING_ART_SCALE2X_HH 00028 00032 00033 00034 # include <mln/core/concept/box.hh> 00035 # include <mln/core/concept/image.hh> 00036 # include <mln/core/alias/neighb2d.hh> 00037 # include <mln/core/alias/dpoint2d.hh> 00038 00039 # include <mln/extension/adjust_duplicate.hh> 00040 00041 00042 namespace mln 00043 { 00044 00045 namespace upscaling 00046 { 00047 00048 namespace art 00049 { 00050 00062 template <typename I> 00063 mln_concrete(I) 00064 scale2x(const Image<I>& input); 00065 00066 00067 # ifndef MLN_INCLUDE_ONLY 00068 00069 00070 template <typename I> 00071 mln_concrete(I) 00072 scale2x(const Image<I>& input_) 00073 { 00074 trace::entering("mln::upscaling::art::scale2x"); 00075 00076 const I& input = exact(input_); 00077 mln_precondition(input.is_valid()); 00078 mlc_is_a(mln_domain(I), Box)::check(); 00079 00080 extension::adjust_duplicate(input, 1); 00081 00082 mln_domain(I) ext_domain(input.domain().pmin() * 2, 00083 input.domain().pmax() * 2 00084 + mln::down_right); 00085 00086 mln_concrete(I) output(ext_domain); 00087 00088 mln_piter(I) p(input.domain()); 00089 for_all(p) 00090 { 00091 00092 // A --\ 1 2 00093 // C P B --/ 3 4 00094 // D 00095 mln_site(I) 00096 pA = p + mln::up, 00097 pB = p + mln::right, 00098 pC = p + mln::left, 00099 pD = p + mln::down, 00100 pOut = p * 2; 00101 00102 // IF C==A AND C!=D AND A!=B => 1=A 00103 if (input(pC) == input(pA) 00104 && input(pC) != input(pD) 00105 && input(pA) != input(pB)) 00106 output(pOut) = input(pA); 00107 else 00108 output(pOut) = input(p); 00109 00110 // IF A==B AND A!=C AND B!=D => 2=B 00111 if (input(pA) == input(pB) 00112 && input(pA) != input(pC) 00113 && input(pB) != input(pD)) 00114 output(pOut + mln::right) = input(pB); 00115 else 00116 output(pOut + mln::right) = input(p); 00117 00118 // IF D==C AND D!=B AND C!=A => 3=C 00119 if (input(pD) == input(pC) 00120 && input(pD) != input(pB) 00121 && input(pC) != input(pA)) 00122 output(pOut + mln::down) = input(pC); 00123 else 00124 output(pOut + mln::down) = input(p); 00125 00126 // IF B==D AND B!=A AND D!=C => 4=D 00127 if (input(pB) == input(pD) 00128 && input(pB) != input(pA) 00129 && input(pD) != input(pC)) 00130 output(pOut + mln::down_right) = input(pD); 00131 else 00132 output(pOut + mln::down_right) = input(p); 00133 00134 } 00135 00136 trace::exiting("mln::upscaling::art::scale2x"); 00137 return output; 00138 } 00139 00140 00141 # endif // ! MLN_INCLUDE_ONLY 00142 00143 00144 } // end of namespace mln::upscaling::art 00145 00146 } // end of namespace mln::upscaling 00147 00148 } // end of namespace mln 00149 00150 00151 #endif // ! MLN_UPSCALING_ART_SCALE2X_HH