Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 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/rgb.hh> 00027 #include <mln/value/rgb8.hh> 00028 #include <mln/value/int_u8.hh> 00029 #include <mln/literal/all.hh> 00030 00031 00032 #define sym_compare_assert(V1, OP, V2) \ 00033 \ 00034 mln_assertion(V1 OP V2); 00035 00036 #define compute_rgb(T, V1, OP, V2) \ 00037 \ 00038 T( \ 00039 V1.red() OP V2.red() , \ 00040 V1.green() OP V2.green() , \ 00041 V1.blue() OP V2.blue() \ 00042 ) 00043 00044 #define compute_rgb_sc(T, V1, OP, V2) \ 00045 \ 00046 T( \ 00047 V1.red() OP V2 , \ 00048 V1.green() OP V2 , \ 00049 V1.blue() OP V2 \ 00050 ) 00051 00052 // Interop between 2 rgbs. 00053 #define test_interop(T1, T2, OP, V1, V2) \ 00054 { \ 00055 T1 i = V1; \ 00056 T2 j = V2; \ 00057 \ 00058 i = i OP j; \ 00059 sym_compare_assert(i, ==, compute_rgb(T1, V1, OP, V2)); \ 00060 sym_compare_assert(j, ==, V2); \ 00061 \ 00062 i = V1; \ 00063 j = V2; \ 00064 \ 00065 j = i OP j; \ 00066 sym_compare_assert(j, ==, compute_rgb(T1,V1, OP, V2)); \ 00067 sym_compare_assert(i, ==, V1); \ 00068 \ 00069 i = V1; \ 00070 i OP##= i; \ 00071 sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V1)); \ 00072 \ 00073 i = V1; \ 00074 j = V2; \ 00075 i OP##= j; \ 00076 sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V2)); \ 00077 \ 00078 j OP##= j; \ 00079 sym_compare_assert(j, ==, compute_rgb(T1,V2, OP, V2)); \ 00080 \ 00081 i = V1; \ 00082 j = V2; \ 00083 j OP##= i; \ 00084 sym_compare_assert(j, ==, compute_rgb(T1,V2, OP, V1)); \ 00085 \ 00086 i = V1; \ 00087 i OP##= i; \ 00088 sym_compare_assert(i, ==, compute_rgb(T1,V1, OP, V1)); \ 00089 } 00090 00091 00092 // T1 is rgb, T2 is scalar 00093 #define test_interop_sc(T1, T2, OP, V1, V2) \ 00094 { \ 00095 T1 i = V1; \ 00096 T2 j = V2; \ 00097 \ 00098 i = i OP j; \ 00099 sym_compare_assert(i, ==, compute_rgb_sc(T1,V1, OP, V2)); \ 00100 sym_compare_assert(j, ==, V2); \ 00101 \ 00102 i = V1; \ 00103 j = V2; \ 00104 i OP##= j; \ 00105 sym_compare_assert(i, ==, compute_rgb_sc(T1, V1, OP, V2)); \ 00106 } 00107 00108 int main() 00109 { 00110 using namespace mln; 00111 using value::rgb; 00112 using value::rgb8; 00113 using value::int_u8; 00114 using value::int_u; 00115 00116 using literal::blue; 00117 using literal::white; 00118 00119 { 00120 test_interop(rgb8, rgb8, +, rgb8(4,5,6), rgb8(1,2,3)); 00121 test_interop(rgb8, rgb8, -, rgb8(4,5,6), rgb8(1,2,3)); 00122 00123 test_interop(rgb<10>, rgb<10>, +, rgb<10>(4,5,6), rgb<10>(1,2,3)); 00124 test_interop(rgb<10>, rgb<10>, -, rgb<10>(4,5,6), rgb<10>(1,2,3)); 00125 00126 test_interop(rgb<16>, rgb<16>, +, rgb<16>(4,5,6), rgb<16>(1,2,3)); 00127 test_interop(rgb<16>, rgb<16>, -, rgb<16>(4,5,6), rgb<16>(1,2,3)); 00128 00129 test_interop_sc(rgb8, int, *, rgb8(4,5,6), 4); 00130 test_interop_sc(rgb8, int, /, rgb8(40,50,60), 10); 00131 00132 test_interop_sc(rgb8, unsigned, *, rgb8(4,5,6), 4); 00133 test_interop_sc(rgb8, unsigned, /, rgb8(40,50,60), 10); 00134 00135 // FIXME : operators *,/ are ambiguous for (rgb8, float)... 00136 // test_interop_sc(rgb8, float, *, rgb8(4,5,6), 4); 00137 // test_interop_sc(rgb8, float, /, rgb8(40,50,60), 10); 00138 00139 test_interop_sc(rgb8, char, *, rgb8(4,5,6), 4); 00140 test_interop_sc(rgb8, char, /, rgb8(40,50,60), 10); 00141 00142 test_interop_sc(rgb8, int_u8, *, rgb8(4,5,6), 4); 00143 test_interop_sc(rgb8, int_u8, /, rgb8(40,50,60), 10); 00144 00145 test_interop_sc(rgb8, int_u<7>, *, rgb8(4,5,6), 4); 00146 test_interop_sc(rgb8, int_u<7>, /, rgb8(40,50,60), 10); 00147 } 00148 }