/***************************************************************
  PROPRIETARY NOTICE: The software information contained
  herein is the sole property of Eastman Kodak Company and is
  provided to Eastman Kodak Company users under license for use on
  their designated equipment only.  Reproduction of this matter in
  whole or in part is forbidden without the express written
  consent of Eastman Kodak Company.

  COPYRIGHT (c) 1991-1994 Eastman Kodak Company.
  As an unpublished work pursuant to Title 17 of the United
  States Code.  All rights reserved.
****************************************************************
*/

/*
 * This is an optimized version of fut_interp_lin2d8 (DIM==2,BITS==8,ORDER==1)
 * which avoids the per pixel function call overhead of the version which would
 * be automatically generated by fut_interp.c.  Some architectures may use an
 * equivalent assembly language version for further optimization.
 */

#include "fut.h"
#include "fut_util.h"             /* internal interface file */
#include "interp.h"           /* interpolation macros and structures */

int
	fut_interp_lin2d8 (generic_u_int8_ptr_t rp, generic_u_int8_ptr_t zp,
						generic_u_int8_ptr_t yp, int32 n, fut_itbldat_ptr_t ztbl,
						fut_itbldat_ptr_t ytbl, fut_gtbldat_ptr_t gtbl, int32 nz,
						fut_otbldat_ptr_t otbl)
{
fut_generic_ptr_t cell;					/* ^ to base of interpolation cell */
longword_t	interpz, interpy;		/* interpolants */
int32	t1, t2;							/* temporary results */
int32	int32fracz;	/* temporary fractions */
int32	sy;

	sy = GDATSIZE * nz; 			/* single stride for y dimension */
		
	while (--n >= 0) {
/* use input lookup tables to get cell coordinates and interpolants */
		interpz.HL = ztbl[*zp++];		/* z cell coordinate and interpolant */
		interpy.HL = ytbl[*yp++];		/* y cell coordinate and interpolant */

/* find base of cell in grid table, using y,z whole parts and grid table base */
		cell = (fut_generic_ptr_t)gtbl;						/* grid table base */
		cell += interpz.shortword.H << GDATSHIFT; /* calculate cell base */
		cell += interpy.shortword.H * sy;

		int32fracz = (int32)interpz.shortword.L;

/* tri-linear interpolation */
		t1 = LINEAR_INTERPOLATE (GRID_VAL (cell), GRID_VAL (cell + GDATSIZE), int32fracz);

		cell += sy;
		t2 = LINEAR_INTERPOLATE (GRID_VAL (cell), GRID_VAL (cell + GDATSIZE), int32fracz);

   	t1 = LINEAR_INTERPOLATE (t1, t2, (int32)interpy.shortword.L);

		if ( otbl != NULL ) {
			t1 = otbl[t1];				/* pass result through output table */
		}

		*rp++ = (u_int8) FUT_OTBL_NINT(t1);	/* place result in output array */
	}

	return (1);

} /* fut_interp_lin2d8 */


