chiark / gitweb /
antialiasing text conversion: seems to handle it in the C code so far ....
[ypp-sc-tools.db-test.git] / pctb / structure.c
index 5a593887350025f8ce39c5e5d2a90e9c72df61e9..da80cb9fda86297b74e57f8e6a37ec7a887244bd 100644 (file)
@@ -320,6 +320,8 @@ void find_structure(CanonImage *im, int *max_relevant_y_r) {
   SET_ONCE(text_h, comminty - 1);
   if (max_relevant_y_r)
     SET_ONCE(*max_relevant_y_r, mainr.br.y + 10);
+
+  MUST( text_h <= OCR_MAX_H, MI(text_h) );
 }                  
 
 void check_correct_commodities(void) {
@@ -527,22 +529,17 @@ static void ocr_rectangle(Rect r, const OcrCellType ct, FILE *tsv_output) {
   Pixcol cols[w+1];
   int x,y;
   for (x=0; x<w; x++) {
-    Pixcol cx, rv;
-    for (y=0, cx=0, rv=1; y<text_h; y++, rv<<=1) {
+    FILLZERO(cols[x]);
+    for (y=0; y<text_h; y++) {
       Point here= { x+r.tl.x, y+r.tl.y };
       int pixel= get_p(here);
-      switch (pixel) {
-      case ' ':                      break;
-      case '0':                      break;
-      case '0'+AAMAXVAL:  cx |= rv;  break;
-      default:
-       MUST(!"wrong pixel",
-            MC(pixel);MP(here);MSB(ocr_celltype_name(ct));MR(r); );
-      }
+      if (pixel==' ') pixel= '0';
+      MUST( pixel >= '0' && pixel <= '0'+AAMAXVAL,
+           MC(pixel);MP(here);MSB(ocr_celltype_name(ct));MR(r); );
+      pixcol_p_add(&cols[x], y, pixel-'0');
     }
-    cols[x]= cx;
   }
-  cols[w]= 0;
+  FILLZERO(cols[w]);
 
   results= ocr(rd,ct,w,cols);
   for (res=results; res->s; res++)