1.1 diff -r 5edfbd3e7a46 -r 1204ebf9340d PTdecode/CImg-1.3.0/examples/generate_loop_macros.cpp 1.2 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 +++ b/PTdecode/CImg-1.3.0/examples/generate_loop_macros.cpp Mon Aug 03 14:09:20 2009 +0100 1.4 @@ -0,0 +1,343 @@ 1.5 +/* 1.6 + # 1.7 + # File : generate_loop_macros.cpp 1.8 + # ( C++ source file ) 1.9 + # 1.10 + # Description : Generate C++ macros to deal with MxN[xP] neighborhood 1.11 + # loops within the CImg Library. 1.12 + # This file is a part of the CImg Library project. 1.13 + # ( http://cimg.sourceforge.net ) 1.14 + # 1.15 + # Copyright : David Tschumperle 1.16 + # ( http://www.greyc.ensicaen.fr/~dtschump/ ) 1.17 + # 1.18 + # License : CeCILL v2.0 1.19 + # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html ) 1.20 + # 1.21 + # This software is governed by the CeCILL license under French law and 1.22 + # abiding by the rules of distribution of free software. You can use, 1.23 + # modify and/ or redistribute the software under the terms of the CeCILL 1.24 + # license as circulated by CEA, CNRS and INRIA at the following URL 1.25 + # "http://www.cecill.info". 1.26 + # 1.27 + # As a counterpart to the access to the source code and rights to copy, 1.28 + # modify and redistribute granted by the license, users are provided only 1.29 + # with a limited warranty and the software's author, the holder of the 1.30 + # economic rights, and the successive licensors have only limited 1.31 + # liability. 1.32 + # 1.33 + # In this respect, the user's attention is drawn to the risks associated 1.34 + # with loading, using, modifying and/or developing or reproducing the 1.35 + # software by the user in light of its specific status of free software, 1.36 + # that may mean that it is complicated to manipulate, and that also 1.37 + # therefore means that it is reserved for developers and experienced 1.38 + # professionals having in-depth computer knowledge. Users are therefore 1.39 + # encouraged to load and test the software's suitability as regards their 1.40 + # requirements in conditions enabling the security of their systems and/or 1.41 + # data to be ensured and, more generally, to use and operate it in the 1.42 + # same conditions as regards security. 1.43 + # 1.44 + # The fact that you are presently reading this means that you have had 1.45 + # knowledge of the CeCILL license and that you accept its terms. 1.46 + # 1.47 +*/ 1.48 + 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 + 1.57 +// Generate macro(s) 'cimg_forN(i,bound)' 1.58 +//---------------------------------------- 1.59 +void generate_forN(const unsigned int N) { 1.60 + if (N>=2) { 1.61 + const unsigned int Nn = N/2, Np = Nn-((N+1)%2); 1.62 + std::printf("#define cimg_for%u(bound,i) for (int i = 0, \\\n",N); 1.63 + { for (unsigned int k=0; k<Np; ++k) std::printf(" _p%u##i = 0,",Np-k); } 1.64 + std::printf(" \\\n"); 1.65 + { 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.66 + std::printf(" _n%u##i<(int)(bound) || ",Nn); 1.67 + { for (unsigned int k=Nn-1; k>=1; --k) std::printf("_n%u##i==--_n%u##i || ",k,k+1); } 1.68 + std::printf("\\\n i==("); 1.69 + { for (unsigned int k=Nn; k>=2; --k) std::printf("_n%u##i = ",k); } 1.70 + std::printf("--_n1##i); \\\n "); 1.71 + { for (unsigned int k=Np; k>=2; --k) std::printf("_p%u##i = _p%u##i, ",k,k-1); } 1.72 + if (Np) std::printf("_p1##i = i++, \\\n "); 1.73 + else std::printf(" ++i, "); 1.74 + { for (unsigned int k=1; k<Nn; ++k) std::printf("++_n%u##i, ",k); } 1.75 + std::printf("++_n%u##i)\n\n",Nn); 1.76 + 1.77 + std::printf("#define cimg_for%uX(img,x) cimg_for%u((img).width,x)\n",N,N); 1.78 + std::printf("#define cimg_for%uY(img,y) cimg_for%u((img).height,y)\n",N,N); 1.79 + std::printf("#define cimg_for%uZ(img,z) cimg_for%u((img).depth,z)\n",N,N); 1.80 + std::printf("#define cimg_for%uV(img,v) cimg_for%u((img).dim,v)\n",N,N); 1.81 + std::printf("#define cimg_for%uXY(img,x,y) cimg_for%uY(img,y) cimg_for%uX(img,x)\n",N,N,N); 1.82 + std::printf("#define cimg_for%uXZ(img,x,z) cimg_for%uZ(img,z) cimg_for%uX(img,x)\n",N,N,N); 1.83 + std::printf("#define cimg_for%uXV(img,x,v) cimg_for%uV(img,v) cimg_for%uX(img,x)\n",N,N,N); 1.84 + std::printf("#define cimg_for%uYZ(img,y,z) cimg_for%uZ(img,z) cimg_for%uY(img,y)\n",N,N,N); 1.85 + std::printf("#define cimg_for%uYV(img,y,v) cimg_for%uV(img,v) cimg_for%uY(img,y)\n",N,N,N); 1.86 + std::printf("#define cimg_for%uZV(img,z,v) cimg_for%uV(img,v) cimg_for%uZ(img,z)\n",N,N,N); 1.87 + 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.88 + 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.89 + 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.90 + 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.91 + } 1.92 +} 1.93 + 1.94 +// Generate macro(s) 'cimg_for_inN(i,bound)' 1.95 +//------------------------------------------ 1.96 +void generate_for_inN(const unsigned int N) { 1.97 + if (N>=2) { 1.98 + const unsigned int Nn = N/2, Np = Nn-((N+1)%2); 1.99 + std::printf("#define cimg_for_in%u(bound,i0,i1,i) for (int i = (int)(i0)<0?0:(int)(i0), \\\n",N); 1.100 + { 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.101 + { 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.102 + std::printf(" i<=(int)(i1) && (_n%u##i<(int)(bound) || ",Nn); 1.103 + { for (unsigned int k=Nn-1; k>=1; --k) std::printf("_n%u##i==--_n%u##i || ",k,k+1); } 1.104 + std::printf("\\\n i==("); 1.105 + { for (unsigned int k=Nn; k>=2; --k) std::printf("_n%u##i = ",k); } 1.106 + std::printf("--_n1##i)); \\\n "); 1.107 + { for (unsigned int k=Np; k>=2; --k) std::printf("_p%u##i = _p%u##i, ",k,k-1); } 1.108 + if (Np) std::printf("_p1##i = i++, \\\n "); 1.109 + else std::printf(" ++i, "); 1.110 + { for (unsigned int k=1; k<Nn; ++k) std::printf("++_n%u##i, ",k); } 1.111 + std::printf("++_n%u##i)\n\n",Nn); 1.112 + } 1.113 + 1.114 + std::printf("#define cimg_for_in%uX(img,x0,x1,x) cimg_for_in%u((img).width,x0,x1,x)\n",N,N); 1.115 + std::printf("#define cimg_for_in%uY(img,y0,y1,y) cimg_for_in%u((img).height,y0,y1,y)\n",N,N); 1.116 + std::printf("#define cimg_for_in%uZ(img,z0,z1,z) cimg_for_in%u((img).depth,z0,z1,z)\n",N,N); 1.117 + std::printf("#define cimg_for_in%uV(img,v0,v1,v) cimg_for_in%u((img).dim,v0,v1,v)\n",N,N); 1.118 + 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.119 + 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.120 + 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.121 + 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.122 + 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.123 + 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.124 + 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.125 + 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.126 + 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.127 + 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.128 + 1.129 +} 1.130 + 1.131 +// Generate macro 'cimg_forMxN[xP](img,x,y,z,v,I)' 1.132 +//------------------------------------------------ 1.133 +void generate_forMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.134 + char indx[16], indy[16], indz[16]; 1.135 + const int 1.136 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.137 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.138 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)), 1.139 + last = (int)(M*N*P); 1.140 + 1.141 + 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.142 + else std::printf("#define cimg_for%ux%u(img,x,y,z,v,I) \\\n",M,N); 1.143 + if (N>1) std::printf(" cimg_for%u((img).height,y) ",N); 1.144 + else std::printf(" cimg_forY(img,y) "); 1.145 + 1.146 + std::printf("for (int x = 0%c \\\n",M>1?',':';'); 1.147 + { for (int k=Mp; k>=1; --k) std::printf(" _p%u##x = 0%s",k,k==1?", \\\n":","); } 1.148 + { 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.149 + 1.150 + if (M>1) { 1.151 + std::printf(" _n%u##x = (int)( \\\n ",Mn); 1.152 + { for (int k=0, z=-Pp; z<=Pn; ++z) 1.153 + for (int y=-Np; y<=Nn; ++y) { 1.154 + for (int x=-Mp; x<=0; ++x) { std::printf("%sI[%d] =",k && x==-Mp?" (":(x==-Mp?"(":" "),k); ++k; } 1.155 + k+=Mn; 1.156 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.157 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.158 + std::printf(" (img)(0,%sy,%sz,v))%s",indy,indz,k>=last?",":", \\\n"); 1.159 + }} 1.160 + 1.161 + std::printf(" \\\n"); 1.162 + for (int x=1; x<Mn; ++x) 1.163 + for (int z=-Pp; z<=Pn; ++z) 1.164 + for (int y=-Np; y<=Nn; ++y) { 1.165 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.166 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.167 + 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.168 + } 1.169 + std::printf(" %u>=((img).width)?(int)((img).width)-1:%u); \\\n",Mn,Mn); 1.170 + } 1.171 + 1.172 + if (M>1) std::printf(" (_n%u##x",Mn); else std::printf(" (x"); 1.173 + std::printf("<(int)((img).width) && ( \\\n"); 1.174 + 1.175 + { for (int z=-Pp; z<=Pn; ++z) 1.176 + for (int y=-Np; y<=Nn; ++y) { 1.177 + if (M>1) std::sprintf(indx,"_n%d##",Mn); else indx[0]='\0'; 1.178 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.179 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.180 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v))%s",M-1+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz, 1.181 + z==Pn && y==Nn?",1))":", \\\n"); 1.182 + }} 1.183 + 1.184 + if (M>1) { 1.185 + std::printf(" || \\\n "); 1.186 + { for (int k=Mn-1; k>=1; --k) std::printf("_n%d##x==--_n%u##x || ",k,k+1); } 1.187 + std::printf("x==("); 1.188 + { for (int k=Mn; k>=2; --k) std::printf("_n%d##x = ",k); } 1.189 + std::printf("--_n1##x); \\\n"); 1.190 + } else std::printf("; \\\n"); 1.191 + 1.192 + if (M>1) { 1.193 + { for (unsigned int k=0, z=0; z<P; ++z) 1.194 + for (unsigned int y=0; y<N; ++y) { 1.195 + for (unsigned int x=0; x<M-1; ++x) { 1.196 + std::printf(" I[%d] = I[%d],",k,k+1); 1.197 + ++k; 1.198 + } 1.199 + std::printf(" \\\n"); 1.200 + ++k; 1.201 + }} 1.202 + std::printf(" "); 1.203 + { for (int k=Mp; k>=2; --k) std::printf("_p%d##x = _p%d##x, ",k,k-1); } 1.204 + if (M>2) std::printf("_p1##x = x++, "); else std::printf("++x, "); 1.205 + { for (int k=1; k<=Mn-1; ++k) std::printf("++_n%d##x, ",k); } 1.206 + std::printf("++_n%d##x)\n\n",Mn); 1.207 + } else std::printf(" ++x)\n\n"); 1.208 +} 1.209 + 1.210 +// Generate macro 'cimg_for_inMxN[xP](img,x,y,z,v,I)' 1.211 +//--------------------------------------------------- 1.212 +void generate_for_inMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.213 + char indx[16], indy[16], indz[16]; 1.214 + const int 1.215 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.216 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.217 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)); 1.218 + 1.219 + 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.220 + else std::printf("#define cimg_for_in%ux%u(img,x0,y0,x1,y1,x,y,z,v,I) \\\n",M,N); 1.221 + if (N>1) std::printf(" cimg_for_in%u((img).height,y0,y1,y) ",N); 1.222 + else std::printf(" cimg_for_inY(img,y0,y1,y) "); 1.223 + 1.224 + std::printf("for (int x = (int)(x0)<0?0:(int)(x0)%c \\\n",M>1?',':';'); 1.225 + { for (int k=Mp; k>=1; --k) std::printf(" _p%u##x = x-%u<0?0:x-%u, \\\n",k,k,k); } 1.226 + { 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.227 + 1.228 + if (M>1) { 1.229 + std::printf(" _n%u##x = (int)( \\\n",Mn); 1.230 + for (int x=-Mp; x<Mn; ++x) 1.231 + for (int z=-Pp; z<=Pn; ++z) 1.232 + for (int y=-Np; y<=Nn; ++y) { 1.233 + if (x<0) std::sprintf(indx,"_p%d##",-x); else if (x>0) std::sprintf(indx,"_n%d##",x); else indx[0]='\0'; 1.234 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.235 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.236 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v)), \\\n",(Mp+x)+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz); 1.237 + } 1.238 + std::printf(" x+%u>=(int)((img).width)?(int)((img).width)-1:x+%u); \\\n",Mn,Mn); 1.239 + } 1.240 + std::printf(" x<=(int)(x1) && ("); 1.241 + if (M>1) std::printf("(_n%u##x",Mn); else std::printf("(x"); 1.242 + std::printf("<(int)((img).width) && ( \\\n"); 1.243 + 1.244 + { for (int z=-Pp; z<=Pn; ++z) 1.245 + for (int y=-Np; y<=Nn; ++y) { 1.246 + if (M>1) std::sprintf(indx,"_n%d##",Mn); else indx[0]='\0'; 1.247 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.248 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.249 + std::printf(" (I[%d] = (img)(%sx,%sy,%sz,v))%s",M-1+(y+Np)*M+(z+Pp)*M*N,indx,indy,indz, 1.250 + z==Pn && y==Nn?",1))":", \\\n"); 1.251 + }} 1.252 + 1.253 + if (M>1) { 1.254 + std::printf(" || \\\n "); 1.255 + { for (int k=Mn-1; k>=1; --k) std::printf("_n%d##x==--_n%u##x || ",k,k+1); } 1.256 + std::printf("x==("); 1.257 + { for (int k=Mn; k>=2; --k) std::printf("_n%d##x = ",k); } 1.258 + std::printf("--_n1##x)); \\\n"); 1.259 + } else std::printf("); \\\n"); 1.260 + 1.261 + if (M>1) { 1.262 + { for (unsigned int k=0, z=0; z<P; ++z) 1.263 + for (unsigned int y=0; y<N; ++y) { 1.264 + for (unsigned int x=0; x<M-1; ++x) { 1.265 + std::printf(" I[%d] = I[%d],",k,k+1); 1.266 + ++k; 1.267 + } 1.268 + std::printf(" \\\n"); 1.269 + ++k; 1.270 + }} 1.271 + std::printf(" "); 1.272 + { for (int k=Mp; k>=2; --k) std::printf("_p%d##x = _p%d##x, ",k,k-1); } 1.273 + if (M>2) std::printf("_p1##x = x++, "); else std::printf("++x, "); 1.274 + { for (int k=1; k<=Mn-1; ++k) std::printf("++_n%d##x, ",k); } 1.275 + std::printf("++_n%d##x)\n\n",Mn); 1.276 + } else std::printf(" ++x)\n\n"); 1.277 +} 1.278 + 1.279 +// Generate macro 'cimg_getMxN[xP](img,x,y,z,v,I)' 1.280 +//------------------------------------------------ 1.281 +void generate_getMxNxP(const unsigned int M, const unsigned int N, const unsigned int P) { 1.282 + const int 1.283 + Mn = (int)(M/2), Mp = (int)(Mn-((M+1)%2)), 1.284 + Nn = (int)(N/2), Np = (int)(Nn-((N+1)%2)), 1.285 + Pn = (int)(P/2), Pp = (int)(Pn-((P+1)%2)), 1.286 + last = M*N*P-1; 1.287 + if (P>1) std::printf("#define cimg_get%ux%ux%u(img,x,y,z,v,I) \\\n",M,N,P); 1.288 + else std::printf("#define cimg_get%ux%u(img,x,y,z,v,I) \\\n",M,N); 1.289 + char indx[16], indy[16], indz[16]; 1.290 + for (int k=0, z=-Pp; z<=Pn; ++z) 1.291 + for (int y=-Np; y<=Nn; ++y) 1.292 + for (int x=-Mp; x<=Mn; ++x) { 1.293 + if (x<0) std::sprintf(indx,"_p%d##",-x); else if (x>0) std::sprintf(indx,"_n%d##",x); else indx[0]='\0'; 1.294 + if (y<0) std::sprintf(indy,"_p%d##",-y); else if (y>0) std::sprintf(indy,"_n%d##",y); else indy[0]='\0'; 1.295 + if (z<0) std::sprintf(indz,"_p%d##",-z); else if (z>0) std::sprintf(indz,"_n%d##",z); else indz[0]='\0'; 1.296 + std::printf(" I[%u] = (img)(%sx,%sy,%sz,v)%s",k,indx,indy,indz, 1.297 + k==last?";\n\n":(x==Mn?", \\\n":",")); 1.298 + ++k; 1.299 + } 1.300 +} 1.301 + 1.302 +//----------------- 1.303 +// Main Procedure 1.304 +//----------------- 1.305 +int main(int argc, char **argv) { 1.306 + 1.307 + cimg_usage("Generate C++ macros to deal with MxN[xP] neighborhood loops within the CImg Library"); 1.308 + 1.309 + // Read command line arguments 1.310 + //---------------------------- 1.311 + const char *const size = cimg_option("-s","5x4","Size of the neighborhood"); 1.312 + const bool do_forN = cimg_option("-forN",true,"Generate 'cimg_forN()'"); 1.313 + const bool do_for_inN = cimg_option("-for_inN",true,"Generate 'cimg_for_inN()'"); 1.314 + const bool do_for = cimg_option("-for",true,"Generate 'cimg_forMxNxP()'"); 1.315 + const bool do_for_in = cimg_option("-for_in",true,"Generate 'cimg_for_inMxNxP()'"); 1.316 + const bool do_get = cimg_option("-get",true,"Generate 'cimg_getMxNxP()'"); 1.317 + if (cimg_option("-h",false,0)) std::exit(0); 1.318 + 1.319 + unsigned int M = 1, N = 1 , P = 1; 1.320 + std::sscanf(size,"%u%*c%u%*c%u",&M,&N,&P); 1.321 + if (!M || !N || !P || (M==1 && N==1 && P==1)) { 1.322 + std::fprintf(stderr,"\n%s : Error, bad neighborhood size '%s'\n",argv[0],size); 1.323 + std::exit(0); 1.324 + } 1.325 + if (!do_forN && !do_get && !do_for) return 0; 1.326 + 1.327 + if (P>1) 1.328 + std::printf("// Define %ux%ux%u loop macros for CImg\n" 1.329 + "//-------------------------------------\n",M,N,P); 1.330 + else 1.331 + std::printf("// Define %ux%u loop macros for CImg\n" 1.332 + "//----------------------------------\n",M,N); 1.333 + 1.334 + if (do_forN) { 1.335 + if (N>1) generate_forN(N); 1.336 + if (P>1 && P!=N) generate_forN(P); 1.337 + } 1.338 + if (do_for_inN) { 1.339 + if (N>1) generate_for_inN(N); 1.340 + if (P>1 && P!=N) generate_for_inN(P); 1.341 + } 1.342 + if (do_for) generate_forMxNxP(M,N,P); 1.343 + if (do_for_in) generate_for_inMxNxP(M,N,P); 1.344 + if (do_get) generate_getMxNxP(M,N,P); 1.345 + 1.346 + return 0; 1.347 +}