src/dewarp.c
PIX *
pixApplyVerticalDisparity(PIX   *pixs,
                          FPIX  *fpix)
{
l_int32     i, j, w, h, d, fw, fh, wpld, wplf, isrc, val8;
l_uint32   *datad, *lined;
l_float32  *dataf, *linef;
void      **lineptrs;
PIX        *pixd;

    PROCNAME("pixApplyVerticalDisparity");

    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!fpix)
        return (PIX *)ERROR_PTR("fpix not defined", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    if (d != 1 && d != 8 && d != 32)
        return (PIX *)ERROR_PTR("pix not 1, 8 or 32 bpp", procName, NULL);
    fpixGetDimensions(fpix, &fw, &fh);
    if (fw < w || fh < h) {
        fprintf(stderr, "fw = %d, w = %d, fh = %d, h = %d\n", fw, w, fh, h);
        return (PIX *)ERROR_PTR("invalid fpix size", procName, NULL);
    }

    pixd = pixCreateTemplate(pixs);
    datad = pixGetData(pixd);
    dataf = fpixGetData(fpix);
    wpld = pixGetWpl(pixd);
    wplf = fpixGetWpl(fpix);
    if (d == 1) {
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                if (GET_DATA_BIT(lineptrs[isrc], j))
                    SET_DATA_BIT(lined, j);
            }
        }
    }
    else if (d == 8) {
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                val8 = GET_DATA_BYTE(lineptrs[isrc], j);
                SET_DATA_BYTE(lined, j, val8);
            }
        }
    }
    else {  /* d == 32 */
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                lined[j] = GET_DATA_FOUR_BYTES(lineptrs[isrc], j);
            }
        }
    }

    FREE(lineptrs);
    return pixd;
}
/*!
 *  pixApplyVerticalDisparity()
 *
 *      Input:  pixs (1, 8 or 32 bpp)
 *              fpix (vertical disparity array)
 *      Return: pixd (modified by fpix), or null on error
 *
 *  Notes:
 *      (1) This applies the vertical disparity array to the specified
 *          image.  For src pixels above the image, we use the pixels
 *          in the first raster line.
 */
pixApplyVerticalDisparity()
Input:  pixs (1, 8 or 32 bpp)
fpix (vertical disparity array)
Return: pixd (modified by fpix), or null on error

(1) This applies the vertical disparity array to the specified
image.  For src pixels above the image, we use the pixels
in the first raster line.
pixApplyVerticalDisparity () Input : pixs ( 1 8 or 32 bpp ) fpix ( vertical disparity array ) Return : pixd ( modified by fpix ) or null on error ( 1 ) This applies the vertical disparity array to the specified image . For src pixels above the image we use the pixels in the first raster line .
PIX *
pixApplyVerticalDisparity(PIX   *pixs,
                          FPIX  *fpix)
{
l_int32     i, j, w, h, d, fw, fh, wpld, wplf, isrc, val8;
l_uint32   *datad, *lined;
l_float32  *dataf, *linef;
void      **lineptrs;
PIX        *pixd;
    PROCNAME("pixApplyVerticalDisparity");
    if (!pixs)
        return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
    if (!fpix)
        return (PIX *)ERROR_PTR("fpix not defined", procName, NULL);
    pixGetDimensions(pixs, &w, &h, &d);
    if (d != 1 && d != 8 && d != 32)
        return (PIX *)ERROR_PTR("pix not 1, 8 or 32 bpp", procName, NULL);
    fpixGetDimensions(fpix, &fw, &fh);
    if (fw < w || fh < h) {
        fprintf(stderr, "fw = %d, w = %d, fh = %d, h = %d\n", fw, w, fh, h);
        return (PIX *)ERROR_PTR("invalid fpix size", procName, NULL);
    }
    pixd = pixCreateTemplate(pixs);
    datad = pixGetData(pixd);
    dataf = fpixGetData(fpix);
    wpld = pixGetWpl(pixd);
    wplf = fpixGetWpl(fpix);
    if (d == 1) {
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                if (GET_DATA_BIT(lineptrs[isrc], j))
                    SET_DATA_BIT(lined, j);
            }
        }
    }
    else if (d == 8) {
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                val8 = GET_DATA_BYTE(lineptrs[isrc], j);
                SET_DATA_BYTE(lined, j, val8);
            }
        }
    }
    else {  
        lineptrs = pixGetLinePtrs(pixs, NULL);
        for (i = 0; i < h; i++) {
            lined = datad + i * wpld;
            linef = dataf + i * wplf;
            for (j = 0; j < w; j++) {
                isrc = (l_int32)(i - linef[j] + 0.5);
                if (isrc < 0) isrc = 0;
                if (isrc > h - 1) isrc = h - 1;
                lined[j] = GET_DATA_FOUR_BYTES(lineptrs[isrc], j);
            }
        }
    }
    FREE(lineptrs);
    return pixd;
}
PIX * pixApplyVerticalDisparity ( PIX * pixs , FPIX * fpix ) { l_int32 i , j , w , h , d , fw , fh , wpld , wplf , isrc , val8 ; l_uint32 * datad , * lined ; l_float32 * dataf , * linef ; void * * lineptrs ; PIX * pixd ; PROCNAME ( " " ) ; if ( ! pixs ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; if ( ! fpix ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; pixGetDimensions ( pixs , & w , & h , & d ) ; if ( d != 1 && d != 8 && d != 32 ) return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; fpixGetDimensions ( fpix , & fw , & fh ) ; if ( fw < w || fh < h ) { fprintf ( stderr , " \n " , fw , w , fh , h ) ; return ( PIX * ) ERROR_PTR ( " " , procName , NULL ) ; } pixd = pixCreateTemplate ( pixs ) ; datad = pixGetData ( pixd ) ; dataf = fpixGetData ( fpix ) ; wpld = pixGetWpl ( pixd ) ; wplf = fpixGetWpl ( fpix ) ; if ( d == 1 ) { lineptrs = pixGetLinePtrs ( pixs , NULL ) ; for ( i = 0 ; i < h ; i ++ ) { lined = datad + i * wpld ; linef = dataf + i * wplf ; for ( j = 0 ; j < w ; j ++ ) { isrc = ( l_int32 ) ( i - linef [ j ] + 0.5 ) ; if ( isrc < 0 ) isrc = 0 ; if ( isrc > h - 1 ) isrc = h - 1 ; if ( GET_DATA_BIT ( lineptrs [ isrc ] , j ) ) SET_DATA_BIT ( lined , j ) ; } } } else if ( d == 8 ) { lineptrs = pixGetLinePtrs ( pixs , NULL ) ; for ( i = 0 ; i < h ; i ++ ) { lined = datad + i * wpld ; linef = dataf + i * wplf ; for ( j = 0 ; j < w ; j ++ ) { isrc = ( l_int32 ) ( i - linef [ j ] + 0.5 ) ; if ( isrc < 0 ) isrc = 0 ; if ( isrc > h - 1 ) isrc = h - 1 ; val8 = GET_DATA_BYTE ( lineptrs [ isrc ] , j ) ; SET_DATA_BYTE ( lined , j , val8 ) ; } } } else { lineptrs = pixGetLinePtrs ( pixs , NULL ) ; for ( i = 0 ; i < h ; i ++ ) { lined = datad + i * wpld ; linef = dataf + i * wplf ; for ( j = 0 ; j < w ; j ++ ) { isrc = ( l_int32 ) ( i - linef [ j ] + 0.5 ) ; if ( isrc < 0 ) isrc = 0 ; if ( isrc > h - 1 ) isrc = h - 1 ; lined [ j ] = GET_DATA_FOUR_BYTES ( lineptrs [ isrc ] , j ) ; } } } FREE ( lineptrs ) ; return pixd ; }
pixApplyVerticalDisparity()
      Input:  pixs (1, 8 or 32 bpp)
              fpix (vertical disparity array)
      Return: pixd (modified by fpix), or null on error
pixApplyVerticalDisparity () Input : pixs ( 1 8 or 32 bpp ) fpix ( vertical disparity array ) Return : pixd ( modified by fpix ) or null on error
/* d == 32 */