PageRenderTime 71ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/Inc/CImg.h

http://asmodeling.codeplex.com
C++ Header | 7837 lines | 7298 code | 240 blank | 299 comment | 568 complexity | 8c7492f19b329e8d0013faaf6d9d3510 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. #
  3. # File : CImg.h
  4. # ( C++ header file )
  5. #
  6. # Description : The C++ Template Image Processing Library.
  7. # This file is the main part of the CImg Library project.
  8. # ( http://cimg.sourceforge.net )
  9. #
  10. # Project manager : David Tschumperle.
  11. # ( http://www.greyc.ensicaen.fr/~dtschump/ )
  12. #
  13. # The complete contributor list can be seen in the 'README.txt' file.
  14. #
  15. # Licenses : This file is "dual-licensed", you have to choose one
  16. # of the two licenses below to apply on this file.
  17. #
  18. # CeCILL-C
  19. # The CeCILL-C license is close to the GNU LGPL.
  20. # ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )
  21. #
  22. # or CeCILL v2.0
  23. # The CeCILL license is compatible with the GNU GPL.
  24. # ( http://www.cecill.info/licences/Licence_CeCILL_V2-en.html )
  25. #
  26. # This software is governed either by the CeCILL or the CeCILL-C license
  27. # under French law and abiding by the rules of distribution of free software.
  28. # You can use, modify and or redistribute the software under the terms of
  29. # the CeCILL or CeCILL-C licenses as circulated by CEA, CNRS and INRIA
  30. # at the following URL : "http://www.cecill.info".
  31. #
  32. # As a counterpart to the access to the source code and rights to copy,
  33. # modify and redistribute granted by the license, users are provided only
  34. # with a limited warranty and the software's author, the holder of the
  35. # economic rights, and the successive licensors have only limited
  36. # liability.
  37. #
  38. # In this respect, the user's attention is drawn to the risks associated
  39. # with loading, using, modifying and/or developing or reproducing the
  40. # software by the user in light of its specific status of free software,
  41. # that may mean that it is complicated to manipulate, and that also
  42. # therefore means that it is reserved for developers and experienced
  43. # professionals having in-depth computer knowledge. Users are therefore
  44. # encouraged to load and test the software's suitability as regards their
  45. # requirements in conditions enabling the security of their systems and/or
  46. # data to be ensured and, more generally, to use and operate it in the
  47. # same conditions as regards security.
  48. #
  49. # The fact that you are presently reading this means that you have had
  50. # knowledge of the CeCILL and CeCILL-C licenses and that you accept its terms.
  51. #
  52. */
  53. // Define version number of the current file.
  54. //
  55. #ifndef cimg_version
  56. #define cimg_version 131
  57. /*-----------------------------------------------------------
  58. #
  59. # Test/auto-set CImg configuration variables
  60. # and include required headers.
  61. #
  62. # If you find that default configuration variables are
  63. # not adapted, you can override their values before including
  64. # the header file "CImg.h" (using the #define directive).
  65. #
  66. ------------------------------------------------------------*/
  67. // Include required standard C++ headers.
  68. //
  69. #include <cstdio>
  70. #include <cstdlib>
  71. #include <cstdarg>
  72. #include <cstring>
  73. #include <cmath>
  74. #include <ctime>
  75. // Operating system configuration.
  76. //
  77. // Define 'cimg_OS' to : 0 for an unknown OS (will try to minize library dependancies).
  78. // 1 for a Unix-like OS (Linux, Solaris, BSD, MacOSX, Irix, ...).
  79. // 2 for Microsoft Windows.
  80. //
  81. #ifndef cimg_OS
  82. #if defined(unix) || defined(__unix) || defined(__unix__) \
  83. || defined(linux) || defined(__linux) || defined(__linux__) \
  84. || defined(sun) || defined(__sun) \
  85. || defined(BSD) || defined(__OpenBSD__) || defined(__NetBSD__) \
  86. || defined(__FreeBSD__) || defined __DragonFly__ \
  87. || defined(sgi) || defined(__sgi) \
  88. || defined(__MACOSX__) || defined(__APPLE__) \
  89. || defined(__CYGWIN__)
  90. #define cimg_OS 1
  91. #elif defined(_MSC_VER) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
  92. || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
  93. #define cimg_OS 2
  94. #else
  95. #define cimg_OS 0
  96. #endif
  97. #elif !(cimg_OS==0 || cimg_OS==1 || cimg_OS==2)
  98. #error CImg Library : Configuration variable 'cimg_OS' is badly defined.
  99. #error (valid values are '0=unknown OS', '1=Unix-like OS', '2=Microsoft Windows').
  100. #endif
  101. // Compiler configuration.
  102. //
  103. // Try to detect Microsoft VC++ compilers.
  104. // (lot of workarounds are needed afterwards to
  105. // make CImg working, particularly with VC++ 6.0).
  106. //
  107. #ifdef _MSC_VER
  108. #pragma warning(push)
  109. #pragma warning(disable:4311)
  110. #pragma warning(disable:4312)
  111. #pragma warning(disable:4800)
  112. #pragma warning(disable:4804)
  113. #pragma warning(disable:4996)
  114. #define _CRT_SECURE_NO_DEPRECATE 1
  115. #define _CRT_NONSTDC_NO_DEPRECATE 1
  116. #if _MSC_VER<1300
  117. #define cimg_use_visualcpp6
  118. #define cimg_std
  119. #define _WIN32_WINNT 0x0500
  120. #endif
  121. #endif
  122. // Include OS-specific headers.
  123. //
  124. #if cimg_OS==1
  125. #include <sys/time.h>
  126. #include <unistd.h>
  127. #elif cimg_OS==2
  128. #include <windows.h>
  129. #ifndef _WIN32_IE
  130. #define _WIN32_IE 0x0400
  131. #endif
  132. #include <shlobj.h>
  133. #endif
  134. // Define default pipe for output messages.
  135. //
  136. // Define 'cimg_stdout' to : stdout to print CImg messages on the standard output.
  137. // stderr to print CImg messages on the standart error output (default behavior).
  138. //
  139. #ifndef cimg_std
  140. #define cimg_std std
  141. #endif
  142. #ifndef cimg_stdout
  143. #define cimg_stdout stderr
  144. #endif
  145. // Define default filename separator.
  146. #ifndef cimg_file_separator
  147. #if cimg_OS==2
  148. #define cimg_file_separator "\\"
  149. #else
  150. #define cimg_file_separator "/"
  151. #endif
  152. #endif
  153. // Output messages configuration.
  154. //
  155. // Define 'cimg_debug' to : 0 to hide debug messages (quiet mode, but exceptions are still thrown).
  156. // 1 to display debug messages on the console.
  157. // 2 to display debug messages with dialog windows (default behavior).
  158. // 3 to do as 1 + add extra warnings (may slow down the code !).
  159. // 4 to do as 2 + add extra warnings (may slow down the code !).
  160. //
  161. // Define 'cimg_strict_warnings' to replace warning messages by exception throwns.
  162. //
  163. // Define 'cimg_use_vt100' to allow output of color messages (require VT100-compatible terminal).
  164. //
  165. #ifndef cimg_debug
  166. #define cimg_debug 2
  167. #elif !(cimg_debug==0 || cimg_debug==1 || cimg_debug==2 || cimg_debug==3 || cimg_debug==4)
  168. #error CImg Library : Configuration variable 'cimg_debug' is badly defined.
  169. #error (valid values are '0=quiet', '1=console', '2=dialog', '3=console+warnings', '4=dialog+warnings').
  170. #endif
  171. // Display framework configuration.
  172. //
  173. // Define 'cimg_display' to : 0 to disable display capabilities.
  174. // 1 to use X-Window framework (X11).
  175. // 2 to use Microsoft GDI32 framework.
  176. // 3 to use Apple Carbon framework.
  177. //
  178. #ifndef cimg_display
  179. #if cimg_OS==0
  180. #define cimg_display 0
  181. #elif cimg_OS==1
  182. #if defined(__MACOSX__) || defined(__APPLE__)
  183. #define cimg_display 1
  184. #else
  185. #define cimg_display 1
  186. #endif
  187. #elif cimg_OS==2
  188. #define cimg_display 2
  189. #endif
  190. #elif !(cimg_display==0 || cimg_display==1 || cimg_display==2 || cimg_display==3)
  191. #error CImg Library : Configuration variable 'cimg_display' is badly defined.
  192. #error (valid values are '0=disable', '1=X-Window (X11)', '2=Microsoft GDI32', '3=Apple Carbon').
  193. #endif
  194. // Include display-specific headers.
  195. //
  196. #if cimg_display==1
  197. #include <X11/Xlib.h>
  198. #include <X11/Xutil.h>
  199. #include <X11/keysym.h>
  200. #include <pthread.h>
  201. #ifdef cimg_use_xshm
  202. #include <sys/ipc.h>
  203. #include <sys/shm.h>
  204. #include <X11/extensions/XShm.h>
  205. #endif
  206. #ifdef cimg_use_xrandr
  207. #include <X11/extensions/Xrandr.h>
  208. #endif
  209. #elif cimg_display==3
  210. #include <Carbon/Carbon.h>
  211. #include <pthread.h>
  212. #endif
  213. // OpenMP configuration.
  214. // (http://www.openmp.org)
  215. //
  216. // Define 'cimg_use_openmp' to enable OpenMP support.
  217. //
  218. // OpenMP directives can be used in few CImg functions to get
  219. // advantages of multi-core CPUs. Using OpenMP is not mandatory.
  220. //
  221. #ifdef cimg_use_openmp
  222. #include "omp.h"
  223. #endif
  224. // LibPNG configuration.
  225. // (http://www.libpng.org)
  226. //
  227. // Define 'cimg_use_png' to enable LibPNG support.
  228. //
  229. // LibPNG can be used in functions 'CImg<T>::{load,save}_png()'
  230. // to get a builtin support of PNG files. Using LibPNG is not mandatory.
  231. //
  232. #ifdef cimg_use_png
  233. extern "C" {
  234. #include "png.h"
  235. }
  236. #endif
  237. // LibJPEG configuration.
  238. // (http://en.wikipedia.org/wiki/Libjpeg)
  239. //
  240. // Define 'cimg_use_jpeg' to enable LibJPEG support.
  241. //
  242. // LibJPEG can be used in functions 'CImg<T>::{load,save}_jpeg()'
  243. // to get a builtin support of JPEG files. Using LibJPEG is not mandatory.
  244. //
  245. #ifdef cimg_use_jpeg
  246. extern "C" {
  247. #include "jpeglib.h"
  248. }
  249. #endif
  250. // LibTIFF configuration.
  251. // (http://www.libtiff.org)
  252. //
  253. // Define 'cimg_use_tiff' to enable LibTIFF support.
  254. //
  255. // LibTIFF can be used in functions 'CImg[List]<T>::{load,save}_tiff()'
  256. // to get a builtin support of TIFF files. Using LibTIFF is not mandatory.
  257. //
  258. #ifdef cimg_use_tiff
  259. extern "C" {
  260. #include "tiffio.h"
  261. }
  262. #endif
  263. // FFMPEG Avcodec and Avformat libraries configuration.
  264. // (http://www.ffmpeg.org)
  265. //
  266. // Define 'cimg_use_ffmpeg' to enable FFMPEG lib support.
  267. //
  268. // Avcodec and Avformat libraries can be used in functions
  269. // 'CImg[List]<T>::load_ffmpeg()' to get a builtin
  270. // support of various image sequences files.
  271. // Using FFMPEG libraries is not mandatory.
  272. //
  273. #ifdef cimg_use_ffmpeg
  274. extern "C" {
  275. #include "avformat.h"
  276. #include "avcodec.h"
  277. #include "swscale.h"
  278. }
  279. #endif
  280. // Zlib configuration
  281. // (http://www.zlib.net)
  282. //
  283. // Define 'cimg_use_zlib' to enable Zlib support.
  284. //
  285. // Zlib can be used in functions 'CImg[List]<T>::{load,save}_cimg()'
  286. // to allow compressed data in '.cimg' files. Using Zlib is not mandatory.
  287. //
  288. #ifdef cimg_use_zlib
  289. extern "C" {
  290. #include "zlib.h"
  291. }
  292. #endif
  293. // Magick++ configuration.
  294. // (http://www.imagemagick.org/Magick++)
  295. //
  296. // Define 'cimg_use_magick' to enable Magick++ support.
  297. //
  298. // Magick++ library can be used in functions 'CImg<T>::{load,save}()'
  299. // to get a builtin support of various image formats (PNG,JPEG,TIFF,...).
  300. // Using Magick++ is not mandatory.
  301. //
  302. #ifdef cimg_use_magick
  303. #include "Magick++.h"
  304. #endif
  305. // FFTW3 configuration.
  306. // (http://www.fftw.org)
  307. //
  308. // Define 'cimg_use_fftw3' to enable libFFTW3 support.
  309. //
  310. // FFTW3 library can be used in functions 'CImg[List]<T>::FFT()' to
  311. // efficiently compile the Fast Fourier Transform of image data.
  312. //
  313. #ifdef cimg_use_fftw3
  314. extern "C" {
  315. #include "fftw3.h"
  316. }
  317. #endif
  318. // Board configuration.
  319. // (http://libboard.sourceforge.net/)
  320. //
  321. // Define 'cimg_use_board' to enable Board support.
  322. //
  323. // Board library can be used in functions 'CImg<T>::draw_object3d()'
  324. // to draw objects 3D in vector-graphics canvas that can be saved
  325. // as .PS or .SVG files afterwards.
  326. //
  327. #ifdef cimg_use_board
  328. #include "Board.h"
  329. #endif
  330. // Lapack configuration.
  331. // (http://www.netlib.org/lapack)
  332. //
  333. // Define 'cimg_use_lapack' to enable LAPACK support.
  334. //
  335. // Lapack can be used in various CImg functions dealing with
  336. // matrix computation and algorithms (eigenvalues, inverse, ...).
  337. // Using Lapack is not mandatory.
  338. //
  339. #ifdef cimg_use_lapack
  340. extern "C" {
  341. extern void sgetrf_(int*, int*, float*, int*, int*, int*);
  342. extern void sgetri_(int*, float*, int*, int*, float*, int*, int*);
  343. extern void sgetrs_(char*, int*, int*, float*, int*, int*, float*, int*, int*);
  344. extern void sgesvd_(char*, char*, int*, int*, float*, int*, float*, float*, int*, float*, int*, float*, int*, int*);
  345. extern void ssyev_(char*, char*, int*, float*, int*, float*, float*, int*, int*);
  346. extern void dgetrf_(int*, int*, double*, int*, int*, int*);
  347. extern void dgetri_(int*, double*, int*, int*, double*, int*, int*);
  348. extern void dgetrs_(char*, int*, int*, double*, int*, int*, double*, int*, int*);
  349. extern void dgesvd_(char*, char*, int*, int*, double*, int*, double*, double*, int*, double*, int*, double*, int*, int*);
  350. extern void dsyev_(char*, char*, int*, double*, int*, double*, double*, int*, int*);
  351. }
  352. #endif
  353. // Check if min/max macros are defined.
  354. //
  355. // CImg does not compile if macros 'min' or 'max' are defined,
  356. // because min() and max() functions are also defined in the cimg:: namespace.
  357. // so it '#undef' these macros if necessary, and restore them to reasonable
  358. // values at the end of the file.
  359. //
  360. #ifdef min
  361. #undef min
  362. #define _cimg_redefine_min
  363. #endif
  364. #ifdef max
  365. #undef max
  366. #define _cimg_redefine_max
  367. #endif
  368. // Set the current working directory for native MacOSX bundled applications.
  369. //
  370. // By default, MacOS bundled applications set the cwd at the root directory '/',
  371. // the code below allows to set it to the current exec directory instead when
  372. // a CImg-based program is executed.
  373. //
  374. #if cimg_OS==1 && cimg_display==3
  375. static struct _cimg_macosx_setcwd {
  376. _cimg_macosx_setcwd() {
  377. FSRef location;
  378. ProcessSerialNumber psn;
  379. char filePath[512];
  380. if (GetCurrentProcess(&psn)!=noErr) return;
  381. if (GetProcessBundleLocation(&psn,&location)!=noErr) return;
  382. FSRefMakePath(&location,(UInt8*)filePath,sizeof(filePath)-1);
  383. unsigned int p = cimg_std::strlen(filePath);
  384. while (filePath[p] != '/') --p;
  385. filePath[p] = 0;
  386. chdir(filePath);
  387. }
  388. } cimg_macosx_setcwd;
  389. #endif
  390. /*------------------------------------------------------------------------------
  391. #
  392. # Define user-friendly macros.
  393. #
  394. # User macros are prefixed by 'cimg_' and can be used in your own code.
  395. # They are particularly useful for option parsing, and image loops creation.
  396. #
  397. ------------------------------------------------------------------------------*/
  398. // Define the program usage, and retrieve command line arguments.
  399. //
  400. #define cimg_usage(usage) cimg_library::cimg::option((char*)0,argc,argv,(char*)0,usage)
  401. #define cimg_help(str) cimg_library::cimg::option((char*)0,argc,argv,str,(char*)0)
  402. #define cimg_option(name,defaut,usage) cimg_library::cimg::option(name,argc,argv,defaut,usage)
  403. #define cimg_argument(pos) cimg_library::cimg::argument(pos,argc,argv)
  404. #define cimg_argument1(pos,s0) cimg_library::cimg::argument(pos,argc,argv,1,s0)
  405. #define cimg_argument2(pos,s0,s1) cimg_library::cimg::argument(pos,argc,argv,2,s0,s1)
  406. #define cimg_argument3(pos,s0,s1,s2) cimg_library::cimg::argument(pos,argc,argv,3,s0,s1,s2)
  407. #define cimg_argument4(pos,s0,s1,s2,s3) cimg_library::cimg::argument(pos,argc,argv,4,s0,s1,s2,s3)
  408. #define cimg_argument5(pos,s0,s1,s2,s3,s4) cimg_library::cimg::argument(pos,argc,argv,5,s0,s1,s2,s3,s4)
  409. #define cimg_argument6(pos,s0,s1,s2,s3,s4,s5) cimg_library::cimg::argument(pos,argc,argv,6,s0,s1,s2,s3,s4,s5)
  410. #define cimg_argument7(pos,s0,s1,s2,s3,s4,s5,s6) cimg_library::cimg::argument(pos,argc,argv,7,s0,s1,s2,s3,s4,s5,s6)
  411. #define cimg_argument8(pos,s0,s1,s2,s3,s4,s5,s6,s7) cimg_library::cimg::argument(pos,argc,argv,8,s0,s1,s2,s3,s4,s5,s6,s7)
  412. #define cimg_argument9(pos,s0,s1,s2,s3,s4,s5,s6,s7,s8) cimg_library::cimg::argument(pos,argc,argv,9,s0,s1,s2,s3,s4,s5,s6,s7,s8)
  413. // Define and manipulate local neighborhoods.
  414. //
  415. #define CImg_2x2(I,T) T I[4]; \
  416. T& I##cc = I[0]; T& I##nc = I[1]; \
  417. T& I##cn = I[2]; T& I##nn = I[3]; \
  418. I##cc = I##nc = \
  419. I##cn = I##nn = 0
  420. #define CImg_3x3(I,T) T I[9]; \
  421. T& I##pp = I[0]; T& I##cp = I[1]; T& I##np = I[2]; \
  422. T& I##pc = I[3]; T& I##cc = I[4]; T& I##nc = I[5]; \
  423. T& I##pn = I[6]; T& I##cn = I[7]; T& I##nn = I[8]; \
  424. I##pp = I##cp = I##np = \
  425. I##pc = I##cc = I##nc = \
  426. I##pn = I##cn = I##nn = 0
  427. #define CImg_4x4(I,T) T I[16]; \
  428. T& I##pp = I[0]; T& I##cp = I[1]; T& I##np = I[2]; T& I##ap = I[3]; \
  429. T& I##pc = I[4]; T& I##cc = I[5]; T& I##nc = I[6]; T& I##ac = I[7]; \
  430. T& I##pn = I[8]; T& I##cn = I[9]; T& I##nn = I[10]; T& I##an = I[11]; \
  431. T& I##pa = I[12]; T& I##ca = I[13]; T& I##na = I[14]; T& I##aa = I[15]; \
  432. I##pp = I##cp = I##np = I##ap = \
  433. I##pc = I##cc = I##nc = I##ac = \
  434. I##pn = I##cn = I##nn = I##an = \
  435. I##pa = I##ca = I##na = I##aa = 0
  436. #define CImg_5x5(I,T) T I[25]; \
  437. T& I##bb = I[0]; T& I##pb = I[1]; T& I##cb = I[2]; T& I##nb = I[3]; T& I##ab = I[4]; \
  438. T& I##bp = I[5]; T& I##pp = I[6]; T& I##cp = I[7]; T& I##np = I[8]; T& I##ap = I[9]; \
  439. T& I##bc = I[10]; T& I##pc = I[11]; T& I##cc = I[12]; T& I##nc = I[13]; T& I##ac = I[14]; \
  440. T& I##bn = I[15]; T& I##pn = I[16]; T& I##cn = I[17]; T& I##nn = I[18]; T& I##an = I[19]; \
  441. T& I##ba = I[20]; T& I##pa = I[21]; T& I##ca = I[22]; T& I##na = I[23]; T& I##aa = I[24]; \
  442. I##bb = I##pb = I##cb = I##nb = I##ab = \
  443. I##bp = I##pp = I##cp = I##np = I##ap = \
  444. I##bc = I##pc = I##cc = I##nc = I##ac = \
  445. I##bn = I##pn = I##cn = I##nn = I##an = \
  446. I##ba = I##pa = I##ca = I##na = I##aa = 0
  447. #define CImg_2x2x2(I,T) T I[8]; \
  448. T& I##ccc = I[0]; T& I##ncc = I[1]; \
  449. T& I##cnc = I[2]; T& I##nnc = I[3]; \
  450. T& I##ccn = I[4]; T& I##ncn = I[5]; \
  451. T& I##cnn = I[6]; T& I##nnn = I[7]; \
  452. I##ccc = I##ncc = \
  453. I##cnc = I##nnc = \
  454. I##ccn = I##ncn = \
  455. I##cnn = I##nnn = 0
  456. #define CImg_3x3x3(I,T) T I[27]; \
  457. T& I##ppp = I[0]; T& I##cpp = I[1]; T& I##npp = I[2]; \
  458. T& I##pcp = I[3]; T& I##ccp = I[4]; T& I##ncp = I[5]; \
  459. T& I##pnp = I[6]; T& I##cnp = I[7]; T& I##nnp = I[8]; \
  460. T& I##ppc = I[9]; T& I##cpc = I[10]; T& I##npc = I[11]; \
  461. T& I##pcc = I[12]; T& I##ccc = I[13]; T& I##ncc = I[14]; \
  462. T& I##pnc = I[15]; T& I##cnc = I[16]; T& I##nnc = I[17]; \
  463. T& I##ppn = I[18]; T& I##cpn = I[19]; T& I##npn = I[20]; \
  464. T& I##pcn = I[21]; T& I##ccn = I[22]; T& I##ncn = I[23]; \
  465. T& I##pnn = I[24]; T& I##cnn = I[25]; T& I##nnn = I[26]; \
  466. I##ppp = I##cpp = I##npp = \
  467. I##pcp = I##ccp = I##ncp = \
  468. I##pnp = I##cnp = I##nnp = \
  469. I##ppc = I##cpc = I##npc = \
  470. I##pcc = I##ccc = I##ncc = \
  471. I##pnc = I##cnc = I##nnc = \
  472. I##ppn = I##cpn = I##npn = \
  473. I##pcn = I##ccn = I##ncn = \
  474. I##pnn = I##cnn = I##nnn = 0
  475. #define cimg_get2x2(img,x,y,z,v,I) \
  476. I[0] = (img)(x,y,z,v), I[1] = (img)(_n1##x,y,z,v), I[2] = (img)(x,_n1##y,z,v), I[3] = (img)(_n1##x,_n1##y,z,v)
  477. #define cimg_get3x3(img,x,y,z,v,I) \
  478. I[0] = (img)(_p1##x,_p1##y,z,v), I[1] = (img)(x,_p1##y,z,v), I[2] = (img)(_n1##x,_p1##y,z,v), I[3] = (img)(_p1##x,y,z,v), \
  479. I[4] = (img)(x,y,z,v), I[5] = (img)(_n1##x,y,z,v), I[6] = (img)(_p1##x,_n1##y,z,v), I[7] = (img)(x,_n1##y,z,v), \
  480. I[8] = (img)(_n1##x,_n1##y,z,v)
  481. #define cimg_get4x4(img,x,y,z,v,I) \
  482. I[0] = (img)(_p1##x,_p1##y,z,v), I[1] = (img)(x,_p1##y,z,v), I[2] = (img)(_n1##x,_p1##y,z,v), I[3] = (img)(_n2##x,_p1##y,z,v), \
  483. I[4] = (img)(_p1##x,y,z,v), I[5] = (img)(x,y,z,v), I[6] = (img)(_n1##x,y,z,v), I[7] = (img)(_n2##x,y,z,v), \
  484. I[8] = (img)(_p1##x,_n1##y,z,v), I[9] = (img)(x,_n1##y,z,v), I[10] = (img)(_n1##x,_n1##y,z,v), I[11] = (img)(_n2##x,_n1##y,z,v), \
  485. I[12] = (img)(_p1##x,_n2##y,z,v), I[13] = (img)(x,_n2##y,z,v), I[14] = (img)(_n1##x,_n2##y,z,v), I[15] = (img)(_n2##x,_n2##y,z,v)
  486. #define cimg_get5x5(img,x,y,z,v,I) \
  487. I[0] = (img)(_p2##x,_p2##y,z,v), I[1] = (img)(_p1##x,_p2##y,z,v), I[2] = (img)(x,_p2##y,z,v), I[3] = (img)(_n1##x,_p2##y,z,v), \
  488. I[4] = (img)(_n2##x,_p2##y,z,v), I[5] = (img)(_p2##x,_p1##y,z,v), I[6] = (img)(_p1##x,_p1##y,z,v), I[7] = (img)(x,_p1##y,z,v), \
  489. I[8] = (img)(_n1##x,_p1##y,z,v), I[9] = (img)(_n2##x,_p1##y,z,v), I[10] = (img)(_p2##x,y,z,v), I[11] = (img)(_p1##x,y,z,v), \
  490. I[12] = (img)(x,y,z,v), I[13] = (img)(_n1##x,y,z,v), I[14] = (img)(_n2##x,y,z,v), I[15] = (img)(_p2##x,_n1##y,z,v), \
  491. I[16] = (img)(_p1##x,_n1##y,z,v), I[17] = (img)(x,_n1##y,z,v), I[18] = (img)(_n1##x,_n1##y,z,v), I[19] = (img)(_n2##x,_n1##y,z,v), \
  492. I[20] = (img)(_p2##x,_n2##y,z,v), I[21] = (img)(_p1##x,_n2##y,z,v), I[22] = (img)(x,_n2##y,z,v), I[23] = (img)(_n1##x,_n2##y,z,v), \
  493. I[24] = (img)(_n2##x,_n2##y,z,v)
  494. #define cimg_get6x6(img,x,y,z,v,I) \
  495. I[0] = (img)(_p2##x,_p2##y,z,v), I[1] = (img)(_p1##x,_p2##y,z,v), I[2] = (img)(x,_p2##y,z,v), I[3] = (img)(_n1##x,_p2##y,z,v), \
  496. I[4] = (img)(_n2##x,_p2##y,z,v), I[5] = (img)(_n3##x,_p2##y,z,v), I[6] = (img)(_p2##x,_p1##y,z,v), I[7] = (img)(_p1##x,_p1##y,z,v), \
  497. I[8] = (img)(x,_p1##y,z,v), I[9] = (img)(_n1##x,_p1##y,z,v), I[10] = (img)(_n2##x,_p1##y,z,v), I[11] = (img)(_n3##x,_p1##y,z,v), \
  498. I[12] = (img)(_p2##x,y,z,v), I[13] = (img)(_p1##x,y,z,v), I[14] = (img)(x,y,z,v), I[15] = (img)(_n1##x,y,z,v), \
  499. I[16] = (img)(_n2##x,y,z,v), I[17] = (img)(_n3##x,y,z,v), I[18] = (img)(_p2##x,_n1##y,z,v), I[19] = (img)(_p1##x,_n1##y,z,v), \
  500. I[20] = (img)(x,_n1##y,z,v), I[21] = (img)(_n1##x,_n1##y,z,v), I[22] = (img)(_n2##x,_n1##y,z,v), I[23] = (img)(_n3##x,_n1##y,z,v), \
  501. I[24] = (img)(_p2##x,_n2##y,z,v), I[25] = (img)(_p1##x,_n2##y,z,v), I[26] = (img)(x,_n2##y,z,v), I[27] = (img)(_n1##x,_n2##y,z,v), \
  502. I[28] = (img)(_n2##x,_n2##y,z,v), I[29] = (img)(_n3##x,_n2##y,z,v), I[30] = (img)(_p2##x,_n3##y,z,v), I[31] = (img)(_p1##x,_n3##y,z,v), \
  503. I[32] = (img)(x,_n3##y,z,v), I[33] = (img)(_n1##x,_n3##y,z,v), I[34] = (img)(_n2##x,_n3##y,z,v), I[35] = (img)(_n3##x,_n3##y,z,v)
  504. #define cimg_get7x7(img,x,y,z,v,I) \
  505. I[0] = (img)(_p3##x,_p3##y,z,v), I[1] = (img)(_p2##x,_p3##y,z,v), I[2] = (img)(_p1##x,_p3##y,z,v), I[3] = (img)(x,_p3##y,z,v), \
  506. I[4] = (img)(_n1##x,_p3##y,z,v), I[5] = (img)(_n2##x,_p3##y,z,v), I[6] = (img)(_n3##x,_p3##y,z,v), I[7] = (img)(_p3##x,_p2##y,z,v), \
  507. I[8] = (img)(_p2##x,_p2##y,z,v), I[9] = (img)(_p1##x,_p2##y,z,v), I[10] = (img)(x,_p2##y,z,v), I[11] = (img)(_n1##x,_p2##y,z,v), \
  508. I[12] = (img)(_n2##x,_p2##y,z,v), I[13] = (img)(_n3##x,_p2##y,z,v), I[14] = (img)(_p3##x,_p1##y,z,v), I[15] = (img)(_p2##x,_p1##y,z,v), \
  509. I[16] = (img)(_p1##x,_p1##y,z,v), I[17] = (img)(x,_p1##y,z,v), I[18] = (img)(_n1##x,_p1##y,z,v), I[19] = (img)(_n2##x,_p1##y,z,v), \
  510. I[20] = (img)(_n3##x,_p1##y,z,v), I[21] = (img)(_p3##x,y,z,v), I[22] = (img)(_p2##x,y,z,v), I[23] = (img)(_p1##x,y,z,v), \
  511. I[24] = (img)(x,y,z,v), I[25] = (img)(_n1##x,y,z,v), I[26] = (img)(_n2##x,y,z,v), I[27] = (img)(_n3##x,y,z,v), \
  512. I[28] = (img)(_p3##x,_n1##y,z,v), I[29] = (img)(_p2##x,_n1##y,z,v), I[30] = (img)(_p1##x,_n1##y,z,v), I[31] = (img)(x,_n1##y,z,v), \
  513. I[32] = (img)(_n1##x,_n1##y,z,v), I[33] = (img)(_n2##x,_n1##y,z,v), I[34] = (img)(_n3##x,_n1##y,z,v), I[35] = (img)(_p3##x,_n2##y,z,v), \
  514. I[36] = (img)(_p2##x,_n2##y,z,v), I[37] = (img)(_p1##x,_n2##y,z,v), I[38] = (img)(x,_n2##y,z,v), I[39] = (img)(_n1##x,_n2##y,z,v), \
  515. I[40] = (img)(_n2##x,_n2##y,z,v), I[41] = (img)(_n3##x,_n2##y,z,v), I[42] = (img)(_p3##x,_n3##y,z,v), I[43] = (img)(_p2##x,_n3##y,z,v), \
  516. I[44] = (img)(_p1##x,_n3##y,z,v), I[45] = (img)(x,_n3##y,z,v), I[46] = (img)(_n1##x,_n3##y,z,v), I[47] = (img)(_n2##x,_n3##y,z,v), \
  517. I[48] = (img)(_n3##x,_n3##y,z,v)
  518. #define cimg_get8x8(img,x,y,z,v,I) \
  519. I[0] = (img)(_p3##x,_p3##y,z,v), I[1] = (img)(_p2##x,_p3##y,z,v), I[2] = (img)(_p1##x,_p3##y,z,v), I[3] = (img)(x,_p3##y,z,v), \
  520. I[4] = (img)(_n1##x,_p3##y,z,v), I[5] = (img)(_n2##x,_p3##y,z,v), I[6] = (img)(_n3##x,_p3##y,z,v), I[7] = (img)(_n4##x,_p3##y,z,v), \
  521. I[8] = (img)(_p3##x,_p2##y,z,v), I[9] = (img)(_p2##x,_p2##y,z,v), I[10] = (img)(_p1##x,_p2##y,z,v), I[11] = (img)(x,_p2##y,z,v), \
  522. I[12] = (img)(_n1##x,_p2##y,z,v), I[13] = (img)(_n2##x,_p2##y,z,v), I[14] = (img)(_n3##x,_p2##y,z,v), I[15] = (img)(_n4##x,_p2##y,z,v), \
  523. I[16] = (img)(_p3##x,_p1##y,z,v), I[17] = (img)(_p2##x,_p1##y,z,v), I[18] = (img)(_p1##x,_p1##y,z,v), I[19] = (img)(x,_p1##y,z,v), \
  524. I[20] = (img)(_n1##x,_p1##y,z,v), I[21] = (img)(_n2##x,_p1##y,z,v), I[22] = (img)(_n3##x,_p1##y,z,v), I[23] = (img)(_n4##x,_p1##y,z,v), \
  525. I[24] = (img)(_p3##x,y,z,v), I[25] = (img)(_p2##x,y,z,v), I[26] = (img)(_p1##x,y,z,v), I[27] = (img)(x,y,z,v), \
  526. I[28] = (img)(_n1##x,y,z,v), I[29] = (img)(_n2##x,y,z,v), I[30] = (img)(_n3##x,y,z,v), I[31] = (img)(_n4##x,y,z,v), \
  527. I[32] = (img)(_p3##x,_n1##y,z,v), I[33] = (img)(_p2##x,_n1##y,z,v), I[34] = (img)(_p1##x,_n1##y,z,v), I[35] = (img)(x,_n1##y,z,v), \
  528. I[36] = (img)(_n1##x,_n1##y,z,v), I[37] = (img)(_n2##x,_n1##y,z,v), I[38] = (img)(_n3##x,_n1##y,z,v), I[39] = (img)(_n4##x,_n1##y,z,v), \
  529. I[40] = (img)(_p3##x,_n2##y,z,v), I[41] = (img)(_p2##x,_n2##y,z,v), I[42] = (img)(_p1##x,_n2##y,z,v), I[43] = (img)(x,_n2##y,z,v), \
  530. I[44] = (img)(_n1##x,_n2##y,z,v), I[45] = (img)(_n2##x,_n2##y,z,v), I[46] = (img)(_n3##x,_n2##y,z,v), I[47] = (img)(_n4##x,_n2##y,z,v), \
  531. I[48] = (img)(_p3##x,_n3##y,z,v), I[49] = (img)(_p2##x,_n3##y,z,v), I[50] = (img)(_p1##x,_n3##y,z,v), I[51] = (img)(x,_n3##y,z,v), \
  532. I[52] = (img)(_n1##x,_n3##y,z,v), I[53] = (img)(_n2##x,_n3##y,z,v), I[54] = (img)(_n3##x,_n3##y,z,v), I[55] = (img)(_n4##x,_n3##y,z,v), \
  533. I[56] = (img)(_p3##x,_n4##y,z,v), I[57] = (img)(_p2##x,_n4##y,z,v), I[58] = (img)(_p1##x,_n4##y,z,v), I[59] = (img)(x,_n4##y,z,v), \
  534. I[60] = (img)(_n1##x,_n4##y,z,v), I[61] = (img)(_n2##x,_n4##y,z,v), I[62] = (img)(_n3##x,_n4##y,z,v), I[63] = (img)(_n4##x,_n4##y,z,v);
  535. #define cimg_get9x9(img,x,y,z,v,I) \
  536. I[0] = (img)(_p4##x,_p4##y,z,v), I[1] = (img)(_p3##x,_p4##y,z,v), I[2] = (img)(_p2##x,_p4##y,z,v), I[3] = (img)(_p1##x,_p4##y,z,v), \
  537. I[4] = (img)(x,_p4##y,z,v), I[5] = (img)(_n1##x,_p4##y,z,v), I[6] = (img)(_n2##x,_p4##y,z,v), I[7] = (img)(_n3##x,_p4##y,z,v), \
  538. I[8] = (img)(_n4##x,_p4##y,z,v), I[9] = (img)(_p4##x,_p3##y,z,v), I[10] = (img)(_p3##x,_p3##y,z,v), I[11] = (img)(_p2##x,_p3##y,z,v), \
  539. I[12] = (img)(_p1##x,_p3##y,z,v), I[13] = (img)(x,_p3##y,z,v), I[14] = (img)(_n1##x,_p3##y,z,v), I[15] = (img)(_n2##x,_p3##y,z,v), \
  540. I[16] = (img)(_n3##x,_p3##y,z,v), I[17] = (img)(_n4##x,_p3##y,z,v), I[18] = (img)(_p4##x,_p2##y,z,v), I[19] = (img)(_p3##x,_p2##y,z,v), \
  541. I[20] = (img)(_p2##x,_p2##y,z,v), I[21] = (img)(_p1##x,_p2##y,z,v), I[22] = (img)(x,_p2##y,z,v), I[23] = (img)(_n1##x,_p2##y,z,v), \
  542. I[24] = (img)(_n2##x,_p2##y,z,v), I[25] = (img)(_n3##x,_p2##y,z,v), I[26] = (img)(_n4##x,_p2##y,z,v), I[27] = (img)(_p4##x,_p1##y,z,v), \
  543. I[28] = (img)(_p3##x,_p1##y,z,v), I[29] = (img)(_p2##x,_p1##y,z,v), I[30] = (img)(_p1##x,_p1##y,z,v), I[31] = (img)(x,_p1##y,z,v), \
  544. I[32] = (img)(_n1##x,_p1##y,z,v), I[33] = (img)(_n2##x,_p1##y,z,v), I[34] = (img)(_n3##x,_p1##y,z,v), I[35] = (img)(_n4##x,_p1##y,z,v), \
  545. I[36] = (img)(_p4##x,y,z,v), I[37] = (img)(_p3##x,y,z,v), I[38] = (img)(_p2##x,y,z,v), I[39] = (img)(_p1##x,y,z,v), \
  546. I[40] = (img)(x,y,z,v), I[41] = (img)(_n1##x,y,z,v), I[42] = (img)(_n2##x,y,z,v), I[43] = (img)(_n3##x,y,z,v), \
  547. I[44] = (img)(_n4##x,y,z,v), I[45] = (img)(_p4##x,_n1##y,z,v), I[46] = (img)(_p3##x,_n1##y,z,v), I[47] = (img)(_p2##x,_n1##y,z,v), \
  548. I[48] = (img)(_p1##x,_n1##y,z,v), I[49] = (img)(x,_n1##y,z,v), I[50] = (img)(_n1##x,_n1##y,z,v), I[51] = (img)(_n2##x,_n1##y,z,v), \
  549. I[52] = (img)(_n3##x,_n1##y,z,v), I[53] = (img)(_n4##x,_n1##y,z,v), I[54] = (img)(_p4##x,_n2##y,z,v), I[55] = (img)(_p3##x,_n2##y,z,v), \
  550. I[56] = (img)(_p2##x,_n2##y,z,v), I[57] = (img)(_p1##x,_n2##y,z,v), I[58] = (img)(x,_n2##y,z,v), I[59] = (img)(_n1##x,_n2##y,z,v), \
  551. I[60] = (img)(_n2##x,_n2##y,z,v), I[61] = (img)(_n3##x,_n2##y,z,v), I[62] = (img)(_n4##x,_n2##y,z,v), I[63] = (img)(_p4##x,_n3##y,z,v), \
  552. I[64] = (img)(_p3##x,_n3##y,z,v), I[65] = (img)(_p2##x,_n3##y,z,v), I[66] = (img)(_p1##x,_n3##y,z,v), I[67] = (img)(x,_n3##y,z,v), \
  553. I[68] = (img)(_n1##x,_n3##y,z,v), I[69] = (img)(_n2##x,_n3##y,z,v), I[70] = (img)(_n3##x,_n3##y,z,v), I[71] = (img)(_n4##x,_n3##y,z,v), \
  554. I[72] = (img)(_p4##x,_n4##y,z,v), I[73] = (img)(_p3##x,_n4##y,z,v), I[74] = (img)(_p2##x,_n4##y,z,v), I[75] = (img)(_p1##x,_n4##y,z,v), \
  555. I[76] = (img)(x,_n4##y,z,v), I[77] = (img)(_n1##x,_n4##y,z,v), I[78] = (img)(_n2##x,_n4##y,z,v), I[79] = (img)(_n3##x,_n4##y,z,v), \
  556. I[80] = (img)(_n4##x,_n4##y,z,v)
  557. #define cimg_get2x2x2(img,x,y,z,v,I) \
  558. I[0] = (img)(x,y,z,v), I[1] = (img)(_n1##x,y,z,v), I[2] = (img)(x,_n1##y,z,v), I[3] = (img)(_n1##x,_n1##y,z,v), \
  559. I[4] = (img)(x,y,_n1##z,v), I[5] = (img)(_n1##x,y,_n1##z,v), I[6] = (img)(x,_n1##y,_n1##z,v), I[7] = (img)(_n1##x,_n1##y,_n1##z,v)
  560. #define cimg_get3x3x3(img,x,y,z,v,I) \
  561. I[0] = (img)(_p1##x,_p1##y,_p1##z,v), I[1] = (img)(x,_p1##y,_p1##z,v), I[2] = (img)(_n1##x,_p1##y,_p1##z,v), \
  562. I[3] = (img)(_p1##x,y,_p1##z,v), I[4] = (img)(x,y,_p1##z,v), I[5] = (img)(_n1##x,y,_p1##z,v), \
  563. I[6] = (img)(_p1##x,_n1##y,_p1##z,v), I[7] = (img)(x,_n1##y,_p1##z,v), I[8] = (img)(_n1##x,_n1##y,_p1##z,v), \
  564. I[9] = (img)(_p1##x,_p1##y,z,v), I[10] = (img)(x,_p1##y,z,v), I[11] = (img)(_n1##x,_p1##y,z,v), \
  565. I[12] = (img)(_p1##x,y,z,v), I[13] = (img)(x,y,z,v), I[14] = (img)(_n1##x,y,z,v), \
  566. I[15] = (img)(_p1##x,_n1##y,z,v), I[16] = (img)(x,_n1##y,z,v), I[17] = (img)(_n1##x,_n1##y,z,v), \
  567. I[18] = (img)(_p1##x,_p1##y,_n1##z,v), I[19] = (img)(x,_p1##y,_n1##z,v), I[20] = (img)(_n1##x,_p1##y,_n1##z,v), \
  568. I[21] = (img)(_p1##x,y,_n1##z,v), I[22] = (img)(x,y,_n1##z,v), I[23] = (img)(_n1##x,y,_n1##z,v), \
  569. I[24] = (img)(_p1##x,_n1##y,_n1##z,v), I[25] = (img)(x,_n1##y,_n1##z,v), I[26] = (img)(_n1##x,_n1##y,_n1##z,v)
  570. // Define various image loops.
  571. //
  572. // These macros generally avoid the use of iterators, but you are not forced to used them !
  573. //
  574. #define cimg_for(img,ptr,T_ptr) for (T_ptr *ptr = (img).data + (img).size(); (ptr--)>(img).data; )
  575. #define cimg_foroff(img,off) for (unsigned int off = 0, _max##off = (unsigned int)(img).size(); off<_max##off; ++off)
  576. #define cimglist_for(list,l) for (unsigned int l = 0; l<(list).size; ++l)
  577. #define cimglist_apply(list,fn) cimglist_for(list,__##fn) (list)[__##fn].fn
  578. #define cimg_for1(bound,i) for (int i = 0; i<(int)(bound); ++i)
  579. #define cimg_forX(img,x) cimg_for1((img).width,x)
  580. #define cimg_forY(img,y) cimg_for1((img).height,y)
  581. #define cimg_forZ(img,z) cimg_for1((img).depth,z)
  582. #define cimg_forV(img,v) cimg_for1((img).dim,v)
  583. #define cimg_forXY(img,x,y) cimg_forY(img,y) cimg_forX(img,x)
  584. #define cimg_forXZ(img,x,z) cimg_forZ(img,z) cimg_forX(img,x)
  585. #define cimg_forYZ(img,y,z) cimg_forZ(img,z) cimg_forY(img,y)
  586. #define cimg_forXV(img,x,v) cimg_forV(img,v) cimg_forX(img,x)
  587. #define cimg_forYV(img,y,v) cimg_forV(img,v) cimg_forY(img,y)
  588. #define cimg_forZV(img,z,v) cimg_forV(img,v) cimg_forZ(img,z)
  589. #define cimg_forXYZ(img,x,y,z) cimg_forZ(img,z) cimg_forXY(img,x,y)
  590. #define cimg_forXYV(img,x,y,v) cimg_forV(img,v) cimg_forXY(img,x,y)
  591. #define cimg_forXZV(img,x,z,v) cimg_forV(img,v) cimg_forXZ(img,x,z)
  592. #define cimg_forYZV(img,y,z,v) cimg_forV(img,v) cimg_forYZ(img,y,z)
  593. #define cimg_forXYZV(img,x,y,z,v) cimg_forV(img,v) cimg_forXYZ(img,x,y,z)
  594. #define cimg_for_in1(bound,i0,i1,i) \
  595. for (int i = (int)(i0)<0?0:(int)(i0), _max##i = (int)(i1)<(int)(bound)?(int)(i1):(int)(bound)-1; i<=_max##i; ++i)
  596. #define cimg_for_inX(img,x0,x1,x) cimg_for_in1((img).width,x0,x1,x)
  597. #define cimg_for_inY(img,y0,y1,y) cimg_for_in1((img).height,y0,y1,y)
  598. #define cimg_for_inZ(img,z0,z1,z) cimg_for_in1((img).depth,z0,z1,z)
  599. #define cimg_for_inV(img,v0,v1,v) cimg_for_in1((img).dim,v0,v1,v)
  600. #define cimg_for_inXY(img,x0,y0,x1,y1,x,y) cimg_for_inY(img,y0,y1,y) cimg_for_inX(img,x0,x1,x)
  601. #define cimg_for_inXZ(img,x0,z0,x1,z1,x,z) cimg_for_inZ(img,z0,z1,z) cimg_for_inX(img,x0,x1,x)
  602. #define cimg_for_inXV(img,x0,v0,x1,v1,x,v) cimg_for_inV(img,v0,v1,v) cimg_for_inX(img,x0,x1,x)
  603. #define cimg_for_inYZ(img,y0,z0,y1,z1,y,z) cimg_for_inZ(img,x0,z1,z) cimg_for_inY(img,y0,y1,y)
  604. #define cimg_for_inYV(img,y0,v0,y1,v1,y,v) cimg_for_inV(img,v0,v1,v) cimg_for_inY(img,y0,y1,y)
  605. #define cimg_for_inZV(img,z0,v0,z1,v1,z,v) cimg_for_inV(img,v0,v1,v) cimg_for_inZ(img,z0,z1,z)
  606. #define cimg_for_inXYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_inZ(img,z0,z1,z) cimg_for_inXY(img,x0,y0,x1,y1,x,y)
  607. #define cimg_for_inXYV(img,x0,y0,v0,x1,y1,v1,x,y,v) cimg_for_inV(img,v0,v1,v) cimg_for_inXY(img,x0,y0,x1,y1,x,y)
  608. #define cimg_for_inXZV(img,x0,z0,v0,x1,z1,v1,x,z,v) cimg_for_inV(img,v0,v1,v) cimg_for_inXZ(img,x0,z0,x1,z1,x,z)
  609. #define cimg_for_inYZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_inV(img,v0,v1,v) cimg_for_inYZ(img,y0,z0,y1,z1,y,z)
  610. #define cimg_for_inXYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_inV(img,v0,v1,v) cimg_for_inXYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)
  611. #define cimg_for_insideX(img,x,n) cimg_for_inX(img,n,(img).width-1-(n),x)
  612. #define cimg_for_insideY(img,y,n) cimg_for_inY(img,n,(img).height-1-(n),y)
  613. #define cimg_for_insideZ(img,z,n) cimg_for_inZ(img,n,(img).depth-1-(n),z)
  614. #define cimg_for_insideV(img,v,n) cimg_for_inV(img,n,(img).dim-1-(n),v)
  615. #define cimg_for_insideXY(img,x,y,n) cimg_for_inXY(img,n,n,(img).width-1-(n),(img).height-1-(n),x,y)
  616. #define cimg_for_insideXYZ(img,x,y,z,n) cimg_for_inXYZ(img,n,n,n,(img).width-1-(n),(img).height-1-(n),(img).depth-1-(n),x,y,z)
  617. #define cimg_for_insideXYZV(img,x,y,z,v,n) cimg_for_inXYZ(img,n,n,n,(img).width-1-(n),(img).height-1-(n),(img).depth-1-(n),x,y,z)
  618. #define cimg_for_out1(boundi,i0,i1,i) \
  619. for (int i = (int)(i0)>0?0:(int)(i1)+1; i<(int)(boundi); ++i, i = i==(int)(i0)?(int)(i1)+1:i)
  620. #define cimg_for_out2(boundi,boundj,i0,j0,i1,j1,i,j) \
  621. for (int j = 0; j<(int)(boundj); ++j) \
  622. for (int _n1j = (int)(j<(int)(j0) || j>(int)(j1)), i = _n1j?0:(int)(i0)>0?0:(int)(i1)+1; i<(int)(boundi); \
  623. ++i, i = _n1j?i:(i==(int)(i0)?(int)(i1)+1:i))
  624. #define cimg_for_out3(boundi,boundj,boundk,i0,j0,k0,i1,j1,k1,i,j,k) \
  625. for (int k = 0; k<(int)(boundk); ++k) \
  626. for (int _n1k = (int)(k<(int)(k0) || k>(int)(k1)), j = 0; j<(int)(boundj); ++j) \
  627. for (int _n1j = (int)(j<(int)(j0) || j>(int)(j1)), i = _n1j || _n1k?0:(int)(i0)>0?0:(int)(i1)+1; i<(int)(boundi); \
  628. ++i, i = _n1j || _n1k?i:(i==(int)(i0)?(int)(i1)+1:i))
  629. #define cimg_for_out4(boundi,boundj,boundk,boundl,i0,j0,k0,l0,i1,j1,k1,l1,i,j,k,l) \
  630. for (int l = 0; l<(int)(boundl); ++l) \
  631. for (int _n1l = (int)(l<(int)(l0) || l>(int)(l1)), k = 0; k<(int)(boundk); ++k) \
  632. for (int _n1k = (int)(k<(int)(k0) || k>(int)(k1)), j = 0; j<(int)(boundj); ++j) \
  633. for (int _n1j = (int)(j<(int)(j0) || j>(int)(j1)), i = _n1j || _n1k || _n1l?0:(int)(i0)>0?0:(int)(i1)+1; i<(int)(boundi); \
  634. ++i, i = _n1j || _n1k || _n1l?i:(i==(int)(i0)?(int)(i1)+1:i))
  635. #define cimg_for_outX(img,x0,x1,x) cimg_for_out1((img).width,x0,x1,x)
  636. #define cimg_for_outY(img,y0,y1,y) cimg_for_out1((img).height,y0,y1,y)
  637. #define cimg_for_outZ(img,z0,z1,z) cimg_for_out1((img).depth,z0,z1,z)
  638. #define cimg_for_outV(img,v0,v1,v) cimg_for_out1((img).dim,v0,v1,v)
  639. #define cimg_for_outXY(img,x0,y0,x1,y1,x,y) cimg_for_out2((img).width,(img).height,x0,y0,x1,y1,x,y)
  640. #define cimg_for_outXZ(img,x0,z0,x1,z1,x,z) cimg_for_out2((img).width,(img).depth,x0,z0,x1,z1,x,z)
  641. #define cimg_for_outXV(img,x0,v0,x1,v1,x,v) cimg_for_out2((img).width,(img).dim,x0,v0,x1,v1,x,v)
  642. #define cimg_for_outYZ(img,y0,z0,y1,z1,y,z) cimg_for_out2((img).height,(img).depth,y0,z0,y1,z1,y,z)
  643. #define cimg_for_outYV(img,y0,v0,y1,v1,y,v) cimg_for_out2((img).height,(img).dim,y0,v0,y1,v1,y,v)
  644. #define cimg_for_outZV(img,z0,v0,z1,v1,z,v) cimg_for_out2((img).depth,(img).dim,z0,v0,z1,v1,z,v)
  645. #define cimg_for_outXYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_out3((img).width,(img).height,(img).depth,x0,y0,z0,x1,y1,z1,x,y,z)
  646. #define cimg_for_outXYV(img,x0,y0,v0,x1,y1,v1,x,y,v) cimg_for_out3((img).width,(img).height,(img).dim,x0,y0,v0,x1,y1,v1,x,y,v)
  647. #define cimg_for_outXZV(img,x0,z0,v0,x1,z1,v1,x,z,v) cimg_for_out3((img).width,(img).depth,(img).dim,x0,z0,v0,x1,z1,v1,x,z,v)
  648. #define cimg_for_outYZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_out3((img).height,(img).depth,(img).dim,y0,z0,v0,y1,z1,v1,y,z,v)
  649. #define cimg_for_outXYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) \
  650. cimg_for_out4((img).width,(img).height,(img).depth,(img).dim,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v)
  651. #define cimg_for_borderX(img,x,n) cimg_for_outX(img,n,(img).width-1-(n),x)
  652. #define cimg_for_borderY(img,y,n) cimg_for_outY(img,n,(img).height-1-(n),y)
  653. #define cimg_for_borderZ(img,z,n) cimg_for_outZ(img,n,(img).depth-1-(n),z)
  654. #define cimg_for_borderV(img,v,n) cimg_for_outV(img,n,(img).dim-1-(n),v)
  655. #define cimg_for_borderXY(img,x,y,n) cimg_for_outXY(img,n,n,(img).width-1-(n),(img).height-1-(n),x,y)
  656. #define cimg_for_borderXYZ(img,x,y,z,n) cimg_for_outXYZ(img,n,n,n,(img).width-1-(n),(img).height-1-(n),(img).depth-1-(n),x,y,z)
  657. #define cimg_for_borderXYZV(img,x,y,z,v,n) \
  658. cimg_for_outXYZV(img,n,n,n,n,(img).width-1-(n),(img).height-1-(n),(img).depth-1-(n),(img).dim-1-(n),x,y,z,v)
  659. #define cimg_for_spiralXY(img,x,y) \
  660. for (int x = 0, y = 0, _n1##x = 1, _n1##y = (int)((img).width*(img).height); _n1##y; \
  661. --_n1##y, _n1##x += (_n1##x>>2)-((!(_n1##x&3)?--y:((_n1##x&3)==1?(img).width-1-++x:((_n1##x&3)==2?(img).height-1-++y:--x))))?0:1)
  662. #define cimg_for_lineXY(x,y,x0,y0,x1,y1) \
  663. for (int x = (int)(x0), y = (int)(y0), _sx = 1, _sy = 1, _steep = 0, \
  664. _dx=(x1)>(x0)?(int)(x1)-(int)(x0):(_sx=-1,(int)(x0)-(int)(x1)), \
  665. _dy=(y1)>(y0)?(int)(y1)-(int)(y0):(_sy=-1,(int)(y0)-(int)(y1)), \
  666. _counter = _dx, \
  667. _err = _dx>_dy?(_dy>>1):((_steep=1),(_counter=_dy),(_dx>>1)); \
  668. _counter>=0; \
  669. --_counter, x+=_steep? \
  670. (y+=_sy,(_err-=_dx)<0?_err+=_dy,_sx:0): \
  671. (y+=(_err-=_dy)<0?_err+=_dx,_sy:0,_sx))
  672. #define cimg_for2(bound,i) \
  673. for (int i = 0, _n1##i = 1>=(bound)?(int)(bound)-1:1; \
  674. _n1##i<(int)(bound) || i==--_n1##i; \
  675. ++i, ++_n1##i)
  676. #define cimg_for2X(img,x) cimg_for2((img).width,x)
  677. #define cimg_for2Y(img,y) cimg_for2((img).height,y)
  678. #define cimg_for2Z(img,z) cimg_for2((img).depth,z)
  679. #define cimg_for2V(img,v) cimg_for2((img).dim,v)
  680. #define cimg_for2XY(img,x,y) cimg_for2Y(img,y) cimg_for2X(img,x)
  681. #define cimg_for2XZ(img,x,z) cimg_for2Z(img,z) cimg_for2X(img,x)
  682. #define cimg_for2XV(img,x,v) cimg_for2V(img,v) cimg_for2X(img,x)
  683. #define cimg_for2YZ(img,y,z) cimg_for2Z(img,z) cimg_for2Y(img,y)
  684. #define cimg_for2YV(img,y,v) cimg_for2V(img,v) cimg_for2Y(img,y)
  685. #define cimg_for2ZV(img,z,v) cimg_for2V(img,v) cimg_for2Z(img,z)
  686. #define cimg_for2XYZ(img,x,y,z) cimg_for2Z(img,z) cimg_for2XY(img,x,y)
  687. #define cimg_for2XZV(img,x,z,v) cimg_for2V(img,v) cimg_for2XZ(img,x,z)
  688. #define cimg_for2YZV(img,y,z,v) cimg_for2V(img,v) cimg_for2YZ(img,y,z)
  689. #define cimg_for2XYZV(img,x,y,z,v) cimg_for2V(img,v) cimg_for2XYZ(img,x,y,z)
  690. #define cimg_for_in2(bound,i0,i1,i) \
  691. for (int i = (int)(i0)<0?0:(int)(i0), \
  692. _n1##i = i+1>=(int)(bound)?(int)(bound)-1:i+1; \
  693. i<=(int)(i1) && (_n1##i<(int)(bound) || i==--_n1##i); \
  694. ++i, ++_n1##i)
  695. #define cimg_for_in2X(img,x0,x1,x) cimg_for_in2((img).width,x0,x1,x)
  696. #define cimg_for_in2Y(img,y0,y1,y) cimg_for_in2((img).height,y0,y1,y)
  697. #define cimg_for_in2Z(img,z0,z1,z) cimg_for_in2((img).depth,z0,z1,z)
  698. #define cimg_for_in2V(img,v0,v1,v) cimg_for_in2((img).dim,v0,v1,v)
  699. #define cimg_for_in2XY(img,x0,y0,x1,y1,x,y) cimg_for_in2Y(img,y0,y1,y) cimg_for_in2X(img,x0,x1,x)
  700. #define cimg_for_in2XZ(img,x0,z0,x1,z1,x,z) cimg_for_in2Z(img,z0,z1,z) cimg_for_in2X(img,x0,x1,x)
  701. #define cimg_for_in2XV(img,x0,v0,x1,v1,x,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2X(img,x0,x1,x)
  702. #define cimg_for_in2YZ(img,y0,z0,y1,z1,y,z) cimg_for_in2Z(img,z0,z1,z) cimg_for_in2Y(img,y0,y1,y)
  703. #define cimg_for_in2YV(img,y0,v0,y1,v1,y,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2Y(img,y0,y1,y)
  704. #define cimg_for_in2ZV(img,z0,v0,z1,v1,z,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2Z(img,z0,z1,z)
  705. #define cimg_for_in2XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_in2Z(img,z0,z1,z) cimg_for_in2XY(img,x0,y0,x1,y1,x,y)
  706. #define cimg_for_in2XZV(img,x0,z0,v0,x1,y1,v1,x,z,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2XZ(img,x0,y0,x1,y1,x,z)
  707. #define cimg_for_in2YZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2YZ(img,y0,z0,y1,z1,y,z)
  708. #define cimg_for_in2XYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_in2V(img,v0,v1,v) cimg_for_in2XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)
  709. #define cimg_for3(bound,i) \
  710. for (int i = 0, _p1##i = 0, \
  711. _n1##i = 1>=(bound)?(int)(bound)-1:1; \
  712. _n1##i<(int)(bound) || i==--_n1##i; \
  713. _p1##i = i++, ++_n1##i)
  714. #define cimg_for3X(img,x) cimg_for3((img).width,x)
  715. #define cimg_for3Y(img,y) cimg_for3((img).height,y)
  716. #define cimg_for3Z(img,z) cimg_for3((img).depth,z)
  717. #define cimg_for3V(img,v) cimg_for3((img).dim,v)
  718. #define cimg_for3XY(img,x,y) cimg_for3Y(img,y) cimg_for3X(img,x)
  719. #define cimg_for3XZ(img,x,z) cimg_for3Z(img,z) cimg_for3X(img,x)
  720. #define cimg_for3XV(img,x,v) cimg_for3V(img,v) cimg_for3X(img,x)
  721. #define cimg_for3YZ(img,y,z) cimg_for3Z(img,z) cimg_for3Y(img,y)
  722. #define cimg_for3YV(img,y,v) cimg_for3V(img,v) cimg_for3Y(img,y)
  723. #define cimg_for3ZV(img,z,v) cimg_for3V(img,v) cimg_for3Z(img,z)
  724. #define cimg_for3XYZ(img,x,y,z) cimg_for3Z(img,z) cimg_for3XY(img,x,y)
  725. #define cimg_for3XZV(img,x,z,v) cimg_for3V(img,v) cimg_for3XZ(img,x,z)
  726. #define cimg_for3YZV(img,y,z,v) cimg_for3V(img,v) cimg_for3YZ(img,y,z)
  727. #define cimg_for3XYZV(img,x,y,z,v) cimg_for3V(img,v) cimg_for3XYZ(img,x,y,z)
  728. #define cimg_for_in3(bound,i0,i1,i) \
  729. for (int i = (int)(i0)<0?0:(int)(i0), \
  730. _p1##i = i-1<0?0:i-1, \
  731. _n1##i = i+1>=(int)(bound)?(int)(bound)-1:i+1; \
  732. i<=(int)(i1) && (_n1##i<(int)(bound) || i==--_n1##i); \
  733. _p1##i = i++, ++_n1##i)
  734. #define cimg_for_in3X(img,x0,x1,x) cimg_for_in3((img).width,x0,x1,x)
  735. #define cimg_for_in3Y(img,y0,y1,y) cimg_for_in3((img).height,y0,y1,y)
  736. #define cimg_for_in3Z(img,z0,z1,z) cimg_for_in3((img).depth,z0,z1,z)
  737. #define cimg_for_in3V(img,v0,v1,v) cimg_for_in3((img).dim,v0,v1,v)
  738. #define cimg_for_in3XY(img,x0,y0,x1,y1,x,y) cimg_for_in3Y(img,y0,y1,y) cimg_for_in3X(img,x0,x1,x)
  739. #define cimg_for_in3XZ(img,x0,z0,x1,z1,x,z) cimg_for_in3Z(img,z0,z1,z) cimg_for_in3X(img,x0,x1,x)
  740. #define cimg_for_in3XV(img,x0,v0,x1,v1,x,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3X(img,x0,x1,x)
  741. #define cimg_for_in3YZ(img,y0,z0,y1,z1,y,z) cimg_for_in3Z(img,z0,z1,z) cimg_for_in3Y(img,y0,y1,y)
  742. #define cimg_for_in3YV(img,y0,v0,y1,v1,y,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3Y(img,y0,y1,y)
  743. #define cimg_for_in3ZV(img,z0,v0,z1,v1,z,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3Z(img,z0,z1,z)
  744. #define cimg_for_in3XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_in3Z(img,z0,z1,z) cimg_for_in3XY(img,x0,y0,x1,y1,x,y)
  745. #define cimg_for_in3XZV(img,x0,z0,v0,x1,y1,v1,x,z,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3XZ(img,x0,y0,x1,y1,x,z)
  746. #define cimg_for_in3YZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3YZ(img,y0,z0,y1,z1,y,z)
  747. #define cimg_for_in3XYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_in3V(img,v0,v1,v) cimg_for_in3XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)
  748. #define cimg_for4(bound,i) \
  749. for (int i = 0, _p1##i = 0, _n1##i = 1>=(bound)?(int)(bound)-1:1, \
  750. _n2##i = 2>=(bound)?(int)(bound)-1:2; \
  751. _n2##i<(int)(bound) || _n1##i==--_n2##i || i==(_n2##i = --_n1##i); \
  752. _p1##i = i++, ++_n1##i, ++_n2##i)
  753. #define cimg_for4X(img,x) cimg_for4((img).width,x)
  754. #define cimg_for4Y(img,y) cimg_for4((img).height,y)
  755. #define cimg_for4Z(img,z) cimg_for4((img).depth,z)
  756. #define cimg_for4V(img,v) cimg_for4((img).dim,v)
  757. #define cimg_for4XY(img,x,y) cimg_for4Y(img,y) cimg_for4X(img,x)
  758. #define cimg_for4XZ(img,x,z) cimg_for4Z(img,z) cimg_for4X(img,x)
  759. #define cimg_for4XV(img,x,v) cimg_for4V(img,v) cimg_for4X(img,x)
  760. #define cimg_for4YZ(img,y,z) cimg_for4Z(img,z) cimg_for4Y(img,y)
  761. #define cimg_for4YV(img,y,v) cimg_for4V(img,v) cimg_for4Y(img,y)
  762. #define cimg_for4ZV(img,z,v) cimg_for4V(img,v) cimg_for4Z(img,z)
  763. #define cimg_for4XYZ(img,x,y,z) cimg_for4Z(img,z) cimg_for4XY(img,x,y)
  764. #define cimg_for4XZV(img,x,z,v) cimg_for4V(img,v) cimg_for4XZ(img,x,z)
  765. #define cimg_for4YZV(img,y,z,v) cimg_for4V(img,v) cimg_for4YZ(img,y,z)
  766. #define cimg_for4XYZV(img,x,y,z,v) cimg_for4V(img,v) cimg_for4XYZ(img,x,y,z)
  767. #define cimg_for_in4(bound,i0,i1,i) \
  768. for (int i = (int)(i0)<0?0:(int)(i0), \
  769. _p1##i = i-1<0?0:i-1, \
  770. _n1##i = i+1>=(int)(bound)?(int)(bound)-1:i+1, \
  771. _n2##i = i+2>=(int)(bound)?(int)(bound)-1:i+2; \
  772. i<=(int)(i1) && (_n2##i<(int)(bound) || _n1##i==--_n2##i || i==(_n2##i = --_n1##i)); \
  773. _p1##i = i++, ++_n1##i, ++_n2##i)
  774. #define cimg_for_in4X(img,x0,x1,x) cimg_for_in4((img).width,x0,x1,x)
  775. #define cimg_for_in4Y(img,y0,y1,y) cimg_for_in4((img).height,y0,y1,y)
  776. #define cimg_for_in4Z(img,z0,z1,z) cimg_for_in4((img).depth,z0,z1,z)
  777. #define cimg_for_in4V(img,v0,v1,v) cimg_for_in4((img).dim,v0,v1,v)
  778. #define cimg_for_in4XY(img,x0,y0,x1,y1,x,y) cimg_for_in4Y(img,y0,y1,y) cimg_for_in4X(img,x0,x1,x)
  779. #define cimg_for_in4XZ(img,x0,z0,x1,z1,x,z) cimg_for_in4Z(img,z0,z1,z) cimg_for_in4X(img,x0,x1,x)
  780. #define cimg_for_in4XV(img,x0,v0,x1,v1,x,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4X(img,x0,x1,x)
  781. #define cimg_for_in4YZ(img,y0,z0,y1,z1,y,z) cimg_for_in4Z(img,z0,z1,z) cimg_for_in4Y(img,y0,y1,y)
  782. #define cimg_for_in4YV(img,y0,v0,y1,v1,y,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4Y(img,y0,y1,y)
  783. #define cimg_for_in4ZV(img,z0,v0,z1,v1,z,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4Z(img,z0,z1,z)
  784. #define cimg_for_in4XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_in4Z(img,z0,z1,z) cimg_for_in4XY(img,x0,y0,x1,y1,x,y)
  785. #define cimg_for_in4XZV(img,x0,z0,v0,x1,y1,v1,x,z,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4XZ(img,x0,y0,x1,y1,x,z)
  786. #define cimg_for_in4YZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4YZ(img,y0,z0,y1,z1,y,z)
  787. #define cimg_for_in4XYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_in4V(img,v0,v1,v) cimg_for_in4XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)
  788. #define cimg_for5(bound,i) \
  789. for (int i = 0, _p2##i = 0, _p1##i = 0, \
  790. _n1##i = 1>=(bound)?(int)(bound)-1:1, \
  791. _n2##i = 2>=(bound)?(int)(bound)-1:2; \
  792. _n2##i<(int)(bound) || _n1##i==--_n2##i || i==(_n2##i = --_n1##i); \
  793. _p2##i = _p1##i, _p1##i = i++, ++_n1##i, ++_n2##i)
  794. #define cimg_for5X(img,x) cimg_for5((img).width,x)
  795. #define cimg_for5Y(img,y) cimg_for5((img).height,y)
  796. #define cimg_for5Z(img,z) cimg_for5((img).depth,z)
  797. #define cimg_for5V(img,v) cimg_for5((img).dim,v)
  798. #define cimg_for5XY(img,x,y) cimg_for5Y(img,y) cimg_for5X(img,x)
  799. #define cimg_for5XZ(img,x,z) cimg_for5Z(img,z) cimg_for5X(img,x)
  800. #define cimg_for5XV(img,x,v) cimg_for5V(img,v) cimg_for5X(img,x)
  801. #define cimg_for5YZ(img,y,z) cimg_for5Z(img,z) cimg_for5Y(img,y)
  802. #define cimg_for5YV(img,y,v) cimg_for5V(img,v) cimg_for5Y(img,y)
  803. #define cimg_for5ZV(img,z,v) cimg_for5V(img,v) cimg_for5Z(img,z)
  804. #define cimg_for5XYZ(img,x,y,z) cimg_for5Z(img,z) cimg_for5XY(img,x,y)
  805. #define cimg_for5XZV(img,x,z,v) cimg_for5V(img,v) cimg_for5XZ(img,x,z)
  806. #define cimg_for5YZV(img,y,z,v) cimg_for5V(img,v) cimg_for5YZ(img,y,z)
  807. #define cimg_for5XYZV(img,x,y,z,v) cimg_for5V(img,v) cimg_for5XYZ(img,x,y,z)
  808. #define cimg_for_in5(bound,i0,i1,i) \
  809. for (int i = (int)(i0)<0?0:(int)(i0), \
  810. _p2##i = i-2<0?0:i-2, \
  811. _p1##i = i-1<0?0:i-1, \
  812. _n1##i = i+1>=(int)(bound)?(int)(bound)-1:i+1, \
  813. _n2##i = i+2>=(int)(bound)?(int)(bound)-1:i+2; \
  814. i<=(int)(i1) && (_n2##i<(int)(bound) || _n1##i==--_n2##i || i==(_n2##i = --_n1##i)); \
  815. _p2##i = _p1##i, _p1##i = i++, ++_n1##i, ++_n2##i)
  816. #define cimg_for_in5X(img,x0,x1,x) cimg_for_in5((img).width,x0,x1,x)
  817. #define cimg_for_in5Y(img,y0,y1,y) cimg_for_in5((img).height,y0,y1,y)
  818. #define cimg_for_in5Z(img,z0,z1,z) cimg_for_in5((img).depth,z0,z1,z)
  819. #define cimg_for_in5V(img,v0,v1,v) cimg_for_in5((img).dim,v0,v1,v)
  820. #define cimg_for_in5XY(img,x0,y0,x1,y1,x,y) cimg_for_in5Y(img,y0,y1,y) cimg_for_in5X(img,x0,x1,x)
  821. #define cimg_for_in5XZ(img,x0,z0,x1,z1,x,z) cimg_for_in5Z(img,z0,z1,z) cimg_for_in5X(img,x0,x1,x)
  822. #define cimg_for_in5XV(img,x0,v0,x1,v1,x,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5X(img,x0,x1,x)
  823. #define cimg_for_in5YZ(img,y0,z0,y1,z1,y,z) cimg_for_in5Z(img,z0,z1,z) cimg_for_in5Y(img,y0,y1,y)
  824. #define cimg_for_in5YV(img,y0,v0,y1,v1,y,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5Y(img,y0,y1,y)
  825. #define cimg_for_in5ZV(img,z0,v0,z1,v1,z,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5Z(img,z0,z1,z)
  826. #define cimg_for_in5XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z) cimg_for_in5Z(img,z0,z1,z) cimg_for_in5XY(img,x0,y0,x1,y1,x,y)
  827. #define cimg_for_in5XZV(img,x0,z0,v0,x1,y1,v1,x,z,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5XZ(img,x0,y0,x1,y1,x,z)
  828. #define cimg_for_in5YZV(img,y0,z0,v0,y1,z1,v1,y,z,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5YZ(img,y0,z0,y1,z1,y,z)
  829. #define cimg_for_in5XYZV(img,x0,y0,z0,v0,x1,y1,z1,v1,x,y,z,v) cimg_for_in5V(img,v0,v1,v) cimg_for_in5XYZ(img,x0,y0,z0,x1,y1,z1,x,y,z)
  830. #define cimg_for6(bound,i) \
  831. for (int i = 0, _p2##i = 0, _p1##i = 0, \
  832. _n1##i = 1>=(bound)?(int)(bound)-1:1, \
  833. _n2##i = 2>=(bound)?(int)(bound)-1:2, \
  834. _n3##i = 3>=(bound)?(int)(bound)-1:3; \
  835. _n3##i<(int)(bound) || _n2##i==--_n3##i || _n1##i==--_n2##i || i==(_n3##i = _n2##i = --_n1##i); \
  836. _p2##i = _p1##i, _p1##i = i++, ++_n1##i, ++_n2##i, ++_n3##i)
  837. #define cimg_for6X(img,x) cimg_for6((img).width,x)
  838. #define cimg_for6Y(img,y) cimg_for6((img).height,y)
  839. #define cimg_for6Z(img,z) cimg_for6((img).depth,z)
  840. #define cimg_for6V(img,v) cimg_for6((img).dim,v)
  841. #define cimg_for6XY(img,x,y) cimg_for6Y(img,y) cimg_for6X(img,x)
  842. #define cimg_for6XZ(img,x,z) cimg_for6Z(img,z) cimg_for6X(img,x)
  843. #define cimg_for6XV(img,x,v) cimg_for6V(img,v) cimg_for6X(img,x)
  844. #define cimg_for6YZ(img,y,z) cimg_for6Z(img,z) cimg_for6Y(img,y)
  845. #define cimg_for6YV(img,y,v) cimg_for6V(img,v) cimg_for6Y(img,y)
  846. #define cimg_for6ZV(img,z,v) cimg_for6V(img,v) cimg_for6Z(img,z)
  847. #define cimg_for6XYZ(img,x,y,z) cimg_for6Z(img,z) cimg_for6XY(img,x,y)
  848. #define cimg_for6XZV(img,x,z,v) cimg_for6V(img,v) cimg_for6XZ(img,x,z)
  849. #define cimg_for6YZV(img,y,z,v) cimg_for6V(img,v) cimg_for6YZ(img,y,z)
  850. #define cimg_for6XYZV(img,x,y,z,v) cimg_for6V(img,v) cimg_for6XYZ(img,x,y,z)
  851. #define cimg_for_in6(bound

Large files files are truncated, but you can click here to view the full file