1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/fade_images.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/fade_images.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,101 @@ 1.5 +/* 1.6 + # 1.7 + # File : fade_images.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : Compute a linear fading between two images. 1.11 + # This file is a part of the CImg Library project. 1.12 + # ( http://cimg.sourceforge.net ) 1.13 + # 1.14 + # Copyright : David Tschumperle 1.15 + # ( http://www.greyc.ensicaen.fr/~dtschump/ ) 1.16 + # 1.17 + # License : CeCILL v2.0 1.18 + # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.19 + # 1.20 + # This software is governed by the CeCILL license under French law and 1.21 + # abiding by the rules of distribution of free software. You can use, 1.22 + # modify and/ or redistribute the software under the terms of the CeCILL 1.23 + # license as circulated by CEA, CNRS and INRIA at the following URL 1.24 + # "http://www.cecill.info". 1.25 + # 1.26 + # As a counterpart to the access to the source code and rights to copy, 1.27 + # modify and redistribute granted by the license, users are provided only 1.28 + # with a limited warranty and the software's author, the holder of the 1.29 + # economic rights, and the successive licensors have only limited 1.30 + # liability. 1.31 + # 1.32 + # In this respect, the user's attention is drawn to the risks associated 1.33 + # with loading, using, modifying and/or developing or reproducing the 1.34 + # software by the user in light of its specific status of free software, 1.35 + # that may mean that it is complicated to manipulate, and that also 1.36 + # therefore means that it is reserved for developers and experienced 1.37 + # professionals having in-depth computer knowledge. Users are therefore 1.38 + # encouraged to load and test the software's suitability as regards their 1.39 + # requirements in conditions enabling the security of their systems and/or 1.40 + # data to be ensured and, more generally, to use and operate it in the 1.41 + # same conditions as regards security. 1.42 + # 1.43 + # The fact that you are presently reading this means that you have had 1.44 + # knowledge of the CeCILL license and that you accept its terms. 1.45 + # 1.46 +*/ 1.47 + 1.48 +#include "CImg.h" 1.49 + 1.50 +// The lines below are necessary when using a non-standard compiler as visualcpp6. 1.51 +#ifdef cimg_use_visualcpp6 1.52 +#define std 1.53 +#endif 1.54 +#ifdef min 1.55 +#undef min 1.56 +#undef max 1.57 +#endif 1.58 + 1.59 +#ifndef cimg_imagepath 1.60 +#define cimg_imagepath "img/" 1.61 +#endif 1.62 + 1.63 +// Main procedure 1.64 +//--------------- 1.65 +int main(int argc,char **argv) { 1.66 + 1.67 + // Read and check command line parameters 1.68 + cimg_usage("Compute a linear fading between two 2D images"); 1.69 + const char *file_i1 = cimg_option("-i1",cimg_imagepath "sh0r.pgm","Input Image 1"); 1.70 + const char *file_i2 = cimg_option("-i2",cimg_imagepath "milla.bmp","Input Image 2"); 1.71 + const char *file_o = cimg_option("-o",(char*)0,"Output Image"); 1.72 + const bool visu = cimg_option("-visu",true,"Visualization mode"); 1.73 + const double pmin = cimg_option("-min",40.0,"Begin of the fade (in %)")/100.0; 1.74 + const double pmax = cimg_option("-max",60.0,"End of the fade (in %)")/100.0; 1.75 + const double angle = cimg_option("-angle",0.0,"Fade angle")*cimg_library::cimg::valuePI/180; 1.76 + 1.77 + // Init images 1.78 + cimg_library::CImg<unsigned char> img1(file_i1), img2(file_i2); 1.79 + if (img2.dimx()!=img1.dimx() || img2.dimy()!=img1.dimy() || img2.dimz()!=img1.dimz() || img2.dimv()!=img1.dimv()) { 1.80 + int 1.81 + dx = cimg_library::cimg::max(img1.dimx(),img2.dimx()), 1.82 + dy = cimg_library::cimg::max(img1.dimy(),img2.dimy()), 1.83 + dz = cimg_library::cimg::max(img1.dimz(),img2.dimz()), 1.84 + dv = cimg_library::cimg::max(img1.dimv(),img2.dimv()); 1.85 + img1.resize(dx,dy,dz,dv,3); 1.86 + img2.resize(dx,dy,dz,dv,3); 1.87 + } 1.88 + cimg_library::CImg<unsigned char> dest(img1.dimx(),img1.dimy(),img1.dimz(),img1.dimv()); 1.89 + 1.90 + // Compute the faded image 1.91 + const double ca=std::cos(angle), sa=std::sin(angle); 1.92 + double alpha; 1.93 + cimg_forXYZV(dest,x,y,z,k) { 1.94 + const double X = ((double)x/img1.dimx()-0.5)*ca + ((double)y/img1.dimy()-0.5)*sa; 1.95 + if (X+0.5<pmin) alpha=0; else { 1.96 + if (X+0.5>pmax) alpha=1; else alpha=(X+0.5-pmin)/(pmax-pmin); 1.97 + } 1.98 + dest(x,y,z,k) = (unsigned char)((1-alpha)*img1(x,y,z,k) + alpha*img2(x,y,z,k)); 1.99 + } 1.100 + 1.101 + // Save and exit 1.102 + if (file_o) dest.save(file_o); 1.103 + if (visu) dest.display("Image fading"); 1.104 + return 0; 1.105 +}