1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/PTdecode/CImg-1.3.0/examples/generate_loop_macros.cpp Mon Aug 03 14:09:20 2009 +0100 1.3 @@ -0,0 +1,343 @@ 1.4 +/* 1.5 + # 1.6 + # File : generate_loop_macros.cpp 1.7 + # ( C++ source file ) 1.8 + # 1.9 + # Description : Generate C++ macros to deal with MxN[xP] neighborhood 1.10 + # loops within the CImg Library. 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.h" 1.49 +using namespace cimg_library; 1.50 + 1.51 +// The lines below are necessary when using a non-standard compiler as visualcpp6. 1.52 +#ifdef cimg_use_visualcpp6 1.53 +#define std 1.54 +#endif 1.55 + 1.56 +// Generate macro(s) 'cimg_forN(i,bound)' 1.57 +//---------------------------------------- 1.58 +void generate_forN(const unsigned int N) { 1.59 + if (N>=2) { 1.60 + const unsigned int Nn = N/2, Np = Nn-((N+1)%2); 1.61 + std::printf("#define cimg_for%u(bound,i) for (int i = 0, \\\n",N); 1.62 + { for (unsigned int k=0; k<Np; ++k) std::printf(" _p%u##i = 0,",Np-k); } 1.63 + std::printf(" \\\n"); 1.64 + { for (unsigned int k=1; k<=Nn; ++k) std::printf(" _n%u##i = %u>=(int)(bound)?(int)(bound)-1:%u%c \\\n",k,k,k,k==Nn?';':','); } 1.65 + std::printf(" _n%u##i<(int)(bound) || ",Nn); 1.66 + { for (unsigned int k=Nn-1; k>=1; --k) std::printf("_n%u##i==--_n%u##i || ",k,k+1); } 1.67 + std::printf("\\\n i==("); 1.68 + { for (unsigned int k=Nn; k>=2; --k) std::printf("_n%u##i = ",k); } 1.69 + std::printf("--_n1##i); \\\n "); 1.70 + { for (unsigned int k=Np; k>=2; --k) std::printf("_p%u##i = _p%u##i, ",k,k-1); } 1.71 + if (Np) std::printf("_p1##i = i++, \\\n "); 1.72 + else std::printf(" ++i, "); 1.73 + { for (unsigned int k=1; k<Nn; ++k) std::printf("++_n%u##i, ",k); } 1.74 + std::printf("++_n%u##i)\n\n",Nn); 1.75 + 1.76 + std::printf("#define cimg_for%uX(img,x) cimg_for%u((img).width,x)\n",N,N); 1.77 + std::printf("#define cimg_for%uY(img,y) cimg_for%u((img).height,y)\n",N,N); 1.78 + std::printf("#define cimg_for%uZ(img,z) cimg_for%u((img).depth,z)\n",N,N); 1.79 + std::printf("#define cimg_for%uV(img,v) cimg_for%u((img).dim,v)\n",N,N); 1.80 + std::printf("#define cimg_for%uXY(img,x,y) cimg_for%uY(img,y) cimg_for%uX(img,x)\n",N,N,N); 1.81 + std::printf("#define cimg_for%uXZ(img,x,z) cimg_for%uZ(img,z) cimg_for%uX(img,x)\n",N,N,N); 1.82 + std::printf("#define cimg_for%uXV(img,x,v) cimg_for%uV(img,v) cimg_for%uX(img,x)\n",N,N,N); 1.83 + std::printf("#define cimg_for%uYZ(img,y,z) cimg_for%uZ(img,z) cimg_for%uY(img,y)\n",N,N,N); 1.84 + std::printf("#define cimg_for%uYV(img,y,v) cimg_for%uV(img,v) cimg_for%uY(img,y)\n",N,N,N); 1.85 + std::printf("#define cimg_for%uZV(img,z,v) cimg_for%uV(img,v) cimg_for%uZ(img,z)\n",N,N,N); 1.86 + std::printf("#define cimg_for%uXYZ(img,x,y,z) cimg_for%uZ(img,z) cimg_for%uXY(img,x,y)\n",N,N,N); 1.87 + std::printf("#define cimg_for%uXZV(img,x,z,v) cimg_for%uV(img,v) cimg_for%uXZ(img,x,z)\n",N,N,N); 1.88 + std::printf("#define cimg_for%uYZV(img,y,z,v) cimg_for%uV(img,v) cimg_for%uYZ(img,y,z)\n",N,N,N); 1.89 + std::printf("#define cimg_for%uXYZV(img,x,y,z,v) cimg_for%uV(img,v) cimg_for%uXYZ(img,x,y,z)\n\n",N,N,N); 1.90 + } 1.91 +} 1.92 + 1.93 +// Generate macro(s) 'cimg_for_inN(i,bound)' 1.94 +//------------------------------------------ 1.95 +void generate_for_inN(const unsigned int N) { 1.96 + if (N>=2) { 1.97 + const unsigned int Nn = N/2, Np = Nn-((N+1)%2); 1.98 + std::printf("#define cimg_for_in%u(bound,i0,i1,i) for (int i = (int)(i0)<0?0:(int)(i0), \\\n",N); 1.99 + { for (unsigned int k=0; k<Np; ++k) std::printf(" _p%u##i = i-%u<0?0:i-%u, \\\n",Np-k,Np-k,Np-k); } 1.100 + { for (unsigned int k=1; k<=Nn; ++k) std::printf(" _n%u##i = i+%u>=(int)(bound)?(int)(bound)-1:i+%u%c \\\n",k,k,k,k==Nn?';':','); } 1.101 + std::printf(" i<=(int)(i1) && (_n%u##i<(int)(bound) || ",Nn); 1.102 + { for (unsigned int k=Nn-1; k>=1; --k) std::printf("_n%u##i==--_n%u##i || ",k,k+1); } 1.103 + std::printf("\\\n i==("); 1.104 + { for (unsigned int k=Nn; k>=2; --k) std::printf("_n%u##i = ",k); } 1.105 + std::printf("--_n1##i)); \\\n "); 1.106 + { for (unsigned int k=Np; k>=2; --k) std::printf("_p%u##i = _p%u##i, ",k,k-1); } 1.107 + if (Np) std::printf("_p1##i = i++, \\\n "); 1.108 + else std::printf(" ++i, "); 1.109 + { for (unsigned int k=1; k<Nn; ++k) std::printf("++_n%u##i, ",k); } 1.110 + std::printf("++_n%u##i)\n\n",Nn); 1.111 + } 1.112 + 1.113 + std::printf("#define cimg_for_in%uX(img,x0,x1,x) cimg_for_in%u((img).width,x0,x1,x)\n",N,N); 1.114 + std::printf("#define cimg_for_in%uY(img,y0,y1,y) cimg_for_in%u((img).height,y0,y1,y)\n",N,N); 1.115 + std::printf("#define cimg_for_in%uZ(img,z0,z1,z) cimg_for_in%u((img).depth,z0,z1,z)\n",N,N); 1.116 + std::printf("#define cimg_for_in%uV(img,v0,v1,v) cimg_for_in%u((img).dim,v0,v1,v)\n",N,N); 1.117 + std::printf("#define cimg_for_in%uXY(img,x0,y0,x1,y1,x,y) cimg_for_in%uY(img,y0,y1,y) cimg_for_in%uX(img,x0,x1,x)\n",N,N,N); 1.118 + std::printf("#define cimg_for_in%uXZ(img,x0,z0,x1,z1,x,z) cimg_for_in%uZ(img,z0,z1,z) cimg_for_in%uX(img,x0,x1,x)\n",N,N,N); 1.119 + std::printf("#define cimg_for_in%uXV(img,x0,v0,x1,v1,x,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uX(img,x0,x1,x)\n",N,N,N); 1.120 + std::printf("#define cimg_for_in%uYZ(img,y0,z0,y1,z1,y,z) cimg_for_in%uZ(img,z0,z1,z) cimg_for_in%uY(img,y0,y1,y)\n",N,N,N); 1.121 + std::printf("#define cimg_for_in%uYV(img,y0,v0,y1,v1,y,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uY(img,y0,y1,y)\n",N,N,N); 1.122 + std::printf("#define cimg_for_in%uZV(img,z0,v0,z1,v1,z,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uZ(img,z0,z1,z)\n",N,N,N); 1.123 + std::printf("#define cimg_for_in%uXYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_in%uZ(img,z0,z1,z) cimg_for_in%uXY(img,x0,y0,x1,y1,x,y)\n",N,N,N); 1.124 + std::printf("#define cimg_for_in%uXZV(img,x0,z0,v0,x1,y1,v1,x,z,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uXZ(img,x0,y0,x1,y1,x,z)\n",N,N,N); 1.125 + std::printf("#define cimg_for_in%uYZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uYZ(img,y0,z0,y1,z1,y,z)\n",N,N,N); 1.126 + std::printf("#define cimg_for_in%uXYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_in%uV(img,v0,v1,v) cimg_for_in%uXYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)\n\n",N,N,N); 1.127 + 1.128 +} 1.129 + 1.130 +// Generate macro 'cimg_forMxN[xP](img,x,y,z,v,I)' 1.131 +//------------------------------------------------ 1.132 +void generate_forMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.133 + char indx[16], indy[16], indz[16]; 1.134 + const int 1.135 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.136 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.137 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)), 1.138 + last = (int)(M*N*P); 1.139 + 1.140 + if (P>1) std::printf("#define cimg_for%ux%ux%u(img,x,y,z,v,I) \\\n cimg_for%u((img).depth,z)",M,N,P,P); 1.141 + else std::printf("#define cimg_for%ux%u(img,x,y,z,v,I) \\\n",M,N); 1.142 + if (N>1) std::printf(" cimg_for%u((img).height,y) ",N); 1.143 + else std::printf(" cimg_forY(img,y) "); 1.144 + 1.145 + std::printf("for (int x = 0%c \\\n",M>1?',':';'); 1.146 + { for (int k=Mp; k>=1; --k) std::printf(" _p%u##x = 0%s",k,k==1?", \\\n":","); } 1.147 + { for (int k=1; k<Mn; ++k) std::printf(" _n%u##x = %u>=((img).width)?(int)((img).width)-1:%u, \\\n",k,k,k); } 1.148 + 1.149 + if (M>1) { 1.150 + std::printf(" _n%u##x = (int)( \\\n ",Mn); 1.151 + { for (int k=0, z=-Pp; z<=Pn; ++z) 1.152 + for (int y=-Np; y<=Nn; ++y) { 1.153 + for (int x=-Mp; x<=0; ++x) { std::printf("%sI[%d] =",k && x==-Mp?" (":(x==-Mp?"(":" "),k); ++k; } 1.154 + k+=Mn; 1.155 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.156 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.157 + std::printf(" (img)(0,%sy,%sz,v))%s",indy,indz,k>=last?",":", \\\n"); 1.158 + }} 1.159 + 1.160 + std::printf(" \\\n"); 1.161 + for (int x=1; x<Mn; ++x) 1.162 + for (int z=-Pp; z<=Pn; ++z) 1.163 + for (int y=-Np; y<=Nn; ++y) { 1.164 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.165 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.166 + std::printf(" (I[%d] = (img)(_n%d##x,%sy,%sz,v)), \\\n",(Mp+x)+(y+Np)*M+(z+Pp)*M*N,x,indy,indz); 1.167 + } 1.168 + std::printf(" %u>=((img).width)?(int)((img).width)-1:%u); \\\n",Mn,Mn); 1.169 + } 1.170 + 1.171 + if (M>1) std::printf(" (_n%u##x",Mn); else std::printf(" (x"); 1.172 + std::printf("<(int)((img).width) && ( \\\n"); 1.173 + 1.174 + { for (int z=-Pp; z<=Pn; ++z) 1.175 + for (int y=-Np; y<=Nn; ++y) { 1.176 + if (M>1) std::sprintf(indx,"_n%d##",Mn); else indx[0]='\0'; 1.177 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.178 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.179 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v))%s",M-1+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz, 1.180 + z==Pn && y==Nn?",1))":", \\\n"); 1.181 + }} 1.182 + 1.183 + if (M>1) { 1.184 + std::printf(" || \\\n "); 1.185 + { for (int k=Mn-1; k>=1; --k) std::printf("_n%d##x==--_n%u##x || ",k,k+1); } 1.186 + std::printf("x==("); 1.187 + { for (int k=Mn; k>=2; --k) std::printf("_n%d##x = ",k); } 1.188 + std::printf("--_n1##x); \\\n"); 1.189 + } else std::printf("; \\\n"); 1.190 + 1.191 + if (M>1) { 1.192 + { for (unsigned int k=0, z=0; z<P; ++z) 1.193 + for (unsigned int y=0; y<N; ++y) { 1.194 + for (unsigned int x=0; x<M-1; ++x) { 1.195 + std::printf(" I[%d] = I[%d],",k,k+1); 1.196 + ++k; 1.197 + } 1.198 + std::printf(" \\\n"); 1.199 + ++k; 1.200 + }} 1.201 + std::printf(" "); 1.202 + { for (int k=Mp; k>=2; --k) std::printf("_p%d##x = _p%d##x, ",k,k-1); } 1.203 + if (M>2) std::printf("_p1##x = x++, "); else std::printf("++x, "); 1.204 + { for (int k=1; k<=Mn-1; ++k) std::printf("++_n%d##x, ",k); } 1.205 + std::printf("++_n%d##x)\n\n",Mn); 1.206 + } else std::printf(" ++x)\n\n"); 1.207 +} 1.208 + 1.209 +// Generate macro 'cimg_for_inMxN[xP](img,x,y,z,v,I)' 1.210 +//--------------------------------------------------- 1.211 +void generate_for_inMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.212 + char indx[16], indy[16], indz[16]; 1.213 + const int 1.214 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.215 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.216 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)); 1.217 + 1.218 + if (P>1) std::printf("#define cimg_for_in%ux%ux%u(img,x0,y0,z0,x1,y1,z1,x,y,z,v,I) \\\n cimg_for_in%u((img).depth,z0,z1,z)",M,N,P,P); 1.219 + else std::printf("#define cimg_for_in%ux%u(img,x0,y0,x1,y1,x,y,z,v,I) \\\n",M,N); 1.220 + if (N>1) std::printf(" cimg_for_in%u((img).height,y0,y1,y) ",N); 1.221 + else std::printf(" cimg_for_inY(img,y0,y1,y) "); 1.222 + 1.223 + std::printf("for (int x = (int)(x0)<0?0:(int)(x0)%c \\\n",M>1?',':';'); 1.224 + { for (int k=Mp; k>=1; --k) std::printf(" _p%u##x = x-%u<0?0:x-%u, \\\n",k,k,k); } 1.225 + { for (int k=1; k<Mn; ++k) std::printf(" _n%u##x = x+%u>=(int)((img).width)?(int)((img).width)-1:x+%u, \\\n",k,k,k); } 1.226 + 1.227 + if (M>1) { 1.228 + std::printf(" _n%u##x = (int)( \\\n",Mn); 1.229 + for (int x=-Mp; x<Mn; ++x) 1.230 + for (int z=-Pp; z<=Pn; ++z) 1.231 + for (int y=-Np; y<=Nn; ++y) { 1.232 + if (x<0) std::sprintf(indx,"_p%d##",-x); else if (x>0) std::sprintf(indx,"_n%d##",x); else indx[0]='\0'; 1.233 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.234 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.235 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v)), \\\n",(Mp+x)+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz); 1.236 + } 1.237 + std::printf(" x+%u>=(int)((img).width)?(int)((img).width)-1:x+%u); \\\n",Mn,Mn); 1.238 + } 1.239 + std::printf(" x<=(int)(x1) && ("); 1.240 + if (M>1) std::printf("(_n%u##x",Mn); else std::printf("(x"); 1.241 + std::printf("<(int)((img).width) && ( \\\n"); 1.242 + 1.243 + { for (int z=-Pp; z<=Pn; ++z) 1.244 + for (int y=-Np; y<=Nn; ++y) { 1.245 + if (M>1) std::sprintf(indx,"_n%d##",Mn); else indx[0]='\0'; 1.246 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.247 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.248 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v))%s",M-1+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz, 1.249 + z==Pn && y==Nn?",1))":", \\\n"); 1.250 + }} 1.251 + 1.252 + if (M>1) { 1.253 + std::printf(" || \\\n "); 1.254 + { for (int k=Mn-1; k>=1; --k) std::printf("_n%d##x==--_n%u##x || ",k,k+1); } 1.255 + std::printf("x==("); 1.256 + { for (int k=Mn; k>=2; --k) std::printf("_n%d##x = ",k); } 1.257 + std::printf("--_n1##x)); \\\n"); 1.258 + } else std::printf("); \\\n"); 1.259 + 1.260 + if (M>1) { 1.261 + { for (unsigned int k=0, z=0; z<P; ++z) 1.262 + for (unsigned int y=0; y<N; ++y) { 1.263 + for (unsigned int x=0; x<M-1; ++x) { 1.264 + std::printf(" I[%d] = I[%d],",k,k+1); 1.265 + ++k; 1.266 + } 1.267 + std::printf(" \\\n"); 1.268 + ++k; 1.269 + }} 1.270 + std::printf(" "); 1.271 + { for (int k=Mp; k>=2; --k) std::printf("_p%d##x = _p%d##x, ",k,k-1); } 1.272 + if (M>2) std::printf("_p1##x = x++, "); else std::printf("++x, "); 1.273 + { for (int k=1; k<=Mn-1; ++k) std::printf("++_n%d##x, ",k); } 1.274 + std::printf("++_n%d##x)\n\n",Mn); 1.275 + } else std::printf(" ++x)\n\n"); 1.276 +} 1.277 + 1.278 +// Generate macro 'cimg_getMxN[xP](img,x,y,z,v,I)' 1.279 +//------------------------------------------------ 1.280 +void generate_getMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.281 + const int 1.282 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.283 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.284 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)), 1.285 + last = M*N*P-1; 1.286 + if (P>1) std::printf("#define cimg_get%ux%ux%u(img,x,y,z,v,I) \\\n",M,N,P); 1.287 + else std::printf("#define cimg_get%ux%u(img,x,y,z,v,I) \\\n",M,N); 1.288 + char indx[16], indy[16], indz[16]; 1.289 + for (int k=0, z=-Pp; z<=Pn; ++z) 1.290 + for (int y=-Np; y<=Nn; ++y) 1.291 + for (int x=-Mp; x<=Mn; ++x) { 1.292 + if (x<0) std::sprintf(indx,"_p%d##",-x); else if (x>0) std::sprintf(indx,"_n%d##",x); else indx[0]='\0'; 1.293 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.294 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.295 + std::printf(" I[%u] = (img)(%sx,%sy,%sz,v)%s",k,indx,indy,indz, 1.296 + k==last?";\n\n":(x==Mn?", \\\n":",")); 1.297 + ++k; 1.298 + } 1.299 +} 1.300 + 1.301 +//----------------- 1.302 +// Main Procedure 1.303 +//----------------- 1.304 +int main(int argc, char **argv) { 1.305 + 1.306 + cimg_usage("Generate C++ macros to deal with MxN[xP] neighborhood loops within the CImg Library"); 1.307 + 1.308 + // Read command line arguments 1.309 + //---------------------------- 1.310 + const char *const size = cimg_option("-s","5x4","Size of the neighborhood"); 1.311 + const bool do_forN = cimg_option("-forN",true,"Generate 'cimg_forN()'"); 1.312 + const bool do_for_inN = cimg_option("-for_inN",true,"Generate 'cimg_for_inN()'"); 1.313 + const bool do_for = cimg_option("-for",true,"Generate 'cimg_forMxNxP()'"); 1.314 + const bool do_for_in = cimg_option("-for_in",true,"Generate 'cimg_for_inMxNxP()'"); 1.315 + const bool do_get = cimg_option("-get",true,"Generate 'cimg_getMxNxP()'"); 1.316 + if (cimg_option("-h",false,0)) std::exit(0); 1.317 + 1.318 + unsigned int M = 1, N = 1 , P = 1; 1.319 + std::sscanf(size,"%u%*c%u%*c%u",&M,&N,&P); 1.320 + if (!M || !N || !P || (M==1 && N==1 && P==1)) { 1.321 + std::fprintf(stderr,"\n%s : Error, bad neighborhood size '%s'\n",argv[0],size); 1.322 + std::exit(0); 1.323 + } 1.324 + if (!do_forN && !do_get && !do_for) return 0; 1.325 + 1.326 + if (P>1) 1.327 + std::printf("// Define %ux%ux%u loop macros for CImg\n" 1.328 + "//-------------------------------------\n",M,N,P); 1.329 + else 1.330 + std::printf("// Define %ux%u loop macros for CImg\n" 1.331 + "//----------------------------------\n",M,N); 1.332 + 1.333 + if (do_forN) { 1.334 + if (N>1) generate_forN(N); 1.335 + if (P>1 && P!=N) generate_forN(P); 1.336 + } 1.337 + if (do_for_inN) { 1.338 + if (N>1) generate_for_inN(N); 1.339 + if (P>1 && P!=N) generate_for_inN(P); 1.340 + } 1.341 + if (do_for) generate_forMxNxP(M,N,P); 1.342 + if (do_for_in) generate_for_inMxNxP(M,N,P); 1.343 + if (do_get) generate_getMxNxP(M,N,P); 1.344 + 1.345 + return 0; 1.346 +}