-typedef struct {
- int w, h;
- char data[];
- /* red = data[ y*w*3 + x*3 + 0 ] = RI_PIXEL(ri,x,y)[0]
- * green = data[ y*w*3 + x*3 + 1 ] = RI_PIXEL(ri,x,y)[1]
- * blue = data[ y*w*3 + x*3 + 2 ] = RI_PIXEL(ri,x,y)[2]
- */
-} RgbImage;
-
-RgbImage *alloc_rgb_image(int w, int h);
+#define CANONICALISE_IMAGE(im,w,h,rgb_save, COMPUTE_RGB) do{ \
+ /* compute_rgb should be a number of statements, or \
+ * a block, which assigns to \
+ * Rgb rgb; \
+ * given the values of \
+ * int x,y; \
+ * all of which are anamorphic. Result is stored in im. \
+ * The COMPUTE_RGB is executed exactly once for \
+ * each pixel in reading order. \
+ */ \
+ (im)= alloc_canon_image((w), (h)); \
+ (rgb_save)= alloc_rgb_image((w), (h)); \
+ \
+ int x,y; \
+ for (y=0; y<(h); y++) { \
+ for (x=0; x<(w); x++) { \
+ Rgb rgb; \
+ COMPUTE_RGB; \
+ CANONIMG_ALSO_STORERGB((rgb_save)); \
+ (im)->d[y*(w) + x]= canon_lookup_colour(rgb, rgb>>8, rgb>>16); \
+ } \
+ if (DEBUGP(rect)) { \
+ fprintf(debug, "%4d ",y); \
+ fwrite(im->d + y*(w), 1,(w), debug); \
+ fputc('\n',debug); \
+ } \
+ } \
+ debug_flush(); \
+ }while(0)