00001 // Copyright (C) 2007, 2008, 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 #include <mln/value/gl8.hh> 00027 #include <mln/value/gl16.hh> 00028 #include <mln/value/int_u8.hh> 00029 00030 #include <mln/literal/black.hh> 00031 #include <mln/literal/white.hh> 00032 00033 00034 00035 int main() 00036 { 00037 using namespace mln::value; 00038 00039 using mln::literal::white; 00040 using mln::literal::black; 00041 00042 gl8 a = 255; 00043 gl8 b = 255; 00044 00045 // Constructions 00046 { 00047 // With int 00048 gl8 x; 00049 gl8 a = 12; 00050 gl8 b(12); 00051 mln_assertion(a == b); 00052 00053 { 00054 gl16 c = 2335; 00055 gl8 d = c; 00056 mln_assertion(c == d); 00057 } 00058 00059 gl8 d = 250; 00060 gl16 c = d; 00061 mln_assertion(c == d); 00062 00063 gl8 e = white; 00064 00065 mln_assertion(e == gl8(white)); 00066 00067 gl8 f = 12; 00068 gl8 g = f; 00069 gl8 h(f); 00070 00071 mln_assertion(f == g); 00072 mln_assertion(h == g); 00073 00074 // FIXME: Make the following tests compile. 00075 { 00076 // With gray_f. 00077 //gl8 a = mln::value::internal::gray_f(12.5); 00078 00079 } 00080 } 00081 00082 // Literals 00083 // { 00084 // gl8 a(white); 00085 // gl16 b(white); 00086 00087 // a = white; 00088 // b = white; 00089 00090 // mln_assertion(a == b); 00091 // mln_assertion(a.value() == float(255)); 00092 // mln_assertion(b.value() == float(65535)); 00093 // mln_assertion(a == white); 00094 // mln_assertion(b == white); 00095 00096 // gl8 c(white); 00097 // mln_assertion(c == white); 00098 // mln_assertion(c.value() == float(255)); 00099 00100 // a = black; 00101 // b = black; 00102 00103 // mln_assertion(a == b); 00104 // mln_assertion(a.value() == float(0)); 00105 // mln_assertion(b.value() == float(0)); 00106 // } 00107 00108 // // Assigment 00109 // { 00110 // gl8 a; 00111 // gl16 b; 00112 00113 // a = white; 00114 // mln_assertion(a == white); 00115 // mln_assertion(a.value() == float(255)); 00116 00117 // a = 23; 00118 // mln_assertion(a != white); 00119 // mln_assertion(a != black); 00120 // mln_assertion(a.value() == float(23)); 00121 00122 // b = 2; 00123 // mln_assertion(b != white); 00124 // mln_assertion(b != black); 00125 // mln_assertion(b.value() == float(2)); 00126 00127 // a = b; 00128 // mln_assertion(a.value() == float(2 / 256)); 00129 00130 // signed char c = 51; 00131 // a = c; 00132 // mln_assertion(a.value() == float(51)); 00133 00134 // // bounds 00135 // a = 255; 00136 // mln_assertion(a.value() == float(255)); 00137 // a = 0; 00138 // mln_assertion(a.value() == float(0)); 00139 // } 00140 00141 // Addition 00142 { 00143 // gl8 a; 00144 // gl16 b; 00145 00146 // // gl8 <- gl8 + gl8 00147 // a = 42; 00148 // a += a; 00149 // mln_assertion(a.value() == float(84)); 00150 00151 // a = 42; 00152 // a = a + a; 00153 // mln_assertion(a.value() == float(84)); 00154 00155 // // gl8 <- gl8 + gl16 00156 // a = 42; 00157 // b = 16969; 00158 // a = a + b; 00159 // mln_assertion(a.value() == float((42 + b.value() / 257) )); 00160 // a = 42; 00161 // b = 16969; 00162 // a += b; 00163 // mln_assertion(a.value() == float((42 + b.value() / 256) )); 00164 00165 00166 // // gl16 <- gl8 + gl16 00167 // a = 42; 00168 // b = 16969; 00169 // b += a; 00170 // mln_assertion(b.value() == float((42 * 256 + 16969) )); 00171 00172 // a = 42; 00173 // b = 16969; 00174 // b = b + a; 00175 00176 // mln_assertion(b.value() == float((42 * 256 + 16969) )); 00177 00178 // a = 42; 00179 // b = 16969; 00180 // b = a + b; 00181 // mln_assertion(b.value() == float((42 * 256 + 16969) )); 00182 00183 // // misc 00184 // a = 255; 00185 // b = 0; 00186 // a = a + b; 00187 // mln_assertion(a.value() == float(255)); 00188 00189 // a = 0; 00190 // b = 65535; 00191 // a = a + b; 00192 // mln_assertion(a.value() == float(255)); 00193 } 00194 00195 00196 // // Soustraction 00197 // { 00198 // gl8 a; 00199 // gl16 b; 00200 00201 // // gl8 <- gl8 - gl8 00202 // a = 42; 00203 // a -= a; 00204 // mln_assertion(a == black); 00205 00206 // a = 42; 00207 // a = a - a; 00208 // mln_assertion(a == black); 00209 00210 // // gl8 <- gl8 - gl16 00211 // a = 42; 00212 // b = 5969; 00213 00214 // a = b; 00215 00216 // { 00217 // a = 42; 00218 // gl16 t; 00219 00220 // t = a - b; 00221 // t = t + b; 00222 // mln_assertion(a == t); 00223 // } 00224 00225 // a = 42; 00226 // a = a - b; 00227 // mln_assertion(a.value() == (42 * 256 - b.value()) / 256 ); 00228 // a = 42; 00229 // b = 9969; 00230 // a -= b; 00231 // mln_assertion(a.value() == (42 * 256 - b.value()) / 256 ); 00232 00233 00234 // // gl16 <- gl8 - gl16 00235 // a = 100; 00236 // b = 30969; 00237 // b -= a; 00238 // mln_assertion(b.value() == float(30969 - 100 * 256)); 00239 00240 // a = 100; 00241 // b = 20969; 00242 // b = a - b; 00243 // mln_assertion(b.value() == float((100 * 256 - 20969) )); 00244 00245 // // misc 00246 // a = 255; 00247 // b = 0; 00248 // a = a - b; 00249 // mln_assertion(a.value() == float(255)); 00250 00251 // gl8(255) - gl16(65535); 00252 // mln_assertion( gl8(255) == gl16(65535) ); 00253 // a = 255; 00254 // b = 65535; 00255 // a = a - b; 00256 // mln_assertion(a.value() == float(0)); 00257 00258 // // ... 00259 // { 00260 // graylevel<2> a = 1; 00261 // graylevel<3> b = 5; 00262 // graylevel<2> c; 00263 // graylevel<3> d; 00264 00265 // c = b - a; 00266 // d = b - a; 00267 // mln_assertion(c == d); 00268 // } 00269 00270 // } 00271 00272 // // Multiplication 00273 // { 00274 // gl8 a; 00275 // gl16 b; 00276 00277 // // gl8 <- gl8 * gl8 00278 // a = 8; 00279 // a *= a; 00280 // mln_assertion(a.value() == 64); 00281 00282 // a = 7; 00283 // a = a * a; 00284 // mln_assertion(a.value() == 49); 00285 00286 // // gl8 <- gl8 * gl16 00287 // a = 10; 00288 // b = 20; 00289 // a = a * b; 00290 // mln_assertion(a.value() == float((10 * 256* b.value())/256)); 00291 00292 // a = 10; 00293 // b = 16; 00294 // a *= b; 00295 // mln_assertion(a.value() == float((10 * 256* b.value())/256)); 00296 00297 // mln_assertion((gl8(12) * gl16(12345)).to_enc() == float((12 * 256* 12345))); 00298 00299 00300 // // gl16 <- gl8 * gl16 00301 // a = 10; 00302 // b = 24; 00303 // b *= a; 00304 // mln_assertion(b.value() == float((10 * 256 * 24) )); 00305 00306 // a = 10; 00307 // b = 24; 00308 // b = a * b; 00309 // mln_assertion(b.value() == float((10 * 256 * 24) )); 00310 00311 // // misc 00312 // a = 255; 00313 // b = 0; 00314 // a = a * b; 00315 // mln_assertion(a == black); 00316 00317 // a = 0; 00318 // b = 65535; 00319 // a = a * b; 00320 // mln_assertion(a == black); 00321 00322 00323 // // With Floating. 00324 // // a = 8; 00325 // // a = a * 0.5; 00326 // // mln_assertion(a.value() == 4.f); 00327 00328 // // a = 8; 00329 // // a *= 0.5; 00330 // // mln_assertion(a.value() == 4.f); 00331 00332 // // ... 00333 // { 00334 // graylevel<2> a = 1; 00335 // graylevel<3> b = 2; 00336 // graylevel<2> c; 00337 // graylevel<3> d; 00338 00339 // c = a * b; 00340 // d = a * b; 00341 // mln_assertion(c == d); 00342 // } 00343 00344 // { 00345 00346 // // ... 00347 // gl8 a = 7; 00348 // gl16 b = 596; 00349 00350 // gl8 p; 00351 // p = b; 00352 00353 // gl8 q; 00354 // gl8 r; 00355 00356 // q = a * p; 00357 // r = a * b / 256; 00358 // } 00359 00360 // } 00361 // // division 00362 // { 00363 // // gl8 a = 2; 00364 // // a = a / 2; 00365 // // mln_assertion(a.value() == 1); 00366 00367 // // a = 6; 00368 // // a = a / 1.5; 00369 // // mln_assertion(a.value() == 4.f); 00370 00371 // } 00372 00373 // { 00374 // gl8 a = 1; 00375 // int_u8 b = 1; 00376 // float01_f c = 0.5; 00377 00378 // // Theses lines are forbidden. Since we can't add or substract 00379 // // graylevel with int or float. 00380 // // a + b; 00381 // // a - b; 00382 // // a + c; 00383 // // a - c; 00384 // } 00385 00386 }