There are already many questions/answers about macro overloading. But, I cannot find a way to apply it to my particular problem.
I would like to conveniently assign values to my 3D images in C. For now, I do as follow:
#define IMGET(im,y,x,c) im.data[(y)+im.height*((x)+im.width*(c))]
#define IMSET(im,y,x,c,v) IMGET(im,y,x,c)=v
It works well.
But, I would like to use it also when I have black&white images, which are only 2D. Something, like that:
#define IMGET(im,y,x,c) im.data[(y)+im.height*((x)+im.width*(c))] //3D case
#define IMSET(im,y,x,c,v) IMGET(im,y,x,c)=v //3D case
#define IMGET(im,y,x) im.data[(y)+im.height*(x)] //2D case
#define IMSET(im,y,x,v) IMGET(im,y,x)=v //2D case
Is it possible?