1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/tutorial.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/tutorial.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,130 @@ 1.5 +/* 1.6 + # 1.7 + # File : tutorial.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : View the color profile of an image, along the X-axis. 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 library file and use its main namespace 1.49 +#include "CImg.h" 1.50 +using namespace cimg_library; 1.51 + 1.52 +#ifndef cimg_imagepath 1.53 +#define cimg_imagepath "img/" 1.54 +#endif 1.55 + 1.56 +// Begin the program 1.57 +int main(int argc,char **argv) { 1.58 + 1.59 + // Define program usage and read command line parameters 1.60 + //------------------------------------------------------- 1.61 + 1.62 + // Display program usage, when invoked from the command line with option '-h'. 1.63 + cimg_usage("View the color profile of an image along the X axis"); 1.64 + 1.65 + // Read image filename from the command line (or set it to "img/parrot_original.ppm" if option '-i' is not provided). 1.66 + const char* file_i = cimg_option("-i",cimg_imagepath "parrot_original.ppm","Input image"); 1.67 + 1.68 + // Read pre-blurring variance from the command line (or set it to 1.0 if option '-blur' is not provided). 1.69 + const double sigma = cimg_option("-blur",1.0,"Variance of gaussian pre-blurring"); 1.70 + 1.71 + // Init variables 1.72 + //---------------- 1.73 + 1.74 + // Load an image, transform it to a color image (if necessary) and blur it with the standard deviation sigma. 1.75 + const CImg<unsigned char> image = CImg<>(file_i).normalize(0,255).blur((float)sigma).resize(-100,-100,1,3); 1.76 + 1.77 + // Create two display window, one for the image, the other for the color profile. 1.78 + CImgDisplay 1.79 + main_disp(image,"Color image (Try to move mouse pointer over)",0), 1.80 + draw_disp(500,400,"Color profile of the X-axis",0); 1.81 + 1.82 + // Define colors used to plot the profile, and a hatch to draw the vertical line 1.83 + unsigned long hatch = 0xF0F0F0F0; 1.84 + const unsigned char 1.85 + red[] = { 255,0,0 }, 1.86 + green[] = { 0,255,0 }, 1.87 + blue [] = { 0,0,255 }, 1.88 + black[] = { 0,0,0 }; 1.89 + 1.90 + // Enter event loop. This loop ends when one of the two display window is closed or when the keys 'ESC' or 'Q' are pressed. 1.91 + while (!main_disp.is_closed && !draw_disp.is_closed && 1.92 + !main_disp.is_keyESC && !draw_disp.is_keyESC && !main_disp.is_keyQ && !draw_disp.is_keyQ) { 1.93 + 1.94 + // Handle display window resizing (if any) 1.95 + if (main_disp.is_resized) main_disp.resize().display(image); 1.96 + draw_disp.resize(); 1.97 + 1.98 + if (main_disp.mouse_x>=0 && main_disp.mouse_y>=0) { // Mouse pointer is over the image 1.99 + 1.100 + const int 1.101 + xm = main_disp.mouse_x, // X-coordinate of the mouse pointer over the image 1.102 + ym = main_disp.mouse_y, // Y-coordinate of the mouse pointer over the image 1.103 + xl = xm*draw_disp.dimx()/main_disp.dimx(), // Corresponding X-coordinate of the hatched line 1.104 + x = xm*image.dimx()/main_disp.dimx(), // Corresponding X-coordinate of the pointed pixel in the image 1.105 + y = ym*image.dimy()/main_disp.dimy(); // Corresponding Y-coordinate of the pointex pixel in the image 1.106 + 1.107 + // Retrieve color component values at pixel (x,y) 1.108 + const unsigned int 1.109 + val_red = image(x,y,0), 1.110 + val_green = image(x,y,1), 1.111 + val_blue = image(x,y,2); 1.112 + 1.113 + // Create and display the image of the intensity profile 1.114 + CImg<unsigned char>(draw_disp.dimx(),draw_disp.dimy(),1,3,255). 1.115 + draw_grid(-50*100.0f/image.dimx(),-50*100.0f/256,0,0,false,true,black,0.2f,0xCCCCCCCC,0xCCCCCCCC). 1.116 + draw_axis(0,image.dimx()-1.0f,255.0f,0.0f,black). 1.117 + draw_graph(image.get_shared_line(y,0,0),red,1,1,0,255,1). 1.118 + draw_graph(image.get_shared_line(y,0,1),green,1,1,0,255,1). 1.119 + draw_graph(image.get_shared_line(y,0,2),blue,1,1,0,255,1). 1.120 + draw_text(30,5,"Pixel (%d,%d)={%d %d %d}",black,0,1,11, 1.121 + main_disp.mouse_x,main_disp.mouse_y,val_red,val_green,val_blue). 1.122 + draw_line(xl,0,xl,draw_disp.dimy()-1,black,0.5f,hatch=cimg::rol(hatch)). 1.123 + display(draw_disp); 1.124 + } else 1.125 + // else display a text in the profile display window. 1.126 + CImg<unsigned char>(draw_disp.dimx(),draw_disp.dimy()).fill(255). 1.127 + draw_text(draw_disp.dimx()/2-110,draw_disp.dimy()/2-5,"Mouse pointer is outside the image",black).display(draw_disp); 1.128 + 1.129 + // Temporize event loop 1.130 + cimg::wait(20); 1.131 + } 1.132 + 1.133 + return 0; 1.134 +}