chiark / gitweb /
make AADEPTH configurable
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Jul 2009 19:01:42 +0000 (20:01 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 4 Jul 2009 19:01:42 +0000 (20:01 +0100)
pctb/common.h
pctb/dictionary-manager
pctb/dictionary-update-receiver
pctb/ocr.c
pctb/ocr.h

index fe87e16bbb566525a166bce6f5e3a7384a32fca2..5044bb35ee8015a3e109b71a1c2b167fbcfac2c6 100644 (file)
@@ -166,4 +166,6 @@ char *masprintf(const char *fmt, ...) FMT(1,2);
 #define ARRAYSIZE(a) ((sizeof((a)) / sizeof((a)[0])))
 #define FILLZERO(obj) (memset(&(obj),0,sizeof((obj))))
 
 #define ARRAYSIZE(a) ((sizeof((a)) / sizeof((a)[0])))
 #define FILLZERO(obj) (memset(&(obj),0,sizeof((obj))))
 
+#define STRING(x) #x
+
 #endif /*COMMON_H*/
 #endif /*COMMON_H*/
index 365aecb01fb1184fc865faa979ae58bba551ff81..7091964c779a6eb6f09989a2ea44e275a5826fff 100755 (executable)
@@ -42,6 +42,9 @@
 #  if it wrote a byte to fd 4, it can take another question
 
 
 #  if it wrote a byte to fd 4, it can take another question
 
 
+set aadepth 3
+
+
 #---------- library routines ----------
 
 proc manyset {list args} {
 #---------- library routines ----------
 
 proc manyset {list args} {
@@ -898,7 +901,7 @@ proc recursor {} {
 
 # $database($context 0x<bits> 0x<bits>...) = $hex
 
 
 # $database($context 0x<bits> 0x<bits>...) = $hex
 
-set database_magic/char {# ypp-sc-tools pctb font v2}
+set database_magic/char "# ypp-sc-tools pctb font v3 depth=$aadepth"
     
 proc read_database_header/char {f} {
     global rows
     
 proc read_database_header/char {f} {
     global rows
@@ -1134,10 +1137,10 @@ proc chop_counted {var} {
 }
 
 proc approve_decompose_data {specdata} {
 }
 
 proc approve_decompose_data {specdata} {
-    global data
+    global data aadepth
     set data $specdata
     
     set data $specdata
     
-    regsub-data {^ypp-sc-tools dictionary update v2\n} {}
+    regsub-data "^ypp-sc-tools dictionary update v3 depth=$aadepth\\n" {}
     uplevel 1 chop_counted pirate
     uplevel 1 chop_counted caller
     uplevel 1 chop_counted dict
     uplevel 1 chop_counted pirate
     uplevel 1 chop_counted caller
     uplevel 1 chop_counted dict
index 99a580e46888280c1c589a442edff38c6ea662cc..d80ab216b338220049d8ab6387061cf1c0d4386f 100755 (executable)
@@ -19,6 +19,8 @@ use CGI qw/:standard -private_tempfiles/;
 use IO::Pipe;
 use IO::Handle;
 
 use IO::Pipe;
 use IO::Handle;
 
+my $aadepth=3;
+
 #---------- pixmaps ----------
 
 sub parseentryin__pixmap ($) {
 #---------- pixmaps ----------
 
 sub parseentryin__pixmap ($) {
@@ -78,9 +80,12 @@ print STDERR ">@d<\n";
 
     my $w= @d;
 
 
     my $w= @d;
 
-    my $pgm= "P2\n$h $w\n7\n";
+    my $maxval= (1<<$aadepth)-1;
+    die 'cannot do [^0...$maxval]!' if $maxval>9;
+
+    my $pgm= "P2\n$h $w\n$maxval\n";
     map { # x, left to right
     map { # x, left to right
-       m/[^0-7]/ and die "$_ ?";
+       m/[^0-$maxval]/ and die "$_ ?";
        my $l= $_;
        $l =~ s/./ $&/g;
        $pgm .= "$l\n";
        my $l= $_;
        $l =~ s/./ $&/g;
        $pgm .= "$l\n";
@@ -257,7 +262,7 @@ open F, "> $fn_t" or die "$fn_t $!";
 (stat F) or die $!;
 my $fn_i= sprintf "_update.$$-%016x.rdy", (stat _)[1];
 
 (stat F) or die $!;
 my $fn_i= sprintf "_update.$$-%016x.rdy", (stat _)[1];
 
-print F "ypp-sc-tools dictionary update v2\n";
+print F "ypp-sc-tools dictionary update v3 depth=$aadepth\n";
 
 foreach my $v ($pirate,$caller,$dict,$ctx,$def,$image,$key,$val) {
     printf F "%d\n", length($v) or die $!;
 
 foreach my $v ($pirate,$caller,$dict,$ctx,$def,$image,$key,$val) {
     printf F "%d\n", length($v) or die $!;
index 4b9fa505b156afa3a001f3635ad0efeca5de2c84..8d1b88bbf1f20f35e992c82cbf357ecb1385800b 100644 (file)
@@ -132,7 +132,7 @@ static void readdb1(OcrReader *rd, const char *which, int local) {
     o_flags |= ff_charset_havelocal;
 
   FGETSLINE;
     o_flags |= ff_charset_havelocal;
 
   FGETSLINE;
-  dbassert(!strcmp(lbuf,"# ypp-sc-tools pctb font v2"));
+  dbassert(!strcmp(lbuf,"# ypp-sc-tools pctb font v3 depth=" STRING(AADEPTH)));
 
   dbassert( dbfile_scanf("%d", &h) == 1);
   dbassert(h==rd->h);
 
   dbassert( dbfile_scanf("%d", &h) == 1);
   dbassert(h==rd->h);
index 7848ae7d2601988043c61363106d8a21a341148f..93d619af4c7a12ec22646a893cd691824211ce46 100644 (file)
 
 #define AADEPTH 3
 #define AAMAXVAL ((1<<AADEPTH)-1)
 
 #define AADEPTH 3
 #define AAMAXVAL ((1<<AADEPTH)-1)
+ /* Change this ?  Also change in
+  *   dictionary-manager            set aadepth
+  *   dictionary-update-receiver    my $aadepth
+  */
 
 
 typedef uint32_t Pixcolv;
 
 
 typedef uint32_t Pixcolv;
@@ -66,19 +70,32 @@ static inline int pixcol_nonzero(const Pixcol *pixcol) {
 
 #if AADEPTH==3
 # define PRPIXCOL1 "%0*" PRIo32
 
 #if AADEPTH==3
 # define PRPIXCOL1 "%0*" PRIo32
+# define PIXCOL_P_PER_FMT 1
+#elif AADEPTH==2
+# define PRPIXCOL1 "%0*" PRIx32
+# define PIXCOL_P_PER_FMT 2
 #else
 # error need to implement PRPIXCOL1 for this AADEPTH
 #endif
 
 #else
 # error need to implement PRPIXCOL1 for this AADEPTH
 #endif
 
-#if PIXCOL_WORDS==3
+# define PIXCOL_FMT_PER_WORD (PIXCOL_P_PER_WORD / PIXCOL_P_PER_FMT)
+
+#if PIXCOL_WORDS==2
+# define PIXCOL_PRFMT                          \
+                             PRPIXCOL1 "-"     \
+                             PRPIXCOL1
+# define PIXCOL_PRVAL(pixcol)                                          \
+                             PIXCOL_FMT_PER_WORD, (pixcol).w[1],       \
+                             PIXCOL_FMT_PER_WORD, (pixcol).w[0]
+#elif PIXCOL_WORDS==3
 # define PIXCOL_PRFMT                          \
                              PRPIXCOL1 "-"     \
                              PRPIXCOL1 "-"     \
                              PRPIXCOL1
 # define PIXCOL_PRFMT                          \
                              PRPIXCOL1 "-"     \
                              PRPIXCOL1 "-"     \
                              PRPIXCOL1
-# define PIXCOL_PRVAL(pixcol)                                  \
-                             PIXCOL_P_PER_WORD, (pixcol).w[2], \
-                             PIXCOL_P_PER_WORD, (pixcol).w[1], \
-                             PIXCOL_P_PER_WORD, (pixcol).w[0]
+# define PIXCOL_PRVAL(pixcol)                                          \
+                             PIXCOL_FMT_PER_WORD, (pixcol).w[2],       \
+                             PIXCOL_FMT_PER_WORD, (pixcol).w[1],       \
+                             PIXCOL_FMT_PER_WORD, (pixcol).w[0]
 #else
 # error need to implement PIXCOL_PR{FMT,VAL} for this PIXCOL_WORDS
 #endif
 #else
 # error need to implement PIXCOL_PR{FMT,VAL} for this PIXCOL_WORDS
 #endif