1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/PTdecode/CImg-1.3.0/html/reference/group__cimg__options.html Mon Aug 03 14:09:20 2009 +0100 1.3 @@ -0,0 +1,197 @@ 1.4 + xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 1.5 +<head> 1.6 +<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta> 1.7 +<title>The CImg Library - C++ Template Image Processing Toolkit</title> 1.8 +<meta content="David Tschumperle" name="author"></meta> 1.9 +<link rel="shortcut icon" type="image/x-icon" href="http://cimg.sourceforge.net/favicon.ico"></link> 1.10 +<link rel="icon" type="image/png" href="favicon.png"></link> 1.11 +<link href="doxygen.css" rel="stylesheet" type="text/css"> 1.12 +<link href="tabs.css" rel="stylesheet" type="text/css"> 1.13 +<style type="text/css"> 1.14 +<!-- 1.15 +body {background-color:white; font-family:sans-serif; } 1.16 +a:active{text-decoration:none; color:#303090} 1.17 +a:link{text-decoration:none; color:#303090} 1.18 +a:visited{text-decoration:none; color:#303090} 1.19 +a:hover{text-decoration:underline; color:#4E9F71} 1.20 +--> 1.21 +</style> 1.22 +<script language="JavaScript" type="text/javascript"> 1.23 + <!-- Original: Eric King (eric_andrew_king@hotmail.com) is used to display images in popup windows --> 1.24 + <!-- Web Site: http://redrival.com/eak/ --> 1.25 + <!-- This script and many more are available free online at --> 1.26 + <!-- The JavaScript Source!! http://javascript.internet.com --> 1.27 + <!-- Begin 1.28 + function NewWindow(mypage, myname, w, h, scroll) { 1.29 + var winl = (screen.width - w) / 2; 1.30 + var wint = (screen.height - h) / 2; 1.31 + winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable' 1.32 + win = window.open(mypage, myname, winprops) 1.33 + if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); } 1.34 + } 1.35 + // End --> 1.36 +</script> 1.37 +</head> 1.38 +<body> 1.39 + <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"> 1.40 + <tbody><tr><td> 1.41 + <hr noshade="noshade" size="1" width="90%"></hr> 1.42 + <center> 1.43 + <br/> 1.44 + <a href="http://cimg.sourceforge.net"><img src="http://cimg.sourceforge.net/img/CImgLogo.jpg" alt="" border="0"></img></a><br/> 1.45 + <br/> 1.46 + </center> 1.47 + <hr noshade="noshade" size="1" width="90%"></hr> 1.48 + <center> 1.49 + <table bgcolor="#EEEEFF" style="width: 90%; text-align: left; margin-left: auto; margin-right: auto;" border="0" cellpadding="3" cellspacing="0"> 1.50 + <tbody><tr><td style="text-align: center; vertical-align: top;"> 1.51 + <font color="#FFFFFF" face="Arial,Helvetica" size="-1"> 1.52 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/index.shtml">Main</a> <b>]</b> 1.53 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/news.shtml">News</a><b>] </b> 1.54 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/download.shtml">Download</a> <b>]</b> 1.55 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/screenshots.shtml">Screenshots</a> <b>]</b> 1.56 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__faq.html">FAQ</a> <b>]</b> 1.57 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/group__cimg__tutorial.html">Tutorial</a> <b>]</b> 1.58 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/reference/index.html">Documentation</a> <b>]</b> 1.59 + <b>[</b> <a target="_parent" href="http://sourceforge.net/forum/forum.php?forum_id=334630">Forum</a> <b>]</b> 1.60 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/chat.shtml">Chat</a> <b>]</b> 1.61 + <b>[</b> <a target="_parent" href="http://cimg.sourceforge.net/links.shtml">Links</a> <b>]</b> 1.62 + </font> 1.63 + </td></tr></tbody> 1.64 + </table> 1.65 + </center> 1.66 + <hr noshade="noshade" size="1" width="90%"></hr> 1.67 + </td></tr></tbody> 1.68 +</table> 1.69 +<!-- Generated by Doxygen 1.5.7.1 --> 1.70 +<script type="text/javascript"> 1.71 +<!-- 1.72 +function changeDisplayState (e){ 1.73 + var num=this.id.replace(/[^[0-9]/g,''); 1.74 + var button=this.firstChild; 1.75 + var sectionDiv=document.getElementById('dynsection'+num); 1.76 + if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){ 1.77 + sectionDiv.style.display='block'; 1.78 + button.src='open.gif'; 1.79 + }else{ 1.80 + sectionDiv.style.display='none'; 1.81 + button.src='closed.gif'; 1.82 + } 1.83 +} 1.84 +function initDynSections(){ 1.85 + var divs=document.getElementsByTagName('div'); 1.86 + var sectionCounter=1; 1.87 + for(var i=0;i<divs.length-1;i++){ 1.88 + if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){ 1.89 + var header=divs[i]; 1.90 + var section=divs[i+1]; 1.91 + var button=header.firstChild; 1.92 + if (button!='IMG'){ 1.93 + divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild); 1.94 + button=document.createElement('img'); 1.95 + divs[i].insertBefore(button,divs[i].firstChild); 1.96 + } 1.97 + header.style.cursor='pointer'; 1.98 + header.onclick=changeDisplayState; 1.99 + header.id='dynheader'+sectionCounter; 1.100 + button.src='closed.gif'; 1.101 + section.id='dynsection'+sectionCounter; 1.102 + section.style.display='none'; 1.103 + section.style.marginLeft='14px'; 1.104 + sectionCounter++; 1.105 + } 1.106 + } 1.107 +} 1.108 +window.onload = initDynSections; 1.109 +--> 1.110 +</script> 1.111 +<div class="navigation" id="top"> 1.112 + <div class="tabs"> 1.113 + <ul> 1.114 + <li><a href="index.html"><span>Main Page</span></a></li> 1.115 + <li><a href="modules.html"><span>Modules</span></a></li> 1.116 + <li><a href="namespaces.html"><span>Namespaces</span></a></li> 1.117 + <li><a href="annotated.html"><span>Classes</span></a></li> 1.118 + </ul> 1.119 + </div> 1.120 +</div> 1.121 +<div class="contents"> 1.122 +<h1>Retrieving Command Line Arguments.</h1><table border="0" cellpadding="0" cellspacing="0"> 1.123 +<tr><td></td></tr> 1.124 +</table> 1.125 +The CImg library offers facilities to retrieve command line arguments in a console-based program, as it is a commonly needed operation. Three macros <code>cimg_usage()</code>, <code>cimg_help()</code> and <code>cimg_option()</code> are defined for this purpose. Using these macros allows to easily retrieve options values from the command line. Invoking the compiled executable with the option <code>-h</code> or <code>--help</code> will automatically display the program usage, followed by the list of requested options.<h2><a class="anchor" name="so1"> 1.126 +The cimg_usage() macro</a></h2> 1.127 +The macro <code>cimg_usage(usage)</code> may be used to describe the program goal and usage. It is generally inserted one time after the <code>int main(int argc,char **argv)</code> definition.<p> 1.128 +<dl compact><dt><b>Parameters:</b></dt><dd> 1.129 + <table border="0" cellspacing="2" cellpadding="0"> 1.130 + <tr><td valign="top"></td><td valign="top"><em>usage</em> </td><td>: A string describing the program goal and usage. </td></tr> 1.131 + </table> 1.132 +</dl> 1.133 +<dl class="pre" compact><dt><b>Precondition:</b></dt><dd>The function where <code>cimg_usage()</code> is used must have correctly defined <code>argc</code> and <code>argv</code> variables.</dd></dl> 1.134 +<h2><a class="anchor" name="so1_5"> 1.135 +The cimg_help() macro</a></h2> 1.136 +The macro <code>cimg_help(str)</code> will display the string <code>str</code> only if the <code>-help</code> or <code>--help</code> option are invoked when running the programm.<h2><a class="anchor" name="so2"> 1.137 +The cimg_option() macro</a></h2> 1.138 +The macro <code>cimg_option(name,default,usage)</code> may be used to retrieve an option value from the command line.<p> 1.139 +<dl compact><dt><b>Parameters:</b></dt><dd> 1.140 + <table border="0" cellspacing="2" cellpadding="0"> 1.141 + <tr><td valign="top"></td><td valign="top"><em>name</em> </td><td>: The name of the option to be retrieved from the command line. </td></tr> 1.142 + <tr><td valign="top"></td><td valign="top"><em>default</em> </td><td>: The default value returned by the macro if no options <code>name</code> has been specified when running the program. </td></tr> 1.143 + <tr><td valign="top"></td><td valign="top"><em>usage</em> </td><td>: A brief explanation of the option. If <code>usage==0</code>, the option won't appear on the option list when invoking the executable with options <code>-h</code> or <code>--help</code> (hidden option).</td></tr> 1.144 + </table> 1.145 +</dl> 1.146 +<dl class="return" compact><dt><b>Returns:</b></dt><dd><code>cimg_option()</code> returns an object that has the <em>same</em> <em>type</em> than the default value <code>default</code>. The return value is equal to the one specified on the command line. If no such option have been specified, the return value is equal to the default value <code>default</code>. Warning, this can be confusing in some situations (look at the end of the next section). </dd></dl> 1.147 +<dl class="pre" compact><dt><b>Precondition:</b></dt><dd>The function where <code>cimg_option()</code> is used must have correctly defined <code>argc</code> and <code>argv</code> variables.</dd></dl> 1.148 +<h2><a class="anchor" name="so3"> 1.149 +Example of use</a></h2> 1.150 +The code below uses the macros <code>cimg_usage()</code> and <code>cimg_option()</code>. It loads an image, smoothes it an quantifies it with a specified number of values. <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include "CImg.h"</span> 1.151 + <span class="keyword">using namespace </span>cimg_library; 1.152 + <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc,<span class="keywordtype">char</span> **argv) { 1.153 + cimg_usage(<span class="stringliteral">"Retrieve command line arguments"</span>); 1.154 + <span class="keyword">const</span> <span class="keywordtype">char</span>* filename = cimg_option(<span class="stringliteral">"-i"</span>,<span class="stringliteral">"image.gif"</span>,<span class="stringliteral">"Input image file"</span>); 1.155 + <span class="keyword">const</span> <span class="keywordtype">char</span>* output = cimg_option(<span class="stringliteral">"-o"</span>,(<span class="keywordtype">char</span>*)0,<span class="stringliteral">"Output image file"</span>); 1.156 + <span class="keyword">const</span> <span class="keywordtype">double</span> sigma = cimg_option(<span class="stringliteral">"-s"</span>,1.0,<span class="stringliteral">"Standard variation of the gaussian smoothing"</span>); 1.157 + <span class="keyword">const</span> <span class="keywordtype">int</span> nblevels = cimg_option(<span class="stringliteral">"-n"</span>,16,<span class="stringliteral">"Number of quantification levels"</span>); 1.158 + <span class="keyword">const</span> <span class="keywordtype">bool</span> hidden = cimg_option(<span class="stringliteral">"-hidden"</span>,<span class="keyword">false</span>,0); <span class="comment">// This is a hidden option</span> 1.159 + 1.160 + CImg<unsigned char> img(filename); 1.161 + img.blur(sigma).quantize(nblevels); 1.162 + <span class="keywordflow">if</span> (output) img.save(output); <span class="keywordflow">else</span> img.display(<span class="stringliteral">"Output image"</span>); 1.163 + <span class="keywordflow">if</span> (hidden) std::fprintf(stderr,<span class="stringliteral">"You found me !\n"</span>); 1.164 + <span class="keywordflow">return</span> 0; 1.165 + } 1.166 +</pre></div><p> 1.167 +Invoking the corresponding executable with <code>test -h -hidden -n 20 -i foo.jpg</code> will display : <div class="fragment"><pre class="fragment"> 1.168 + ./test -h -hidden -n 20 -i foo.jpg 1.169 + 1.170 + test : Retrieve command line arguments (Oct 16 2004, 12:34:26) 1.171 + 1.172 + -i = foo.jpg : Input image file 1.173 + -o = 0 : Output image file 1.174 + -s = 1 : Standard variation of the gaussian smoothing 1.175 + -n = 20 : Number of quantification levels 1.176 + 1.177 + You found me ! 1.178 +</pre></div><p> 1.179 +<dl class="warning" compact><dt><b>Warning:</b></dt><dd>As the type of object returned by the macro <code>cimg_option(option,default,usage)</code> is defined by the type of <code>default</code>, undesired casts may appear when writting code such as : <div class="fragment"><pre class="fragment"> <span class="keyword">const</span> <span class="keywordtype">double</span> sigma = cimg_option(<span class="stringliteral">"-val"</span>,0,<span class="stringliteral">"A floating point value"</span>); 1.180 +</pre></div> In this case, <code>sigma</code> will always be equal to an integer (since the default value <code>0</code> is an integer). When passing a float value on the command line, a <em>float</em> <em>to</em> <em>integer</em> cast is then done, truncating the given parameter to an integer value (this is surely not a desired behavior). You must specify <code>0.0</code> as the default value in this case.</dd></dl> 1.181 +<h2><a class="anchor" name="so4"> 1.182 +How to learn more about command line options ?</a></h2> 1.183 +You should take a look at the examples <code>examples/gmic.cpp</code> provided in the CImg Library package. This is a command line based image converter which intensively uses the <code>cimg_option()</code> and <code>cimg_usage()</code> macros to retrieve command line parameters. </div> 1.184 +<hr noshade="noshade" size="1" width="100%"> 1.185 +<a href="http://sourceforge.net"> 1.186 +<img src="http://sourceforge.net/sflogo.php?group_id=96492&type=3" border="0" height="37" width="125"></img> 1.187 +</a> 1.188 +<!-- Start of StatCounter Code --> 1.189 +<script type="text/javascript" language="javascript"> 1.190 +<!-- 1.191 +var sc_project=895001; 1.192 +var sc_invisible=1; 1.193 +var sc_partition=7; 1.194 +var sc_security="5ea85181"; 1.195 +//--> 1.196 +</script> 1.197 +<script type="text/javascript" language="javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img src="http://c8.statcounter.com/counter.php?sc_project=895001&java=0&security=5ea85181&invisible=1" alt="counter stats" border="0"></a> </noscript> 1.198 +<!-- End of StatCounter Code --> 1.199 +</body> 1.200 +</html>