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