src/morphdwa.c
PIX *
pixDilateCompBrickExtendDwa(PIX     *pixd,
                            PIX     *pixs,
                            l_int32  hsize,
                            l_int32  vsize)
{
l_int32  i, nops, nh, extrah, nv, extrav;
PIX     *pixt1, *pixt2, *pixt3;

    PROCNAME("pixDilateCompBrickExtendDwa");

    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, pixd);
    if (pixGetDepth(pixs) != 1)
        return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, pixd);
    if (hsize < 1 || vsize < 1)
        return (PIX *)ERROR_PTR("hsize and vsize not >= 1", procName, pixd);

    if (hsize < 64 && vsize < 64)
        return pixDilateCompBrickDwa(pixd, pixs, hsize, vsize);

    if (hsize > 63)
        getExtendedCompositeParameters(hsize, &nh, &extrah, NULL);
    if (vsize > 63)
        getExtendedCompositeParameters(vsize, &nv, &extrav, NULL);

        /* Horizontal dilation first: pixs --> pixt2.  Do not alter pixs. */
    pixt1 = pixCreateTemplateNoInit(pixs);  /* temp image */
    if (hsize == 1)
        pixt2 = pixClone(pixs);
    else if (hsize < 64)
        pixt2 = pixDilateCompBrickDwa(NULL, pixs, hsize, 1);
    else if (hsize == 64)  /* approximate */
        pixt2 = pixDilateCompBrickDwa(NULL, pixs, 63, 1);
    else {
        nops = (extrah < 3) ? nh : nh + 1;
        if (nops & 1) {  /* odd */
            if (extrah > 2)
                pixt2 = pixDilateCompBrickDwa(NULL, pixs, extrah, 1);
            else
                pixt2 = pixDilateCompBrickDwa(NULL, pixs, 63, 1);
            for (i = 0; i < nops / 2; i++) {
                pixDilateCompBrickDwa(pixt1, pixt2, 63, 1);
                pixDilateCompBrickDwa(pixt2, pixt1, 63, 1);
            }
        }
        else {  /* nops even */
            if (extrah > 2) {
                pixDilateCompBrickDwa(pixt1, pixs, extrah, 1);
                pixt2 = pixDilateCompBrickDwa(NULL, pixt1, 63, 1);
            }
            else {  /* they're all 63s */
                pixDilateCompBrickDwa(pixt1, pixs, 63, 1);
                pixt2 = pixDilateCompBrickDwa(NULL, pixt1, 63, 1);
            }
            for (i = 0; i < nops / 2 - 1; i++) {
                pixDilateCompBrickDwa(pixt1, pixt2, 63, 1);
                pixDilateCompBrickDwa(pixt2, pixt1, 63, 1);
            }
        }
    }

        /* Vertical dilation: pixt2 --> pixt3.  */
    if (vsize == 1)
        pixt3 = pixClone(pixt2);
    else if (vsize < 64)
        pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, vsize);
    else if (vsize == 64)  /* approximate */
        pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, 63);
    else {
        nops = (extrav < 3) ? nv : nv + 1;
        if (nops & 1) {  /* odd */
            if (extrav > 2)
                pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, extrav);
            else
                pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, 63);
            for (i = 0; i < nops / 2; i++) {
                pixDilateCompBrickDwa(pixt1, pixt3, 1, 63);
                pixDilateCompBrickDwa(pixt3, pixt1, 1, 63);
            }
        }
        else {  /* nops even */
            if (extrav > 2) {
                pixDilateCompBrickDwa(pixt1, pixt2, 1, extrav);
                pixt3 = pixDilateCompBrickDwa(NULL, pixt1, 1, 63);
            }
            else {  /* they're all 63s */
                pixDilateCompBrickDwa(pixt1, pixt2, 1, 63);
                pixt3 = pixDilateCompBrickDwa(NULL, pixt1, 1, 63);
            }
            for (i = 0; i < nops / 2 - 1; i++) {
                pixDilateCompBrickDwa(pixt1, pixt3, 1, 63);
                pixDilateCompBrickDwa(pixt3, pixt1, 1, 63);
            }
        }
    }
    pixDestroy(&pixt1);
    pixDestroy(&pixt2);

    if (!pixd)
        return pixt3;

    pixTransferAllData(pixd, &pixt3, 0, 0);
    return pixd;
}
/*!
 *  pixDilateCompBrickExtendDwa()
 *
 *      Input:  pixd  (<optional>; this can be null, equal to pixs,
 *                     or different from pixs)
 *              pixs (1 bpp)
 *              hsize (width of brick Sel)
 *              vsize (height of brick Sel)
 *      Return: pixd
 * 
 *  Notes:
 *      (1) Ankur Jain suggested and implemented extending the composite
 *          DWA operations beyond the 63 pixel limit.  This is a
 *          simplified and approximate implementation of the extension.
 *          This allows arbitrary Dwa morph operations using brick Sels,
 *          by decomposing the horizontal and vertical dilations into
 *          a sequence of 63-element dilations plus a dilation of size
 *          between 3 and 62.
 *      (2) The 63-element dilations are exact, whereas the extra dilation
 *          is approximate, because the underlying decomposition is
 *          in pixDilateCompBrickDwa().  See there for further details.
 *      (3) There are three cases:
 *          (a) pixd == null   (result into new pixd)
 *          (b) pixd == pixs   (in-place; writes result back to pixs)
 *          (c) pixd != pixs   (puts result into existing pixd)
 *      (4) There is no need to call this directly:  pixDilateCompBrickDwa()
 *          calls this function if either brick dimension exceeds 63.
 */
pixDilateCompBrickExtendDwa()
Input:  pixd  (; this can be null, equal to pixs,
or different from pixs)
pixs (1 bpp)
hsize (width of brick Sel)
vsize (height of brick Sel)
Return: pixd

(1) Ankur Jain suggested and implemented extending the composite
DWA operations beyond the 63 pixel limit.  This is a
simplified and approximate implementation of the extension.
This allows arbitrary Dwa morph operations using brick Sels,
by decomposing the horizontal and vertical dilations into
a sequence of 63-element dilations plus a dilation of size
between 3 and 62.
(2) The 63-element dilations are exact, whereas the extra dilation
is approximate, because the underlying decomposition is
in pixDilateCompBrickDwa().  See there for further details.
pixDilateCompBrickExtendDwa () Input : pixd ( ; this can be null equal to pixs or different from pixs ) pixs ( 1 bpp ) hsize ( width of brick Sel ) vsize ( height of brick Sel ) Return : pixd ( 1 ) Ankur Jain suggested and implemented extending the composite DWA operations beyond the 63 pixel limit . This is a simplified and approximate implementation of the extension . This allows arbitrary Dwa morph operations using brick Sels by decomposing the horizontal and vertical dilations into a sequence of 63 - element dilations plus a dilation of size between 3 and 62 . ( 2 ) The 63 - element dilations are exact whereas the extra dilation is approximate because the underlying decomposition is in pixDilateCompBrickDwa () . See there for further details .
PIX *
pixDilateCompBrickExtendDwa(PIX     *pixd,
                            PIX     *pixs,
                            l_int32  hsize,
                            l_int32  vsize)
{
l_int32  i, nops, nh, extrah, nv, extrav;
PIX     *pixt1, *pixt2, *pixt3;
    PROCNAME("pixDilateCompBrickExtendDwa");
    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, pixd);
    if (pixGetDepth(pixs) != 1)
        return (PIX *)ERROR_PTR("pixs not 1 bpp", procName, pixd);
    if (hsize < 1 || vsize < 1)
        return (PIX *)ERROR_PTR("hsize and vsize not >= 1", procName, pixd);
    if (hsize < 64 && vsize < 64)
        return pixDilateCompBrickDwa(pixd, pixs, hsize, vsize);
    if (hsize > 63)
        getExtendedCompositeParameters(hsize, &nh, &extrah, NULL);
    if (vsize > 63)
        getExtendedCompositeParameters(vsize, &nv, &extrav, NULL);
    pixt1 = pixCreateTemplateNoInit(pixs);  
    if (hsize == 1)
        pixt2 = pixClone(pixs);
    else if (hsize < 64)
        pixt2 = pixDilateCompBrickDwa(NULL, pixs, hsize, 1);
    else if (hsize == 64)  
        pixt2 = pixDilateCompBrickDwa(NULL, pixs, 63, 1);
    else {
        nops = (extrah < 3) ? nh : nh + 1;
        if (nops & 1) {  
            if (extrah > 2)
                pixt2 = pixDilateCompBrickDwa(NULL, pixs, extrah, 1);
            else
                pixt2 = pixDilateCompBrickDwa(NULL, pixs, 63, 1);
            for (i = 0; i < nops / 2; i++) {
                pixDilateCompBrickDwa(pixt1, pixt2, 63, 1);
                pixDilateCompBrickDwa(pixt2, pixt1, 63, 1);
            }
        }
        else {  
            if (extrah > 2) {
                pixDilateCompBrickDwa(pixt1, pixs, extrah, 1);
                pixt2 = pixDilateCompBrickDwa(NULL, pixt1, 63, 1);
            }
            else {  
                pixDilateCompBrickDwa(pixt1, pixs, 63, 1);
                pixt2 = pixDilateCompBrickDwa(NULL, pixt1, 63, 1);
            }
            for (i = 0; i < nops / 2 - 1; i++) {
                pixDilateCompBrickDwa(pixt1, pixt2, 63, 1);
                pixDilateCompBrickDwa(pixt2, pixt1, 63, 1);
            }
        }
    }
    if (vsize == 1)
        pixt3 = pixClone(pixt2);
    else if (vsize < 64)
        pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, vsize);
    else if (vsize == 64)  
        pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, 63);
    else {
        nops = (extrav < 3) ? nv : nv + 1;
        if (nops & 1) {  
            if (extrav > 2)
                pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, extrav);
            else
                pixt3 = pixDilateCompBrickDwa(NULL, pixt2, 1, 63);
            for (i = 0; i < nops / 2; i++) {
                pixDilateCompBrickDwa(pixt1, pixt3, 1, 63);
                pixDilateCompBrickDwa(pixt3, pixt1, 1, 63);
            }
        }
        else {  
            if (extrav > 2) {
                pixDilateCompBrickDwa(pixt1, pixt2, 1, extrav);
                pixt3 = pixDilateCompBrickDwa(NULL, pixt1, 1, 63);
            }
            else {  
                pixDilateCompBrickDwa(pixt1, pixt2, 1, 63);
                pixt3 = pixDilateCompBrickDwa(NULL, pixt1, 1, 63);
            }
            for (i = 0; i < nops / 2 - 1; i++) {
                pixDilateCompBrickDwa(pixt1, pixt3, 1, 63);
                pixDilateCompBrickDwa(pixt3, pixt1, 1, 63);
            }
        }
    }
    pixDestroy(&pixt1);
    pixDestroy(&pixt2);
    if (!pixd)
        return pixt3;
    pixTransferAllData(pixd, &pixt3, 0, 0);
    return pixd;
}
PIX * pixDilateCompBrickExtendDwa ( PIX * pixd , PIX * pixs , l_int32 hsize , l_int32 vsize ) { l_int32 i , nops , nh , extrah , nv , extrav ; PIX * pixt1 , * pixt2 , * pixt3 ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIX * ) ERROR_PTR ( " " , procName , pixd ) ; if ( pixGetDepth ( pixs ) != 1 ) return ( PIX * ) ERROR_PTR ( " " , procName , pixd ) ; if ( hsize < 1 || vsize < 1 ) return ( PIX * ) ERROR_PTR ( " " , procName , pixd ) ; if ( hsize < 64 && vsize < 64 ) return pixDilateCompBrickDwa ( pixd , pixs , hsize , vsize ) ; if ( hsize > 63 ) getExtendedCompositeParameters ( hsize , & nh , & extrah , NULL ) ; if ( vsize > 63 ) getExtendedCompositeParameters ( vsize , & nv , & extrav , NULL ) ; pixt1 = pixCreateTemplateNoInit ( pixs ) ; if ( hsize == 1 ) pixt2 = pixClone ( pixs ) ; else if ( hsize < 64 ) pixt2 = pixDilateCompBrickDwa ( NULL , pixs , hsize , 1 ) ; else if ( hsize == 64 ) pixt2 = pixDilateCompBrickDwa ( NULL , pixs , 63 , 1 ) ; else { nops = ( extrah < 3 ) ? nh : nh + 1 ; if ( nops & 1 ) { if ( extrah > 2 ) pixt2 = pixDilateCompBrickDwa ( NULL , pixs , extrah , 1 ) ; else pixt2 = pixDilateCompBrickDwa ( NULL , pixs , 63 , 1 ) ; for ( i = 0 ; i < nops / 2 ; i ++ ) { pixDilateCompBrickDwa ( pixt1 , pixt2 , 63 , 1 ) ; pixDilateCompBrickDwa ( pixt2 , pixt1 , 63 , 1 ) ; } } else { if ( extrah > 2 ) { pixDilateCompBrickDwa ( pixt1 , pixs , extrah , 1 ) ; pixt2 = pixDilateCompBrickDwa ( NULL , pixt1 , 63 , 1 ) ; } else { pixDilateCompBrickDwa ( pixt1 , pixs , 63 , 1 ) ; pixt2 = pixDilateCompBrickDwa ( NULL , pixt1 , 63 , 1 ) ; } for ( i = 0 ; i < nops / 2 - 1 ; i ++ ) { pixDilateCompBrickDwa ( pixt1 , pixt2 , 63 , 1 ) ; pixDilateCompBrickDwa ( pixt2 , pixt1 , 63 , 1 ) ; } } } if ( vsize == 1 ) pixt3 = pixClone ( pixt2 ) ; else if ( vsize < 64 ) pixt3 = pixDilateCompBrickDwa ( NULL , pixt2 , 1 , vsize ) ; else if ( vsize == 64 ) pixt3 = pixDilateCompBrickDwa ( NULL , pixt2 , 1 , 63 ) ; else { nops = ( extrav < 3 ) ? nv : nv + 1 ; if ( nops & 1 ) { if ( extrav > 2 ) pixt3 = pixDilateCompBrickDwa ( NULL , pixt2 , 1 , extrav ) ; else pixt3 = pixDilateCompBrickDwa ( NULL , pixt2 , 1 , 63 ) ; for ( i = 0 ; i < nops / 2 ; i ++ ) { pixDilateCompBrickDwa ( pixt1 , pixt3 , 1 , 63 ) ; pixDilateCompBrickDwa ( pixt3 , pixt1 , 1 , 63 ) ; } } else { if ( extrav > 2 ) { pixDilateCompBrickDwa ( pixt1 , pixt2 , 1 , extrav ) ; pixt3 = pixDilateCompBrickDwa ( NULL , pixt1 , 1 , 63 ) ; } else { pixDilateCompBrickDwa ( pixt1 , pixt2 , 1 , 63 ) ; pixt3 = pixDilateCompBrickDwa ( NULL , pixt1 , 1 , 63 ) ; } for ( i = 0 ; i < nops / 2 - 1 ; i ++ ) { pixDilateCompBrickDwa ( pixt1 , pixt3 , 1 , 63 ) ; pixDilateCompBrickDwa ( pixt3 , pixt1 , 1 , 63 ) ; } } } pixDestroy ( & pixt1 ) ; pixDestroy ( & pixt2 ) ; if ( ! pixd ) return pixt3 ; pixTransferAllData ( pixd , & pixt3 , 0 , 0 ) ; return pixd ; }
pixDilateCompBrickExtendDwa()
      Input:  pixd  (<optional>; this can be null, equal to pixs,
                     or different from pixs)
              pixs (1 bpp)
              hsize (width of brick Sel)
              vsize (height of brick Sel)
      Return: pixd
pixDilateCompBrickExtendDwa () Input : pixd ( <optional > ; this can be null equal to pixs or different from pixs ) pixs ( 1 bpp ) hsize ( width of brick Sel ) vsize ( height of brick Sel ) Return : pixd
/* Horizontal dilation first: pixs --> pixt2.  Do not alter pixs. */ /* temp image */ /* approximate */ /* odd */ /* nops even */ /* they're all 63s */ /* Vertical dilation: pixt2 --> pixt3.  */ /* approximate */ /* odd */ /* nops even */ /* they're all 63s */