chiark / gitweb /
WIP actual useful structure
[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 #ifdef DEBUG_RECTANGLES
18 # define CANIMG_DEBUG_RECTANGLE_1LINE(im,w,h)   \
19       fprintf(debug, "%4d ",y);                 \
20       int r= fwrite(im->d + y*w, 1,w, debug);   \
21       eassert(r==w);                            \
22       fputc('\n',debug);
23 #else
24 # define CANIMG_DEBUG_RECTANGLE_1LINE(im,y,h) /* nothing */
25 #endif
26
27 #define CANONICALISE_IMAGE(im,w,h, COMPUTE_RGB) do{             \
28     /* compute_rgb should be a number of statements, or         \
29      * a block, which assigns to                                \
30      *   unsigned long rgb;                                     \
31      * given the values of                                      \
32      *   int x,y;                                               \
33      * all of which are anamorphic.  Result is stored in im.    \
34      * The COMPUTE_RGB is executed exactly once for             \
35      * each pixel in reading order.                             \
36      */                                                         \
37     (im)= alloc_canon_image((w), (h));                          \
38                                                                 \
39     int x,y;                                                    \
40     for (y=0; y<(h); y++) {                                     \
41       for (x=0; x<(w); x++) {                                   \
42         const CanonColourInfo *cci;                             \
43         unsigned long rgb;                                      \
44         COMPUTE_RGB;                                            \
45         for (cci=canoncolourinfos; cci->c; cci++)               \
46           if (cci->rgb == rgb) {                                \
47             (im)->d[y*(w) + x]= cci->c;                         \
48             break;                                              \
49           }                                                     \
50       }                                                         \
51       CANIMG_DEBUG_RECTANGLE_1LINE((im),(w),(h))                \
52     }                                                           \
53     debug_flush();                                              \
54   }while(0)
55
56
57 #endif /*STRUCTURE_H*/