10 unsigned long rgb; /* on screen */
11 char c; /* canonical */
14 static const CanonColourInfo canoncolourinfos[]= {
15 { 0x475A5E, '*' }, /* edge */
16 { 0x7D9094, '+' }, /* interbox */
17 { 0xBDC5BF, ' ' }, /* background - pale */
18 { 0xADB5AF, ' ' }, /* background - dark */
19 { 0x000000, 'o' }, /* foreground */
20 { 0xD4B356, ' ' }, /* background (cursor) */
21 { 0xFFFFFF, 'o' }, /* foreground (cursor) */
25 static int height, width;
28 static void load_image_and_canonify(void) {
32 const CanonColourInfo *cci;
34 pnm_readpaminit(stdin, &inpam, sizeof(inpam));
37 eassert(inpam.maxval == 255);
38 eassert(inpam.bytes_per_sample == 1);
40 image= malloc(width*height);
42 memset(image,'?',width*height);
44 for (y=0; y<height; y++) {
45 for (x=0; x<width; x++) {
46 r= fread(&rgb,1,3,stdin); eassert(r==3);
48 ((unsigned long)rgb[0]<<16) |
49 ((unsigned long)rgb[1]<<8) |
51 for (cci=canoncolourinfos; cci->c; cci++)
52 if (cci->rgb == rgb_l) {
53 image[y*width + x]= cci->c;
56 if (y==234 && x==82) {
57 printf("y=%d/%d x=%d/%d rgb=%d,%d,%d rgb_l=%lx c=%c\n",
58 y,height,x,width, rgb[0],rgb[1],rgb[2], rgb_l, image[y*width+x]);
61 r= fwrite(image + y*width, 1,width, stdout); eassert(r==width);
64 eassert(!fflush(stdout));
65 eassert(!ferror(stdout));
69 load_image_and_canonify();
71 find_main_rectangle();
72 repeatedly_find_top_thing();