chiark / gitweb /
Store full-colour image with every screenshot
[ypp-sc-tools.db-test.git] / pctb / convert.c
index 21445c563b6108ed117304c8a27fb9eb4fdd23ab..8101fb920a40adafad02ab92ed4efd5181c2ae44 100644 (file)
@@ -37,16 +37,18 @@ const char *get_libdir(void) { return "."; }
 
 
 enum mode {
 
 
 enum mode {
-  mf_findwindow=      0001,
-  mf_screenshot=      0010,
-  mf_readscreenshot=  0020,
-  mf_analyse=         0100,
+  mf_findwindow=      00001,
+  mf_screenshot=      00010,
+  mf_readscreenshot=  00020,
+  mf_analyse=         00100,
+  mfm_special=        07000,
   
   
-  mode_findwindow=    0001,
-  mode_screenshot=    0011,
-  mode_analyse=       0120,
+  mode_findwindow=    00001,
+  mode_screenshot=    00011,
+  mode_analyse=       00120,
+  mode_showcharset=   01000,
 
 
-  mode_all=           0111,
+  mode_all=           00111,
 };
 
 enum outmodekind {
 };
 
 enum outmodekind {
@@ -90,7 +92,7 @@ static void run_analysis(void) {
   analyse(tf);
 
   if (o_flags & ff_upload) {
   analyse(tf);
 
   if (o_flags & ff_upload) {
-    if (o_flags & ff_singlepage)
+    if (npages<=1)
       fatal("Recognition successful, but refusing to upload partial data\n"
            " (--single-page specified).  Specify an output mode?");
   }
       fatal("Recognition successful, but refusing to upload partial data\n"
            " (--single-page specified).  Specify an output mode?");
   }
@@ -122,8 +124,10 @@ void fetch_with_rsync(const char *stem) {
     const char *src= getenv("YPPSC_PCTB_DICT_UPDATE");
     char *remote= masprintf("%s/master-%s.txt", src, stem);
     char *local= masprintf("#master-%s#.txt", stem);
     const char *src= getenv("YPPSC_PCTB_DICT_UPDATE");
     char *remote= masprintf("%s/master-%s.txt", src, stem);
     char *local= masprintf("#master-%s#.txt", stem);
+    if (DEBUGP(rsync))
+      fprintf(stderr,"executing rsync to fetch %s to %s\n",remote,local);
     execlp(rsync, "rsync",
     execlp(rsync, "rsync",
-          DEBUGP(rsync) ? "-vLt" : "-Lt",
+          DEBUGP(rsync) ? "-zvLt" : "-zLt",
           "--",remote,local,(char*)0);
     sysassert(!"exec rsync failed");
   }
           "--",remote,local,(char*)0);
     sysassert(!"exec rsync failed");
   }
@@ -184,6 +188,7 @@ int main(int argc, char **argv) {
   while ((arg=*++argv)) {
     if (IS("--find-window-only"))      o_mode= mode_findwindow;
     else if (IS("--screenshot-only"))  o_mode= mode_screenshot;
   while ((arg=*++argv)) {
     if (IS("--find-window-only"))      o_mode= mode_findwindow;
     else if (IS("--screenshot-only"))  o_mode= mode_screenshot;
+    else if (IS("--show-charset"))     o_mode= mode_showcharset;
     else if (IS("--analyse-only") ||
             IS("--same"))             o_mode= mode_analyse;
     else if (IS("--everything"))       o_mode= mode_all;
     else if (IS("--analyse-only") ||
             IS("--same"))             o_mode= mode_analyse;
     else if (IS("--everything"))       o_mode= mode_all;
@@ -231,7 +236,7 @@ int main(int argc, char **argv) {
        o_outmode_kind= omk_none;
        o_flags |= ff_singlepage;
       } else {
        o_outmode_kind= omk_none;
        o_flags |= ff_singlepage;
       } else {
-       o_outmode_kind= omk_str;
+       o_outmode_kind= omk_upload;
       }
     }
 
       }
     }
 
@@ -272,28 +277,38 @@ int main(int argc, char **argv) {
   
   if (o_flags & ff_needisland)
     if (!ocean)
   
   if (o_flags & ff_needisland)
     if (!ocean)
-      badusage("need --ocean option when replaying images"
+      badusage("need --ocean option when not using actual YPP client window"
               " (consider supplying --pirate too)");
   if (ocean)
     sysassert(! setenv("YPPSC_OCEAN",ocean,1) );
   if (pirate && (o_flags & ff_dict_pirate))
     sysassert(! setenv("YPPSC_PIRATE",pirate,1) );
 
               " (consider supplying --pirate too)");
   if (ocean)
     sysassert(! setenv("YPPSC_OCEAN",ocean,1) );
   if (pirate && (o_flags & ff_dict_pirate))
     sysassert(! setenv("YPPSC_PIRATE",pirate,1) );
 
+  switch (o_mode & mfm_special) {
+  case 0:                                      break;
+  case mode_showcharset:  ocr_showcharsets();  exit(0);
+  default:                                     abort();
+  }
+
   if (o_mode & mf_screenshot) {
     open_screenshot_file("w");
     if (o_flags & ff_singlepage) take_one_screenshot();
     else take_screenshots();
   if (o_mode & mf_screenshot) {
     open_screenshot_file("w");
     if (o_flags & ff_singlepage) take_one_screenshot();
     else take_screenshots();
+    progress_log("OK for you to move the mouse now.");
   }
   if (o_mode & mf_readscreenshot) {
   }
   if (o_mode & mf_readscreenshot) {
+    if ((o_flags & ff_upload) && !(o_flags & ff_testservers))
+      badusage("must not reuse screenshots for upload to live PCTB database");
     open_screenshot_file("r");
     if (o_flags & ff_singlepage) read_one_screenshot();
     else read_screenshots();
   }
   if (o_mode & mf_analyse) {
     if (o_flags & ff_needisland) {
     open_screenshot_file("r");
     if (o_flags & ff_singlepage) read_one_screenshot();
     else read_screenshots();
   }
   if (o_mode & mf_analyse) {
     if (o_flags & ff_needisland) {
-      find_islandname();
+      find_islandname(page_images[0]->rgb);
       if (o_flags & ff_printisland)
        printf("%s, %s\n", archipelago, island);
       if (o_flags & ff_printisland)
        printf("%s, %s\n", archipelago, island);
+      sysassert(! setenv("YPPSC_ISLAND",island,1) );
     }
     switch (o_outmode_kind) {
     case omk_upload: case omk_str:   run_analysis();        break;
     }
     switch (o_outmode_kind) {
     case omk_upload: case omk_str:   run_analysis();        break;