+static void ocr_rectangle(Rect r, const OcrCellType ct, FILE *tsv_output) {
+ OcrResultGlyph *results, *res;
+
+ int w= r.br.x - r.tl.x + 1;
+ Pixcol cols[w+1];
+ int x,y;
+ for (x=0; x<w; x++) {
+ 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);
+ 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');
+ }
+ }
+ FILLZERO(cols[w]);
+
+ results= ocr(rd,ct,w,cols);
+ for (res=results; res->s; res++)
+ fputs(res->s,tsv_output);
+}
+
+#define FOR_COMMODITY_CELL(ROW_START, CELL, ROW_END) do{ \
+ Rect rowr, cell; \
+ int tryrect, colno; \
+ \
+ for (tryrect= +cim->h; tryrect >= -cim->h; tryrect--) { \
+ find_commodity(tryrect, &rowr); \
+ if (rowr.tl.x < 0) \
+ continue; \
+ debug_rect("commod",tryrect, rowr); \
+ \
+ ROW_START; \
+ \
+ for (colno=0; colno<columns; colno++) { \
+ compute_table_location(rowr,colno,&cell); \
+ \
+ CELL; \
+ } \
+ \
+ ROW_END; \
+ } \
+ }while(0);
+
+static void adjust_colours_cell(CanonImage *ci, const RgbImage *ri,
+ int colno, Rect cell) {