src/affine.c
l_int32
linearInterpolatePixelGray(l_uint32  *datas,
                           l_int32    wpls,
                           l_int32    w,
                           l_int32    h,
                           l_float32  x,
                           l_float32  y,
                           l_int32    grayval,
                           l_int32   *pval)
{
l_int32    xpm, ypm, xp, yp, xf, yf, v00, v10, v01, v11;
l_uint32  *lines;

    PROCNAME("linearInterpolatePixelGray");

    if (!pval)
        return ERROR_INT("&val not defined", procName, 1);
    *pval = grayval;
    if (!datas)
        return ERROR_INT("datas not defined", procName, 1);

        /* Skip if off the edge */
    if (x < 0.0 || y < 0.0 || x > w - 2.0 || y > h - 2.0)
        return 0;

    xpm = (l_int32)(16.0 * x + 0.5);
    ypm = (l_int32)(16.0 * y + 0.5);
    xp = xpm >> 4;
    yp = ypm >> 4;
    xf = xpm & 0x0f;
    yf = ypm & 0x0f;

#if  DEBUG
    if (xf < 0 || yf < 0)
        fprintf(stderr, "xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
#endif  /* DEBUG */

        /* Interpolate by area weighting. */
    lines = datas + yp * wpls;
    v00 = (16 - xf) * (16 - yf) * GET_DATA_BYTE(lines, xp);
    v10 = xf * (16 - yf) * GET_DATA_BYTE(lines, xp + 1);
    v01 = (16 - xf) * yf * GET_DATA_BYTE(lines + wpls, xp);
    v11 = xf * yf * GET_DATA_BYTE(lines + wpls, xp + 1);
    *pval = (v00 + v01 + v10 + v11 + 128) / 256;
    return 0;
}
/*!
 *  linearInterpolatePixelGray()
 *
 *      Input:  datas (ptr to beginning of image data)
 *              wpls (32-bit word/line for this data array)
 *              w, h (of image)
 *              x, y (floating pt location for evaluation)
 *              grayval (color brought in from the outside when the
 *                       input x,y location is outside the image)
 *              &val (<return> interpolated gray value)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This is a standard linear interpolation function.  It is
 *          equivalent to area weighting on each component, and
 *          avoids "jaggies" when rendering sharp edges.
 */


(1) This is a standard linear interpolation function.  It is
equivalent to area weighting on each component, and
avoids "jaggies" when rendering sharp edges.
( 1 ) This is a standard linear interpolation function . It is equivalent to area weighting on each component and avoids " jaggies " when rendering sharp edges .
l_int32
linearInterpolatePixelGray(l_uint32  *datas,
                           l_int32    wpls,
                           l_int32    w,
                           l_int32    h,
                           l_float32  x,
                           l_float32  y,
                           l_int32    grayval,
                           l_int32   *pval)
{
l_int32    xpm, ypm, xp, yp, xf, yf, v00, v10, v01, v11;
l_uint32  *lines;
    PROCNAME("linearInterpolatePixelGray");
    if (!pval)
        return ERROR_INT("&val not defined", procName, 1);
    *pval = grayval;
    if (!datas)
        return ERROR_INT("datas not defined", procName, 1);
    if (x < 0.0 || y < 0.0 || x > w - 2.0 || y > h - 2.0)
        return 0;
    xpm = (l_int32)(16.0 * x + 0.5);
    ypm = (l_int32)(16.0 * y + 0.5);
    xp = xpm >> 4;
    yp = ypm >> 4;
    xf = xpm & 0x0f;
    yf = ypm & 0x0f;
#if  DEBUG
    if (xf < 0 || yf < 0)
        fprintf(stderr, "xp = %d, yp = %d, xf = %d, yf = %d\n", xp, yp, xf, yf);
#endif  
    lines = datas + yp * wpls;
    v00 = (16 - xf) * (16 - yf) * GET_DATA_BYTE(lines, xp);
    v10 = xf * (16 - yf) * GET_DATA_BYTE(lines, xp + 1);
    v01 = (16 - xf) * yf * GET_DATA_BYTE(lines + wpls, xp);
    v11 = xf * yf * GET_DATA_BYTE(lines + wpls, xp + 1);
    *pval = (v00 + v01 + v10 + v11 + 128) / 256;
    return 0;
}
l_int32 linearInterpolatePixelGray ( l_uint32 * datas , l_int32 wpls , l_int32 w , l_int32 h , l_float32 x , l_float32 y , l_int32 grayval , l_int32 * pval ) { l_int32 xpm , ypm , xp , yp , xf , yf , v00 , v10 , v01 , v11 ; l_uint32 * lines ; PROCNAME ( " " ) ; if ( ! pval ) return ERROR_INT ( " " , procName , 1 ) ; * pval = grayval ; if ( ! datas ) return ERROR_INT ( " " , procName , 1 ) ; if ( x < 0.0 || y < 0.0 || x > w - 2.0 || y > h - 2.0 ) return 0 ; xpm = ( l_int32 ) ( 16.0 * x + 0.5 ) ; ypm = ( l_int32 ) ( 16.0 * y + 0.5 ) ; xp = xpm >> 4 ; yp = ypm >> 4 ; xf = xpm & 0x0f ; yf = ypm & 0x0f ; #if DEBUG if ( xf < 0 || yf < 0 ) fprintf ( stderr , " \n " , xp , yp , xf , yf ) ; #endif lines = datas + yp * wpls ; v00 = ( 16 - xf ) * ( 16 - yf ) * GET_DATA_BYTE ( lines , xp ) ; v10 = xf * ( 16 - yf ) * GET_DATA_BYTE ( lines , xp + 1 ) ; v01 = ( 16 - xf ) * yf * GET_DATA_BYTE ( lines + wpls , xp ) ; v11 = xf * yf * GET_DATA_BYTE ( lines + wpls , xp + 1 ) ; * pval = ( v00 + v01 + v10 + v11 + 128 ) / 256 ; return 0 ; }
linearInterpolatePixelGray()
      Input:  datas (ptr to beginning of image data)
              wpls (32-bit word/line for this data array)
              w, h (of image)
              x, y (floating pt location for evaluation)
              grayval (color brought in from the outside when the
                       input x,y location is outside the image)
              &val (<return> interpolated gray value)
      Return: 0 if OK, 1 on error
linearInterpolatePixelGray () Input : datas ( ptr to beginning of image data ) wpls ( 32 - bit word / line for this data array ) w h ( of image ) x y ( floating pt location for evaluation ) grayval ( color brought in from the outside when the input x y location is outside the image ) &val ( <return > interpolated gray value ) Return : 0 if OK 1 on error
/* Skip if off the edge */ /* DEBUG */ /* Interpolate by area weighting. */