src/jbclass.c
PIXA *
jbDataRender(JBDATA  *data,
             l_int32  debugflag)
{
l_int32   i, w, h, cellw, cellh, x, y, iclass, ipage;
l_int32   npages, nclass, ncomp, wp, hp;
BOX      *box;
NUMA     *naclass, *napage;
PIX      *pixt, *pixt2, *pix, *pixd;
PIXA     *pixat;   /* pixa of templates */
PIXA     *pixad;   /* pixa of output images */
PIXCMAP  *cmap;
PTA      *ptaul;
    
    PROCNAME("jbDataRender");

    if (!data)
        return (PIXA *)ERROR_PTR("data not defined", procName, NULL);

    npages = data->npages;
    w = data->w;
    h = data->h;
    pixt = data->pix;
    nclass = data->nclass;
    cellw = data->latticew;
    cellh = data->latticeh;
    naclass = data->naclass;
    napage = data->napage;
    ptaul = data->ptaul;
    ncomp = numaGetCount(naclass);
    
        /* Reconstruct the original set of images from the templates
         * and the data associated with each component.  First,
         * generate the output pixa as a set of empty pix. */
    if ((pixad = pixaCreate(npages)) == NULL)
        return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
    for (i = 0; i < npages; i++) {
        if (debugflag == FALSE)
            pix = pixCreate(w, h, 1);
        else {
            pix = pixCreate(w, h, 2);
            cmap = pixcmapCreate(2);
            pixcmapAddColor(cmap, 255, 255, 255);
            pixcmapAddColor(cmap, 0, 0, 0);
            pixcmapAddColor(cmap, 255, 0, 0);  /* for box outlines */
            pixSetColormap(pix, cmap);
        }
        pixaAddPix(pixad, pix, L_INSERT);
    }
    
        /* Put the class templates into a pixa. */
    if ((pixat = pixaCreateFromPix(pixt, nclass, cellw, cellh)) == NULL)
        return (PIXA *)ERROR_PTR("pixat not made", procName, NULL);

        /* Place each component in the right location on its page. */
    for (i = 0; i < ncomp; i++) {
        numaGetIValue(napage, i, &ipage);
        numaGetIValue(naclass, i, &iclass);
        pix = pixaGetPix(pixat, iclass, L_CLONE);  /* the template */
        wp = pixGetWidth(pix);
        hp = pixGetHeight(pix);
        ptaGetIPt(ptaul, i, &x, &y);
        pixd = pixaGetPix(pixad, ipage, L_CLONE);   /* the output page */
        if (debugflag == FALSE)
            pixRasterop(pixd, x, y, wp, hp, PIX_SRC | PIX_DST, pix, 0, 0);
        else {
            pixt2 = pixConvert1To2Cmap(pix);
            pixRasterop(pixd, x, y, wp, hp, PIX_SRC | PIX_DST, pixt2, 0, 0);
            box = boxCreate(x, y, wp, hp);
            pixRenderBoxArb(pixd, box, 1, 255, 0, 0);
            pixDestroy(&pixt2);
            boxDestroy(&box);
        }
        pixDestroy(&pix);   /* the clone only */
        pixDestroy(&pixd);  /* the clone only */
    }

    pixaDestroy(&pixat);
    return pixad;
}
/*!
 *  jbDataRender()
 *
 *      Input:  jbdata
 *              debugflag (if TRUE, writes into 2 bpp pix and adds 
 *                         component outlines in color)
 *      Return: pixa (reconstruction of original images, using templates) or
 *              null on error
 */
jbDataRender()
Input:  jbdata
debugflag (if TRUE, writes into 2 bpp pix and adds
component outlines in color)
Return: pixa (reconstruction of original images, using templates) or
null on error
jbDataRender () Input : jbdata debugflag ( if TRUE writes into 2 bpp pix and adds component outlines in color ) Return : pixa ( reconstruction of original images using templates ) or null on error
PIXA *
jbDataRender(JBDATA  *data,
             l_int32  debugflag)
{
l_int32   i, w, h, cellw, cellh, x, y, iclass, ipage;
l_int32   npages, nclass, ncomp, wp, hp;
BOX      *box;
NUMA     *naclass, *napage;
PIX      *pixt, *pixt2, *pix, *pixd;
PIXA     *pixat;   
PIXA     *pixad;   
PIXCMAP  *cmap;
PTA      *ptaul;
    PROCNAME("jbDataRender");
    if (!data)
        return (PIXA *)ERROR_PTR("data not defined", procName, NULL);
    npages = data->npages;
    w = data->w;
    h = data->h;
    pixt = data->pix;
    nclass = data->nclass;
    cellw = data->latticew;
    cellh = data->latticeh;
    naclass = data->naclass;
    napage = data->napage;
    ptaul = data->ptaul;
    ncomp = numaGetCount(naclass);
    if ((pixad = pixaCreate(npages)) == NULL)
        return (PIXA *)ERROR_PTR("pixad not made", procName, NULL);
    for (i = 0; i < npages; i++) {
        if (debugflag == FALSE)
            pix = pixCreate(w, h, 1);
        else {
            pix = pixCreate(w, h, 2);
            cmap = pixcmapCreate(2);
            pixcmapAddColor(cmap, 255, 255, 255);
            pixcmapAddColor(cmap, 0, 0, 0);
            pixcmapAddColor(cmap, 255, 0, 0);  
            pixSetColormap(pix, cmap);
        }
        pixaAddPix(pixad, pix, L_INSERT);
    }
    if ((pixat = pixaCreateFromPix(pixt, nclass, cellw, cellh)) == NULL)
        return (PIXA *)ERROR_PTR("pixat not made", procName, NULL);
    for (i = 0; i < ncomp; i++) {
        numaGetIValue(napage, i, &ipage);
        numaGetIValue(naclass, i, &iclass);
        pix = pixaGetPix(pixat, iclass, L_CLONE);  
        wp = pixGetWidth(pix);
        hp = pixGetHeight(pix);
        ptaGetIPt(ptaul, i, &x, &y);
        pixd = pixaGetPix(pixad, ipage, L_CLONE);   
        if (debugflag == FALSE)
            pixRasterop(pixd, x, y, wp, hp, PIX_SRC | PIX_DST, pix, 0, 0);
        else {
            pixt2 = pixConvert1To2Cmap(pix);
            pixRasterop(pixd, x, y, wp, hp, PIX_SRC | PIX_DST, pixt2, 0, 0);
            box = boxCreate(x, y, wp, hp);
            pixRenderBoxArb(pixd, box, 1, 255, 0, 0);
            pixDestroy(&pixt2);
            boxDestroy(&box);
        }
        pixDestroy(&pix);   
        pixDestroy(&pixd);  
    }
    pixaDestroy(&pixat);
    return pixad;
}
PIXA * jbDataRender ( JBDATA * data , l_int32 debugflag ) { l_int32 i , w , h , cellw , cellh , x , y , iclass , ipage ; l_int32 npages , nclass , ncomp , wp , hp ; BOX * box ; NUMA * naclass , * napage ; PIX * pixt , * pixt2 , * pix , * pixd ; PIXA * pixat ; PIXA * pixad ; PIXCMAP * cmap ; PTA * ptaul ; PROCNAME ( " " ) ; if ( ! data ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; npages = data -> npages ; w = data -> w ; h = data -> h ; pixt = data -> pix ; nclass = data -> nclass ; cellw = data -> latticew ; cellh = data -> latticeh ; naclass = data -> naclass ; napage = data -> napage ; ptaul = data -> ptaul ; ncomp = numaGetCount ( naclass ) ; if ( ( pixad = pixaCreate ( npages ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; for ( i = 0 ; i < npages ; i ++ ) { if ( debugflag == FALSE ) pix = pixCreate ( w , h , 1 ) ; else { pix = pixCreate ( w , h , 2 ) ; cmap = pixcmapCreate ( 2 ) ; pixcmapAddColor ( cmap , 255 , 255 , 255 ) ; pixcmapAddColor ( cmap , 0 , 0 , 0 ) ; pixcmapAddColor ( cmap , 255 , 0 , 0 ) ; pixSetColormap ( pix , cmap ) ; } pixaAddPix ( pixad , pix , L_INSERT ) ; } if ( ( pixat = pixaCreateFromPix ( pixt , nclass , cellw , cellh ) ) == NULL ) return ( PIXA * ) ERROR_PTR ( " " , procName , NULL ) ; for ( i = 0 ; i < ncomp ; i ++ ) { numaGetIValue ( napage , i , & ipage ) ; numaGetIValue ( naclass , i , & iclass ) ; pix = pixaGetPix ( pixat , iclass , L_CLONE ) ; wp = pixGetWidth ( pix ) ; hp = pixGetHeight ( pix ) ; ptaGetIPt ( ptaul , i , & x , & y ) ; pixd = pixaGetPix ( pixad , ipage , L_CLONE ) ; if ( debugflag == FALSE ) pixRasterop ( pixd , x , y , wp , hp , PIX_SRC | PIX_DST , pix , 0 , 0 ) ; else { pixt2 = pixConvert1To2Cmap ( pix ) ; pixRasterop ( pixd , x , y , wp , hp , PIX_SRC | PIX_DST , pixt2 , 0 , 0 ) ; box = boxCreate ( x , y , wp , hp ) ; pixRenderBoxArb ( pixd , box , 1 , 255 , 0 , 0 ) ; pixDestroy ( & pixt2 ) ; boxDestroy ( & box ) ; } pixDestroy ( & pix ) ; pixDestroy ( & pixd ) ; } pixaDestroy ( & pixat ) ; return pixad ; }
jbDataRender()
      Input:  jbdata
              debugflag (if TRUE, writes into 2 bpp pix and adds
                         component outlines in color)
      Return: pixa (reconstruction of original images, using templates) or
              null on error
jbDataRender () Input : jbdata debugflag ( if TRUE writes into 2 bpp pix and adds component outlines in color ) Return : pixa ( reconstruction of original images using templates ) or null on error
/* pixa of templates */ /* pixa of output images */ /* Reconstruct the original set of images from the templates
         * and the data associated with each component.  First,
         * generate the output pixa as a set of empty pix. */ /* for box outlines */ /* Put the class templates into a pixa. */ /* Place each component in the right location on its page. */ /* the template */ /* the output page */ /* the clone only */ /* the clone only */