CImg 库中的奇怪语法,不知道它叫什么

Strange syntax in CImg library, don't know what it's called

我一直在使用 CImg 生成一些图像,但我遇到了一种奇怪的语法,我不知道它叫什么。它允许你做这样的事情:

cimg_forXYC(image, x, y, z){
    // I can set things about the image here
    image(x, y, z) = 100.;
}

我以前从未遇到过这种奇怪的用户自定义样式函数。它叫什么,它是如何创建的?

cimg_forXYC 是一个 macro,它大致取代了 for 循环,它用于遍历图像尺寸:

cimg_forXYC(img,x,y,v) : equivalent to : cimg_forC(img,v) cimg_forXY(img,x,y)

cimg_forC(img,v) : equivalent to : for (int v = 0; v<img.spectrum(); v++)
cimg_forXY(img,x,y) : equivalent to : cimg_forY(img,y) cimg_forX(img,x)

最后

cimg_forX(img,x) : equivalent to : for (int x = 0; x<img.width(); x++)

如果您 check the documentation,您将看到所有详细信息。

您的 image.operator()(int, int, int) returns 参考,因此您可以按照自己的方式使用它。