00001 /*!@file TestSuite/whitebox-Pixels.C Test PixRGB and other Pixels class */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TestSuite/whitebox-Pixels.C $ 00035 // $Id: whitebox-Pixels.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #include "Image/Pixels.H" 00039 #include "TestSuite/TestSuite.H" 00040 #include "Util/fpe.H" 00041 #include "Util/log.H" 00042 00043 #include <cstdlib> 00044 #include <cstring> 00045 #include <typeinfo> 00046 00047 /////////////////////////////////////////////////////////////////////// 00048 // 00049 // Test functions 00050 // 00051 // note that these funny _xx_'s are just used as a hierarchical 00052 // separator (since e.g. double-underscore __ is reserved for 00053 // implementation-defined identifiers in C/C++); the _xx_ is expected 00054 // to be replaced by something prettier, like "--", by the test driver 00055 // script. 00056 // 00057 /////////////////////////////////////////////////////////////////////// 00058 00059 //! Shorthand for checking the values of any 3-element pixel: 00060 #define REQUIRE_PIX3_EQ(pp,x1,x2,x3) \ 00061 REQUIRE_EQ((pp)[0], (x1)); \ 00062 REQUIRE_EQ((pp)[1], (x2)); \ 00063 REQUIRE_EQ((pp)[2], (x3)); 00064 00065 //! Shorthand for checking the values of any 3-element pixel: 00066 #define REQUIRE_PIX3_EQ2(pixel1,pixel2) \ 00067 REQUIRE_EQ((pixel1)[0], (pixel2)[0]); \ 00068 REQUIRE_EQ((pixel1)[1], (pixel2)[1]); \ 00069 REQUIRE_EQ((pixel1)[2], (pixel2)[2]); 00070 00071 //! Shorthand for checking the values of any 4-element pixel: 00072 #define REQUIRE_PIX4_EQ(pp,x1,x2,x3,x4) \ 00073 REQUIRE_EQ((pp)[0], (x1)); \ 00074 REQUIRE_EQ((pp)[1], (x2)); \ 00075 REQUIRE_EQ((pp)[2], (x3)); \ 00076 REQUIRE_EQ((pp)[3], (x4)); 00077 00078 //! Shorthand for checking the values of any 4-element pixel: 00079 #define REQUIRE_PIX4_EQ2(pixel1,pixel2) \ 00080 REQUIRE_EQ((pixel1)[0], (pixel2)[0]); \ 00081 REQUIRE_EQ((pixel1)[1], (pixel2)[1]); \ 00082 REQUIRE_EQ((pixel1)[2], (pixel2)[2]); \ 00083 REQUIRE_EQ((pixel1)[3], (pixel2)[3]); 00084 00085 //--------------------------------------------------------------------- 00086 // 00087 // Constructors & Destructors 00088 // 00089 //--------------------------------------------------------------------- 00090 00091 static void Pixels_xx_constructors_xx_1(TestSuite& suite) 00092 { 00093 PixRGB<int32> p1; // zero-initialization in default constructor 00094 REQUIRE_PIX3_EQ(p1, 0, 0, 0); 00095 00096 p1.setRed(255); p1.setGreen(128); p1.setBlue(0); // setter functions 00097 REQUIRE_PIX3_EQ(p1, 255, 128, 0); 00098 00099 PixRGB<byte> p2(1, 18, 57); // initialization of 3 individual elements 00100 REQUIRE_PIX3_EQ(p2, 1, 18, 57); 00101 00102 PixRGB<int16> p3(-1256); // initialization of all elements to a single value 00103 REQUIRE_PIX3_EQ(p3, -1256, -1256, -1256); 00104 00105 PixRGB<byte> p4(p2); // copy-initialization 00106 REQUIRE_PIX3_EQ(p4, 1, 18, 57); 00107 } 00108 00109 static void Pixels_xx_conversions_xx_1(TestSuite& suite) 00110 { 00111 PixRGB<byte> p1(12, 34, 56); 00112 00113 PixRGB<int16> p2(p1); 00114 REQUIRE_PIX3_EQ(p2, 12, 34, 56); 00115 00116 PixRGB<int32> p3(p1); 00117 REQUIRE_PIX3_EQ(p3, 12, 34, 56); 00118 00119 PixRGB<float> p4(p1); 00120 REQUIRE_PIX3_EQ(p4, 12.0f, 34.0f, 56.0f); 00121 00122 PixRGB<float> p5(-23.0f, 128.2f, 257.9f); 00123 PixRGB<byte> p6(p5); 00124 REQUIRE_PIX3_EQ(p6, 0, 128, 255); // clamped conversion 00125 00126 PixRGB<byte> p7(p5); 00127 REQUIRE_PIX3_EQ(p7, 0, 128, 255); // clamped conversion 00128 00129 PixRGB<double> p8(p5); // this is to check correct use of numeric_limits: 00130 PixRGB<float> p9(p8); // float to double and back to float 00131 REQUIRE_PIX3_EQ(p9, -23.0f, 128.2f, 257.9f); 00132 00133 PixRGB<byte> p10(1.6f); // check that float->PixRGB<byte> conversion 00134 // works, AND doesn't produce a warning if 00135 // we're using "-Wall -Werror" 00136 REQUIRE_PIX3_EQ(p10, 1, 1, 1); 00137 00138 PixRGB<byte> p11(1000.0f); // check that float->PixRGB<byte> 00139 // conversion does proper clamping 00140 REQUIRE_PIX3_EQ(p11, 255, 255, 255); 00141 00142 PixRGB<byte> p12(-1000.0f); // check that float->PixRGB<byte> 00143 // conversion does proper clamping 00144 REQUIRE_PIX3_EQ(p12, 0, 0, 0); 00145 00146 } 00147 00148 static void Pixels_xx_conversions_xx_2(TestSuite& suite) 00149 { 00150 // check all pix-pix conversions among PixRGB<byte>/PixRGB<int>/PixRGB<float> 00151 00152 REQUIRE(typeid(PixRGB<byte>() + PixRGB<byte> ()) == typeid(PixRGB<int>)); 00153 REQUIRE(typeid(PixRGB<byte>() + PixRGB<int> ()) == typeid(PixRGB<int>)); 00154 REQUIRE(typeid(PixRGB<byte>() + PixRGB<float>()) == typeid(PixRGB<float>)); 00155 00156 REQUIRE(typeid(PixRGB<int>() + PixRGB<byte> ()) == typeid(PixRGB<int>)); 00157 REQUIRE(typeid(PixRGB<int>() + PixRGB<int> ()) == typeid(PixRGB<int>)); 00158 REQUIRE(typeid(PixRGB<int>() + PixRGB<float>()) == typeid(PixRGB<float>)); 00159 00160 REQUIRE(typeid(PixRGB<float>() + PixRGB<byte> ()) == typeid(PixRGB<float>)); 00161 REQUIRE(typeid(PixRGB<float>() + PixRGB<int> ()) == typeid(PixRGB<float>)); 00162 REQUIRE(typeid(PixRGB<float>() + PixRGB<float>()) == typeid(PixRGB<float>)); 00163 } 00164 00165 static void Pixels_xx_conversions_xx_3(TestSuite& suite) 00166 { 00167 // check all pix-scalar conversions among 00168 // PixRGB<byte>/PixRGB<int>/PixRGB<float> and byte/int/float 00169 00170 REQUIRE(typeid(PixRGB<byte>() + byte ()) == typeid(PixRGB<int>)); 00171 REQUIRE(typeid(PixRGB<byte>() + int ()) == typeid(PixRGB<int>)); 00172 REQUIRE(typeid(PixRGB<byte>() + float()) == typeid(PixRGB<float>)); 00173 00174 REQUIRE(typeid(PixRGB<int>() + byte ()) == typeid(PixRGB<int>)); 00175 REQUIRE(typeid(PixRGB<int>() + int ()) == typeid(PixRGB<int>)); 00176 REQUIRE(typeid(PixRGB<int>() + float()) == typeid(PixRGB<float>)); 00177 00178 REQUIRE(typeid(PixRGB<float>() + byte ()) == typeid(PixRGB<float>)); 00179 REQUIRE(typeid(PixRGB<float>() + int ()) == typeid(PixRGB<float>)); 00180 REQUIRE(typeid(PixRGB<float>() + float()) == typeid(PixRGB<float>)); 00181 } 00182 00183 static void Pixels_xx_conversions_xx_4(TestSuite& suite) 00184 { 00185 const PixRGB<byte> rgb1 ( 0, 0, 0); 00186 const PixRGB<byte> rgb2 (127, 127, 127); 00187 const PixRGB<byte> rgb3 (255, 255, 255); 00188 const PixRGB<byte> rgb4 (255, 0, 0); 00189 const PixRGB<byte> rgb5 ( 0, 255, 0); 00190 const PixRGB<byte> rgb6 ( 0, 0, 255); 00191 const PixRGB<byte> rgb7 (255, 127, 63); 00192 const PixRGB<byte> rgb8 (255, 63, 127); 00193 const PixRGB<byte> rgb9 (127, 255, 63); 00194 const PixRGB<byte> rgb10 ( 63, 255, 127); 00195 const PixRGB<byte> rgb11 (127, 63, 255); 00196 const PixRGB<byte> rgb12 ( 63, 127, 255); 00197 00198 // test conversions rgb-->jpegyuv 00199 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb1), 0, 128, 128); 00200 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb2), 127, 128, 128); 00201 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb3), 255, 128, 128); 00202 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb4), 76, 84, 255); 00203 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb5), 150, 43, 21); 00204 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb6), 29, 255, 107); 00205 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb7), 158, 74, 197); 00206 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb8), 128, 127, 218); 00207 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb9), 195, 53, 79); 00208 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb10), 183, 96, 42); 00209 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb11), 104, 213, 144); 00210 REQUIRE_PIX3_EQ(PixJpegYUV<byte>(rgb12), 122, 202, 85); 00211 00212 // test conversions rgb-->videoyuv 00213 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb1), 16, 128, 128); 00214 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb2), 125, 128, 128); 00215 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb3), 235, 128, 128); 00216 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb4), 81, 90, 240); 00217 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb5), 145, 54, 34); 00218 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb6), 41, 240, 110); 00219 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb7), 152, 81, 189); 00220 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb8), 126, 128, 208); 00221 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb9), 183, 63, 85); 00222 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb10), 173, 100, 53); 00223 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb11), 105, 203, 142); 00224 REQUIRE_PIX3_EQ(PixVideoYUV<byte>(rgb12), 121, 194, 91); 00225 00226 // test round-trip conversions rgb-->jpegyuv-->rgb 00227 { 00228 PixRGB<byte> rgb2yuv2rgb1 ((PixJpegYUV<double>(rgb1))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb1 , rgb1 ); 00229 PixRGB<byte> rgb2yuv2rgb2 ((PixJpegYUV<double>(rgb2))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb2 , rgb2 ); 00230 PixRGB<byte> rgb2yuv2rgb3 ((PixJpegYUV<double>(rgb3))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb3 , rgb3 ); 00231 PixRGB<byte> rgb2yuv2rgb4 ((PixJpegYUV<double>(rgb4))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb4 , rgb4 ); 00232 PixRGB<byte> rgb2yuv2rgb5 ((PixJpegYUV<double>(rgb5))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb5 , rgb5 ); 00233 PixRGB<byte> rgb2yuv2rgb6 ((PixJpegYUV<double>(rgb6))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb6 , rgb6 ); 00234 PixRGB<byte> rgb2yuv2rgb7 ((PixJpegYUV<double>(rgb7))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb7 , rgb7 ); 00235 PixRGB<byte> rgb2yuv2rgb8 ((PixJpegYUV<double>(rgb8))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb8 , rgb8 ); 00236 PixRGB<byte> rgb2yuv2rgb9 ((PixJpegYUV<double>(rgb9))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb9 , rgb9 ); 00237 PixRGB<byte> rgb2yuv2rgb10((PixJpegYUV<double>(rgb10))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb10, rgb10); 00238 PixRGB<byte> rgb2yuv2rgb11((PixJpegYUV<double>(rgb11))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb11, rgb11); 00239 PixRGB<byte> rgb2yuv2rgb12((PixJpegYUV<double>(rgb12))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb12, rgb12); 00240 } 00241 00242 // test round-trip conversions rgb-->videoyuv-->rgb 00243 { 00244 PixRGB<byte> rgb2yuv2rgb1 ((PixVideoYUV<double>(rgb1))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb1 , rgb1 ); 00245 PixRGB<byte> rgb2yuv2rgb2 ((PixVideoYUV<double>(rgb2))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb2 , rgb2 ); 00246 PixRGB<byte> rgb2yuv2rgb3 ((PixVideoYUV<double>(rgb3))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb3 , rgb3 ); 00247 PixRGB<byte> rgb2yuv2rgb4 ((PixVideoYUV<double>(rgb4))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb4 , rgb4 ); 00248 PixRGB<byte> rgb2yuv2rgb5 ((PixVideoYUV<double>(rgb5))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb5 , rgb5 ); 00249 PixRGB<byte> rgb2yuv2rgb6 ((PixVideoYUV<double>(rgb6))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb6 , rgb6 ); 00250 PixRGB<byte> rgb2yuv2rgb7 ((PixVideoYUV<double>(rgb7))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb7 , rgb7 ); 00251 PixRGB<byte> rgb2yuv2rgb8 ((PixVideoYUV<double>(rgb8))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb8 , rgb8 ); 00252 PixRGB<byte> rgb2yuv2rgb9 ((PixVideoYUV<double>(rgb9))) ; REQUIRE_PIX3_EQ2(rgb2yuv2rgb9 , rgb9 ); 00253 PixRGB<byte> rgb2yuv2rgb10((PixVideoYUV<double>(rgb10))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb10, rgb10); 00254 PixRGB<byte> rgb2yuv2rgb11((PixVideoYUV<double>(rgb11))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb11, rgb11); 00255 PixRGB<byte> rgb2yuv2rgb12((PixVideoYUV<double>(rgb12))); REQUIRE_PIX3_EQ2(rgb2yuv2rgb12, rgb12); 00256 } 00257 } 00258 00259 static void Pixels_xx_conversions_xx_5(TestSuite& suite) 00260 { 00261 const PixRGB<byte> rgb1 ( 0, 0, 0); 00262 const PixRGB<byte> rgb2 (127, 127, 127); 00263 const PixRGB<byte> rgb3 (255, 255, 255); 00264 const PixRGB<byte> rgb4 (255, 0, 0); 00265 const PixRGB<byte> rgb5 ( 0, 255, 0); 00266 const PixRGB<byte> rgb6 ( 0, 0, 255); 00267 const PixRGB<byte> rgb7 (255, 127, 63); 00268 const PixRGB<byte> rgb8 (255, 63, 127); 00269 const PixRGB<byte> rgb9 (127, 255, 63); 00270 const PixRGB<byte> rgb10 ( 63, 255, 127); 00271 const PixRGB<byte> rgb11 (127, 63, 255); 00272 const PixRGB<byte> rgb12 ( 63, 127, 255); 00273 00274 // test conversions rgb-->hsv 00275 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb1)), 0, 0, 0); 00276 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb2)), 0, 0, 127); 00277 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb3)), 0, 0, 255); 00278 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb4)), 0, 100, 255); 00279 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb5)), 120, 100, 255); 00280 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb6)), 240, 100, 255); 00281 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb7)), 20, 75, 255); 00282 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb8)), 340, 75, 255); 00283 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb9)), 100, 75, 255); 00284 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb10)), 140, 75, 255); 00285 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb11)), 260, 75, 255); 00286 REQUIRE_PIX3_EQ(PixHSV<int>(PixHSV<double>(rgb12)), 220, 75, 255); 00287 00288 // test conversions rgb-->h2sv2 (use floating point but not double precision to keep somewhat sane) 00289 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb1), 0.500000,0.500000,0.000000,0.000000); 00290 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb2), 0.500000,0.500000,0.000000,0.4980392158029999793988906731101451441645622253417968750f); 00291 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb3), 0.500000,0.500000,0.000000,1.000000); 00292 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb4), 0.666666686535000052593602504202863201498985290527343750f,1.000000,1.000000,1.000000); 00293 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb5), 0.666666686535000052593602504202863201498985290527343750f,0.000000,1.000000,1.000000); 00294 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb6), 0.000000,0.500000,1.000000,1.000000); 00295 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb7), 00296 0.777777791023000042436308376636588945984840393066406250f, 00297 0.833333313465118408203125000000f, 00298 0.75294119119600000367142911272821947932243347167968750f, 00299 1.000000); 00300 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb8), 00301 0.555555582046999951728594169253483414649963378906250f, 00302 0.916666686535000052593602504202863201498985290527343750f, 00303 0.75294119119600000367142911272821947932243347167968750f, 00304 1.000000); 00305 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb9), 00306 0.777777791023000042436308376636588945984840393066406250f, 00307 0.1666666716340000076179705956747056916356086730957031250f, 00308 0.75294119119600000367142911272821947932243347167968750f, 00309 1.000000); 00310 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb10), 00311 0.555555582046999951728594169253483414649963378906250f, 00312 0.0833333358169000004700421868619741871953010559082031250f, 00313 0.75294119119600000367142911272821947932243347167968750f, 00314 1.000000); 00315 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb11), 00316 0.11111111193900000126966176594578428193926811218261718750f, 00317 0.583333313464999947406397495797136798501014709472656250f, 00318 0.75294119119600000367142911272821947932243347167968750f, 00319 1.000000); 00320 REQUIRE_PIX4_EQ(PixH2SV2<float>(rgb12), 00321 0.11111111193900000126966176594578428193926811218261718750f, 00322 0.4166666567330000181534899184043752029538154602050781250f, 00323 0.75294119119600000367142911272821947932243347167968750f, 00324 1.000000); 00325 00326 // test round-trip conversions rgb-->hsv-->rgb 00327 { 00328 PixRGB<byte> rgb2hsv2rgb1 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb1))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb1 , rgb1 ); 00329 PixRGB<byte> rgb2hsv2rgb2 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb2))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb2 , rgb2 ); 00330 PixRGB<byte> rgb2hsv2rgb3 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb3))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb3 , rgb3 ); 00331 PixRGB<byte> rgb2hsv2rgb4 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb4))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb4 , rgb4 ); 00332 PixRGB<byte> rgb2hsv2rgb5 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb5))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb5 , rgb5 ); 00333 PixRGB<byte> rgb2hsv2rgb6 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb6))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb6 , rgb6 ); 00334 PixRGB<byte> rgb2hsv2rgb7 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb7))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb7 , rgb7 ); 00335 PixRGB<byte> rgb2hsv2rgb8 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb8))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb8 , rgb8 ); 00336 PixRGB<byte> rgb2hsv2rgb9 ((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb9))))) ; REQUIRE_PIX3_EQ2(rgb2hsv2rgb9 , rgb9 ); 00337 PixRGB<byte> rgb2hsv2rgb10((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb10))))); REQUIRE_PIX3_EQ2(rgb2hsv2rgb10, rgb10); 00338 PixRGB<byte> rgb2hsv2rgb11((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb11))))); REQUIRE_PIX3_EQ2(rgb2hsv2rgb11, rgb11); 00339 PixRGB<byte> rgb2hsv2rgb12((PixRGB<double>(PixHSV<int>(PixHSV<double>(rgb12))))); REQUIRE_PIX3_EQ2(rgb2hsv2rgb12, rgb12); 00340 } 00341 } 00342 00343 static void Pixels_xx_promotions_xx_1(TestSuite& suite) 00344 { 00345 // check all pix-pix conversions among PixRGB<byte>/PixRGB<int>/PixRGB<float> 00346 00347 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<byte> >::TP) == typeid(PixRGB<int>)); 00348 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<int16> >::TP) == typeid(PixRGB<int>)); 00349 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<int32> >::TP) == typeid(PixRGB<int>)); 00350 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<float> >::TP) == typeid(PixRGB<float>)); 00351 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<double> >::TP) == typeid(PixRGB<double>)); 00352 REQUIRE(typeid(promote_trait<PixRGB<byte> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00353 00354 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<byte> >::TP) == typeid(PixRGB<int>)); 00355 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<int16> >::TP) == typeid(PixRGB<int>)); 00356 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<int32> >::TP) == typeid(PixRGB<int>)); 00357 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<float> >::TP) == typeid(PixRGB<float>)); 00358 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<double> >::TP) == typeid(PixRGB<double>)); 00359 REQUIRE(typeid(promote_trait<PixRGB<int16> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00360 00361 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<byte> >::TP) == typeid(PixRGB<int>)); 00362 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<int16> >::TP) == typeid(PixRGB<int>)); 00363 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<int32> >::TP) == typeid(PixRGB<int>)); 00364 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<float> >::TP) == typeid(PixRGB<float>)); 00365 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<double> >::TP) == typeid(PixRGB<double>)); 00366 REQUIRE(typeid(promote_trait<PixRGB<int32> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00367 00368 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<byte> >::TP) == typeid(PixRGB<float>)); 00369 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<int16> >::TP) == typeid(PixRGB<float>)); 00370 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<int32> >::TP) == typeid(PixRGB<float>)); 00371 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<float> >::TP) == typeid(PixRGB<float>)); 00372 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<double> >::TP) == typeid(PixRGB<double>)); 00373 REQUIRE(typeid(promote_trait<PixRGB<float> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00374 00375 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<byte> >::TP) == typeid(PixRGB<double>)); 00376 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<int16> >::TP) == typeid(PixRGB<double>)); 00377 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<int32> >::TP) == typeid(PixRGB<double>)); 00378 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<float> >::TP) == typeid(PixRGB<double>)); 00379 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<double> >::TP) == typeid(PixRGB<double>)); 00380 REQUIRE(typeid(promote_trait<PixRGB<double> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00381 00382 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<byte> >::TP) == typeid(PixRGB<long double>)); 00383 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<int16> >::TP) == typeid(PixRGB<long double>)); 00384 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<int32> >::TP) == typeid(PixRGB<long double>)); 00385 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<float> >::TP) == typeid(PixRGB<long double>)); 00386 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<double> >::TP) == typeid(PixRGB<long double>)); 00387 REQUIRE(typeid(promote_trait<PixRGB<long double> , PixRGB<long double> >::TP) == typeid(PixRGB<long double>)); 00388 } 00389 00390 static void Pixels_xx_conversions_xx_6(TestSuite& suite) 00391 { 00392 PixRGB<float> p1(255.0f, 128.0f, 0.0f); 00393 PixH2SV2<float> p2(p1); 00394 00395 REQUIRE(fabs(p2.H1() - 0.83399f) < 0.00001f); 00396 REQUIRE(fabs(p2.H2() - 0.74901f) < 0.00001f); 00397 REQUIRE(fabs(p2.S() - 1.0f) < 0.00001f); 00398 REQUIRE(fabs(p2.V() - 1.0f) < 0.00001f); 00399 } 00400 00401 static void Pixels_xx_conversions_xx_7(TestSuite& suite) 00402 { 00403 const PixRGB<byte> rgb1 ( 0, 0, 0); 00404 const PixRGB<byte> rgb2 (127, 127, 127); 00405 const PixRGB<byte> rgb3 (255, 255, 255); 00406 const PixRGB<byte> rgb4 (255, 0, 0); 00407 const PixRGB<byte> rgb5 ( 0, 255, 0); 00408 const PixRGB<byte> rgb6 ( 0, 0, 255); 00409 const PixRGB<byte> rgb7 (255, 127, 63); 00410 const PixRGB<byte> rgb8 (255, 63, 127); 00411 const PixRGB<byte> rgb9 (127, 255, 63); 00412 const PixRGB<byte> rgb10 ( 63, 255, 127); 00413 const PixRGB<byte> rgb11 (127, 63, 255); 00414 const PixRGB<byte> rgb12 ( 63, 127, 255); 00415 00416 // test conversions rgb-->dkl 00417 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb1) * 127.0F + 128.0F), 5, 128, 130); 00418 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb2) * 127.0F + 128.0F), 77, 125, 132); 00419 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb3) * 127.0F + 128.0F), 257, 127, 127); 00420 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb4) * 127.0F + 128.0F), 56, 206, 109); 00421 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb5) * 127.0F + 128.0F), 174, 81, 64); 00422 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb6) * 127.0F + 128.0F), 36, 95, 215); 00423 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb7) * 127.0F + 128.0F), 106, 191, 93); 00424 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb8) * 127.0F + 128.0F), 71, 195, 133); 00425 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb9) * 127.0F + 128.0F), 189, 101, 61); 00426 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb10) * 127.0F + 128.0F), 185, 73, 89); 00427 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb11) * 127.0F + 128.0F), 56, 115, 207); 00428 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb12) * 127.0F + 128.0F), 86, 84, 195); 00429 00430 // let's now enforce a bit more accuracy: 00431 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb1) * 10000.0F), -9684, 17, 210); 00432 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb2) * 10000.0F), -3989, -163, 316); 00433 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb3) * 10000.0F), 10162, -24, -28); 00434 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb4) * 10000.0F), -5652, 6193, -1454); 00435 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb5) * 10000.0F), 3637, -3656, -5026); 00436 REQUIRE_PIX3_EQ(PixDKL<int>(PixDKL<float>(rgb6) * 10000.0F), -7190, -2526, 6873); 00437 } 00438 00439 static void Pixels_xx_operators_xx_1(TestSuite& suite) 00440 { 00441 { 00442 PixRGB<byte> p1(12, 34, 56); 00443 REQUIRE_PIX3_EQ(p1 * 10, 120, 340, 560); // promoted to int 00444 p1 *= 10; 00445 REQUIRE_PIX3_EQ(p1, 120, 255, 255); // clamped to byte range 00446 } 00447 00448 { 00449 PixRGB<byte> p1(120, 255, 255); 00450 REQUIRE_PIX3_EQ(p1 - 200, -80, 55, 55) // promoted to int 00451 p1 -= 200; 00452 REQUIRE_PIX3_EQ(p1, 0, 55, 55); // clamped to byte range 00453 } 00454 00455 { 00456 PixRGB<byte> p1(0, 55, 55); 00457 REQUIRE_PIX3_EQ(p1 / 5, 0, 11, 11); // promoted to int 00458 REQUIRE_PIX3_EQ(p1 / -5, 0, -11, -11); // promoted to int 00459 p1 /= 5; 00460 REQUIRE_PIX3_EQ(p1, 0, 11, 11); // clamped to byte range 00461 } 00462 00463 { 00464 PixRGB<byte> p1(0, 11, 11); 00465 REQUIRE_PIX3_EQ(p1 + 251, 251, 262, 262); // promoted to int 00466 p1 += 251; 00467 REQUIRE_PIX3_EQ(p1, 251, 255, 255); // clamped to byte range 00468 } 00469 00470 { 00471 PixRGB<byte> p1(251, 255, 255); 00472 PixRGB<byte> p2(12, 34, 56); 00473 REQUIRE_PIX3_EQ(p1 / p2, 20, 7, 4); // (p1/p2) promoted to int 00474 p1 /= p2; 00475 REQUIRE_PIX3_EQ(p1, 20, 7, 4); // (p1/=p2) clamped to byte range 00476 } 00477 00478 { 00479 PixRGB<byte> p1(20, 7, 4); 00480 REQUIRE_PIX3_EQ(p1 * p1, 400, 49, 16); // (p1*p1) promoted to int 00481 p1 *= p1; 00482 REQUIRE_PIX3_EQ(p1, 255, 49, 16); // (p1*=p1) clamped to byte range 00483 } 00484 00485 { 00486 PixRGB<byte> p1(255, 49, 16); 00487 PixRGB<byte> p2(12, 34, 56); 00488 REQUIRE_PIX3_EQ(p2 - p1, -243, -15, 40); // (p2-1) promoted to int 00489 p2 -= p1; 00490 REQUIRE_PIX3_EQ(p2, 0, 0, 40); // (p2-=p1) clamped to byte range 00491 } 00492 00493 { 00494 PixRGB<byte> p1(255, 49, 16); 00495 PixRGB<byte> p2(0, 220, 40); 00496 REQUIRE_PIX3_EQ(p1 + p2, 255, 269, 56); // (p1+p2) promoted to int 00497 p1 += p2; 00498 REQUIRE_PIX3_EQ(p1, 255, 255, 56); // (p1+=p2) clamped to byte range 00499 } 00500 00501 { 00502 PixJpegYUV<int> p1(10, 20, 30); 00503 PixJpegYUV<float> p2(1, 2, 3); 00504 00505 REQUIRE_PIX3_EQ(p1 * p2, 10.0f, 40.0f, 90.0f); // promoted to float 00506 p1 *= p2; 00507 REQUIRE_PIX3_EQ(p1, 10, 40, 90); // clamped back to int range 00508 } 00509 } 00510 00511 static void Pixels_xx_operators_xx_2(TestSuite& suite) 00512 { 00513 PixRGB<byte> p1(12, 34, 56); 00514 00515 // here the result of p1 * float will be promoted to PixRGB<float> 00516 // and then assigned to p2: 00517 PixRGB<float> p2 = p1 * 100.0f; 00518 REQUIRE_PIX3_EQ(p2, 1200.0f, 3400.0f, 5600.0f); 00519 00520 p2 = p1 / -2.0f; 00521 REQUIRE_PIX3_EQ(p2, -6.0f, -17.0f, -28.0f); 00522 00523 // now, p1 * int will be promoted to PixRGB<int> then 00524 // range-converted to PixRGB<byte> then assigned to p3: 00525 PixRGB<byte> p3( p1 * 10 ); 00526 REQUIRE_PIX3_EQ(p3, 120, 255, 255); 00527 00528 // here, p1 * int will be PixRGB<int>, idem after division, then 00529 // clamped convert to PixRGB<byte> -- so, no overflow should occur: 00530 p3 = PixRGB<byte>( (p1 * 1000) / 1000 ); 00531 REQUIRE_PIX3_EQ(p3, 12, 34, 56); 00532 00533 // PixRGB<int> -> PixRGB<float> -> same -> same, will clamp to byte 00534 p3 = PixRGB<byte>( ( ( (p1 * 1000) - 5000.0f ) + 5000 ) / 1000.0f ); 00535 REQUIRE_PIX3_EQ(p3, 12, 34, 56); 00536 } 00537 00538 static void Pixels_xx_binary_layout_xx_1(TestSuite& suite) 00539 { 00540 // Here we're checking that a PixRGB<byte> array has the expected 00541 // binary layout, i.e. is the same as a simple byte array with a 00542 // sequence of r, g, b values, in that order. We want to test this 00543 // because certain places in the code assume that PixRGB<byte> has 00544 // this layout, e.g. in PnmParser we slurp a series of raw bytes out 00545 // of the file into a PixRGB<byte> array. 00546 00547 PixRGB<byte> pixels[2] = 00548 { 00549 PixRGB<byte>(55, 66, 77), 00550 PixRGB<byte>(111, 122, 133) 00551 }; 00552 00553 byte* mem = reinterpret_cast<byte*>(&pixels); 00554 00555 REQUIRE_EQ(mem[0], 55); 00556 REQUIRE_EQ(mem[1], 66); 00557 REQUIRE_EQ(mem[2], 77); 00558 REQUIRE_EQ(mem[3], 111); 00559 REQUIRE_EQ(mem[4], 122); 00560 REQUIRE_EQ(mem[5], 133); 00561 00562 mem[0] = 5; 00563 mem[1] = 6; 00564 mem[2] = 7; 00565 mem[3] = 11; 00566 mem[4] = 12; 00567 mem[5] = 13; 00568 00569 REQUIRE_EQ(pixels[0].red(), 5); 00570 REQUIRE_EQ(pixels[0].green(), 6); 00571 REQUIRE_EQ(pixels[0].blue(), 7); 00572 REQUIRE_EQ(pixels[1].red(), 11); 00573 REQUIRE_EQ(pixels[1].green(), 12); 00574 REQUIRE_EQ(pixels[1].blue(), 13); 00575 } 00576 00577 namespace 00578 { 00579 const PixRGB<double> p1(-1.0, 2.4, 0.6); 00580 const PixRGB<double> p2(4.0, 9.0, 64.0); 00581 const PixRGB<double> p3(14.1, 0.3, 7.0); 00582 const PixRGB<double> p4(-1.0, 0.8, -0.3); 00583 const PixRGB<double> p5(-0.9, 0.8, -0.3); 00584 const PixRGB<double> p6(0.2, 0.4, 0.6); 00585 00586 double coeff[4] = { 1.3, 1.5, 1.9, 2.1 } ; 00587 } 00588 00589 static void Pixels_xx_math_functions_xx_1(TestSuite& suite) 00590 { 00591 REQUIRE_PIX3_EQ(PixRGB<int>(maxmerge(p1,p3)*100.0), 1410, 240, 700); 00592 } 00593 static void Pixels_xx_math_functions_xx_2(TestSuite& suite) 00594 { 00595 REQUIRE_PIX3_EQ(PixRGB<int>(minmerge(p2,p3)*100.0), 400, 30, 700); 00596 } 00597 static void Pixels_xx_math_functions_xx_3(TestSuite& suite) 00598 { 00599 REQUIRE_PIX3_EQ(PixRGB<int>(abs(p1)*100.0), 100, 240, 60); 00600 } 00601 static void Pixels_xx_math_functions_xx_4(TestSuite& suite) 00602 { 00603 REQUIRE_PIX3_EQ(PixRGB<int>(sqrt(p2)*100.0), 200, 300, 800); 00604 } 00605 static void Pixels_xx_math_functions_xx_5(TestSuite& suite) 00606 { 00607 REQUIRE_PIX3_EQ(floor(p1), -1.0, 2.0, 0.0); 00608 } 00609 static void Pixels_xx_math_functions_xx_6(TestSuite& suite) 00610 { 00611 REQUIRE_PIX3_EQ(ceil(p1), -1.0, 3.0, 1.0); 00612 } 00613 static void Pixels_xx_math_functions_xx_7(TestSuite& suite) 00614 { 00615 REQUIRE_PIX3_EQ(round(p1), -1.0, 2.0, 1.0); 00616 } 00617 static void Pixels_xx_math_functions_xx_8(TestSuite& suite) 00618 { 00619 REQUIRE_PIX3_EQ(PixRGB<int>(log(p2)*100.0), 138, 219, 415); 00620 } 00621 static void Pixels_xx_math_functions_xx_9(TestSuite& suite) 00622 { 00623 REQUIRE_PIX3_EQ(PixRGB<int>(log10(p2)*100.0), 60, 95, 180); 00624 } 00625 static void Pixels_xx_math_functions_xx_10(TestSuite& suite) 00626 { 00627 REQUIRE_PIX3_EQ(PixRGB<int>(exp(p1)*100.0), 36, 1102, 182); 00628 } 00629 static void Pixels_xx_math_functions_xx_11(TestSuite& suite) 00630 { 00631 REQUIRE_PIX3_EQ(PixRGB<int>(sin(p1)*100.0), -84, 67, 56); 00632 } 00633 static void Pixels_xx_math_functions_xx_12(TestSuite& suite) 00634 { 00635 REQUIRE_PIX3_EQ(PixRGB<int>(cos(p1)*100.0), 54, -73, 82); 00636 } 00637 static void Pixels_xx_math_functions_xx_13(TestSuite& suite) 00638 { 00639 REQUIRE_PIX3_EQ(PixRGB<int>(tan(p1)*100.0), -155, -91, 68); 00640 } 00641 static void Pixels_xx_math_functions_xx_14(TestSuite& suite) 00642 { 00643 REQUIRE_PIX3_EQ(PixRGB<int>(atan(p1)*100.0), -78, 117, 54); 00644 } 00645 static void Pixels_xx_math_functions_xx_15(TestSuite& suite) 00646 { 00647 REQUIRE_PIX3_EQ(PixRGB<int>(pow(p1, 3.0)*100.0), -100, 1382, 21); 00648 } 00649 static void Pixels_xx_math_functions_xx_16(TestSuite& suite) 00650 { 00651 REQUIRE_PIX3_EQ(PixRGB<int>(pow(p3, p1)*100.0), 7, 5, 321); 00652 } 00653 static void Pixels_xx_math_functions_xx_17(TestSuite& suite) 00654 { 00655 REQUIRE_PIX3_EQ(PixRGB<int>(erf(p1)*100.0), -84, 99, 60); 00656 } 00657 static void Pixels_xx_math_functions_xx_18(TestSuite& suite) 00658 { 00659 REQUIRE_PIX3_EQ(PixRGB<int>(erfc(p1)*100.0), 184, 0, 39); 00660 } 00661 static void Pixels_xx_math_functions_xx_19(TestSuite& suite) 00662 { 00663 REQUIRE_PIX3_EQ(PixRGB<int>(sec(p1)*100.0), 185, -135, 121); 00664 } 00665 static void Pixels_xx_math_functions_xx_20(TestSuite& suite) 00666 { 00667 REQUIRE_PIX3_EQ(PixRGB<int>(cosec(p1)*100.0), -118, 148, 177); 00668 } 00669 static void Pixels_xx_math_functions_xx_21(TestSuite& suite) 00670 { 00671 REQUIRE_PIX3_EQ(PixRGB<int>(cotan(p1)*100.0), -64, -109, 146); 00672 } 00673 static void Pixels_xx_math_functions_xx_22(TestSuite& suite) 00674 { 00675 REQUIRE_PIX3_EQ(PixRGB<int>(asin(p4)*100.0), -157, 92, -30); 00676 } 00677 static void Pixels_xx_math_functions_xx_23(TestSuite& suite) 00678 { 00679 REQUIRE_PIX3_EQ(PixRGB<int>(acos(p4)*100.0), 314, 64, 187); 00680 } 00681 static void Pixels_xx_math_functions_xx_24(TestSuite& suite) 00682 { 00683 REQUIRE_PIX3_EQ(PixRGB<int>(asec(p2)*100.0), 131, 145, 155); 00684 } 00685 static void Pixels_xx_math_functions_xx_25(TestSuite& suite) 00686 { 00687 REQUIRE_PIX3_EQ(PixRGB<int>(acosec(p2)*100.0), 25, 11, 1); 00688 } 00689 static void Pixels_xx_math_functions_xx_26(TestSuite& suite) 00690 { 00691 REQUIRE_PIX3_EQ(PixRGB<int>(acotan(p1)*100.0), -78, 39, 103); 00692 } 00693 static void Pixels_xx_math_functions_xx_27(TestSuite& suite) 00694 { 00695 REQUIRE_PIX3_EQ(PixRGB<int>(sinh(p1)*100.0), -117, 546, 63); 00696 } 00697 static void Pixels_xx_math_functions_xx_28(TestSuite& suite) 00698 { 00699 REQUIRE_PIX3_EQ(PixRGB<int>(cosh(p1)*100.0), 154, 555, 118); 00700 } 00701 static void Pixels_xx_math_functions_xx_29(TestSuite& suite) 00702 { 00703 REQUIRE_PIX3_EQ(PixRGB<int>(tanh(p1)*100.0), -76, 98, 53); 00704 } 00705 static void Pixels_xx_math_functions_xx_30(TestSuite& suite) 00706 { 00707 REQUIRE_PIX3_EQ(PixRGB<int>(sech(p1)*100.0), 64, 17, 84); 00708 } 00709 static void Pixels_xx_math_functions_xx_31(TestSuite& suite) 00710 { 00711 REQUIRE_PIX3_EQ(PixRGB<int>(cosech(p1)*100.0), -85, 18, 157); 00712 } 00713 static void Pixels_xx_math_functions_xx_32(TestSuite& suite) 00714 { 00715 REQUIRE_PIX3_EQ(PixRGB<int>(cotanh(p1)*100.0), -131, 101, 186); 00716 } 00717 static void Pixels_xx_math_functions_xx_33(TestSuite& suite) 00718 { 00719 REQUIRE_PIX3_EQ(PixRGB<int>(asinh(p1)*100.0), -88, 160, 56); 00720 } 00721 static void Pixels_xx_math_functions_xx_34(TestSuite& suite) 00722 { 00723 REQUIRE_PIX3_EQ(PixRGB<int>(acosh(p2)*100.0), 206, 288, 485); 00724 } 00725 static void Pixels_xx_math_functions_xx_35(TestSuite& suite) 00726 { 00727 REQUIRE_PIX3_EQ(PixRGB<int>(atanh(p5)*100.0), -147, 109, -30); 00728 } 00729 static void Pixels_xx_math_functions_xx_36(TestSuite& suite) 00730 { 00731 REQUIRE_PIX3_EQ(PixRGB<int>(asech(p6)*100.0), 229, 156, 109); 00732 } 00733 static void Pixels_xx_math_functions_xx_37(TestSuite& suite) 00734 { 00735 REQUIRE_PIX3_EQ(PixRGB<int>(acosech(p2)*100.0), 24, 11, 1); 00736 } 00737 static void Pixels_xx_math_functions_xx_38(TestSuite& suite) 00738 { 00739 REQUIRE_PIX3_EQ(PixRGB<int>(acotanh(p2)*100.0), 25, 11, 1); 00740 } 00741 static void Pixels_xx_math_functions_xx_39(TestSuite& suite) 00742 { 00743 REQUIRE_PIX3_EQ(PixRGB<int>(sign(p1)), -1, 1, 1); 00744 } 00745 static void Pixels_xx_math_functions_xx_40(TestSuite& suite) 00746 { 00747 REQUIRE_PIX3_EQ(PixRGB<int>(logN(p2, 3.0)*100.0), 126, 200, 378); 00748 } 00749 static void Pixels_xx_math_functions_xx_41(TestSuite& suite) 00750 { 00751 REQUIRE_PIX3_EQ(PixRGB<int>(logsig(p2, 3.0, 5.0)*100.0), 99, 99, 100); 00752 } 00753 static void Pixels_xx_math_functions_xx_42(TestSuite& suite) 00754 { 00755 REQUIRE_PIX3_EQ(PixRGB<int>(tansig(p1)*100.0), 838, 100, 130); 00756 } 00757 static void Pixels_xx_math_functions_xx_43(TestSuite& suite) 00758 { 00759 REQUIRE_PIX3_EQ(PixRGB<int>(saturate(p3, 6.6)*100.0), 660, 30, 660); 00760 } 00761 static void Pixels_xx_math_functions_xx_44(TestSuite& suite) 00762 { 00763 REQUIRE_PIX3_EQ(PixRGB<int>(poly(p3, &coeff[0], 4)*100.0), 628695, 197, 82520); 00764 } 00765 static void Pixels_xx_math_functions_xx_45(TestSuite& suite) 00766 { 00767 REQUIRE_PIX3_EQ(PixRGB<int>(gauss(p1, p3, p2)*100.0), 0, 4, 0); 00768 } 00769 static void Pixels_xx_math_functions_xx_46(TestSuite& suite) 00770 { 00771 REQUIRE_PIX3_EQ(PixRGB<int>(gauss(p1, 1.0, 1.0)*100.0), 5, 14, 36); 00772 } 00773 static void Pixels_xx_math_functions_xx_47(TestSuite& suite) 00774 { 00775 REQUIRE_EQ(int(max(p1)*100.0), 240); 00776 } 00777 static void Pixels_xx_math_functions_xx_48(TestSuite& suite) 00778 { 00779 REQUIRE_EQ(int(min(p1)*100.0), -100); 00780 } 00781 static void Pixels_xx_math_functions_xx_49(TestSuite& suite) 00782 { 00783 REQUIRE_EQ(isFinite(p1), true); 00784 } 00785 static void Pixels_xx_math_functions_xx_50(TestSuite& suite) 00786 { 00787 REQUIRE_EQ(int(0.5 + sum(p1)*100.0), 200); 00788 } 00789 static void Pixels_xx_math_functions_xx_51(TestSuite& suite) 00790 { 00791 REQUIRE_EQ(int(mean(p1)*100.0), 66); 00792 } 00793 00794 /////////////////////////////////////////////////////////////////////// 00795 // 00796 // main 00797 // 00798 /////////////////////////////////////////////////////////////////////// 00799 00800 int main(int argc, const char** argv) 00801 { 00802 TestSuite suite; 00803 00804 suite.ADD_TEST(Pixels_xx_constructors_xx_1); 00805 suite.ADD_TEST(Pixels_xx_conversions_xx_1); 00806 suite.ADD_TEST(Pixels_xx_conversions_xx_2); 00807 suite.ADD_TEST(Pixels_xx_conversions_xx_3); 00808 suite.ADD_TEST(Pixels_xx_conversions_xx_4); 00809 suite.ADD_TEST(Pixels_xx_conversions_xx_5); 00810 suite.ADD_TEST(Pixels_xx_conversions_xx_6); 00811 suite.ADD_TEST(Pixels_xx_conversions_xx_7); 00812 suite.ADD_TEST(Pixels_xx_promotions_xx_1); 00813 suite.ADD_TEST(Pixels_xx_operators_xx_1); 00814 suite.ADD_TEST(Pixels_xx_operators_xx_2); 00815 suite.ADD_TEST(Pixels_xx_binary_layout_xx_1); 00816 00817 suite.ADD_TEST(Pixels_xx_math_functions_xx_1); 00818 suite.ADD_TEST(Pixels_xx_math_functions_xx_2); 00819 suite.ADD_TEST(Pixels_xx_math_functions_xx_3); 00820 suite.ADD_TEST(Pixels_xx_math_functions_xx_4); 00821 suite.ADD_TEST(Pixels_xx_math_functions_xx_5); 00822 suite.ADD_TEST(Pixels_xx_math_functions_xx_6); 00823 suite.ADD_TEST(Pixels_xx_math_functions_xx_7); 00824 suite.ADD_TEST(Pixels_xx_math_functions_xx_8); 00825 suite.ADD_TEST(Pixels_xx_math_functions_xx_9); 00826 suite.ADD_TEST(Pixels_xx_math_functions_xx_10); 00827 suite.ADD_TEST(Pixels_xx_math_functions_xx_11); 00828 suite.ADD_TEST(Pixels_xx_math_functions_xx_12); 00829 suite.ADD_TEST(Pixels_xx_math_functions_xx_13); 00830 suite.ADD_TEST(Pixels_xx_math_functions_xx_14); 00831 suite.ADD_TEST(Pixels_xx_math_functions_xx_15); 00832 suite.ADD_TEST(Pixels_xx_math_functions_xx_16); 00833 suite.ADD_TEST(Pixels_xx_math_functions_xx_17); 00834 suite.ADD_TEST(Pixels_xx_math_functions_xx_18); 00835 suite.ADD_TEST(Pixels_xx_math_functions_xx_19); 00836 suite.ADD_TEST(Pixels_xx_math_functions_xx_20); 00837 suite.ADD_TEST(Pixels_xx_math_functions_xx_21); 00838 suite.ADD_TEST(Pixels_xx_math_functions_xx_22); 00839 suite.ADD_TEST(Pixels_xx_math_functions_xx_23); 00840 suite.ADD_TEST(Pixels_xx_math_functions_xx_24); 00841 suite.ADD_TEST(Pixels_xx_math_functions_xx_25); 00842 suite.ADD_TEST(Pixels_xx_math_functions_xx_26); 00843 suite.ADD_TEST(Pixels_xx_math_functions_xx_27); 00844 suite.ADD_TEST(Pixels_xx_math_functions_xx_28); 00845 suite.ADD_TEST(Pixels_xx_math_functions_xx_29); 00846 suite.ADD_TEST(Pixels_xx_math_functions_xx_30); 00847 suite.ADD_TEST(Pixels_xx_math_functions_xx_31); 00848 suite.ADD_TEST(Pixels_xx_math_functions_xx_32); 00849 suite.ADD_TEST(Pixels_xx_math_functions_xx_33); 00850 suite.ADD_TEST(Pixels_xx_math_functions_xx_34); 00851 suite.ADD_TEST(Pixels_xx_math_functions_xx_35); 00852 suite.ADD_TEST(Pixels_xx_math_functions_xx_36); 00853 suite.ADD_TEST(Pixels_xx_math_functions_xx_37); 00854 suite.ADD_TEST(Pixels_xx_math_functions_xx_38); 00855 suite.ADD_TEST(Pixels_xx_math_functions_xx_39); 00856 suite.ADD_TEST(Pixels_xx_math_functions_xx_40); 00857 suite.ADD_TEST(Pixels_xx_math_functions_xx_41); 00858 suite.ADD_TEST(Pixels_xx_math_functions_xx_42); 00859 suite.ADD_TEST(Pixels_xx_math_functions_xx_43); 00860 suite.ADD_TEST(Pixels_xx_math_functions_xx_44); 00861 suite.ADD_TEST(Pixels_xx_math_functions_xx_45); 00862 suite.ADD_TEST(Pixels_xx_math_functions_xx_46); 00863 suite.ADD_TEST(Pixels_xx_math_functions_xx_47); 00864 suite.ADD_TEST(Pixels_xx_math_functions_xx_48); 00865 suite.ADD_TEST(Pixels_xx_math_functions_xx_49); 00866 suite.ADD_TEST(Pixels_xx_math_functions_xx_50); 00867 suite.ADD_TEST(Pixels_xx_math_functions_xx_51); 00868 00869 suite.parseAndRun(argc, argv); 00870 00871 return 0; 00872 } 00873 00874 // ###################################################################### 00875 /* So things look consistent in everyone's emacs... */ 00876 /* Local Variables: */ 00877 /* indent-tabs-mode: nil */ 00878 /* End: */