Mon, 03 Aug 2009 23:39:53 +0100
add basic test routine for Ptouch library
1 /*
2 #
3 # File : use_draw_gradient.cpp
4 # ( C++ source file )
5 #
6 # Description : Example of use for the CImg plugin 'plugins/draw_gradient.h'.
7 # This file is a part of the CImg Library project.
8 # ( http://cimg.sourceforge.net )
9 #
10 # Copyright : Jerome Boulanger
11 # ( http://www.ricam.oeaw.ac.at/people/page.cgi?firstn=Jerome;lastn=Boulanger )
12 #
13 # License : CeCILL v2.0
14 # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
15 #
16 # This software is governed by the CeCILL license under French law and
17 # abiding by the rules of distribution of free software. You can use,
18 # modify and/ or redistribute the software under the terms of the CeCILL
19 # license as circulated by CEA, CNRS and INRIA at the following URL
20 # "http://www.cecill.info".
21 #
22 # As a counterpart to the access to the source code and rights to copy,
23 # modify and redistribute granted by the license, users are provided only
24 # with a limited warranty and the software's author, the holder of the
25 # economic rights, and the successive licensors have only limited
26 # liability.
27 #
28 # In this respect, the user's attention is drawn to the risks associated
29 # with loading, using, modifying and/or developing or reproducing the
30 # software by the user in light of its specific status of free software,
31 # that may mean that it is complicated to manipulate, and that also
32 # therefore means that it is reserved for developers and experienced
33 # professionals having in-depth computer knowledge. Users are therefore
34 # encouraged to load and test the software's suitability as regards their
35 # requirements in conditions enabling the security of their systems and/or
36 # data to be ensured and, more generally, to use and operate it in the
37 # same conditions as regards security.
38 #
39 # The fact that you are presently reading this means that you have had
40 # knowledge of the CeCILL license and that you accept its terms.
41 #
42 */
44 #define cimg_plugin "plugins/draw_gradient.h"
45 #include "CImg.h"
46 using namespace cimg_library;
48 // The lines below are necessary when using a non-standard compiler as visualcpp6.
49 #ifdef cimg_use_visualcpp6
50 #define std
51 #endif
52 #ifdef min
53 #undef min
54 #undef max
55 #endif
57 // Main procedure
58 //---------------
59 int main(int argc,char **argv) {
61 // Read command line arguments
62 //----------------------------
63 cimg_usage("Example of the use of draw_gradient CImg plugin");
64 const char *const file_i = cimg_option("-i",(char*)0,"Input image");
65 const int shape = cimg_option("-s",1,"shape [0,6]");
66 const int profile = cimg_option("-p",0,"profile [0,7]");
68 // Define an image
69 CImg<unsigned char> img;
70 if (file_i) img.load(file_i).resize(-100,-100,-100,3);
71 else img.assign(300,200,1,3,0);
73 // Define the color of the gradient
74 CImg<unsigned char> col(3);
75 const unsigned char col1[3] = { 0,0,255 }, col2[3] = { 255,255,255 };
76 CImgDisplay disp(img,"Click and drag to create color gradient",0);
77 while (!disp.is_closed && !disp.key) {
79 // Get a vector direction from the user.
80 const CImg<int> selection = img.get_select(disp,1);
82 // Draw a gradient using the selected coordinated.
83 col.rand(100,255);
84 printf("Gradient with %s from color (%d,%d,%d) to (%d,%d,%d)\n",
85 CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2),col1[0],col1[1],col2[2]);
86 img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
87 col.ptr(),col1,shape,profile,.7f).display(disp);
88 }
90 // color 0 to transparency
91 if (file_i) img.load(file_i).resize(-100,-100,-100,3);
92 else img.assign(300,200,1,3,0);
93 img.display(disp);
94 disp.show().flush();
95 while (!disp.is_closed && !disp.key) {
97 // Get a vector direction from the user.
98 const CImg<int> selection = img.get_select(disp,1);
100 // Draw a gradient using the selected coordinated.
101 col.rand(100,255);
102 printf("Gradient with %s from color (%d,%d,%d) to transparency\n",
103 CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2));
104 img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
105 col.ptr(),0,shape,profile,.7f).display(disp);
106 }
109 // transparency to color 1
110 if (file_i) img.load(file_i).resize(-100,-100,-100,3);
111 else img.assign(300,200,1,3,0);
112 img.display(disp);
113 disp.show().flush();
114 while (!disp.is_closed && !disp.key) {
116 // Get a vector direction from the user.
117 const CImg<int> selection = img.get_select(disp,1);
119 // Draw a gradient using the selected coordinated.
120 col.rand(100,255);
121 printf("Gradient with %s from transparency to color (%d,%d,%d)\n",
122 CImg<>::get_gradient_str(shape,profile),col(0),col(1),col(2));
123 img.draw_gradient(selection(0),selection(1),selection(3),selection(4),
124 0,col.ptr(),shape,profile,.7f).display(disp);
125 }
127 // random
128 if (file_i) img.load(file_i).resize(-100,-100,-100,3);
129 else img.assign(300,200,1,3,0);
130 disp.set_title("Random color gradient").show().flush();
131 CImg<unsigned char> visu(img);
132 visu.display(disp);
133 while (!disp.is_closed && !disp.key) {
134 const int
135 x = (int)(cimg::rand()*visu.dimx()),
136 y = (int)(cimg::rand()*visu.dimy()),
137 rx = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1)),
138 ry = (int)((cimg::rand()*25+5)*(cimg::rand()>.5?-1:1));
139 col.rand(64,255);
140 img.draw_gradient(x,y,x+rx,y+ry,col.ptr(),0,shape,profile,.4f);
141 visu = img;
142 visu.draw_text(10,10,"%.1ffps",col2,0,1,11,disp.frames_per_second()).display(disp);
143 if (disp.is_resized) disp.resize();
144 }
146 return 0;
147 }