src/affine.c
l_int32
linearInterpolatePixelColor(l_uint32  *datas,
                            l_int32    wpls,
                            l_int32    w,
                            l_int32    h,
                            l_float32  x,
                            l_float32  y,
                            l_uint32   colorval,
                            l_uint32  *pval)
{
l_int32    xpm, ypm, xp, yp, xf, yf;
l_int32    rval, gval, bval;
l_uint32   word00, word01, word10, word11;
l_uint32  *lines;

    PROCNAME("linearInterpolatePixelColor");

    if (!pval)
        return ERROR_INT("&val not defined", procName, 1);
    *pval = colorval;
    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 */

        /* Do area weighting (eqiv. to linear interpolation) */
    lines = datas + yp * wpls;
    word00 = *(lines + xp);
    word10 = *(lines + xp + 1);
    word01 = *(lines + wpls + xp);
    word11 = *(lines + wpls + xp + 1);
    rval = ((16 - xf) * (16 - yf) * ((word00 >> L_RED_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_RED_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_RED_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_RED_SHIFT) & 0xff) + 128) / 256;
    gval = ((16 - xf) * (16 - yf) * ((word00 >> L_GREEN_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_GREEN_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_GREEN_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_GREEN_SHIFT) & 0xff) + 128) / 256;
    bval = ((16 - xf) * (16 - yf) * ((word00 >> L_BLUE_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_BLUE_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_BLUE_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_BLUE_SHIFT) & 0xff) + 128) / 256;
    *pval = (rval << L_RED_SHIFT) | (gval << L_GREEN_SHIFT) |
          (bval << L_BLUE_SHIFT);
    return 0;
}
/*!
 *  linearInterpolatePixelColor()
 *
 *      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)
 *              colorval (color brought in from the outside when the
 *                        input x,y location is outside the image;
 *                        in 0xrrggbb00 format))
 *              &val (<return> interpolated color 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
linearInterpolatePixelColor(l_uint32  *datas,
                            l_int32    wpls,
                            l_int32    w,
                            l_int32    h,
                            l_float32  x,
                            l_float32  y,
                            l_uint32   colorval,
                            l_uint32  *pval)
{
l_int32    xpm, ypm, xp, yp, xf, yf;
l_int32    rval, gval, bval;
l_uint32   word00, word01, word10, word11;
l_uint32  *lines;
    PROCNAME("linearInterpolatePixelColor");
    if (!pval)
        return ERROR_INT("&val not defined", procName, 1);
    *pval = colorval;
    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;
    word00 = *(lines + xp);
    word10 = *(lines + xp + 1);
    word01 = *(lines + wpls + xp);
    word11 = *(lines + wpls + xp + 1);
    rval = ((16 - xf) * (16 - yf) * ((word00 >> L_RED_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_RED_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_RED_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_RED_SHIFT) & 0xff) + 128) / 256;
    gval = ((16 - xf) * (16 - yf) * ((word00 >> L_GREEN_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_GREEN_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_GREEN_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_GREEN_SHIFT) & 0xff) + 128) / 256;
    bval = ((16 - xf) * (16 - yf) * ((word00 >> L_BLUE_SHIFT) & 0xff) +
        xf * (16 - yf) * ((word10 >> L_BLUE_SHIFT) & 0xff) +
        (16 - xf) * yf * ((word01 >> L_BLUE_SHIFT) & 0xff) +
        xf * yf * ((word11 >> L_BLUE_SHIFT) & 0xff) + 128) / 256;
    *pval = (rval << L_RED_SHIFT) | (gval << L_GREEN_SHIFT) |
          (bval << L_BLUE_SHIFT);
    return 0;
}
l_int32 linearInterpolatePixelColor ( l_uint32 * datas , l_int32 wpls , l_int32 w , l_int32 h , l_float32 x , l_float32 y , l_uint32 colorval , l_uint32 * pval ) { l_int32 xpm , ypm , xp , yp , xf , yf ; l_int32 rval , gval , bval ; l_uint32 word00 , word01 , word10 , word11 ; l_uint32 * lines ; PROCNAME ( " " ) ; if ( ! pval ) return ERROR_INT ( " " , procName , 1 ) ; * pval = colorval ; 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 ; word00 = * ( lines + xp ) ; word10 = * ( lines + xp + 1 ) ; word01 = * ( lines + wpls + xp ) ; word11 = * ( lines + wpls + xp + 1 ) ; rval = ( ( 16 - xf ) * ( 16 - yf ) * ( ( word00 >> L_RED_SHIFT ) & 0xff ) + xf * ( 16 - yf ) * ( ( word10 >> L_RED_SHIFT ) & 0xff ) + ( 16 - xf ) * yf * ( ( word01 >> L_RED_SHIFT ) & 0xff ) + xf * yf * ( ( word11 >> L_RED_SHIFT ) & 0xff ) + 128 ) / 256 ; gval = ( ( 16 - xf ) * ( 16 - yf ) * ( ( word00 >> L_GREEN_SHIFT ) & 0xff ) + xf * ( 16 - yf ) * ( ( word10 >> L_GREEN_SHIFT ) & 0xff ) + ( 16 - xf ) * yf * ( ( word01 >> L_GREEN_SHIFT ) & 0xff ) + xf * yf * ( ( word11 >> L_GREEN_SHIFT ) & 0xff ) + 128 ) / 256 ; bval = ( ( 16 - xf ) * ( 16 - yf ) * ( ( word00 >> L_BLUE_SHIFT ) & 0xff ) + xf * ( 16 - yf ) * ( ( word10 >> L_BLUE_SHIFT ) & 0xff ) + ( 16 - xf ) * yf * ( ( word01 >> L_BLUE_SHIFT ) & 0xff ) + xf * yf * ( ( word11 >> L_BLUE_SHIFT ) & 0xff ) + 128 ) / 256 ; * pval = ( rval << L_RED_SHIFT ) | ( gval << L_GREEN_SHIFT ) | ( bval << L_BLUE_SHIFT ) ; return 0 ; }
linearInterpolatePixelColor()
      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)
              colorval (color brought in from the outside when the
                        input x,y location is outside the image;
                        in 0xrrggbb00 format))
              &val (<return> interpolated color value)
      Return: 0 if OK, 1 on error
linearInterpolatePixelColor () 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 ) colorval ( color brought in from the outside when the input x y location is outside the image ; in 0xrrggbb00 format )) &val ( <return > interpolated color value ) Return : 0 if OK 1 on error
/* Skip if off the edge */ /* DEBUG */ /* Do area weighting (eqiv. to linear interpolation) */