X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=pctb%2Fstructure.c;h=f0de5fa964d05f0c9e135b17fb99965200fff10b;hb=64063c86071bbfc2de0fe032e372e1321c4b34e5;hp=cb79f9996606b8209f0913267d0a3aed250a7370;hpb=5a8b5305bfbff13a3952e93d35e46c32b80c7606;p=ypp-sc-tools.web-live.git diff --git a/pctb/structure.c b/pctb/structure.c index cb79f99..f0de5fa 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -51,7 +51,12 @@ char *archipelago, *island; #define OTHERCOORD_x y #define OTHERCOORD_y x -const CanonColourInfo canoncolourinfos[]= { +typedef struct { + Rgb rgb; /* on screen */ + char c; /* canonical */ +} CanonColourInfo; + +const CanonColourInfo canoncolourinfo_table[]= { { 0x475A5E, '*' }, /* edge */ { 0x2C5F7A, '*' }, /* edge just under box heading shadow */ { 0xC5C7AE, '*' }, /* blank area of partial commodities list */ @@ -89,6 +94,31 @@ const CanonColourInfo canoncolourinfos[]= { { 0,0 } }; +CanonColourInfoReds canoncolourinfo_tree; + +void canon_colour_prepare(void) { + const CanonColourInfo *cci; + for (cci=canoncolourinfo_table; cci->c; cci++) { + unsigned char r= cci->rgb >> 16; + unsigned char g= cci->rgb >> 8; + unsigned char b= cci->rgb; + + CanonColourInfoGreens *greens= canoncolourinfo_tree.red2[r]; + if (!greens) { + greens= canoncolourinfo_tree.red2[r]= mmalloc(sizeof(*greens)); + FILLZERO(*greens); + } + + CanonColourInfoBlues *blues= greens->green2[g]; + if (!blues) { + blues= greens->green2[g]= mmalloc(sizeof(*blues)); + memset(blues, '?', sizeof(blues)); + } + + blues->blue2[b]= cci->c; + } +} + static void mustfail1(const char *file, int line, const char *what) { fprintf(stderr, @@ -390,15 +420,13 @@ static void file_read_image_ppm(FILE *f) { fatal("PNM screenshot(s) file must be 8bpp 1 byte-per-sample RGB raw"); CANONICALISE_IMAGE(im, inpam.width, inpam.height, { - int r= fread(&rgb_buf,1,3,f); + int rr= fread(&rgb_buf,1,3,f); sysassert(!ferror(f)); - if (r!=3) fatal("PNM screenshot(s) file ends unexpectedly"); - - rgb= - ((unsigned long)rgb_buf[0]<<16) | - ((unsigned long)rgb_buf[1]<<8) | - (rgb_buf[2]); + if (rr!=3) fatal("PNM screenshot(s) file ends unexpectedly"); + r= rgb_buf[0]; + g= rgb_buf[1]; + b= rgb_buf[2]; }); sysassert(!ferror(screenshot_file));