chiark / gitweb /
008c183421dd1a00a8148f5872240cc2d40d466c
[ypp-sc-tools.db-test.git] / pctb / structure.h
1 #ifndef STRUCTURE_H
2 #define STRUCTURE_H
3
4
5 #include "convert.h"
6
7
8 typedef struct {
9   unsigned long rgb; /* on screen */
10   char c; /* canonical */
11 } CanonColourInfo;
12
13 extern const CanonColourInfo canoncolourinfos[];
14
15 CanonImage *alloc_canon_image(int w, int h);
16
17 #define CANONICALISE_IMAGE(im,w,h, COMPUTE_RGB) do{             \
18     /* compute_rgb should be a number of statements, or         \
19      * a block, which assigns to                                \
20      *   unsigned long rgb;                                     \
21      * given the values of                                      \
22      *   int x,y;                                               \
23      * all of which are anamorphic.  Result is stored in im.    \
24      * The COMPUTE_RGB is executed exactly once for             \
25      * each pixel in reading order.                             \
26      */                                                         \
27     (im)= alloc_canon_image((w), (h));                          \
28                                                                 \
29     int x,y;                                                    \
30     for (y=0; y<(h); y++) {                                     \
31       for (x=0; x<(w); x++) {                                   \
32         const CanonColourInfo *cci;                             \
33         unsigned long rgb;                                      \
34         COMPUTE_RGB;                                            \
35         for (cci=canoncolourinfos; cci->c; cci++) {             \
36           if (cci->rgb == rgb) {                                \
37             (im)->d[y*(w) + x]= cci->c;                         \
38             break;                                              \
39           }                                                     \
40         }                                                       \
41       }                                                         \
42       if (DEBUGP(rect)) {                                       \
43         fprintf(debug, "%4d ",y);                               \
44         fwrite(im->d + y*w, 1,w, debug);                        \
45         fputc('\n',debug);                                      \
46       }                                                         \
47     }                                                           \
48     debug_flush();                                              \
49   }while(0)
50
51
52 #endif /*STRUCTURE_H*/