1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/use_draw_gradient.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/use_draw_gradient.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,147 @@ 1.5 +/* 1.6 + # 1.7 + # File : use_draw_gradient.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : Example of use for the CImg plugin 'plugins/draw_gradient.h'. 1.11 + # This file is a part of the CImg Library project. 1.12 + # ( http://cimg.sourceforge.net ) 1.13 + # 1.14 + # Copyright : Jerome Boulanger 1.15 + # ( http://www.ricam.oeaw.ac.at/people/page.cgi?firstn=Jerome;lastn=Boulanger ) 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 +#define cimg_plugin "plugins/draw_gradient.h" 1.49 +#include "CImg.h" 1.50 +using namespace cimg_library; 1.51 + 1.52 +// The lines below are necessary when using a non-standard compiler as visualcpp6. 1.53 +#ifdef cimg_use_visualcpp6 1.54 +#define std 1.55 +#endif 1.56 +#ifdef min 1.57 +#undef min 1.58 +#undef max 1.59 +#endif 1.60 + 1.61 +// Main procedure 1.62 +//--------------- 1.63 +int main(int argc,char **argv) { 1.64 + 1.65 + // Read command line arguments 1.66 + //---------------------------- 1.67 + cimg_usage("Example of the use of draw_gradient CImg plugin"); 1.68 + const char *const file_i = cimg_option("-i",(char*)0,"Input image"); 1.69 + const int shape = cimg_option("-s",1,"shape [0,6]"); 1.70 + const int profile = cimg_option("-p",0,"profile [0,7]"); 1.71 + 1.72 + // Define an image 1.73 + CImg<unsigned char> img; 1.74 + if (file_i) img.load(file_i).resize(-100,-100,-100,3); 1.75 + else img.assign(300,200,1,3,0); 1.76 + 1.77 + // Define the color of the gradient 1.78 + CImg<unsigned char> col(3); 1.79 + const unsigned char col1[3] = { 0,0,255 }, col2[3] = { 255,255,255 }; 1.80 + CImgDisplay disp(img,"Click and drag to create color gradient",0); 1.81 + while (!disp.is_closed && !disp.key) { 1.82 + 1.83 + // Get a vector direction from the user. 1.84 + const CImg<int> selection = img.get_select(disp,1); 1.85 + 1.86 + // Draw a gradient using the selected coordinated. 1.87 + col.rand(100,255); 1.88 + printf("Gradient with %s from color (%d,%d,%d) to (%d,%d,%d)\n", 1.89 + CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2),col1[0],col1[1],col2[2]); 1.90 + img.draw_gradient(selection(0),selection(1),selection(3),selection(4), 1.91 + col.ptr(),col1,shape,profile,.7f).display(disp); 1.92 + } 1.93 + 1.94 + // color 0 to transparency 1.95 + if (file_i) img.load(file_i).resize(-100,-100,-100,3); 1.96 + else img.assign(300,200,1,3,0); 1.97 + img.display(disp); 1.98 + disp.show().flush(); 1.99 + while (!disp.is_closed && !disp.key) { 1.100 + 1.101 + // Get a vector direction from the user. 1.102 + const CImg<int> selection = img.get_select(disp,1); 1.103 + 1.104 + // Draw a gradient using the selected coordinated. 1.105 + col.rand(100,255); 1.106 + printf("Gradient with %s from color (%d,%d,%d) to transparency\n", 1.107 + CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2)); 1.108 + img.draw_gradient(selection(0),selection(1),selection(3),selection(4), 1.109 + col.ptr(),0,shape,profile,.7f).display(disp); 1.110 + } 1.111 + 1.112 + 1.113 + // transparency to color 1 1.114 + if (file_i) img.load(file_i).resize(-100,-100,-100,3); 1.115 + else img.assign(300,200,1,3,0); 1.116 + img.display(disp); 1.117 + disp.show().flush(); 1.118 + while (!disp.is_closed && !disp.key) { 1.119 + 1.120 + // Get a vector direction from the user. 1.121 + const CImg<int> selection = img.get_select(disp,1); 1.122 + 1.123 + // Draw a gradient using the selected coordinated. 1.124 + col.rand(100,255); 1.125 + printf("Gradient with %s from transparency to color (%d,%d,%d)\n", 1.126 + CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2)); 1.127 + img.draw_gradient(selection(0),selection(1),selection(3),selection(4), 1.128 + 0,col.ptr(),shape,profile,.7f).display(disp); 1.129 + } 1.130 + 1.131 + // random 1.132 + if (file_i) img.load(file_i).resize(-100,-100,-100,3); 1.133 + else img.assign(300,200,1,3,0); 1.134 + disp.set_title("Random color gradient").show().flush(); 1.135 + CImg<unsigned char> visu(img); 1.136 + visu.display(disp); 1.137 + while (!disp.is_closed && !disp.key) { 1.138 + const int 1.139 + x = (int)(cimg::rand()*visu.dimx()), 1.140 + y = (int)(cimg::rand()*visu.dimy()), 1.141 + rx = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)), 1.142 + ry = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)); 1.143 + col.rand(64,255); 1.144 + img.draw_gradient(x,y,x+rx,y+ry,col.ptr(),0,shape,profile,.4f); 1.145 + visu = img; 1.146 + visu.draw_text(10,10,"%.1ffps",col2,0,1,11,disp.frames_per_second()).display(disp); 1.147 + if (disp.is_resized) disp.resize(); 1.148 + } 1.149 + 1.150 + return 0; 1.151 +}