admGlyph *clippedGlyph(admGlyph *in)
{
    uint32_t w,h,lonecount,lone;
    int32_t top,bottom,left,right;
    admGlyph *nw=NULL;
    w=in->width;
    h=in->height;
    // Look if we got a lonely point at the first line
    lonecount=0;
    if(w>3)
        for(uint32_t i=0; i<w; i++)
            if(in->data[i])
            {
                lonecount++;
                lone=i;
            }
    if(lonecount==1)
    {
        if(!lone) lone++;
        if(lone==w-1) lone--;
        if(!in->data[w+lone-1] && !in->data[w+lone] && !in->data[w+lone+1])
            in->data[lone]=0;
    }
    // Go!
    left=0;
    while(columnEmpty(in->data+left,w,h) && left<w) left++;
    if(left==w)
    {
        in->width=in->height=0;
        return in;
    }
    right=w-1;
    while(columnEmpty(in->data+right,w,h) && right>=left) right--;

    top=0;
    while(lineEmpty(in->data,w,w,top) && top<h) top++;

    bottom=h-1;
    while(lineEmpty(in->data,w,w,bottom) && bottom>=top) bottom--;

    nw=new admGlyph(right-left+1,bottom-top+1);
    nw->create(in->data+left+top*w,w);
    delete in;
    return nw;

}
Exemple #2
0
void SumProduct::fillDown() {
  for (int cpt = 0; cpt < components(); ++cpt) {
    LogThisAt(8,"Sending root-to-tip messages, component #" << cpt << " column " << join(gappedCol,"") << endl);
    if (!columnEmpty()) {
      for (auto r: preorder) {
	if (!isGap(r)) {
	  const TreeNodeIndex rp = tree.parentNode(r);
	  if (rp < 0 || isGap(rp)) {
	    G[cpt][r] = insProb[cpt];
	    logG[cpt][r] = 0;
	  } else {
	    const vguard<TreeNodeIndex> rsibs = tree.getSiblings(r);
	    logG[cpt][r] = logG[cpt][rp];
	    for (auto rs: rsibs)
	      logG[cpt][r] += logE[cpt][rs];
	    for (AlphTok j = 0; j < model.alphabetSize(); ++j) {
	      double Gj = 0;
	      for (AlphTok i = 0; i < model.alphabetSize(); ++i) {
		double p = G[cpt][rp][i] * branchSubProb[cpt][r][i][j];
		for (auto rs: rsibs)
		  if (!isGap(rs))
		    p *= E[cpt][rs][i];
		Gj += p;
	      }
	      G[cpt][r][j] = Gj;
	    }
	  }
	}

	LogThisAt(10,"Row " << setw(3) << r << " " << cpt << " " << gappedCol[r]
		  << " logG=" << setw(9) << setprecision(3) << logG[cpt][r]
		  << " G=(" << to_string_join(G[cpt][r]," ",9,3) << ")" << endl);
      }
    }
  }
}
ReplyType ocrBitmap(uint8_t *data,uint32_t w,uint32_t h)
{
uint8_t found;
uint32_t colstart=0,colend=0,oldcol;
uint32_t line=0,nbLine=1;
uint32_t base=0,bottom,top;    
ReplyType reply;
    // Search First non nul colum
    decodedString[0]=0;
    // Search how much lines there is in the file
    //
    top=bottom=0;
    while(top<h)
    {
        // Search non empty line as top
        while(top<h && lineEmpty(workArea,w,w,top)) top++;
        // Nothing found
        if(top>=h-1) break;

        // 
       

        bottom=top+1;
        // Search empty line if any, bottom is the 1st line full of zero
        while(bottom<h && (!lineEmpty(workArea,w,w,bottom) || bottom-top<7))
        {
            bottom++;
        }
        if(line) strcat(decodedString,"\n"); 
        //printf("\n Top:%lu bottom:%lu\n",top,bottom);
       
        // Scan a full line
        colstart=0;
        oldcol=0;
       
        // Split a line into glyphs
        while(colstart<w)
        {
            GTK_PURGE;
            oldcol=colstart;
            while( columnEmpty(workArea+colstart+top*w, w, bottom-top) && colstart<w) colstart++;
            if(colstart>=w) break;
            // if too far apart, it means probably a blank space
            if(colstart-oldcol>6)
            {
                strcat(decodedString," ");
            }
       
            // We have found a non null column
            // Seek the end now
            colend=colstart+1;
            while( !columnEmpty(workArea+colend+top*w, w, bottom-top) && colend<w) colend++;
         
         
            // printf("Found glyph: %lu %lu\n",colstart,colend);  
            reply=handleGlyph(colstart,colend,w,bottom,top);
            switch(reply)
                {
                        case ReplySkip:break;
                        case ReplyOk:break;
                        case ReplyClose:
                        case ReplyCalibrate: return reply;break;
            
                        case ReplySkipAll: return ReplyOk;break;
                        default: ADM_assert(0);
                }
            
            
            colstart=colend;
      }
      line++;      
      top=bottom;
      
    }
   
    return ReplyOk;
}