chiark / gitweb /
466c46624dda89ce1dafcf2fef8178ba3ddc2bab
[ypp-sc-tools.db-test.git] / pctb / structure.c
1 /*
2  * Parsing of the structure of the YPP client's displayed image
3  */
4 /*
5  *  This is part of ypp-sc-tools, a set of third-party tools for assisting
6  *  players of Yohoho Puzzle Pirates.
7  * 
8  *  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9  * 
10  *  This program is free software: you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation, either version 3 of the License, or
13  *  (at your option) any later version.
14  * 
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  * 
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  * 
23  *  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24  *  are used without permission.  This program is not endorsed or
25  *  sponsored by Three Rings.
26  */
27
28 #include "structure.h"
29
30 static const CanonImage *cim;
31
32 static inline char get(int x, int y) { return cim->d[y * cim->w + x]; }
33 static inline char get_p(Point p) { return get(p.x,p.y); }
34
35 DEBUG_DEFINE_DEBUGF(struct)
36
37 #define START_MAIN {200,200}
38 #define MIN_COLUMNS         6
39 #define INTERESTING_COLUMNS 7
40 #define TEXT_COLUMNS        2
41 #define MAX_COLUMNS         7
42
43 static Rect mainr = { START_MAIN,START_MAIN };
44 static int commbasey, comminty;
45 static int colrightx[INTERESTING_COLUMNS];
46 static int text_h=-1, columns=-1;
47 static OcrReader *rd;
48
49 char *archipelago, *island;
50
51 #define OTHERCOORD_x y
52 #define OTHERCOORD_y x
53
54 const CanonColourInfo canoncolourinfos[]= {
55   { 0x475A5E, '*' }, /* edge */
56   { 0x2C5F7A, '*' }, /* edge just under box heading shadow */
57   { 0xC5C7AE, '*' }, /* blank area of partial commodities list */
58   { 0x6B828C, '*' }, /* background of ship status meter area */
59   { 0x934405, '*' }, /* border of ship meter area */
60   { 0x7D9094, '+' }, /* interbox */
61   { 0x022158, 'a' }, /* ahoy /w output foreground */
62
63   { 0xBDC5BF, ' ' }, /* background - pale  Sugar cane, etc. */
64   { 0xADB5AF, ' ' }, /* background - dark                   */
65   { 0xC7E1C3, ' ' }, /* background - pale  Swill, etc.      */
66   { 0xB5CFB1, ' ' }, /* background - dark                   */
67   { 0xD6CEB0, ' ' }, /* background - pale  Madder, etc.     */
68   { 0xC8C0A2, ' ' }, /* background - dark                   */
69   { 0xE0E1D3, ' ' }, /* background - pale  Lorandite, etc.  */
70   { 0xD0D1C3, ' ' }, /* background - dark                   */
71   { 0xE5E6C1, ' ' }, /* background - pale  Cloth            */
72   { 0xD7D8B3, ' ' }, /* background - dark                   */
73   { 0xEDDED9, ' ' }, /* background - pale  Dye              */
74   { 0xDACBC6, ' ' }, /* background - dark                   */
75   { 0xD3DEDF, ' ' }, /* background - pale  Paint            */
76   { 0xC5D0D1, ' ' }, /* background - dark                   */
77   { 0xDCD1CF, ' ' }, /* background - pale  Enamel           */
78   { 0xCEC3C1, ' ' }, /* background - dark                   */
79   { 0xF3F6F5, ' ' }, /* background - pale  fruit            */
80   { 0xE2E7E5, ' ' }, /* background - dark                   */
81
82   { 0x000000, 'o' }, /* foreground */
83   { 0xD4B356, ' ' }, /* background (cursor) */
84   { 0xFFFFFF, 'o' }, /* foreground (cursor) */
85
86   { 0x5B93BF, '_' }, /* selector dropdown background */
87   { 0xD7C94F, 'X' }, /* selector dropdown foreground */
88   { 0,0 }
89 };
90
91
92 static void mustfail1(const char *file, int line, const char *what) {
93   fprintf(stderr,
94           "\n\n"
95           "Unable to figure out contents of YPP client display.\n"
96           " Check that your client is logged in has the correct display.\n"
97           " If that isn't the problem, please report this as a fault.\n\n"
98           "Technical details:"
99           " %s:%d: requirement failed:\n"
100           " %s\n",
101           file, line, what);
102 }
103 static void mustfail2(void) NORET;
104 static void mustfail2(void) {
105   fprintf(stderr, "\n\nGiving up.\n");
106   exit(8);
107 }
108
109 #define MUST(x, ifnot) do{                      \
110     if (!(x)) {                                 \
111       mustfail1(__FILE__,__LINE__,#x);          \
112       ifnot;                                    \
113       mustfail2();                              \
114     }                                           \
115   }while(0)
116
117 #define MP(v) fprintf(stderr," %s=%d,%d",#v,(v).x,(v).y)
118 #define MI(v) fprintf(stderr," %s=%d",   #v,(v))
119 #define MC(v) fprintf(stderr," %s='%c'", #v,(v))
120 #define MS(v) fprintf(stderr," %s=\"%s\"", #v,(v))
121 #define MSB(v) fprintf(stderr," %s", (v))
122 #define MR(v) fprintf(stderr," %s=%d,%d..%d,%d",\
123                       #v,(v).tl.x,(v).tl.y,(v).br.x,(v).br.y)
124
125
126 #define REQUIRE_RECTANGLE(tlx,tly,brx,bry,ok) \
127  require_rectangle(tlx, tly, brx, bry, ok, __LINE__);
128
129 static void require_rectangle(int tlx, int tly, int brx, int bry,
130                               const char *ok, int lineno) {
131   Point p;
132   for (p.x=tlx; p.x<=brx; p.x++)
133     for (p.y=tly; p.y<=bry; p.y++) {
134       int c= get_p(p);
135       MUST( strchr(ok,c), ({
136              Rect rm={{tlx,tly},{brx,bry}};
137              MI(lineno),MR(rm);MP(p);MS(ok);
138       }));
139     }
140 }
141 static void require_rectangle_r(Rect rr, const char *ok, int lineno) {
142   require_rectangle(rr.tl.x,rr.tl.y, rr.br.x,rr.br.y, ok, lineno);
143 }
144
145 static void debug_rect(const char *what, int whati, Rect rr) {
146   if (!DEBUGP(rect)) return;
147   int y,w;
148   fprintf(debug, "%s %d: %d,%d..%d,%d:\n", what, whati,
149           rr.tl.x,rr.tl.y, rr.br.x,rr.br.y);
150   w= rr.br.x - rr.tl.x + 1;
151   for (y=rr.tl.y; y<=rr.br.y; y++) {
152     fprintf(debug, "%4d%*s|", y, rr.tl.x,"");
153     fwrite(cim->d + y*cim->w + rr.tl.x, 1, w, debug);
154     fputc('|',debug);
155     fputc('\n',debug);
156   }
157   debug_flush();
158 }
159
160 static int commod_selector_matches(Rect search, const char *const *all,
161                                    int allh, int allw) {
162   int alloffy, alloffx;
163   for (alloffy=0; alloffy < search.br.y; alloffy++) {
164     if (alloffy+allh-1 < search.tl.y) continue;
165     for (alloffx=search.tl.x; alloffx+allw-1 <= search.br.x; alloffx++) {
166       int good=0, bad=0;
167       int x,y;
168       for (x=0; x<allw; x++)
169         for (y=0; y<allh; y++) {
170           int want= all[y][x];
171           if (want==' ') continue;
172           if (get(alloffx+x, alloffy+y) == want)
173             good++;
174           else
175             bad++;
176         }
177       debugf("CHECKCOMMOD alloff=%d,%d good=%d bad=%d\n",
178              alloffx,alloffy, good,bad);
179       if (good > 20*bad)
180         return 1;
181     }
182   }
183   return 0;
184 }
185
186 #define WALK_UNTIL(point,coord,increm,last,edge)                        \
187   for (;;) {                                                            \
188     if ((point).coord == (last)+(increm)) break;                        \
189     if (get_p((point)) == (edge)) { (point).coord -= (increm); break; } \
190     (point).coord += (increm);                                          \
191   }
192
193 #define WALK_UNTIL_MUST(point,coord,increm,last,edge)   \
194   do {                                                  \
195     WALK_UNTIL(point,coord,increm,last,edge);           \
196     MUST( (point).coord != (last)+(increm),             \
197           MP(point); MI(increm); MI(last); MC(edge);    \
198           );                                            \
199   }while(0)
200
201 #define ADJUST_BOX(search,insidechrs,want, lim,LIMIT_MUST, TLBR,XY,increm) \
202   for (;;) {                                                               \
203     LIMIT_MUST( (search).tl.XY != (search).br.XY &&                        \
204                 (search).tl.XY != (lim),                                   \
205                 MR((search));MSB(#TLBR);MSB(#XY) );                        \
206     int got=0;                                                             \
207     Point p=(search).tl;                                                   \
208     for (p.XY=(search).TLBR.XY;                                            \
209          p.OTHERCOORD_##XY <= (search).br.OTHERCOORD_##XY;                 \
210          p.OTHERCOORD_##XY++)                                              \
211       got += !!strchr(insidechrs, get_p(p));                               \
212     if (got >= (want))                                                     \
213       break;                                                               \
214     (search).TLBR.XY += increm;                                            \
215   }
216
217 void find_structure(const CanonImage *im, int *max_relevant_y_r) {
218   cim= im;
219   
220   Rect whole = { {0,0}, {cim->w-1,cim->h-1} };
221
222   if (DEBUGP(rect)) {
223     int xscaleunit, y,x;
224     for (y=0, xscaleunit=1; y<4; y++, xscaleunit*=10) {
225       fprintf(debug,"     ");
226       for (x=0; x<=cim->w; x++) {
227         if (x % xscaleunit) fputc(' ',debug);
228         else fprintf(debug,"%d",(x / xscaleunit)%10);
229       }
230       fputc('\n',debug);
231     }
232   }
233
234   WALK_UNTIL_MUST(mainr.tl, x,-1, whole.tl.x, '*');
235   WALK_UNTIL_MUST(mainr.tl, y,-1, whole.tl.y, '*');
236   WALK_UNTIL_MUST(mainr.br, x,+1, whole.br.x, '*');
237   WALK_UNTIL_MUST(mainr.br, y,+1, whole.br.y, '*');
238
239   REQUIRE_RECTANGLE(mainr.tl.x-1, mainr.tl.y, mainr.tl.x-1, mainr.br.y, "*");
240   REQUIRE_RECTANGLE(mainr.br.x+1, mainr.tl.y, mainr.br.x+1, mainr.br.y, "*");
241   REQUIRE_RECTANGLE(mainr.tl.x, mainr.tl.y-1, mainr.br.x, mainr.tl.y-1, "*");
242   REQUIRE_RECTANGLE(mainr.tl.x, mainr.br.y+1, mainr.br.x, mainr.br.y+1, "*");
243
244 #define CHECK_STRIP_BORDER(tlbr,xy,increm)              \
245   do {                                                  \
246     Point csb_p;                                        \
247     Rect csb_r;                                         \
248     csb_p= mainr.tl;                                    \
249     csb_p.xy= mainr.tlbr.xy;                            \
250     if (get_p(csb_p)=='+') {                            \
251       csb_r= mainr;                                     \
252       csb_r.tl.xy= csb_p.xy;                            \
253       csb_r.br.xy= csb_p.xy;                            \
254       require_rectangle_r(csb_r, "+", __LINE__);        \
255       mainr.tlbr.xy += increm;                          \
256     }                                                   \
257   } while(0)
258
259   debug_rect("mainr",0, mainr);
260
261   CHECK_STRIP_BORDER(tl,x,+1);
262   CHECK_STRIP_BORDER(tl,y,+1);
263   CHECK_STRIP_BORDER(br,x,-1);
264   CHECK_STRIP_BORDER(br,y,-1);
265
266   debug_rect("mainr",1, mainr);
267
268   Point up = START_MAIN;
269   WALK_UNTIL_MUST(up, y,-1, mainr.tl.y, '+');
270
271   Point down = START_MAIN;
272   down.y++;
273   WALK_UNTIL_MUST(down, y,+1, mainr.br.y, '+');
274
275   commbasey= up.y;
276   comminty= down.y - up.y + 2;
277
278   Point across= { mainr.tl.x, commbasey };
279   int colno=0;
280   for (;;) {
281     MUST( get_p(across) != '+', MI(colno);MP(across);MR(mainr);MI(commbasey) );
282     WALK_UNTIL(across, x,+1, mainr.br.x, '+');
283     MUST( colno < MAX_COLUMNS, MP(across);MR(mainr);MI(commbasey); );
284     int colrx= across.x;
285     if (colrx > mainr.br.x) colrx= mainr.br.x;
286     if (colno < INTERESTING_COLUMNS)
287       colrightx[colno]= colrx;
288       
289     colno++;
290     
291     if (across.x >= mainr.br.x-1)
292       break;
293
294     across.x++;
295     REQUIRE_RECTANGLE(across.x,mainr.tl.y, across.x,mainr.br.y, "+");
296     across.x++;
297   }
298   MUST( colno >= MIN_COLUMNS, MI(colno);MR(mainr);MP(across); );
299
300 #define SET_ONCE(var,val) do{                                           \
301     int v= (val);                                                       \
302     if ((var)==-1) (var)= v;                                            \
303     else MUST( (var) == v, MSB(#var);MI((var));MI(v);MR(mainr); );      \
304   }while(0)
305
306   SET_ONCE(columns, colno);
307   SET_ONCE(text_h, comminty - 1);
308   if (max_relevant_y_r)
309     SET_ONCE(*max_relevant_y_r, mainr.br.y + 10);
310 }                   
311
312 void check_correct_commodities(void) {
313   Rect search= { { 50,39 }, { 130,59 } };
314
315   ADJUST_BOX(search,"_",10, cim->h, MUST, tl,y,+1);
316   ADJUST_BOX(search,"_",10, 0,      MUST, br,y,-1);
317
318   debug_rect("commodselr",1, search);
319
320   static const char *all_small[]= {
321     "   ___________________________________   ",
322     "  ________X____X__X____________________  ",
323     " ________ X___ X_ X_____XXXXXXXXXXX_____ ",
324     "_________X_X__ X_ X______XXXXXXXXX_______",
325     "________ X X__ X_ X_______XXXXXXX________",
326     "________X_ _X_ X_ X________XXXXX_________",
327     "_______ X__ X_ X_ X_________XXX__________",
328     "_______XXXXXXX X_ X__________X___________",
329     " _____ X     X X_ X______________________",
330     "  ____X_____ _XX_ X______________________",
331     "   __ _______  __ ______________________ ",
332   };
333   static const char *all_big[]= {
334     "???_______________________________________???",
335     "??_________________________________________??",
336     "?_________X______X___X______________________?",
337     "_________?X_____?X__?X______XXXXXXXXXXX______",
338     "_________X_X____?X__?X_______XXXXXXXXX_______",
339     "________?X?X____?X__?X________XXXXXXX________",
340     "________X_?_X___?X__?X_________XXXXX_________",
341     "_______?X__?X___?X__?X__________XXX__________",
342     "_______?XXXXX___?X__?X___________X___________",
343     "_______X????_X__?X__?X_______________________",
344     "?_____?X____?X__?X__?X_______________________",
345     "??____X_____?_X_?X__?X_______________________",
346     "???__?_______?__?___?_______________________?",
347   };
348
349 #define COMMOD_SELECTOR_MATCHES(all)                            \
350   commod_selector_matches(search, all,                          \
351                           sizeof((all))/sizeof((all)[0]),       \
352                           strlen((all)[0]))
353
354   if (!(COMMOD_SELECTOR_MATCHES(all_small) ||
355         COMMOD_SELECTOR_MATCHES(all_big)))
356     fatal("Commodities selector not set to `All'.");
357 }
358
359 CanonImage *alloc_canon_image(int w, int h) {
360   CanonImage *im= mmalloc(sizeof(CanonImage) + w*h);
361   im->w= w;
362   im->h= h;
363   memset(im->d,'?',w*h);
364   return im;
365 }
366
367 static void file_read_image_ppm(FILE *f) {
368   struct pam inpam;
369   unsigned char rgb_buf[3];
370   CanonImage *im;
371   RgbImage *ri=0;
372
373   pnm_readpaminit(f, &inpam, sizeof(inpam));
374   if (!(inpam.maxval == 255 &&
375         inpam.bytes_per_sample == 1 &&
376         inpam.format == RPPM_FORMAT))
377     fatal("PNM screenshot(s) file must be 8bpp 1 byte per sample RGB");
378
379   if (!npages)
380     page0_rgbimage= ri= alloc_rgb_image(inpam.width, inpam.height);
381
382   CANONICALISE_IMAGE(im, inpam.width, inpam.height, {
383     int r= fread(&rgb_buf,1,3,f);
384     sysassert(!ferror(f));
385     if (r!=3) fatal("PNM screenshot(s) file ends unexpectedly");
386
387     rgb=
388         ((unsigned long)rgb_buf[0]<<16) |
389         ((unsigned long)rgb_buf[1]<<8) |
390                        (rgb_buf[2]);
391
392     if (ri)
393       CANONIMG_ALSO_STORERGB(ri);
394   });
395
396   sysassert(!ferror(screenshot_file));
397
398   if (!(npages < MAX_PAGES))
399     fatal("Too many images in screenshots file; max is %d.\n", MAX_PAGES);
400
401   page_images[npages++]= im;
402 }
403
404 void read_one_screenshot(void) {
405   progress("reading screenshot...");
406   file_read_image_ppm(screenshot_file);
407   progress_log("read screenshot.");
408 }
409
410 void read_screenshots(void) {
411   struct stat stab;
412   
413   sysassert(! fstat(fileno(screenshot_file), &stab) );
414   
415   for (;;) {
416     if (S_ISREG(stab.st_mode)) {
417       long pos= ftell(screenshot_file);
418       if (pos == stab.st_size) break;
419     } else {
420       int c= fgetc(screenshot_file);
421       if (c==EOF) break;
422       ungetc(c, screenshot_file);
423     }
424     progress("reading screenshot %d...",npages);
425     file_read_image_ppm(screenshot_file);
426   }
427   sysassert(!ferror(screenshot_file));
428   progress_log("read %d screenshots.",npages);
429 }
430
431 static void find_commodity(int offset, Rect *rr) {
432   /* rr->tl.x==-1 if offset out of range */
433   rr->tl.y= commbasey - offset*comminty;
434   rr->br.y= rr->tl.y + comminty-2;
435   if (rr->tl.y < mainr.tl.y || rr->br.y > mainr.br.y) { rr->tl.x=-1; return; }
436   
437   rr->tl.x= mainr.tl.x;
438   rr->br.x= mainr.br.x;
439
440   if (rr->tl.y > mainr.tl.y)
441     REQUIRE_RECTANGLE(rr->tl.x,rr->tl.y-1, rr->br.x,rr->tl.y-1, "+");
442   if (rr->br.y < mainr.tl.y)
443     REQUIRE_RECTANGLE(rr->tl.x,rr->br.y+1, rr->br.x,rr->br.y+1, "+");
444 }
445
446 static void find_table_entry(Rect commod, int colno, Rect *cellr) {
447   cellr->tl.y= commod.tl.y;
448   cellr->br.y= commod.br.y;
449   cellr->tl.x= !colno ? commod.tl.x : colrightx[colno-1]+2;
450   cellr->br.x=                        colrightx[colno];
451   debug_rect("cell", colno, *cellr);
452   require_rectangle_r(*cellr, " o", __LINE__);
453 }
454
455 static void ocr_rectangle(Rect r, const OcrCellType ct, FILE *tsv_output) {
456   OcrResultGlyph *results, *res;
457
458   int w= r.br.x - r.tl.x + 1;
459   Pixcol cols[w+1];
460   int x,y;
461   for (x=0; x<w; x++) {
462     Pixcol cx, rv;
463     for (y=0, cx=0, rv=1; y<text_h; y++, rv<<=1) {
464       Point here= { x+r.tl.x, y+r.tl.y };
465       int pixel= get_p(here);
466       switch (pixel) {
467       case ' ':           break;
468       case 'o': cx |= rv; break;
469       default:
470         MUST(!"wrong pixel",
471              MC(pixel);MP(here);MSB(ocr_celltype_name(ct));MR(r); );
472       }
473     }
474     cols[x]= cx;
475   }
476   cols[w]= 0;
477
478   results= ocr(rd,ct,w,cols);
479   for (res=results; res->s; res++)
480     fputs(res->s,tsv_output);
481 }
482
483 void analyse(FILE *tsv_output) {
484   Rect thisr, entryr;
485   int page, tryrect, colno;
486
487   for (page=0; page<npages; page++) {
488     find_structure(page_images[page], 0);
489
490     if (!page)
491       check_correct_commodities();
492
493     if (!rd)
494       rd= ocr_init(text_h);
495
496     progress("Scanning page %d...",page);
497
498     for (tryrect= +cim->h; tryrect >= -cim->h; tryrect--) {
499       find_commodity(tryrect, &thisr);
500       if (thisr.tl.x < 0)
501         continue;
502       debug_rect("commod",tryrect, thisr);
503
504       const char *tab= "";
505       for (colno=0; colno<columns; colno++) {
506         find_table_entry(thisr,colno,&entryr);
507         fputs(tab, tsv_output);
508         ocr_rectangle(entryr,
509                       colno<TEXT_COLUMNS
510                       ? &ocr_celltype_text
511                       : &ocr_celltype_number,
512                       tsv_output);
513         tab= "\t";
514       }
515       fputs("\n", tsv_output);
516       sysassert(!ferror(tsv_output));
517       sysassert(!fflush(tsv_output));
518     }
519   }
520   progress("Commodity table scan complete.");
521 }
522
523 //static Rect islandnamer;
524
525 void find_islandname(void) {
526   Rect sunshiner;
527   char sunshine[MAXIMGIDENT], archisland[MAXIMGIDENT];
528
529   RgbImage *ri= alloc_rgb_image(page0_rgbimage->w, page0_rgbimage->h);
530   const unsigned char *srcp;
531   unsigned char *destp, *endp;
532   for (srcp=page0_rgbimage->data, destp=ri->data,
533          endp= ri->data + 3 * ri->w * ri->h;
534        destp < endp;
535        srcp++, destp++) {
536     unsigned char c= *srcp & 0xf0;
537     *destp= c | (c>>4);
538   }
539
540   cim= page_images[0];
541   
542   sunshiner.tl.x= cim->w - 1034 +  885;
543   sunshiner.br.x= cim->w - 1034 + 1020;
544   sunshiner.tl.y= 227;
545   sunshiner.br.y= 228;
546
547   ADJUST_BOX(sunshiner,"o*",30, 100,MUST, tl,y,-1);
548   ADJUST_BOX(sunshiner,"o*",30, 100,MUST, br,y,+1);
549   debug_rect("sunshiner",0, sunshiner);
550
551   MUST(sunshiner.br.y - sunshiner.tl.y > 20, MR(sunshiner));
552   sunshiner.br.y--;
553
554   ADJUST_BOX(sunshiner,"o",20, (cim->w - 1034 + 700), MUST, tl,x,-1);
555   ADJUST_BOX(sunshiner,"o",20,  cim->w,               MUST, br,x,+1);
556   debug_rect("sunshiner",1, sunshiner);
557
558   identify_rgbimage(ri, sunshiner, sunshine, "sunshine widget");
559   
560   if (!memcmp(sunshine,"Vessel ",5)) {
561     Rect islandnamer;
562     
563     islandnamer.tl.x= cim->w - 1034 +  885;
564     islandnamer.br.x= cim->w - 1034 + 1020;
565     islandnamer.tl.y=                 128;
566     islandnamer.br.y=                 156;
567
568     ADJUST_BOX(islandnamer,"o",5, 0,      MUST, tl,y,+1);
569     ADJUST_BOX(islandnamer,"o",5, cim->h, MUST, br,y,-1);
570
571     ADJUST_BOX(islandnamer,"o",1, 0,      MUST, tl,x,+1);
572     ADJUST_BOX(islandnamer,"o",1, cim->w, MUST, br,x,-1);
573
574     debug_rect("islandnamer",0, islandnamer);
575 //    int larger_islandnamebry= islandnamer.tl.y + 25;
576 //    MUST(islandnamer.br.y < larger_islandnamebry,
577 //       MR(islandnamer);MI(larger_islandnamebry));
578 //    islandnamer.br.y = larger_islandnamebry;
579     debug_rect("islandnamer",1, islandnamer);
580
581     int x,y,i;
582     for (x=islandnamer.tl.x; x<=islandnamer.br.x; x++)
583       for (y=islandnamer.tl.y; y<=islandnamer.br.y; y++) {
584         if (RI_PIXEL(ri,x,y)[0] < 0x40) {
585           for (i=0; i<3; i++) {
586             RI_PIXEL(ri,x,y)[i]= 0;
587           }
588         }
589       }
590
591     identify_rgbimage(ri, islandnamer, archisland, "island");
592   } else {
593     assert(!"not vessel");
594   }
595
596   char *delim= strstr(archisland," - ");
597   assert(delim);
598   archipelago= masprintf("%.*s", delim-archisland, archisland);
599   island= masprintf("%s", delim+3);
600
601   free(ri);
602 }