src/projective.c
PIX *
pixProjectiveSampled(PIX        *pixs,
                     l_float32  *vc,
                     l_int32     incolor)
{
l_int32     i, j, w, h, d, x, y, wpls, wpld, color, cmapindex;
l_uint32    val;
l_uint32   *datas, *datad, *lines, *lined;
PIX        *pixd;
PIXCMAP    *cmap;

    PROCNAME("pixProjectiveSampled");

    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!vc)
        return (PIX *)ERROR_PTR("vc not defined", procName, NULL);
    if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
        return (PIX *)ERROR_PTR("invalid incolor", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
        return (PIX *)ERROR_PTR("depth not 1, 2, 4, 8 or 16", procName, NULL);

        /* Init all dest pixels to color to be brought in from outside */
    pixd = pixCreateTemplate(pixs);
    if ((cmap = pixGetColormap(pixs)) != NULL) {
        if (incolor == L_BRING_IN_WHITE)
            color = 1;
        else
            color = 0;
        pixcmapAddBlackOrWhite(cmap, color, &cmapindex);
        pixSetAllArbitrary(pixd, cmapindex);
    }
    else {
        if ((d == 1 && incolor == L_BRING_IN_WHITE) ||
            (d > 1 && incolor == L_BRING_IN_BLACK))
            pixClearAll(pixd);
        else
            pixSetAll(pixd);
    }

        /* Scan over the dest pixels */
    datas = pixGetData(pixs);
    wpls = pixGetWpl(pixs);
    datad = pixGetData(pixd);
    wpld = pixGetWpl(pixd);
    for (i = 0; i < h; i++) {
        lined = datad + i * wpld;
        for (j = 0; j < w; j++) {
            projectiveXformSampledPt(vc, j, i, &x, &y);
            if (x < 0 || y < 0 || x >=w || y >= h)
                continue;
            lines = datas + y * wpls;
            if (d == 1) {
                val = GET_DATA_BIT(lines, x);
                SET_DATA_BIT_VAL(lined, j, val);
            }
            else if (d == 8) {
                val = GET_DATA_BYTE(lines, x);
                SET_DATA_BYTE(lined, j, val);
            }
            else if (d == 32) {
                lined[j] = lines[x];
            }
            else if (d == 2) {
                val = GET_DATA_DIBIT(lines, x);
                SET_DATA_DIBIT(lined, j, val);
            }
            else if (d == 4) {
                val = GET_DATA_QBIT(lines, x);
                SET_DATA_QBIT(lined, j, val);
            }
        }
    }

    return pixd;
}
/*!
 *  pixProjectiveSampled()
 *
 *      Input:  pixs (all depths)
 *              vc  (vector of 8 coefficients for projective transformation)
 *              incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
 *      Return: pixd, or null on error
 *
 *  Notes:
 *      (1) Brings in either black or white pixels from the boundary.
 *      (2) Retains colormap, which you can do for a sampled transform..
 *      (3) For 8 or 32 bpp, much better quality is obtained by the
 *          somewhat slower pixProjective().  See that function
 *          for relative timings between sampled and interpolated.
 */
pixProjectiveSampled()
Input:  pixs (all depths)
vc  (vector of 8 coefficients for projective transformation)
incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
Return: pixd, or null on error

(1) Brings in either black or white pixels from the boundary.
(2) Retains colormap, which you can do for a sampled transform
(3) For 8 or 32 bpp, much better quality is obtained by the
somewhat slower pixProjective().  See that function
for relative timings between sampled and interpolated.
pixProjectiveSampled () Input : pixs ( all depths ) vc ( vector of 8 coefficients for projective transformation ) incolor ( L_BRING_IN_WHITE L_BRING_IN_BLACK ) Return : pixd or null on error ( 1 ) Brings in either black or white pixels from the boundary . ( 2 ) Retains colormap which you can do for a sampled transform ( 3 ) For 8 or 32 bpp much better quality is obtained by the somewhat slower pixProjective () . See that function for relative timings between sampled and interpolated .
PIX *
pixProjectiveSampled(PIX        *pixs,
                     l_float32  *vc,
                     l_int32     incolor)
{
l_int32     i, j, w, h, d, x, y, wpls, wpld, color, cmapindex;
l_uint32    val;
l_uint32   *datas, *datad, *lines, *lined;
PIX        *pixd;
PIXCMAP    *cmap;
    PROCNAME("pixProjectiveSampled");
    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!vc)
        return (PIX *)ERROR_PTR("vc not defined", procName, NULL);
    if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
        return (PIX *)ERROR_PTR("invalid incolor", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    if (d != 1 && d != 2 && d != 4 && d != 8 && d != 32)
        return (PIX *)ERROR_PTR("depth not 1, 2, 4, 8 or 16", procName, NULL);
    pixd = pixCreateTemplate(pixs);
    if ((cmap = pixGetColormap(pixs)) != NULL) {
        if (incolor == L_BRING_IN_WHITE)
            color = 1;
        else
            color = 0;
        pixcmapAddBlackOrWhite(cmap, color, &cmapindex);
        pixSetAllArbitrary(pixd, cmapindex);
    }
    else {
        if ((d == 1 && incolor == L_BRING_IN_WHITE) ||
            (d > 1 && incolor == L_BRING_IN_BLACK))
            pixClearAll(pixd);
        else
            pixSetAll(pixd);
    }
    datas = pixGetData(pixs);
    wpls = pixGetWpl(pixs);
    datad = pixGetData(pixd);
    wpld = pixGetWpl(pixd);
    for (i = 0; i < h; i++) {
        lined = datad + i * wpld;
        for (j = 0; j < w; j++) {
            projectiveXformSampledPt(vc, j, i, &x, &y);
            if (x < 0 || y < 0 || x >=w || y >= h)
                continue;
            lines = datas + y * wpls;
            if (d == 1) {
                val = GET_DATA_BIT(lines, x);
                SET_DATA_BIT_VAL(lined, j, val);
            }
            else if (d == 8) {
                val = GET_DATA_BYTE(lines, x);
                SET_DATA_BYTE(lined, j, val);
            }
            else if (d == 32) {
                lined[j] = lines[x];
            }
            else if (d == 2) {
                val = GET_DATA_DIBIT(lines, x);
                SET_DATA_DIBIT(lined, j, val);
            }
            else if (d == 4) {
                val = GET_DATA_QBIT(lines, x);
                SET_DATA_QBIT(lined, j, val);
            }
        }
    }
    return pixd;
}
PIX * pixProjectiveSampled ( PIX * pixs , l_float32 * vc , l_int32 incolor ) { l_int32 i , j , w , h , d , x , y , wpls , wpld , color , cmapindex ; l_uint32 val ; l_uint32 * datas , * datad , * lines , * lined ; PIX * pixd ; PIXCMAP * cmap ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ! vc ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; if ( incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; pixGetDimensions ( pixs , & w , & h , & d ) ; if ( d != 1 && d != 2 && d != 4 && d != 8 && d != 32 ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; pixd = pixCreateTemplate ( pixs ) ; if ( ( cmap = pixGetColormap ( pixs ) ) != NULL ) { if ( incolor == L_BRING_IN_WHITE ) color = 1 ; else color = 0 ; pixcmapAddBlackOrWhite ( cmap , color , & cmapindex ) ; pixSetAllArbitrary ( pixd , cmapindex ) ; } else { if ( ( d == 1 && incolor == L_BRING_IN_WHITE ) || ( d > 1 && incolor == L_BRING_IN_BLACK ) ) pixClearAll ( pixd ) ; else pixSetAll ( pixd ) ; } datas = pixGetData ( pixs ) ; wpls = pixGetWpl ( pixs ) ; datad = pixGetData ( pixd ) ; wpld = pixGetWpl ( pixd ) ; for ( i = 0 ; i < h ; i ++ ) { lined = datad + i * wpld ; for ( j = 0 ; j < w ; j ++ ) { projectiveXformSampledPt ( vc , j , i , & x , & y ) ; if ( x < 0 || y < 0 || x >= w || y >= h ) continue ; lines = datas + y * wpls ; if ( d == 1 ) { val = GET_DATA_BIT ( lines , x ) ; SET_DATA_BIT_VAL ( lined , j , val ) ; } else if ( d == 8 ) { val = GET_DATA_BYTE ( lines , x ) ; SET_DATA_BYTE ( lined , j , val ) ; } else if ( d == 32 ) { lined [ j ] = lines [ x ] ; } else if ( d == 2 ) { val = GET_DATA_DIBIT ( lines , x ) ; SET_DATA_DIBIT ( lined , j , val ) ; } else if ( d == 4 ) { val = GET_DATA_QBIT ( lines , x ) ; SET_DATA_QBIT ( lined , j , val ) ; } } } return pixd ; }
pixProjectiveSampled()
      Input:  pixs (all depths)
              vc  (vector of 8 coefficients for projective transformation)
              incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
      Return: pixd, or null on error
pixProjectiveSampled () Input : pixs ( all depths ) vc ( vector of 8 coefficients for projective transformation ) incolor ( L_BRING_IN_WHITE L_BRING_IN_BLACK ) Return : pixd or null on error
/* Init all dest pixels to color to be brought in from outside */ /* Scan over the dest pixels */